Skip to content

Commit

Permalink
Fixes for 64-bit rates
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaibrodschi committed Oct 24, 2024
1 parent acdfb02 commit 5223abf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions elements/standard/bandwidthmeter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ BandwidthMeter::configure(Vector<String> &conf, ErrorHandler *errh)
else if (ba.status == NumArg::status_unitless)
errh->warning("no units for bandwidth argument %d, assuming Bps", i+1);

unsigned max_value = 0xFFFFFFFF >> _rate.scale();
uint64_t max_value = UINT64_MAX >> _rate.scale();
for (int i = 0; i < conf.size(); i++) {
if (vals[i] > max_value)
return errh->error("rate %d too large (max %u)", i+1, max_value);
Expand All @@ -78,7 +78,7 @@ BandwidthMeter::push(int, Packet *p)
{
_rate.update(p->length());

unsigned r = _rate.scaled_average();
uint64_t r = _rate.scaled_average();
if (_nmeters < 2) {
int n = (r >= _meter1);
output(n).push(p);
Expand Down
4 changes: 2 additions & 2 deletions elements/standard/bandwidthmeter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ CLICK_DECLS

class BandwidthMeter : public Element { protected:

RateEWMA _rate;
RateEWMAX<RateEWMAXParameters<4, 10, uint64_t, int64_t>> _rate;

uint64_t _meter1;
uint64_t *_meters;
Expand All @@ -55,7 +55,7 @@ class BandwidthMeter : public Element { protected:
const char *port_count() const override { return "1/2-"; }
const char *processing() const override { return PUSH; }

unsigned scaled_rate() const { return _rate.scaled_average(); }
uint64_t scaled_rate() const { return _rate.scaled_average(); }
unsigned rate_scale() const { return _rate.scale(); }
unsigned rate_freq() const { return _rate.epoch_frequency(); }

Expand Down
2 changes: 1 addition & 1 deletion elements/standard/ratedsource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ RatedSource::configure(Vector<String> &conf, ErrorHandler *errh)
rate = bandwidth / (_datasize < 0 ? _data.length() : _datasize);
}

int burst = rate < 200 ? 2 : rate / 100;
uint64_t burst = rate < 200 ? 2 : rate / 100;
if (bandwidth > 0 && burst < 2 * datasize) {
burst = 2 * datasize;
}
Expand Down
6 changes: 3 additions & 3 deletions elements/standard/ratedunqueue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ RatedUnqueue::configure_helper(TokenBucket *tb, bool is_bandwidth, Element *elt,
bigint::limb_type res[2];
bigint::multiply(res[1], res[0], r, dur_msec);
bigint::divide(res, res, 2, 1000);
tokens = res[1] ? UINT_MAX : res[0];
tokens = res[1] ? UINT64_MAX : res[0];
}

if (is_bandwidth) {
unsigned new_tokens = tokens + tb_bandwidth_thresh;
tokens = (tokens < new_tokens ? new_tokens : UINT_MAX);
uint64_t new_tokens = tokens + tb_bandwidth_thresh;
tokens = (tokens < new_tokens ? new_tokens : UINT64_MAX);
}

tb->assign(r, tokens ? tokens : 1);
Expand Down

0 comments on commit 5223abf

Please sign in to comment.