diff mbox series

[ovs-dev,v2,16/28] dpif-netdev: Use seq-pool for mark allocation

Message ID 307451d62af9796cb963fa0d424ea31407a8927c.1618236421.git.grive@u256.net
State Changes Requested
Headers show
Series dpif-netdev: Parallel offload processing | expand

Commit Message

Gaetan Rivet April 12, 2021, 3:20 p.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 seq-pool module for faster concurrent ID allocation.

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

Comments

Maxime Coquelin April 22, 2021, 2:23 p.m. UTC | #1
On 4/12/21 5:20 PM, Gaetan Rivet wrote:
> 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 seq-pool module for faster concurrent ID allocation.
> 
> Signed-off-by: Gaetan Rivet <grive@u256.net>
> Reviewed-by: Eli Britstein <elibr@nvidia.com>
> ---
>  lib/dpif-netdev.c | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
diff mbox series

Patch

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 0b439d90b..851e33f85 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -74,6 +74,7 @@ 
 #include "pvector.h"
 #include "random.h"
 #include "seq.h"
+#include "seq-pool.h"
 #include "smap.h"
 #include "sset.h"
 #include "timeval.h"
@@ -2418,7 +2419,7 @@  struct megaflow_to_mark_data {
 struct flow_mark {
     struct cmap megaflow_to_mark;
     struct cmap mark_to_flow;
-    struct id_pool *pool;
+    struct seq_pool *pool;
 };
 
 static struct flow_mark flow_mark = {
@@ -2429,14 +2430,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 = seq_pool_create(netdev_offload_thread_nb(),
+                                         1, MAX_FLOW_MARK);
+        ovsthread_once_done(&pool_init);
     }
 
-    if (id_pool_alloc_id(flow_mark.pool, &mark)) {
+    if (seq_pool_new_id(flow_mark.pool, tid, &mark)) {
         return mark;
     }
 
@@ -2446,7 +2451,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();
+
+    seq_pool_free_id(flow_mark.pool, tid, mark);
 }
 
 /* associate megaflow with a mark, which is a 1:1 mapping */