aboutsummaryrefslogtreecommitdiffstats
path: root/vnet/vnet/devices/netmap/netmap.c
diff options
context:
space:
mode:
authorMohsin KAZMI <sykazmi@cisco.com>2016-06-16 06:58:34 +0200
committerDamjan Marion <damarion@cisco.com>2016-06-24 21:24:33 +0000
commita7575eacb922965e642e38560be3a2f34c5a6eff (patch)
tree671820782d13a546034c5722eac60f1bc75fa900 /vnet/vnet/devices/netmap/netmap.c
parentd6b3850c64fe6315a17a51ce19a5813fae58ca7a (diff)
netmap: multithreading support
This patch adds multithreading support for netmap interfaces. Change-Id: Iba94386fe309a4aac71646fe567f8dabbebd0459 Signed-off-by: Mohsin KAZMI <sykazmi@cisco.com>
Diffstat (limited to 'vnet/vnet/devices/netmap/netmap.c')
-rw-r--r--vnet/vnet/devices/netmap/netmap.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/vnet/vnet/devices/netmap/netmap.c b/vnet/vnet/devices/netmap/netmap.c
index df3b2be499e..ed90862fdf0 100644
--- a/vnet/vnet/devices/netmap/netmap.c
+++ b/vnet/vnet/devices/netmap/netmap.c
@@ -92,6 +92,7 @@ netmap_create_if(vlib_main_t * vm, u8 * if_name, u8 * hw_addr_set,
uword * p;
struct nmreq * req = 0;
netmap_mem_region_t * reg;
+ vlib_thread_main_t * tm = vlib_get_thread_main();
int fd;
p = mhash_get (&nm->if_index_by_host_if_name, if_name);
@@ -152,6 +153,13 @@ netmap_create_if(vlib_main_t * vm, u8 * if_name, u8 * hw_addr_set,
nif->host_if_name = if_name;
nif->per_interface_next_index = ~0;
+ if (tm->n_vlib_mains > 1)
+ {
+ nif->lockp = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
+ CLIB_CACHE_LINE_BYTES);
+ memset ((void *) nif->lockp, 0, CLIB_CACHE_LINE_BYTES);
+ }
+
{
unix_file_t template = {0};
template.read_function = netmap_fd_read_ready;
@@ -232,11 +240,37 @@ static clib_error_t *
netmap_init (vlib_main_t * vm)
{
netmap_main_t * nm = &netmap_main;
+ vlib_thread_main_t * tm = vlib_get_thread_main();
+ vlib_thread_registration_t * tr;
+ uword * p;
memset (nm, 0, sizeof (netmap_main_t));
+ nm->input_cpu_first_index = 0;
+ nm->input_cpu_count = 1;
+
+ /* find out which cpus will be used for input */
+ p = hash_get_mem (tm->thread_registrations_by_name, "workers");
+ tr = p ? (vlib_thread_registration_t *) p[0] : 0;
+
+ if (tr && tr->count > 0)
+ {
+ nm->input_cpu_first_index = tr->first_index;
+ nm->input_cpu_count = tr->count;
+ }
+
+ /* if worker threads are enabled, switch to polling mode */
+ if (tm->n_vlib_mains > 1)
+ foreach_vlib_main (
+ ({
+ vlib_node_set_state(this_vlib_main, netmap_input_node.index, VLIB_NODE_STATE_POLLING);
+ }));
+
mhash_init_vec_string (&nm->if_index_by_host_if_name, sizeof (uword));
+ vec_validate_aligned (nm->rx_buffers, tm->n_vlib_mains - 1,
+ CLIB_CACHE_LINE_BYTES);
+
return 0;
}