[ovs-dev] flow: Reduce metadata connection state branches in miniflow_extract
diff mbox series

Message ID 20190827182108.11517-1-malvika.gupta@arm.com
State New
Headers show
Series
  • [ovs-dev] flow: Reduce metadata connection state branches in miniflow_extract
Related show

Commit Message

Malvika Gupta Aug. 27, 2019, 6:21 p.m. UTC
This patch merges two separate if-else branches for metadata connection state
into one if-else branch to improve performance. It gives an average performance
improvement of ~3% on arm platforms and ~4.5% on x86 platforms.

Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
Reviewed-by: Yanqin Wei <yanqin.wei@arm.com>
Reviewed-by: Gavin Hu <gavin.hu@arm.com>
---
 lib/flow.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

Comments

Ben Pfaff Aug. 28, 2019, 9:48 p.m. UTC | #1
On Tue, Aug 27, 2019 at 01:21:08PM -0500, Malvika Gupta wrote:
> This patch merges two separate if-else branches for metadata connection state
> into one if-else branch to improve performance. It gives an average performance
> improvement of ~3% on arm platforms and ~4.5% on x86 platforms.
> 
> Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
> Reviewed-by: Yanqin Wei <yanqin.wei@arm.com>
> Reviewed-by: Gavin Hu <gavin.hu@arm.com>

That's an incredible impact.

Thanks, I applied this to master.

Patch
diff mbox series

diff --git a/lib/flow.c b/lib/flow.c
index 5dff6fb4f..bc9d8a1c6 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -786,20 +786,17 @@  miniflow_extract(struct dp_packet *packet, struct miniflow *dst)
         ct_nw_proto_p = miniflow_pointer(mf, ct_nw_proto);
         miniflow_push_uint8(mf, ct_nw_proto, 0);
         miniflow_push_uint16(mf, ct_zone, md->ct_zone);
-    } else if (md->recirc_id) {
-        miniflow_push_uint32(mf, recirc_id, md->recirc_id);
-        miniflow_pad_to_64(mf, recirc_id);
-    }
-
-    if (md->ct_state) {
         miniflow_push_uint32(mf, ct_mark, md->ct_mark);
         miniflow_push_be32(mf, packet_type, packet_type);
-
         if (!ovs_u128_is_zero(md->ct_label)) {
             miniflow_push_words(mf, ct_label, &md->ct_label,
                                 sizeof md->ct_label / sizeof(uint64_t));
         }
     } else {
+        if (md->recirc_id) {
+            miniflow_push_uint32(mf, recirc_id, md->recirc_id);
+            miniflow_pad_to_64(mf, recirc_id);
+        }
         miniflow_pad_from_64(mf, packet_type);
         miniflow_push_be32(mf, packet_type, packet_type);
     }