From: Ben Pfaff Date: Thu, 19 Mar 2009 18:16:08 +0000 (-0700) Subject: pinsched: Move rate-limiting sanity checks into pinsched. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=114795671ea362ea0de48a135c8fd18320fbc91b;p=openvswitch pinsched: Move rate-limiting sanity checks into pinsched. The vswitch will want to do the same sanity checks so it is better to put them in a single place. --- diff --git a/secchan/main.c b/secchan/main.c index 40f1353e..d9d44b9d 100644 --- a/secchan/main.c +++ b/secchan/main.c @@ -521,16 +521,8 @@ parse_options(int argc, char *argv[], struct ofsettings *s) } /* Rate limiting. */ - if (s->rate_limit) { - if (s->rate_limit < 100) { - VLOG_WARN("Rate limit set to unusually low value %d", - s->rate_limit); - } - if (!s->burst_limit) { - s->burst_limit = s->rate_limit / 4; - } - s->burst_limit = MAX(s->burst_limit, 1); - s->burst_limit = MIN(s->burst_limit, INT_MAX / 1000); + if (s->rate_limit && s->rate_limit < 100) { + VLOG_WARN("Rate limit set to unusually low value %d", s->rate_limit); } } diff --git a/secchan/ofproto.c b/secchan/ofproto.c index cf82953b..8a2b7741 100644 --- a/secchan/ofproto.c +++ b/secchan/ofproto.c @@ -570,7 +570,7 @@ void ofproto_set_rate_limit(struct ofproto *ofproto, int rate_limit, int burst_limit) { - if (rate_limit) { + if (rate_limit > 0) { if (!ofproto->miss_sched) { ofproto->miss_sched = pinsched_create(rate_limit, burst_limit, ofproto->switch_status); diff --git a/secchan/pinsched.c b/secchan/pinsched.c index 51e70a36..124aab42 100644 --- a/secchan/pinsched.c +++ b/secchan/pinsched.c @@ -245,8 +245,6 @@ pinsched_create(int rate_limit, int burst_limit, struct switch_status *ss) struct pinsched *ps; ps = xcalloc(1, sizeof *ps); - ps->rate_limit = rate_limit; - ps->burst_limit = burst_limit; port_array_init(&ps->queues); ps->n_queued = 0; ps->last_tx_port = PORT_ARRAY_SIZE; @@ -256,6 +254,7 @@ pinsched_create(int rate_limit, int burst_limit, struct switch_status *ss) ps->n_normal = 0; ps->n_limited = 0; ps->n_queue_dropped = 0; + pinsched_set_limits(ps, rate_limit, burst_limit); if (ss) { ps->ss_cat = switch_status_register(ss, "rate-limit", @@ -285,6 +284,15 @@ pinsched_destroy(struct pinsched *ps) void pinsched_set_limits(struct pinsched *ps, int rate_limit, int burst_limit) { + if (rate_limit <= 0) { + rate_limit = 1000; + } + if (burst_limit <= 0) { + burst_limit = rate_limit / 4; + } + burst_limit = MAX(burst_limit, 1); + burst_limit = MIN(burst_limit, INT_MAX / 1000); + ps->rate_limit = rate_limit; ps->burst_limit = burst_limit; while (ps->n_queued > burst_limit) {