diff mbox series

[ovs-dev,v5,17/27] dpif-netdev: Use id-fpool for mark allocation

Message ID 3bc979319eaccca8db3e7f8d2d486d72de72c076.1631094144.git.grive@u256.net
State Accepted
Commit 73ecf098d2d221df5b9ecbaa00480fc87053a3f4
Headers show
Series dpif-netdev: Parallel offload processing | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Gaetan Rivet Sept. 8, 2021, 9:47 a.m. UTC
Use the netdev-offload multithread API to allow multiple thread
allocating marks concurrently.

Initialize only once the pool in a multithread context by using
the ovsthread_once type.

Use the id-fpool module for faster concurrent ID allocation.

Signed-off-by: Gaetan Rivet <grive@u256.net>
Reviewed-by: Eli Britstein <elibr@nvidia.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/dpif-netdev.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index c3d211858..24ecaa0a8 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -51,6 +51,7 @@ 
 #include "fat-rwlock.h"
 #include "flow.h"
 #include "hmapx.h"
+#include "id-fpool.h"
 #include "id-pool.h"
 #include "ipf.h"
 #include "mov-avg.h"
@@ -2349,7 +2350,7 @@  struct megaflow_to_mark_data {
 struct flow_mark {
     struct cmap megaflow_to_mark;
     struct cmap mark_to_flow;
-    struct id_pool *pool;
+    struct id_fpool *pool;
 };
 
 static struct flow_mark flow_mark = {
@@ -2360,14 +2361,18 @@  static struct flow_mark flow_mark = {
 static uint32_t
 flow_mark_alloc(void)
 {
+    static struct ovsthread_once pool_init = OVSTHREAD_ONCE_INITIALIZER;
+    unsigned int tid = netdev_offload_thread_id();
     uint32_t mark;
 
-    if (!flow_mark.pool) {
+    if (ovsthread_once_start(&pool_init)) {
         /* Haven't initiated yet, do it here */
-        flow_mark.pool = id_pool_create(1, MAX_FLOW_MARK);
+        flow_mark.pool = id_fpool_create(netdev_offload_thread_nb(),
+                                         1, MAX_FLOW_MARK);
+        ovsthread_once_done(&pool_init);
     }
 
-    if (id_pool_alloc_id(flow_mark.pool, &mark)) {
+    if (id_fpool_new_id(flow_mark.pool, tid, &mark)) {
         return mark;
     }
 
@@ -2377,7 +2382,9 @@  flow_mark_alloc(void)
 static void
 flow_mark_free(uint32_t mark)
 {
-    id_pool_free_id(flow_mark.pool, mark);
+    unsigned int tid = netdev_offload_thread_id();
+
+    id_fpool_free_id(flow_mark.pool, tid, mark);
 }
 
 /* associate megaflow with a mark, which is a 1:1 mapping */