[ovs-dev] [Single DP 11/15] ofproto-dpif: Introduce subfacet_destroy_batch().

Justin Pettit jpettit at nicira.com
Thu Oct 18 19:51:56 UTC 2012


A future commit will introduce another caller that wants to destroy
batches of subfacets.  Repurpose expire_batch() to be a more generic
method for destroying batches of subfacets.

Signed-off-by: Justin Pettit <jpettit at nicira.com>
---
 ofproto/ofproto-dpif.c |   69 +++++++++++++++++++++++++-----------------------
 1 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 0c0202b..399ca75 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -368,6 +368,8 @@ struct subfacet {
     ovs_be16 initial_tci;       /* Initial VLAN TCI value. */
 };
 
+#define SUBFACET_DESTROY_MAX_BATCH 50
+
 static struct subfacet *subfacet_create(struct facet *, enum odp_key_fitness,
                                         const struct nlattr *key,
                                         size_t key_len, ovs_be16 initial_tci,
@@ -376,6 +378,8 @@ static struct subfacet *subfacet_find(struct ofproto_dpif *,
                                       const struct nlattr *key, size_t key_len);
 static void subfacet_destroy(struct subfacet *);
 static void subfacet_destroy__(struct subfacet *);
+static void subfacet_destroy_batch(struct ofproto_dpif *,
+                                   struct subfacet **, int n);
 static void subfacet_get_key(struct subfacet *, struct odputil_keybuf *,
                              struct ofpbuf *key);
 static void subfacet_reset_dp_stats(struct subfacet *,
@@ -3556,35 +3560,6 @@ subfacet_max_idle(const struct ofproto_dpif *ofproto)
     return bucket * BUCKET_WIDTH;
 }
 
-enum { EXPIRE_MAX_BATCH = 50 };
-
-static void
-expire_batch(struct ofproto_dpif *ofproto, struct subfacet **subfacets, int n)
-{
-    struct odputil_keybuf keybufs[EXPIRE_MAX_BATCH];
-    struct dpif_op ops[EXPIRE_MAX_BATCH];
-    struct dpif_op *opsp[EXPIRE_MAX_BATCH];
-    struct ofpbuf keys[EXPIRE_MAX_BATCH];
-    struct dpif_flow_stats stats[EXPIRE_MAX_BATCH];
-    int i;
-
-    for (i = 0; i < n; i++) {
-        ops[i].type = DPIF_OP_FLOW_DEL;
-        subfacet_get_key(subfacets[i], &keybufs[i], &keys[i]);
-        ops[i].u.flow_del.key = keys[i].data;
-        ops[i].u.flow_del.key_len = keys[i].size;
-        ops[i].u.flow_del.stats = &stats[i];
-        opsp[i] = &ops[i];
-    }
-
-    dpif_operate(ofproto->dpif, opsp, n);
-    for (i = 0; i < n; i++) {
-        subfacet_reset_dp_stats(subfacets[i], &stats[i]);
-        subfacets[i]->path = SF_NOT_INSTALLED;
-        subfacet_destroy(subfacets[i]);
-    }
-}
-
 static void
 expire_subfacets(struct ofproto_dpif *ofproto, int dp_max_idle)
 {
@@ -3596,7 +3571,7 @@ expire_subfacets(struct ofproto_dpif *ofproto, int dp_max_idle)
     long long int special_cutoff = time_msec() - 10000;
 
     struct subfacet *subfacet, *next_subfacet;
-    struct subfacet *batch[EXPIRE_MAX_BATCH];
+    struct subfacet *batch[SUBFACET_DESTROY_MAX_BATCH];
     int n_batch;
 
     n_batch = 0;
@@ -3610,8 +3585,8 @@ expire_subfacets(struct ofproto_dpif *ofproto, int dp_max_idle)
         if (subfacet->used < cutoff) {
             if (subfacet->path != SF_NOT_INSTALLED) {
                 batch[n_batch++] = subfacet;
-                if (n_batch >= EXPIRE_MAX_BATCH) {
-                    expire_batch(ofproto, batch, n_batch);
+                if (n_batch >= SUBFACET_DESTROY_MAX_BATCH) {
+                    subfacet_destroy_batch(ofproto, batch, n_batch);
                     n_batch = 0;
                 }
             } else {
@@ -3621,7 +3596,7 @@ expire_subfacets(struct ofproto_dpif *ofproto, int dp_max_idle)
     }
 
     if (n_batch > 0) {
-        expire_batch(ofproto, batch, n_batch);
+        subfacet_destroy_batch(ofproto, batch, n_batch);
     }
 }
 
@@ -4405,6 +4380,34 @@ subfacet_destroy(struct subfacet *subfacet)
     }
 }
 
+static void
+subfacet_destroy_batch(struct ofproto_dpif *ofproto,
+                       struct subfacet **subfacets, int n)
+{
+    struct odputil_keybuf keybufs[SUBFACET_DESTROY_MAX_BATCH];
+    struct dpif_op ops[SUBFACET_DESTROY_MAX_BATCH];
+    struct dpif_op *opsp[SUBFACET_DESTROY_MAX_BATCH];
+    struct ofpbuf keys[SUBFACET_DESTROY_MAX_BATCH];
+    struct dpif_flow_stats stats[SUBFACET_DESTROY_MAX_BATCH];
+    int i;
+
+    for (i = 0; i < n; i++) {
+        ops[i].type = DPIF_OP_FLOW_DEL;
+        subfacet_get_key(subfacets[i], &keybufs[i], &keys[i]);
+        ops[i].u.flow_del.key = keys[i].data;
+        ops[i].u.flow_del.key_len = keys[i].size;
+        ops[i].u.flow_del.stats = &stats[i];
+        opsp[i] = &ops[i];
+    }
+
+    dpif_operate(ofproto->dpif, opsp, n);
+    for (i = 0; i < n; i++) {
+        subfacet_reset_dp_stats(subfacets[i], &stats[i]);
+        subfacets[i]->path = SF_NOT_INSTALLED;
+        subfacet_destroy(subfacets[i]);
+    }
+}
+
 /* Initializes 'key' with the sequence of OVS_KEY_ATTR_* Netlink attributes
  * that can be used to refer to 'subfacet'.  The caller must provide 'keybuf'
  * for use as temporary storage. */
-- 
1.7.5.4




More information about the dev mailing list