2#ifndef CLICK_GAPRATE_HH
3#define CLICK_GAPRATE_HH
55 inline uint64_t
rate()
const;
109 enum { UGAP_SHIFT = 43 };
110 enum { MAX_RATE = 1000000ULL << UGAP_SHIFT };
122 inline void initialize_rate(uint64_t
rate);
137GapRate::initialize_rate(uint64_t r)
140 _ugap = (r == 0 ? MAX_RATE + 1 : MAX_RATE / r);
142 click_chatter(
"ugap: %u", _ugap);
153 if (_tv_sec >= 0 && r != 0) {
155 _sec_count = (
static_cast<uint64_t
>(now.
usec()) << UGAP_SHIFT) / _ugap;
186 uint64_t need = (
static_cast<uint64_t
>(now.
usec()) << UGAP_SHIFT) / _ugap;
193 _sec_count = need + ((
static_cast<uint64_t
>(now.
usec()) << UGAP_SHIFT) - (need * _ugap) > _ugap / 2);
194 }
else if (now.
sec() > _tv_sec) {
201 click_chatter(
"%p{timestamp} -> %u @ %u [%d]", &now, need, _sec_count, (
int)need >= _sec_count);
203 return ((int64_t)need >= _sec_count);
221 if (_tv_sec < 0 || _rate == 0)
223 else if (_sec_count < 0)
227 int64_t count = _sec_count;
228 if ((uint64_t) count >= _rate) {
229 sec += count / _rate;
230 count = count % _rate;
234 uint32_t usec = (count * _ugap) >> UGAP_SHIFT;
Error reporting class.
Definition error.hh:90
A helper class for implementing a uniform rate.
Definition gaprate.hh:45
void update_with(int64_t delta)
Increment the user event counter by delta.
Definition gaprate.hh:213
void reset()
Resets the true rate counter.
Definition gaprate.hh:128
Timestamp expiry() const
Returns a time when the user's rate will be behind the true rate.
Definition gaprate.hh:219
void set_rate(uint64_t r)
Set the current rate to r.
Definition gaprate.hh:147
GapRate()
Construct a GapRate object with initial rate 0.
Definition gaprate.hh:161
uint64_t rate() const
Return the current rate.
Definition gaprate.hh:176
bool need_update(const Timestamp &ts)
Returns whether the user's rate is behind the true rate.
Definition gaprate.hh:182
void update()
Increment the user event counter.
Definition gaprate.hh:207
Represents a moment or interval in time.
Definition timestamp.hh:125
static Timestamp now()
Return the current system time.
Definition timestamp.hh:958
static Timestamp make_usec(seconds_type sec, uint32_t usec)
Return a timestamp representing sec seconds plus usec microseconds.
Definition timestamp.hh:349
int32_t seconds_type
Type represents a number of seconds.
Definition timestamp.hh:128
uint32_t usec() const
Return this timestamp's subseconds component, converted to microseconds.
Definition timestamp.hh:1109
seconds_type sec() const
Return this timestamp's seconds component.
Definition timestamp.hh:1075
The Timestamp class represents a moment or interval in time.