Skip to content

Commit

Permalink
dpif-netdev: Use id-fpool for mark allocation.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Eli Britstein <[email protected]>
Reviewed-by: Maxime Coquelin <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
  • Loading branch information
Gaetan Rivet authored and igsilya committed Jan 19, 2022
1 parent 528a8ab commit 73ecf09
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/dpif-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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"
Expand Down Expand Up @@ -2385,7 +2386,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 = {
Expand All @@ -2396,14 +2397,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;
}

Expand All @@ -2413,7 +2418,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 */
Expand Down

0 comments on commit 73ecf09

Please sign in to comment.