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/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/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/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/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