[ovs-dev] [subfacet 1/4] ofproto-dpif: Simplify subfacet stat calculations.

Ethan Jackson ethan at nicira.com
Fri Jun 7 20:22:19 UTC 2013

Here's an incremental.  Also I've changed the commit message to the following:

ofproto-dpif: More responsive average subfacet statistics.

Before this patch, statistics about subfacet average life span,
and count in the datapath, were calculated over the entire lifetime
of the ofproto.  Furthermore, the subfacet lifespan was only
updated when a subfacet was removed from the datapath causing long
lived subfacets to be ignored.  It's far more useful to know these
numbers averaged over all subfacets in the recent past.  This patch
changes the code to implement an exponentially weighted moving
average updated every time statistics are pulled from the datapath.

Signed-off-by: Ethan Jackson <ethan at nicira.com>

 ofproto/ofproto-dpif.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index ee40cf3..f8c0abc 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -4318,11 +4318,12 @@ expire(struct dpif_backer *backer)
             avg_subfacet_life_span /= hmap_count(&ofproto->subfacets);
-        ofproto->avg_subfacet_life_span =
-            (ofproto->avg_subfacet_life_span + avg_subfacet_life_span) / 2;
+        ofproto->avg_subfacet_life_span += avg_subfacet_life_span;
+        ofproto->avg_subfacet_life_span /= 2;
         ofproto->avg_n_subfacet += hmap_count(&ofproto->subfacets);
         ofproto->avg_n_subfacet /= 2;
         ofproto->max_n_subfacet = MAX(ofproto->max_n_subfacet,
@@ -8298,8 +8299,8 @@ show_dp_format(const struct ofproto_dpif *ofproto, struct ds *ds)
                   "\tlookups: hit:%"PRIu64" missed:%"PRIu64"\n",
                   ofproto->n_hit, ofproto->n_missed);
-    ds_put_format(ds, "\tflows: cur: %zu, avg: %d, max: %d,"
-                  " life span: %llu(ms)\n",
+    ds_put_format(ds, "\tflows: cur: %zu, avg: %u, max: %d,"
+                  " life span: %lld(ms)\n",

More information about the dev mailing list