[ovs-dev] [PATCH V4 10/24] datapath: add likely in flow_lookup

Greg Rose gvrose8192 at gmail.com
Mon Oct 12 20:24:57 UTC 2020

From: Tonghao Zhang <xiangxia.m.yue at gmail.com>

Upstream commit:
    commit 0a3e01371db17d753dd92ec4d0fc6247412d3b01
    Author: Tonghao Zhang <xiangxia.m.yue at gmail.com>
    Date:   Fri Nov 1 22:23:51 2019 +0800

    net: openvswitch: add likely in flow_lookup

    The most case *index < ma->max, and flow-mask is not NULL.
    We add un/likely for performance.

    Signed-off-by: Tonghao Zhang <xiangxia.m.yue at gmail.com>
    Tested-by: Greg Rose <gvrose8192 at gmail.com>
    Acked-by: William Tu <u9012063 at gmail.com>
    Acked-by: Pravin B Shelar <pshelar at ovn.org>
    Signed-off-by: David S. Miller <davem at davemloft.net>

Cc: Tonghao Zhang <xiangxia.m.yue at gmail.com>
Reviewed-by: Tonghao Zhang <xiangxia.m.yue at gmail.com>
Signed-off-by: Greg Rose <gvrose8192 at gmail.com>
 datapath/flow_table.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/datapath/flow_table.c b/datapath/flow_table.c
index 7efaa8044..ca2efe94d 100644
--- a/datapath/flow_table.c
+++ b/datapath/flow_table.c
@@ -541,7 +541,7 @@ static struct sw_flow *flow_lookup(struct flow_table *tbl,
 	struct sw_flow_mask *mask;
 	int i;
-	if (*index < ma->max) {
+	if (likely(*index < ma->max)) {
 		mask = rcu_dereference_ovsl(ma->masks[*index]);
 		if (mask) {
 			flow = masked_flow_lookup(ti, key, mask, n_mask_hit);
@@ -556,7 +556,7 @@ static struct sw_flow *flow_lookup(struct flow_table *tbl,
 		mask = rcu_dereference_ovsl(ma->masks[i]);
-		if (!mask)
+		if (unlikely(!mask))
 		flow = masked_flow_lookup(ti, key, mask, n_mask_hit);

More information about the dev mailing list