Commit 23956f1d authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Use roughly throughout.

This very slightly reduces the amount of jitter in some cases.
parent 067cd537
...@@ -512,17 +512,17 @@ main(int argc, char **argv) ...@@ -512,17 +512,17 @@ main(int argc, char **argv)
kernel_routes_changed = 0; kernel_routes_changed = 0;
kernel_link_changed = 0; kernel_link_changed = 0;
kernel_addr_changed = 0; kernel_addr_changed = 0;
kernel_dump_time = now.tv_sec + 20 + random() % 20; kernel_dump_time = now.tv_sec + roughly(30);
schedule_neighbours_check(5000, 1); schedule_neighbours_check(5000, 1);
expiry_time = now.tv_sec + 20 + random() % 20; expiry_time = now.tv_sec + roughly(30);
source_expiry_time = now.tv_sec + 200 + random() % 200; source_expiry_time = now.tv_sec + roughly(300);
/* Make some noise so that others notice us */ /* Make some noise so that others notice us */
FOR_ALL_NETS(net) { FOR_ALL_NETS(net) {
if(!net->up) if(!net->up)
continue; continue;
/* Apply jitter before we send the first message. */ /* Apply jitter before we send the first message. */
usleep(5000 + random() % 10000); usleep(roughly(10000));
gettime(&now); gettime(&now);
send_hello(net); send_hello(net);
send_self_update(net, 0); send_self_update(net, 0);
...@@ -631,9 +631,9 @@ main(int argc, char **argv) ...@@ -631,9 +631,9 @@ main(int argc, char **argv)
fprintf(stderr, "Warning: couldn't check exported routes.\n"); fprintf(stderr, "Warning: couldn't check exported routes.\n");
kernel_routes_changed = kernel_addr_changed = 0; kernel_routes_changed = kernel_addr_changed = 0;
if(kernel_socket >= 0) if(kernel_socket >= 0)
kernel_dump_time = now.tv_sec + 200 + random() % 200; kernel_dump_time = now.tv_sec + roughly(300);
else else
kernel_dump_time = now.tv_sec + 20 + random() % 20; kernel_dump_time = now.tv_sec + roughly(30);
} }
if(timeval_compare(&check_neighbours_timeout, &now) < 0) { if(timeval_compare(&check_neighbours_timeout, &now) < 0) {
...@@ -647,12 +647,12 @@ main(int argc, char **argv) ...@@ -647,12 +647,12 @@ main(int argc, char **argv)
check_networks(); check_networks();
expire_routes(); expire_routes();
expire_resend(); expire_resend();
expiry_time = now.tv_sec + 20 + random() % 20; expiry_time = now.tv_sec + roughly(30);
} }
if(now.tv_sec >= source_expiry_time) { if(now.tv_sec >= source_expiry_time) {
expire_sources(); expire_sources();
source_expiry_time = now.tv_sec + 200 + random() % 200; source_expiry_time = now.tv_sec + roughly(300);
} }
FOR_ALL_NETS(net) { FOR_ALL_NETS(net) {
...@@ -699,7 +699,7 @@ main(int argc, char **argv) ...@@ -699,7 +699,7 @@ main(int argc, char **argv)
} }
debugf("Exiting...\n"); debugf("Exiting...\n");
usleep(5000 + random() % 10000); usleep(roughly(10000));
gettime(&now); gettime(&now);
/* Uninstall and retract all routes. */ /* Uninstall and retract all routes. */
...@@ -726,7 +726,7 @@ main(int argc, char **argv) ...@@ -726,7 +726,7 @@ main(int argc, char **argv)
association caches. */ association caches. */
send_hello_noupdate(net, 10); send_hello_noupdate(net, 10);
flushbuf(net); flushbuf(net);
usleep(500 + random() % 1000); usleep(roughly(1000));
gettime(&now); gettime(&now);
} }
FOR_ALL_NETS(net) { FOR_ALL_NETS(net) {
...@@ -735,7 +735,7 @@ main(int argc, char **argv) ...@@ -735,7 +735,7 @@ main(int argc, char **argv)
/* Make sure they got it. */ /* Make sure they got it. */
send_hello_noupdate(net, 1); send_hello_noupdate(net, 1);
flushbuf(net); flushbuf(net);
usleep(5000 + random() % 10000); usleep(roughly(10000));
gettime(&now); gettime(&now);
network_up(net, 0); network_up(net, 0);
} }
...@@ -808,7 +808,7 @@ schedule_neighbours_check(int msecs, int override) ...@@ -808,7 +808,7 @@ schedule_neighbours_check(int msecs, int override)
{ {
struct timeval timeout; struct timeval timeout;
timeval_plus_msec(&timeout, &now, msecs + random() % msecs); timeval_plus_msec(&timeout, &now, roughly(msecs * 3 / 2));
if(override) if(override)
check_neighbours_timeout = timeout; check_neighbours_timeout = timeout;
else else
......
...@@ -413,7 +413,7 @@ void ...@@ -413,7 +413,7 @@ void
schedule_flush_now(struct network *net) schedule_flush_now(struct network *net)
{ {
/* Almost now */ /* Almost now */
int msecs = 5 + random() % 10; int msecs = roughly(10);
if(net->flush_timeout.tv_sec != 0 && if(net->flush_timeout.tv_sec != 0 &&
timeval_minus_msec(&net->flush_timeout, &now) < msecs) timeval_minus_msec(&net->flush_timeout, &now) < msecs)
return; return;
......
...@@ -127,8 +127,8 @@ jitter(struct network *net, int urgent) ...@@ -127,8 +127,8 @@ jitter(struct network *net, int urgent)
if(urgent) if(urgent)
interval = MIN(interval, 100); interval = MIN(interval, 100);
else else
interval = MIN(interval, 2000); interval = MIN(interval, 4000);
return (interval / 2 + random() % interval) / 4; return roughly(interval) / 4;
} }
unsigned int unsigned int
...@@ -139,17 +139,14 @@ update_jitter(struct network *net, int urgent) ...@@ -139,17 +139,14 @@ update_jitter(struct network *net, int urgent)
interval = MIN(interval, 100); interval = MIN(interval, 100);
else else
interval = MIN(interval, 4000); interval = MIN(interval, 4000);
return (interval / 2 + random() % interval); return roughly(interval);
} }
void void
delay_jitter(struct timeval *time, struct timeval *timeout, int msecs) delay_jitter(struct timeval *time, struct timeval *timeout, int msecs)
{ {
int delay;
delay = msecs * 2 / 3 + random() % (msecs * 2 / 3);
*time = now; *time = now;
timeval_plus_msec(timeout, &now, delay); timeval_plus_msec(timeout, &now, roughly(msecs));
} }
static int static int
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment