diff options
author | Damjan Marion <damarion@cisco.com> | 2016-11-08 13:20:42 +0100 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2016-11-08 19:29:53 +0000 |
commit | 3a4ed3934585eb841fa36f6f062adf4dce9b4661 (patch) | |
tree | d8e2095e3990897140e31796a53c50ba4a960017 | |
parent | 9f6186e055eeb7f25a6ff43834c4bcee56699b3c (diff) |
pg: maintain per-worker bitmap of enabled streams
Change-Id: I38e476c8080faa5a8647ce6be5a71090e0aa8d5b
Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r-- | vlib/vlib/threads.h | 12 | ||||
-rw-r--r-- | vnet/vnet/pg/input.c | 12 | ||||
-rw-r--r-- | vnet/vnet/pg/pg.h | 2 | ||||
-rw-r--r-- | vnet/vnet/pg/stream.c | 9 |
4 files changed, 25 insertions, 10 deletions
diff --git a/vlib/vlib/threads.h b/vlib/vlib/threads.h index e30b9e35118..e264435c3ed 100644 --- a/vlib/vlib/threads.h +++ b/vlib/vlib/threads.h @@ -365,6 +365,18 @@ vlib_get_worker_cpu_index (u32 worker_index) return worker_index + 1; } +always_inline u32 +vlib_get_worker_index (u32 cpu_index) +{ + return cpu_index - 1; +} + +always_inline u32 +vlib_get_current_worker_index () +{ + return os_get_cpu_number () - 1; +} + always_inline vlib_main_t * vlib_get_worker_vlib_main (u32 worker_index) { diff --git a/vnet/vnet/pg/input.c b/vnet/vnet/pg/input.c index 46c8f4fa2f7..735a85e2416 100644 --- a/vnet/vnet/pg/input.c +++ b/vnet/vnet/pg/input.c @@ -1683,15 +1683,15 @@ pg_input (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) uword i; pg_main_t *pg = &pg_main; uword n_packets = 0; - u32 num_workers = vlib_num_workers (); - u32 cpu_index = os_get_cpu_number (); + u32 worker_index = 0; + + if (vlib_num_workers ()) + worker_index = vlib_get_current_worker_index (); /* *INDENT-OFF* */ - clib_bitmap_foreach (i, pg->enabled_streams, ({ + clib_bitmap_foreach (i, pg->enabled_streams[worker_index], ({ pg_stream_t *s = vec_elt_at_index (pg->streams, i); - if (num_workers == 0 || - vlib_get_worker_cpu_index (s->worker_index) == cpu_index) - n_packets += pg_input_stream (node, pg, s); + n_packets += pg_input_stream (node, pg, s); })); /* *INDENT-ON* */ diff --git a/vnet/vnet/pg/pg.h b/vnet/vnet/pg/pg.h index 1cd42229882..a4027834035 100644 --- a/vnet/vnet/pg/pg.h +++ b/vnet/vnet/pg/pg.h @@ -313,7 +313,7 @@ typedef struct pg_main_t pg_stream_t *streams; /* Bitmap indicating which streams are currently enabled. */ - uword *enabled_streams; + uword **enabled_streams; /* Hash mapping name -> stream index. */ uword *stream_index_by_name; diff --git a/vnet/vnet/pg/stream.c b/vnet/vnet/pg/stream.c index eba99419b5a..7c865e13222 100644 --- a/vnet/vnet/pg/stream.c +++ b/vnet/vnet/pg/stream.c @@ -65,8 +65,10 @@ pg_stream_enable_disable (pg_main_t * pg, pg_stream_t * s, int want_enabled) ASSERT (!pool_is_free (pg->streams, s)); - pg->enabled_streams - = clib_bitmap_set (pg->enabled_streams, s - pg->streams, want_enabled); + vec_validate (pg->enabled_streams, s->worker_index); + pg->enabled_streams[s->worker_index] = + clib_bitmap_set (pg->enabled_streams[s->worker_index], s - pg->streams, + want_enabled); if (want_enabled) { @@ -83,7 +85,8 @@ pg_stream_enable_disable (pg_main_t * pg, pg_stream_t * s, int want_enabled) vm = vlib_get_main (); vlib_node_set_state (vm, pg_input_node.index, - (clib_bitmap_is_zero (pg->enabled_streams) ? + (clib_bitmap_is_zero + (pg->enabled_streams[s->worker_index]) ? VLIB_NODE_STATE_DISABLED : VLIB_NODE_STATE_POLLING)); s->packet_accumulator = 0; |