Skip to content

Commit

Permalink
Support bandwidths which must be represented as 64-bit integers
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaibrodschi committed Aug 21, 2024
1 parent 9f0af7e commit d2f6f11
Show file tree
Hide file tree
Showing 24 changed files with 97 additions and 97 deletions.
2 changes: 1 addition & 1 deletion elements/ip/iprewriterbase.hh
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ template<class T> inline IPRewriterEntry *
IPRewriterBase::search_migrate_entry(const IPFlowID &flowid, per_thread<T> &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())
Expand Down
8 changes: 4 additions & 4 deletions elements/standard/bandwidthmeter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BandwidthMeter::configure(Vector<String> &conf, ErrorHandler *errh)
if (conf.size() == 0)
return errh->error("too few arguments to BandwidthMeter(bandwidth, ...)");

Vector<unsigned> vals(conf.size(), 0);
Vector<uint64_t> vals(conf.size(), 0);
BandwidthArg ba;
for (int i = 0; i < conf.size(); i++)
if (!ba.parse(conf[i], vals[i]))
Expand All @@ -63,8 +63,8 @@ BandwidthMeter::configure(Vector<String> &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();
}

Expand All @@ -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]) {
Expand Down
4 changes: 2 additions & 2 deletions elements/standard/bandwidthmeter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion elements/standard/linkunqueue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion elements/standard/linkunqueue.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions elements/standard/meter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
4 changes: 2 additions & 2 deletions elements/standard/ratedsource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ RatedSource::configure(Vector<String> &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;
Expand Down
4 changes: 2 additions & 2 deletions elements/standard/ratedunqueue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ RatedUnqueue::configure(Vector<String> &conf, ErrorHandler *errh)
int
RatedUnqueue::configure_helper(TokenBucket *tb, bool is_bandwidth, Element *elt, Vector<String> &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";

Expand Down
10 changes: 5 additions & 5 deletions elements/standard/ratedunqueue.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion elements/standard/shaper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Shaper::Shaper()
int
Shaper::configure(Vector<String> &conf, ErrorHandler *errh)
{
uint32_t rate;
uint64_t rate;
Args args(conf, this, errh);
if (is_bandwidth())
args.read_mp("RATE", BandwidthArg(), rate);
Expand Down
46 changes: 23 additions & 23 deletions elements/test/biginttest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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];
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions elements/test/confparsetest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions elements/userlevel/jiffieclock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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) {
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion include/click/args.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion include/click/bigint.hh
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class Bigint { public:
};

/** @brief Typical Bigint usage with uint32_t limb_type. */
typedef Bigint<uint32_t> bigint;
typedef Bigint<uint64_t> bigint;

CLICK_ENDDECLS
#endif
2 changes: 1 addition & 1 deletion include/click/confparse.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/click/ewma.hh
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ class RateEWMAXParameters : public FixedEWMAXParameters<STABILITY, SCALE, T, U>
/** @brief A RateEWMAX with stability shift 4 (alpha 1/16), scaling factor 10
* (10 bits of fraction), one rate, and underlying type <code>unsigned</code>
* that measures epochs in jiffies. */
typedef RateEWMAX<RateEWMAXParameters<4, 10> > RateEWMA;
typedef RateEWMAX<RateEWMAXParameters<4, 10, uint64_t, int64_t> > RateEWMA;


template <typename P>
Expand Down
Loading

0 comments on commit d2f6f11

Please sign in to comment.