[ovs-dev] [PATCH 10/11] ofproto-dpif: Avoid extra copy of struct flow in facet_create().

Jarno Rajahalme jarno.rajahalme at nsn.com
Fri May 31 11:35:20 UTC 2013


Signed-off-by: Jarno Rajahalme <jarno.rajahalme at nsn.com>
---
 ofproto/ofproto-dpif.c |   21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 9676a9a..7c4f0e9 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -486,7 +486,7 @@ struct facet {
     long long int learn_rl;      /* Rate limiter for facet_learn(). */
 };
 
-static struct facet *facet_create(const struct flow_miss *, uint32_t hash);
+static struct facet *facet_create(struct flow_miss *, uint32_t hash);
 static void facet_remove(struct facet *);
 static void facet_free(struct facet *);
 
@@ -3741,14 +3741,14 @@ handle_flow_miss_with_facet(struct flow_miss *miss, struct facet *facet,
     struct subfacet *subfacet;
     struct ofpbuf *packet;
 
+    want_path = facet->xout.slow ? SF_SLOW_PATH : SF_FAST_PATH;
     subfacet = subfacet_create(facet, miss, now);
-    want_path = subfacet->facet->xout.slow ? SF_SLOW_PATH : SF_FAST_PATH;
 
     LIST_FOR_EACH (packet, list_node, &miss->packets) {
         struct flow_miss_op *op = &ops[*n_ops];
         struct dpif_flow_stats stats;
 
-        handle_flow_miss_common(facet->rule, packet, &miss->flow);
+        handle_flow_miss_common(facet->rule, packet, &facet->flow);
 
         if (want_path != SF_FAST_PATH) {
             struct xlate_in xin;
@@ -4634,12 +4634,11 @@ rule_expire(struct rule_dpif *rule)
  * The facet will initially have no subfacets.  The caller should create (at
  * least) one subfacet with subfacet_create(). */
 static struct facet *
-facet_create(const struct flow_miss *miss, uint32_t hash)
+facet_create(struct flow_miss *miss, uint32_t hash)
 {
     struct ofproto_dpif *ofproto = miss->ofproto;
     struct xlate_in xin;
     struct facet *facet;
-    struct flow xflow = miss->flow;
 
     facet = xzalloc(sizeof *facet);
     facet->used = time_msec();
@@ -4657,8 +4656,8 @@ facet_create(const struct flow_miss *miss, uint32_t hash)
     xlate_in_init(&xin, ofproto, &facet->flow, &facet->initial_vals,
                   facet->rule, 0, NULL);
     xin.may_learn = true;
-    /* Note: Could use miss->flow */
-    xlate_actions(&xin, &xflow, &facet->xout);
+    /* miss->flow is not needed after this, as we have a copy in facet->flow */
+    xlate_actions(&xin, &miss->flow, &facet->xout);
     facet->nf_flow.output_iface = facet->xout.nf_output_iface;
 
     return facet;
@@ -5586,13 +5585,12 @@ rule_dpif_execute(struct rule_dpif *rule, const struct flow *flow,
     struct dpif_flow_stats stats;
     struct xlate_out xout;
     struct xlate_in xin;
-    struct flow xflow;
+    struct flow xflow = *flow;
 
     dpif_flow_stats_extract(flow, packet, time_msec(), &stats);
     rule_credit_stats(rule, &stats);
 
     initial_vals.vlan_tci = flow->vlan_tci;
-    xflow = *flow;
     xlate_in_init(&xin, ofproto, flow, &initial_vals, rule, stats.tcp_flags,
                   packet);
     xin.resubmit_stats = &stats;
@@ -5655,6 +5653,7 @@ send_packet(const struct ofport_dpif *ofport, struct ofpbuf *packet)
     xin.ofpacts_len = sizeof output;
     xin.ofpacts = &output.ofpact;
     xin.resubmit_stats = &stats;
+    /* flow is not needed after this, so we can xlate on it. */
     xlate_actions(&xin, &flow, &xout);
 
     error = dpif_execute(ofproto->backer->dpif,
@@ -7746,7 +7745,7 @@ packet_out(struct ofproto *ofproto_, struct ofpbuf *packet,
     struct xlate_out xout;
     struct xlate_in xin;
     struct ofpbuf key;
-    struct flow xflow;
+    struct flow xflow = *flow;
 
     ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
     odp_flow_key_from_flow(&key, flow,
@@ -7755,7 +7754,7 @@ packet_out(struct ofproto *ofproto_, struct ofpbuf *packet,
     dpif_flow_stats_extract(flow, packet, time_msec(), &stats);
 
     initial_vals.vlan_tci = flow->vlan_tci;
-    xflow = *flow;
+
     xlate_in_init(&xin, ofproto, flow, &initial_vals, NULL, stats.tcp_flags,
                   packet);
     xin.resubmit_stats = &stats;
-- 
1.7.10.4




More information about the dev mailing list