From d2f6f114d1416044cc3ab1c124f66d7c0ee7f2ec Mon Sep 17 00:00:00 2001 From: Mihai Brodschi Date: Wed, 21 Aug 2024 18:07:27 +0300 Subject: [PATCH] Support bandwidths which must be represented as 64-bit integers --- elements/ip/iprewriterbase.hh | 2 +- elements/standard/bandwidthmeter.cc | 8 ++--- elements/standard/bandwidthmeter.hh | 4 +-- elements/standard/linkunqueue.cc | 2 +- elements/standard/linkunqueue.hh | 2 +- elements/standard/meter.cc | 4 +-- elements/standard/ratedsource.cc | 4 +-- elements/standard/ratedunqueue.cc | 4 +-- elements/standard/ratedunqueue.hh | 10 +++---- elements/standard/shaper.cc | 2 +- elements/test/biginttest.cc | 46 ++++++++++++++--------------- elements/test/confparsetest.cc | 8 ++--- elements/userlevel/jiffieclock.cc | 8 ++--- include/click/args.hh | 2 +- include/click/bigint.hh | 2 +- include/click/confparse.hh | 2 +- include/click/ewma.hh | 2 +- include/click/gaprate.hh | 46 ++++++++++++++--------------- include/click/glue.hh | 4 +-- include/click/tokenbucket.hh | 10 +++---- lib/args.cc | 12 ++++---- lib/confparse.cc | 6 ++-- lib/gaprate.cc | 2 +- lib/glue.cc | 2 +- 24 files changed, 97 insertions(+), 97 deletions(-) diff --git a/elements/ip/iprewriterbase.hh b/elements/ip/iprewriterbase.hh index 187a78ea78..27befb27be 100644 --- a/elements/ip/iprewriterbase.hh +++ b/elements/ip/iprewriterbase.hh @@ -428,7 +428,7 @@ template inline IPRewriterEntry * IPRewriterBase::search_migrate_entry(const IPFlowID &flowid, per_thread &vstate) { //If the flow does not exist, it may be in other thread's stack if there was a migration - if (vstate->rebalance > 0 && click_jiffies() - vstate->rebalance < THREAD_MIGRATION_TIMEOUT * CLICK_HZ ) { + if (vstate->rebalance > 0 && click_jiffies() - vstate->rebalance < (uint64_t) THREAD_MIGRATION_TIMEOUT * CLICK_HZ ) { //Search in other thread's stacks for the flow for (int i = 0; i < vstate.weight(); i++) { if (vstate.get_mapping(i) == click_current_cpu_id()) diff --git a/elements/standard/bandwidthmeter.cc b/elements/standard/bandwidthmeter.cc index 32b2f4b45e..262a04db12 100644 --- a/elements/standard/bandwidthmeter.cc +++ b/elements/standard/bandwidthmeter.cc @@ -42,7 +42,7 @@ BandwidthMeter::configure(Vector &conf, ErrorHandler *errh) if (conf.size() == 0) return errh->error("too few arguments to BandwidthMeter(bandwidth, ...)"); - Vector vals(conf.size(), 0); + Vector vals(conf.size(), 0); BandwidthArg ba; for (int i = 0; i < conf.size(); i++) if (!ba.parse(conf[i], vals[i])) @@ -63,8 +63,8 @@ BandwidthMeter::configure(Vector &conf, ErrorHandler *errh) _meter1 = vals[0]; _nmeters = 1; } else { - _meters = new unsigned[vals.size()]; - memcpy(_meters, &vals[0], vals.size() * sizeof(int)); + _meters = new uint64_t[vals.size()]; + memcpy(_meters, &vals[0], vals.size() * sizeof(uint64_t)); _nmeters = vals.size(); } @@ -83,7 +83,7 @@ BandwidthMeter::push(int, Packet *p) int n = (r >= _meter1); output(n).push(p); } else { - unsigned *meters = _meters; + uint64_t *meters = _meters; int nmeters = _nmeters; for (int i = 0; i < nmeters; i++) if (r < meters[i]) { diff --git a/elements/standard/bandwidthmeter.hh b/elements/standard/bandwidthmeter.hh index d2ac963fa7..2b3fabbf44 100644 --- a/elements/standard/bandwidthmeter.hh +++ b/elements/standard/bandwidthmeter.hh @@ -39,8 +39,8 @@ class BandwidthMeter : public Element { protected: RateEWMA _rate; - unsigned _meter1; - unsigned *_meters; + uint64_t _meter1; + uint64_t *_meters; int _nmeters; static String meters_read_handler(Element *, void *) CLICK_COLD; diff --git a/elements/standard/linkunqueue.cc b/elements/standard/linkunqueue.cc index 1d41cae4e4..587307b56f 100644 --- a/elements/standard/linkunqueue.cc +++ b/elements/standard/linkunqueue.cc @@ -215,7 +215,7 @@ LinkUnqueue::write_handler(const String &s, Element *e, void *thunk, ErrorHandle break; } case H_BANDWIDTH: { - uint32_t bw; + uint64_t bw; if (!cp_bandwidth(s, &bw)) { return errh->error("invalid bandwidth"); } else if (bw < 100) { diff --git a/elements/standard/linkunqueue.hh b/elements/standard/linkunqueue.hh index df4d34b28d..ded66b6801 100644 --- a/elements/standard/linkunqueue.hh +++ b/elements/standard/linkunqueue.hh @@ -79,7 +79,7 @@ class LinkUnqueue : public Element, public Storage { public: Timestamp _latency; // enum { S_TASK, S_TIMER, S_ASLEEP } _state; bool _back_to_back; - uint32_t _bandwidth; + uint64_t _bandwidth; Task _task; Timer _timer; NotifierSignal _signal; diff --git a/elements/standard/meter.cc b/elements/standard/meter.cc index 8c117fca96..81d0c65c63 100644 --- a/elements/standard/meter.cc +++ b/elements/standard/meter.cc @@ -29,12 +29,12 @@ Meter::push(int, Packet *p) { _rate.update(1); // packets, not bytes - unsigned r = _rate.scaled_average(); + uint64_t r = _rate.scaled_average(); if (_nmeters < 2) { int n = (r >= _meter1); output(n).push(p); } else { - unsigned *meters = _meters; + uint64_t *meters = _meters; int nmeters = _nmeters; for (int i = 0; i < nmeters; i++) if (r < meters[i]) { diff --git a/elements/standard/ratedsource.cc b/elements/standard/ratedsource.cc index e3e1e0d879..c780b2765c 100644 --- a/elements/standard/ratedsource.cc +++ b/elements/standard/ratedsource.cc @@ -49,8 +49,8 @@ RatedSource::configure(Vector &conf, ErrorHandler *errh) String data = "Random bullshit in a packet, at least 64 bytes long. Well, now it is."; - unsigned rate = 10; - unsigned bandwidth = 0; + uint64_t rate = 10; + uint64_t bandwidth = 0; int limit = -1; int datasize = -1; bool active = true, stop = false; diff --git a/elements/standard/ratedunqueue.cc b/elements/standard/ratedunqueue.cc index 59b8556d35..da8b7a3102 100644 --- a/elements/standard/ratedunqueue.cc +++ b/elements/standard/ratedunqueue.cc @@ -48,9 +48,9 @@ RatedUnqueue::configure(Vector &conf, ErrorHandler *errh) int RatedUnqueue::configure_helper(TokenBucket *tb, bool is_bandwidth, Element *elt, Vector &conf, ErrorHandler *errh) { - unsigned r; + uint64_t r; unsigned dur_msec = 20; - unsigned tokens; + uint64_t tokens; bool dur_specified, tokens_specified; const char *burst_size = is_bandwidth ? "BURST_BYTES" : "BURST_SIZE"; diff --git a/elements/standard/ratedunqueue.hh b/elements/standard/ratedunqueue.hh index c824b62b3e..3555e70c59 100644 --- a/elements/standard/ratedunqueue.hh +++ b/elements/standard/ratedunqueue.hh @@ -69,11 +69,11 @@ class RatedUnqueue : public BatchElement { public: Task _task; Timer _timer; NotifierSignal _signal; - uint32_t _runs; - uint32_t _packets; - uint32_t _pushes; - uint32_t _failed_pulls; - uint32_t _empty_runs; + uint64_t _runs; + uint64_t _packets; + uint64_t _pushes; + uint64_t _failed_pulls; + uint64_t _empty_runs; uint32_t _burst; enum { h_calls, h_rate }; diff --git a/elements/standard/shaper.cc b/elements/standard/shaper.cc index 9a7ce81c5e..74cae64fce 100644 --- a/elements/standard/shaper.cc +++ b/elements/standard/shaper.cc @@ -32,7 +32,7 @@ Shaper::Shaper() int Shaper::configure(Vector &conf, ErrorHandler *errh) { - uint32_t rate; + uint64_t rate; Args args(conf, this, errh); if (is_bandwidth()) args.read_mp("RATE", BandwidthArg(), rate); diff --git a/elements/test/biginttest.cc b/elements/test/biginttest.cc index 1c734c3b3c..c8f6478379 100644 --- a/elements/test/biginttest.cc +++ b/elements/test/biginttest.cc @@ -36,8 +36,8 @@ BigintTest::BigintTest() #define CHECK(x, a, b) if (!(x)) return errh->error("%s:%d: test `%s' failed [%llu, %u]", __FILE__, __LINE__, #x, a, b); #define CHECK0(x) if (!(x)) return errh->error("%s:%d: test `%s' failed", __FILE__, __LINE__, #x); -static bool test_multiply(uint32_t a, uint32_t b, ErrorHandler *errh) { - uint32_t x[2]; +static bool test_multiply(uint64_t a, uint64_t b, ErrorHandler *errh) { + uint64_t x[2]; bigint::multiply(x[1], x[0], a, b); uint64_t c = (((uint64_t) x[1]) << 32) | x[0]; if (c != (uint64_t) a * b) { @@ -47,11 +47,11 @@ static bool test_multiply(uint32_t a, uint32_t b, ErrorHandler *errh) { return true; } -static bool test_mul(uint64_t a, uint32_t b, ErrorHandler *errh) { - uint32_t ax[2]; +static bool test_mul(uint64_t a, uint64_t b, ErrorHandler *errh) { + uint64_t ax[2]; ax[0] = a; ax[1] = a >> 32; - uint32_t cx[2]; + uint64_t cx[2]; cx[0] = cx[1] = 0; bigint::multiply_add(cx, ax, 2, b); uint64_t c = (((uint64_t) cx[1]) << 32) | cx[0]; @@ -62,11 +62,11 @@ static bool test_mul(uint64_t a, uint32_t b, ErrorHandler *errh) { return true; } -static bool test_div(uint64_t a, uint32_t b, ErrorHandler *errh) { - uint32_t ax[4]; +static bool test_div(uint64_t a, uint64_t b, ErrorHandler *errh) { + uint64_t ax[4]; ax[0] = a; ax[1] = a >> 32; - uint32_t r = bigint::divide(ax+2, ax, 2, b); + uint64_t r = bigint::divide(ax+2, ax, 2, b); uint64_t c = ((uint64_t) ax[3] << 32) | ax[2]; if (c != a / b) { errh->error("%llu / %u == %llu, not %llu", a, b, a * b, c); @@ -79,22 +79,22 @@ static bool test_div(uint64_t a, uint32_t b, ErrorHandler *errh) { return true; } -static bool test_inverse(uint32_t a, ErrorHandler *errh) { - assert(a & (1 << 31)); - uint32_t a_inverse = bigint::inverse(a); +static bool test_inverse(uint64_t a, ErrorHandler *errh) { + assert(a & (1 << 63)); + uint64_t a_inverse = bigint::inverse(a); // "Inverse is floor((b * (b - a) - 1) / a), where b = 2^32." uint64_t b = (uint64_t) 1 << 32; uint64_t want_inverse = (b * (b - a) - 1) / a; assert(want_inverse < b); if (a_inverse != want_inverse) { - errh->error("inverse(%u) == %u, not %u", a, (uint32_t) want_inverse, a_inverse); + errh->error("inverse(%u) == %u, not %u", a, (uint64_t) want_inverse, a_inverse); return false; } return true; } static bool test_add(uint64_t a, uint64_t b, ErrorHandler *errh) { - uint32_t ax[6]; + uint64_t ax[6]; ax[2] = a; ax[3] = a >> 32; ax[4] = b; @@ -112,35 +112,35 @@ int BigintTest::initialize(ErrorHandler *errh) { for (int i = 0; i < 3000; i++) { - uint32_t a = click_random() | (click_random() << 31); - uint32_t b = click_random() | (click_random() << 31); + uint64_t a = click_random() | (click_random() << 63); + uint64_t b = click_random() | (click_random() << 63); CHECK(test_multiply(a, b, errh), a, b); CHECK(test_mul(a, b, errh), a, b); } for (int i = 0; i < 8000; i++) { - uint32_t a = click_random(); + uint64_t a = click_random(); CHECK0(test_inverse(a | 0x80000000, errh)); } CHECK0(test_inverse(0x80000000, errh)); for (int i = 0; i < 8000; i++) { - uint64_t a = click_random() | ((uint64_t) click_random() << 31) | ((uint64_t) click_random() << 62); - uint64_t b = click_random() | ((uint64_t) click_random() << 31) | ((uint64_t) click_random() << 62); + uint64_t a = click_random() | ((uint64_t) click_random() << 63); + uint64_t b = click_random() | ((uint64_t) click_random() << 63); CHECK0(test_add(a, b, errh)); } CHECK0(test_div(12884758640815563913ULL, 2506284098U, errh)); for (int i = 0; i < 3000; i++) { - uint64_t a = click_random() | ((uint64_t) click_random() << 31) | ((uint64_t) click_random() << 62); - uint32_t b = click_random(); + uint64_t a = click_random() | ((uint64_t) click_random() << 63); + uint64_t b = click_random(); CHECK(test_div(a, b | 0x80000000, errh), a, b | 0x80000000); } for (int i = 0; i < 3000; i++) { - uint64_t a = click_random() | ((uint64_t) click_random() << 31) | ((uint64_t) click_random() << 62); - uint32_t b = click_random(); + uint64_t a = click_random() | ((uint64_t) click_random() << 63); + uint64_t b = click_random(); CHECK(test_div(a, b & ~0x80000000, errh), a, b & ~0x80000000); CHECK(test_div(a, b | 0x80000000, errh), a, b | 0x80000000); } - uint32_t x[3] = { 3481, 592182, 3024921038U }; + uint64_t x[3] = { 3481, 592182, 3024921038U }; CHECK0(bigint::unparse_clear(x, 3) == "55799944231168388787108580761"); x[0] = 10; diff --git a/elements/test/confparsetest.cc b/elements/test/confparsetest.cc index cdd2384782..58749204fe 100644 --- a/elements/test/confparsetest.cc +++ b/elements/test/confparsetest.cc @@ -236,10 +236,10 @@ ConfParseTest::initialize(ErrorHandler *errh) #endif BandwidthArg bwarg; - CHECK(bwarg.parse("8", u32) == true && bwarg.status == NumArg::status_unitless && u32 == 8); - CHECK(bwarg.parse("8 baud", u32) == true && bwarg.status == NumArg::status_ok && u32 == 1); - CHECK(bwarg.parse("8Kbps", u32) == true && bwarg.status == NumArg::status_ok && u32 == 1000); - CHECK(bwarg.parse("8KBps", u32) == true && bwarg.status == NumArg::status_ok && u32 == 8000); + CHECK(bwarg.parse("8", u64) == true && bwarg.status == NumArg::status_unitless && u64 == 8); + CHECK(bwarg.parse("8 baud", u64) == true && bwarg.status == NumArg::status_ok && u64 == 1); + CHECK(bwarg.parse("8Kbps", u64) == true && bwarg.status == NumArg::status_ok && u64 == 1000); + CHECK(bwarg.parse("8KBps", u64) == true && bwarg.status == NumArg::status_ok && u64 == 8000); { IPAddress a, m; diff --git a/elements/userlevel/jiffieclock.cc b/elements/userlevel/jiffieclock.cc index 8b12bff502..e085907f1d 100644 --- a/elements/userlevel/jiffieclock.cc +++ b/elements/userlevel/jiffieclock.cc @@ -61,13 +61,13 @@ JiffieClock::initialize(ErrorHandler*) { void JiffieClock::run_timer(Timer* t) { Timestamp current_time = Timestamp::now_steady(); - int64_t delta = (current_time - last_jiffies_update).msec() / (1000 / CLICK_HZ); + int64_t delta = (current_time - last_jiffies_update).usec() / (1000000 / CLICK_HZ); if (delta > 0) { if (unlikely(delta > _minprecision)) {//Accept a little jump from time to time, but not double jump //We try all the click threads int nt = (t->home_thread_id() + 1) % master()->nthreads(); if (nt == home_thread_id()) { - click_chatter("Click tasks are too heavy and the jiffie accumulator cannot run at least once every %dmsec, the user jiffie clock is deactivated.",_minprecision); + click_chatter("Click tasks are too heavy and the jiffie accumulator cannot run at least once every %d jiffies, the user jiffie clock is deactivated.",_minprecision); click_jiffies_fct = &click_timestamp_jiffies; return; } @@ -78,7 +78,7 @@ void JiffieClock::run_timer(Timer* t) { jiffies += delta; last_jiffies_update = current_time; } - t->schedule_at_steady(last_jiffies_update + Timestamp::make_msec(1000 / CLICK_HZ)); + t->schedule_at_steady(last_jiffies_update + Timestamp::make_usec(1000000 / CLICK_HZ)); } click_jiffies_t JiffieClock::read_jiffies(void* data) { @@ -94,7 +94,7 @@ bool JiffieClock::run_task(Task*) { //TODO : this should be rcu protected click_jiffies_fct_data = this; click_jiffies_fct = &read_jiffies; - _timer.schedule_after_msec(1000 / CLICK_HZ); + _timer.schedule_after(Timestamp::make_usec(1000000 / CLICK_HZ)); return true; } diff --git a/include/click/args.hh b/include/click/args.hh index 7f42bc5901..4fb644e2bf 100644 --- a/include/click/args.hh +++ b/include/click/args.hh @@ -1376,7 +1376,7 @@ class UnitArg { public: Handles suffixes such as "Gbps", "k", etc. */ class BandwidthArg : public NumArg { public: - bool parse(const String &str, uint32_t &result, const ArgContext & = blank_args); + bool parse(const String &str, uint64_t &result, const ArgContext & = blank_args); static String unparse(uint32_t x); int status; }; diff --git a/include/click/bigint.hh b/include/click/bigint.hh index de00f75e10..0ff2287115 100644 --- a/include/click/bigint.hh +++ b/include/click/bigint.hh @@ -385,7 +385,7 @@ class Bigint { public: }; /** @brief Typical Bigint usage with uint32_t limb_type. */ -typedef Bigint bigint; +typedef Bigint bigint; CLICK_ENDDECLS #endif diff --git a/include/click/confparse.hh b/include/click/confparse.hh index 08571c44fb..ef6f823760 100644 --- a/include/click/confparse.hh +++ b/include/click/confparse.hh @@ -172,7 +172,7 @@ bool cp_seconds(const String& str, double* result); bool cp_time(const String &str, Timestamp *result, bool allow_negative = false); bool cp_time(const String& str, struct timeval* result); -bool cp_bandwidth(const String& str, uint32_t* result); +bool cp_bandwidth(const String& str, uint64_t* result); // network addresses class IPAddressList; diff --git a/include/click/ewma.hh b/include/click/ewma.hh index e9dada4253..eb4b79fa74 100644 --- a/include/click/ewma.hh +++ b/include/click/ewma.hh @@ -492,7 +492,7 @@ class RateEWMAXParameters : public FixedEWMAXParameters /** @brief A RateEWMAX with stability shift 4 (alpha 1/16), scaling factor 10 * (10 bits of fraction), one rate, and underlying type unsigned * that measures epochs in jiffies. */ -typedef RateEWMAX > RateEWMA; +typedef RateEWMAX > RateEWMA; template diff --git a/include/click/gaprate.hh b/include/click/gaprate.hh index 69a2fb7bf3..e976228d45 100644 --- a/include/click/gaprate.hh +++ b/include/click/gaprate.hh @@ -49,17 +49,17 @@ class GapRate { public: /** @brief Construct a GapRate object with initial rate @a r. * @param r initial rate (events per second) */ - inline GapRate(unsigned r); + inline GapRate(uint64_t r); /** @brief Return the current rate. */ - inline unsigned rate() const; + inline uint64_t rate() const; /** @brief Set the current rate to @a r. * @param r desired rate (events per second) * * Rates larger than MAX_RATE are reduced to MAX_RATE. Also performs the * equivalent of a reset() to flush old state. */ - inline void set_rate(unsigned r); + inline void set_rate(uint64_t r); /** @brief Set the current rate to @a r. * @param r desired rate (events per second) @@ -67,7 +67,7 @@ class GapRate { public: * * Acts like set_rate(@a r), except that an warning is reported to @a errh * if @a r is larger than MAX_RATE. */ - void set_rate(unsigned r, ErrorHandler *errh); + void set_rate(uint64_t r, ErrorHandler *errh); /** @brief Returns whether the user's rate is behind the true rate. @@ -97,7 +97,7 @@ class GapRate { public: * * @note This may be faster than calling update() @a delta times. * Furthermore, @a delta can be negative. */ - inline void update_with(int delta); + inline void update_with(int64_t delta); /** @brief Resets the true rate counter. * @@ -106,20 +106,20 @@ class GapRate { public: inline void reset(); - enum { UGAP_SHIFT = 12 }; - enum { MAX_RATE = 1000000U << UGAP_SHIFT }; + enum { UGAP_SHIFT = 43 }; + enum { MAX_RATE = 1000000UL << UGAP_SHIFT }; private: - unsigned _ugap; // (1000000 << UGAP_SHIFT) / _rate - int _sec_count; // number of updates this second so far + uint64_t _ugap; // (1000000 << UGAP_SHIFT) / _rate + int64_t _sec_count; // number of updates this second so far Timestamp::seconds_type _tv_sec; // current second - unsigned _rate; // desired rate + uint64_t _rate; // desired rate #if DEBUG_GAPRATE Timestamp _last; #endif - inline void initialize_rate(unsigned rate); + inline void initialize_rate(uint64_t rate); }; @@ -134,7 +134,7 @@ GapRate::reset() } inline void -GapRate::initialize_rate(unsigned r) +GapRate::initialize_rate(uint64_t r) { _rate = r; _ugap = (r == 0 ? MAX_RATE + 1 : MAX_RATE / r); @@ -144,7 +144,7 @@ GapRate::initialize_rate(unsigned r) } inline void -GapRate::set_rate(unsigned r) +GapRate::set_rate(uint64_t r) { if (r > MAX_RATE) r = MAX_RATE; @@ -152,7 +152,7 @@ GapRate::set_rate(unsigned r) initialize_rate(r); if (_tv_sec >= 0 && r != 0) { Timestamp now = Timestamp::now(); - _sec_count = (now.usec() << UGAP_SHIFT) / _ugap; + _sec_count = (static_cast(now.usec()) << UGAP_SHIFT) / _ugap; } } } @@ -165,14 +165,14 @@ GapRate::GapRate() } inline -GapRate::GapRate(unsigned r) +GapRate::GapRate(uint64_t r) : _rate(0) { initialize_rate(r); reset(); } -inline unsigned +inline uint64_t GapRate::rate() const { return _rate; @@ -182,15 +182,15 @@ inline bool GapRate::need_update(const Timestamp &now) { // this is an approximation of: - // unsigned need = (unsigned) ((now.usec() / 1000000.0) * _rate) - unsigned need = (now.usec() << UGAP_SHIFT) / _ugap; + // uint64_t need = (uint64_t) ((now.usec() / 1000000.0) * _rate) + uint64_t need = (static_cast(now.usec()) << UGAP_SHIFT) / _ugap; if (_tv_sec < 0) { // 27.Feb.2005: often OK to send a packet after reset unless rate is // 0 -- requested by Bart Braem // check include/click/gaprate.hh (1.2) _tv_sec = now.sec(); - _sec_count = need + ((now.usec() << UGAP_SHIFT) - (need * _ugap) > _ugap / 2); + _sec_count = need + ((static_cast(now.usec()) << UGAP_SHIFT) - (need * _ugap) > _ugap / 2); } else if (now.sec() > _tv_sec) { _tv_sec = now.sec(); if (_sec_count > 0) @@ -200,7 +200,7 @@ GapRate::need_update(const Timestamp &now) #if DEBUG_GAPRATE click_chatter("%p{timestamp} -> %u @ %u [%d]", &now, need, _sec_count, (int)need >= _sec_count); #endif - return ((int)need >= _sec_count); + return ((int64_t)need >= _sec_count); } inline void @@ -210,7 +210,7 @@ GapRate::update() } inline void -GapRate::update_with(int delta) +GapRate::update_with(int64_t delta) { _sec_count += delta; } @@ -224,8 +224,8 @@ GapRate::expiry() const return Timestamp(_tv_sec, 0); else { Timestamp::seconds_type sec = _tv_sec; - int count = _sec_count; - if ((unsigned) count >= _rate) { + int64_t count = _sec_count; + if ((uint64_t) count >= _rate) { sec += count / _rate; count = count % _rate; } diff --git a/include/click/glue.hh b/include/click/glue.hh index eec46e2630..14b532d5df 100644 --- a/include/click/glue.hh +++ b/include/click/glue.hh @@ -528,10 +528,10 @@ typedef click_jiffies_t (*click_jiffies_fct_t)(void*); extern click_jiffies_fct_t click_jiffies_fct; extern void* click_jiffies_fct_data; # define click_jiffies() (click_jiffies_fct(click_jiffies_fct_data)) -# define CLICK_HZ 1000 +# define CLICK_HZ 1000000 # else # define click_jiffies() (click_timestamp_jiffies(0)) -# define CLICK_HZ 1000 +# define CLICK_HZ 1000000 # endif # define HAS_LONG_CLICK_JIFFIES_T 1 # define click_jiffies_less(a, b) ((click_jiffies_difference_t) ((a) - (b)) < 0) diff --git a/include/click/tokenbucket.hh b/include/click/tokenbucket.hh index 5966e9bbf7..d86b936a55 100644 --- a/include/click/tokenbucket.hh +++ b/include/click/tokenbucket.hh @@ -214,7 +214,7 @@ void TokenRateX

::assign(token_type rate, token_type capacity) token_type frequency = P::frequency(); if (rate != 0) { // constrain capacity so _tokens_per_tick fits in 1 limb - unsigned min_capacity = (rate - 1) / frequency + 1; + unsigned long long min_capacity = (rate - 1) / frequency + 1; if (capacity < min_capacity) capacity = min_capacity; } @@ -1009,9 +1009,9 @@ inline typename TokenBucketX

::ticks_type TokenBucketX

::epochs_until_contai * @brief Jiffy-based token bucket rate * * Equivalent to - * @link TokenRateX TokenRateX >@endlink. + * @link TokenRateX TokenRateX >@endlink. * @sa TokenRateX, TokenBucketJiffyParameters */ -typedef TokenRateX > TokenRate; +typedef TokenRateX > TokenRate; /** @class TokenCounter include/click/tokenbucket.hh * @brief Jiffy-based token counter @@ -1025,9 +1025,9 @@ typedef TokenCounterX TokenCounter; * @brief Jiffy-based token bucket rate limiter * * Equivalent to - * @link TokenBucketX TokenBucketX >@endlink. + * @link TokenBucketX TokenBucketX >@endlink. * @sa TokenBucketX, TokenBucketJiffyParameters */ -typedef TokenBucketX > TokenBucket; +typedef TokenBucketX > TokenBucket; CLICK_ENDDECLS #endif diff --git a/lib/args.cc b/lib/args.cc index ecc367f360..475761bb9f 100644 --- a/lib/args.cc +++ b/lib/args.cc @@ -1220,7 +1220,7 @@ static const char byte_bandwidth_units[] = "\ static const char byte_bandwidth_prefixes[] = "\ k\103K\103M\106G\111"; -static uint32_t +static uint64_t multiply_factor(uint32_t ix, uint32_t fx, uint32_t factor, int &status) { if (factor == 1) { @@ -1233,14 +1233,14 @@ multiply_factor(uint32_t ix, uint32_t fx, uint32_t factor, int &status) if (int32_t(flow) < 0) ++ftoint; int_multiply(ix, factor, ilow, ihigh); - if (ihigh != 0 || ilow + ftoint < ftoint) - status = NumArg::status_range; - return ilow + ftoint; + /* if (ihigh != 0 || ilow + ftoint < ftoint) + status = NumArg::status_range; */ + return ((uint64_t) ihigh << 32) + ilow + ftoint; } } bool -BandwidthArg::parse(const String &str, uint32_t &result, const ArgContext &args) +BandwidthArg::parse(const String &str, uint64_t &result, const ArgContext &args) { int power, factor; const char *unit_end = UnitArg(byte_bandwidth_units, byte_bandwidth_prefixes).parse(str.begin(), str.end(), power, factor); @@ -1258,7 +1258,7 @@ BandwidthArg::parse(const String &str, uint32_t &result, const ArgContext &args) ix = multiply_factor(ix, fx, factor, status); if (status == status_range) { args.error("out of range"); - result = 0xFFFFFFFFU; + result = UINT64_MAX; return false; } else { if (unit_end == str.end() && ix) diff --git a/lib/confparse.cc b/lib/confparse.cc index f79f957d49..15be6967ea 100644 --- a/lib/confparse.cc +++ b/lib/confparse.cc @@ -1589,10 +1589,10 @@ bool cp_time(const String &str, timeval *result) * otherwise, cp_errno is set to CPE_FORMAT (unparsable) or CPE_OK (if all was * well). */ -bool cp_bandwidth(const String &str, uint32_t *result) +bool cp_bandwidth(const String &str, uint64_t *result) { BandwidthArg ba; - uint32_t x; + uint64_t x; if (!ba.parse(str, x)) { cp_errno = CPE_FORMAT; return false; @@ -2592,7 +2592,7 @@ default_parsefunc(cp_value *v, const String &arg, case cpiBandwidth: { BandwidthArg ba; - if (!ba.parse(arg, v->v.u32)) + if (!ba.parse(arg, v->v.u64)) goto type_mismatch; else if (ba.status == NumArg::status_range) { String m = cp_unparse_bandwidth(v->v.u32); diff --git a/lib/gaprate.cc b/lib/gaprate.cc index c8af8f3fed..c845437e9e 100644 --- a/lib/gaprate.cc +++ b/lib/gaprate.cc @@ -24,7 +24,7 @@ CLICK_DECLS void -GapRate::set_rate(unsigned r, ErrorHandler *errh) +GapRate::set_rate(uint64_t r, ErrorHandler *errh) { if (r > GapRate::MAX_RATE && errh) errh->error("rate too large; lowered to %u", GapRate::MAX_RATE); diff --git a/lib/glue.cc b/lib/glue.cc index 071e24816f..07a0748bbe 100644 --- a/lib/glue.cc +++ b/lib/glue.cc @@ -716,7 +716,7 @@ click_gettimeofday(timeval *tvp) click_jiffies_t click_timestamp_jiffies(void*) { - return Timestamp::now_steady().msecval() / (1000 / CLICK_HZ); + return Timestamp::now_steady().usecval() / (1000000 / CLICK_HZ); } #if HAVE_USER_TIMING