2012-08-07 12:07:12 +00:00
|
|
|
// (c) 2012 Thomas Schoebel-Theuer / 1&1 Internet AG
|
|
|
|
#ifndef MARS_LIB_LIMITER_H
|
|
|
|
#define MARS_LIB_LIMITER_H
|
|
|
|
|
2012-09-24 09:17:00 +00:00
|
|
|
#include "brick.h"
|
|
|
|
|
2012-08-07 12:07:12 +00:00
|
|
|
#include <linux/utsname.h>
|
|
|
|
|
|
|
|
#define LIMITER_TIME_RESOLUTION NSEC_PER_SEC
|
|
|
|
|
|
|
|
struct mars_limiter {
|
2012-09-24 09:49:29 +00:00
|
|
|
/* hierarchy tree */
|
|
|
|
struct mars_limiter *lim_father;
|
2012-08-07 12:07:12 +00:00
|
|
|
/* tunables */
|
|
|
|
int lim_max_rate;
|
2012-09-24 09:49:29 +00:00
|
|
|
/* readable */
|
|
|
|
int lim_rate;
|
|
|
|
unsigned long long lim_stamp;
|
2012-08-07 12:07:12 +00:00
|
|
|
/* internal */
|
|
|
|
int lim_accu;
|
|
|
|
};
|
|
|
|
|
2012-09-24 09:17:00 +00:00
|
|
|
extern int mars_limit(struct mars_limiter *lim, int amount);
|
2012-08-07 12:07:12 +00:00
|
|
|
|
|
|
|
extern inline
|
|
|
|
void mars_limit_sleep(struct mars_limiter *lim, int amount)
|
|
|
|
{
|
|
|
|
int sleep = mars_limit(lim, amount);
|
|
|
|
if (sleep > 0) {
|
|
|
|
if (sleep > 1000)
|
|
|
|
sleep = 1000;
|
2012-09-17 10:11:25 +00:00
|
|
|
brick_msleep(sleep);
|
2012-08-07 12:07:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|