Revision 574b2324 lib/birdlib.h

View differences:

lib/birdlib.h
69 69
/* Microsecond time */
70 70

  
71 71
typedef s64 btime;
72
typedef s64 bird_clock_t;
72
//typedef s64 bird_clock_t;
73 73

  
74 74
#define S_	* (btime) 1000000
75 75
#define MS_	* (btime) 1000
......
85 85
#define NS	/1000
86 86
#endif
87 87

  
88
#define TIME_INFINITY ((s64) 0x7fffffffffffffff)
89

  
88 90

  
89 91
/* Rate limiting */
90 92

  
91 93
struct tbf {
92
  bird_clock_t timestamp;		/* Last update */
93
  u16 count;				/* Available tokens */
94
  btime timestamp;			/* Last update */
95
  u64 count;				/* Available micro-tokens */
94 96
  u16 burst;				/* Max number of tokens */
95
  u16 rate;				/* Rate of replenishment */
96
  u16 mark;				/* Whether last op was limited */
97
  u16 rate;				/* Rate of replenishment (tokens / sec) */
98
  u32 drop;				/* Number of failed request since last successful */
97 99
};
98 100

  
99 101
/* Default TBF values for rate limiting log messages */
100 102
#define TBF_DEFAULT_LOG_LIMITS { .rate = 1, .burst = 5 }
101 103

  
102
void tbf_update(struct tbf *f);
103

  
104
static inline int
105
tbf_limit(struct tbf *f)
106
{
107
  tbf_update(f);
108

  
109
  if (!f->count)
110
  {
111
    f->mark = 1;
112
    return 1;
113
  }
114

  
115
  f->count--;
116
  f->mark = 0;
117
  return 0;
118
}
104
int tbf_limit(struct tbf *f);
119 105

  
120 106

  
121 107
/* Logging and dying */

Also available in: Unified diff