[ovs-dev] [PATCH] ofproto: Simplify bucket finding in facet_max_idle()

Ben Pfaff blp at nicira.com
Thu Jun 30 16:36:57 UTC 2011


On Thu, Jun 30, 2011 at 08:34:15PM +0900, Simon Horman wrote:
> The existing dual-loop setup is unnecessary
> as the outer loop only skips to the first non-zero value
> and then exits once the inner loop completes.
> Zero values in the inner loop have no affect on its logic.
> 
> Signed-off-by: Simon Horman <horms at verge.net.au>
> 
> ---
> v2 Initialise bucket
> 
> Compile tested only

Fair enough.

I touched it up to suit my notion of style and pushed it as follows.

Thank you!

--8<--------------------------cut here-------------------------->8--

From: Simon Horman <horms at verge.net.au>
Date: Thu, 30 Jun 2011 20:34:15 +0900
Subject: [PATCH] ofproto: Simplify bucket finding in facet_max_idle()

The existing dual-loop setup is unnecessary
as the outer loop only skips to the first non-zero value
and then exits once the inner loop completes.
Zero values in the inner loop have no affect on its logic.

Signed-off-by: Simon Horman <horms at verge.net.au>
[pushed declaration of subtotal out to function scope]
Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 ofproto/ofproto-dpif.c |   15 +++++----------
 1 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index c062ec3..c3ef8f7 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -1863,8 +1863,8 @@ facet_max_idle(const struct ofproto_dpif *ofproto)
     enum { BUCKET_WIDTH = ROUND_UP(100, TIME_UPDATE_INTERVAL) };
     enum { N_BUCKETS = 5000 / BUCKET_WIDTH };
     int buckets[N_BUCKETS] = { 0 };
+    int total, subtotal, bucket;
     struct facet *facet;
-    int total, bucket;
     long long int now;
     int i;
 
@@ -1884,15 +1884,10 @@ facet_max_idle(const struct ofproto_dpif *ofproto)
     }
 
     /* Find the first bucket whose flows should be expired. */
-    for (bucket = 0; bucket < N_BUCKETS; bucket++) {
-        if (buckets[bucket]) {
-            int subtotal = 0;
-            do {
-                subtotal += buckets[bucket++];
-            } while (bucket < N_BUCKETS && subtotal < MAX(1000, total / 100));
-            break;
-        }
-    }
+    subtotal = bucket = 0;
+    do {
+        subtotal += buckets[bucket++];
+    } while (bucket < N_BUCKETS && subtotal < MAX(1000, total / 100));
 
     if (VLOG_IS_DBG_ENABLED()) {
         struct ds s;
-- 
1.7.4.4




More information about the dev mailing list