ofproto-dpif: Avoid redundant facet_find() in facet_lookup_valid().
authorEthan Jackson <ethan@nicira.com>
Tue, 28 May 2013 20:29:50 +0000 (13:29 -0700)
committerEthan Jackson <ethan@nicira.com>
Wed, 29 May 2013 20:15:15 +0000 (13:15 -0700)
Suggested-by: Ben Pfaff <blp@nicira.com>
Signed-off-by: Ethan Jackson <ethan@nicira.com>
ofproto/ofproto-dpif.c

index ae59eda..01eeed9 100644 (file)
@@ -515,7 +515,7 @@ static struct facet *facet_find(struct ofproto_dpif *,
                                 const struct flow *, uint32_t hash);
 static struct facet *facet_lookup_valid(struct ofproto_dpif *,
                                         const struct flow *, uint32_t hash);
-static void facet_revalidate(struct facet *);
+static bool facet_revalidate(struct facet *);
 static bool facet_check_consistency(struct facet *);
 
 static void facet_flush_stats(struct facet *);
@@ -4894,10 +4894,8 @@ facet_lookup_valid(struct ofproto_dpif *ofproto, const struct flow *flow,
     if (facet
         && (ofproto->backer->need_revalidate
             || tag_set_intersects(&ofproto->backer->revalidate_set,
-                                  facet->tags))) {
-        facet_revalidate(facet);
-
-        /* facet_revalidate() may have destroyed 'facet'. */
+                                  facet->tags))
+        && !facet_revalidate(facet)) {
         facet = facet_find(ofproto, flow, hash);
     }
 
@@ -5069,8 +5067,10 @@ facet_check_consistency(struct facet *facet)
  *     where it is and recompiles its actions anyway.
  *
  *   - If any of 'facet''s subfacets correspond to a new flow according to
- *     ofproto_receive(), 'facet' is removed. */
-static void
+ *     ofproto_receive(), 'facet' is removed.
+ *
+ *   Returns true if 'facet' is still valid.  False if 'facet' was removed. */
+static bool
 facet_revalidate(struct facet *facet)
 {
     struct ofproto_dpif *ofproto = ofproto_dpif_cast(facet->rule->up.ofproto);
@@ -5105,7 +5105,7 @@ facet_revalidate(struct facet *facet)
             || recv_ofproto != ofproto
             || memcmp(&recv_flow, &facet->flow, sizeof recv_flow)) {
             facet_remove(facet);
-            return;
+            return false;
         }
     }
 
@@ -5185,6 +5185,8 @@ facet_revalidate(struct facet *facet)
         facet->used = new_rule->up.created;
         facet->prev_used = facet->used;
     }
+
+    return true;
 }
 
 /* Updates 'facet''s used time.  Caller is responsible for calling