From 3b145dd7c001eb22f520b5ffd4179aaec59ebffe Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 13 Aug 2012 09:30:26 -0700 Subject: [PATCH] ofproto-dpif: Avoid searching all subfacets when creating first in a facet. When we create the first subfacet within a facet, we know that there cannot be an existing subfacet with the same key, so we can skip the search through the ofproto's table of subfacets. This is a small optimization, but it should not affect the flow setup rate in most benchmarks, because in the stressful situations that benchmarks create, OVS does not set up flows. Signed-off-by: Ben Pfaff --- ofproto/ofproto-dpif.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index cf34e92d..6da74c48 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -4255,20 +4255,24 @@ subfacet_create(struct facet *facet, enum odp_key_fitness key_fitness, uint32_t key_hash = odp_flow_key_hash(key, key_len); struct subfacet *subfacet; - subfacet = subfacet_find__(ofproto, key, key_len, key_hash, &facet->flow); - if (subfacet) { - if (subfacet->facet == facet) { - return subfacet; + if (list_is_empty(&facet->subfacets)) { + subfacet = &facet->one_subfacet; + } else { + subfacet = subfacet_find__(ofproto, key, key_len, key_hash, + &facet->flow); + if (subfacet) { + if (subfacet->facet == facet) { + return subfacet; + } + + /* This shouldn't happen. */ + VLOG_ERR_RL(&rl, "subfacet with wrong facet"); + subfacet_destroy(subfacet); } - /* This shouldn't happen. */ - VLOG_ERR_RL(&rl, "subfacet with wrong facet"); - subfacet_destroy(subfacet); + subfacet = xmalloc(sizeof *subfacet); } - subfacet = (list_is_empty(&facet->subfacets) - ? &facet->one_subfacet - : xmalloc(sizeof *subfacet)); hmap_insert(&ofproto->subfacets, &subfacet->hmap_node, key_hash); list_push_back(&facet->subfacets, &subfacet->list_node); subfacet->facet = facet; -- 2.30.2