diff options
author | Florin Coras <fcoras@cisco.com> | 2018-01-10 08:17:03 -0800 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2018-01-11 22:06:14 +0000 |
commit | af0ff5af0cd471033169e63c6111d23cd801928c (patch) | |
tree | 26abdbe9637ec38416ea819bc8d0ad1e0a19dfe1 | |
parent | ee7e1f50726490990b593b850857b3877c9a687f (diff) |
api: fix handlers that explicitly depend on svm queue
Fixes the remainig apis that explicitly check svm queue length.
Change-Id: I6055c7c50050affee3098e162e15fb12c205e5db
Signed-off-by: Florin Coras <fcoras@cisco.com>
-rw-r--r-- | src/vlibmemory/api.h | 9 | ||||
-rw-r--r-- | src/vlibmemory/memory_shared.c | 6 | ||||
-rw-r--r-- | src/vlibmemory/memory_shared.h | 1 | ||||
-rw-r--r-- | src/vnet/ip/ip_api.c | 52 | ||||
-rw-r--r-- | src/vnet/l2/l2_fib.c | 16 | ||||
-rw-r--r-- | src/vnet/mfib/mfib_signal.c | 4 | ||||
-rw-r--r-- | src/vnet/mfib/mfib_signal.h | 6 | ||||
-rw-r--r-- | src/vpp/stats/stats.c | 96 |
8 files changed, 102 insertions, 88 deletions
diff --git a/src/vlibmemory/api.h b/src/vlibmemory/api.h index 4f869a64be3..e86b88cdf9e 100644 --- a/src/vlibmemory/api.h +++ b/src/vlibmemory/api.h @@ -43,6 +43,15 @@ vl_api_send_msg (vl_api_registration_t * rp, u8 * elem) } } +always_inline int +vl_api_can_send_msg (vl_api_registration_t * rp) +{ + if (PREDICT_FALSE (rp->registration_type > REGISTRATION_TYPE_SHMEM)) + return 1; + else + return vl_mem_api_can_send (rp->vl_input_queue); +} + always_inline vl_api_registration_t * vl_api_client_index_to_registration (u32 index) { diff --git a/src/vlibmemory/memory_shared.c b/src/vlibmemory/memory_shared.c index 19285df9efe..c9ace1b141d 100644 --- a/src/vlibmemory/memory_shared.c +++ b/src/vlibmemory/memory_shared.c @@ -681,6 +681,12 @@ vl_msg_api_send_shmem (svm_queue_t * q, u8 * elem) (void) svm_queue_add (q, elem, 0 /* nowait */ ); } +int +vl_mem_api_can_send (svm_queue_t * q) +{ + return (q->cursize < q->maxsize); +} + void vl_msg_api_send_shmem_nolock (svm_queue_t * q, u8 * elem) { diff --git a/src/vlibmemory/memory_shared.h b/src/vlibmemory/memory_shared.h index f60224a1815..8a7667c14d3 100644 --- a/src/vlibmemory/memory_shared.h +++ b/src/vlibmemory/memory_shared.h @@ -115,6 +115,7 @@ void vl_unmap_shmem (void); void vl_register_mapped_shmem_region (svm_region_t * rp); void vl_msg_api_send_shmem (svm_queue_t * q, u8 * elem); void vl_msg_api_send_shmem_nolock (svm_queue_t * q, u8 * elem); +int vl_mem_api_can_send (svm_queue_t * q); void vl_set_memory_region_name (const char *name); void vl_set_memory_root_path (const char *root_path); void vl_set_memory_uid (int uid); diff --git a/src/vnet/ip/ip_api.c b/src/vnet/ip/ip_api.c index 2ea1e411764..f4db43c9df6 100644 --- a/src/vnet/ip/ip_api.c +++ b/src/vnet/ip/ip_api.c @@ -1824,7 +1824,7 @@ static void } void -vl_mfib_signal_send_one (svm_queue_t * q, +vl_mfib_signal_send_one (vl_api_registration_t * reg, u32 context, const mfib_signal_t * mfs) { vl_api_mfib_signal_details_t *mp; @@ -1873,21 +1873,19 @@ vl_mfib_signal_send_one (svm_queue_t * q, mp->ip_packet_len = 0; } - vl_msg_api_send_shmem (q, (u8 *) & mp); + vl_api_send_msg (reg, (u8 *) mp); } static void vl_api_mfib_signal_dump_t_handler (vl_api_mfib_signal_dump_t * mp) { - svm_queue_t *q; + vl_api_registration_t *reg; - q = vl_api_client_index_to_input_queue (mp->client_index); - if (q == 0) - { - return; - } + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; - while (q->cursize < q->maxsize && mfib_signal_send_one (q, mp->context)) + while (vl_api_can_send_msg (reg) && mfib_signal_send_one (reg, mp->context)) ; } @@ -2107,7 +2105,7 @@ handle_ip4_arp_event (u32 pool_index) vlib_main_t *vm = vam->vlib_main; vl_api_ip4_arp_event_t *event; vl_api_ip4_arp_event_t *mp; - svm_queue_t *q; + vl_api_registration_t *reg; /* Client can cancel, die, etc. */ if (pool_is_free_index (vam->arp_events, pool_index)) @@ -2115,8 +2113,8 @@ handle_ip4_arp_event (u32 pool_index) event = pool_elt_at_index (vam->arp_events, pool_index); - q = vl_api_client_index_to_input_queue (event->client_index); - if (!q) + reg = vl_api_client_index_to_registration (event->client_index); + if (!reg) { (void) vnet_add_del_ip4_arp_change_event (vnm, arp_change_delete_callback, @@ -2126,11 +2124,11 @@ handle_ip4_arp_event (u32 pool_index) return; } - if (q->cursize < q->maxsize) + if (vl_api_can_send_msg (reg)) { mp = vl_msg_api_alloc (sizeof (*mp)); clib_memcpy (mp, event, sizeof (*mp)); - vl_msg_api_send_shmem (q, (u8 *) & mp); + vl_api_send_msg (reg, (u8 *) mp); } else { @@ -2156,7 +2154,7 @@ handle_ip6_nd_event (u32 pool_index) vlib_main_t *vm = vam->vlib_main; vl_api_ip6_nd_event_t *event; vl_api_ip6_nd_event_t *mp; - svm_queue_t *q; + vl_api_registration_t *reg; /* Client can cancel, die, etc. */ if (pool_is_free_index (vam->nd_events, pool_index)) @@ -2164,8 +2162,8 @@ handle_ip6_nd_event (u32 pool_index) event = pool_elt_at_index (vam->nd_events, pool_index); - q = vl_api_client_index_to_input_queue (event->client_index); - if (!q) + reg = vl_api_client_index_to_registration (event->client_index); + if (!reg) { (void) vnet_add_del_ip6_nd_change_event (vnm, nd_change_delete_callback, @@ -2175,11 +2173,11 @@ handle_ip6_nd_event (u32 pool_index) return; } - if (q->cursize < q->maxsize) + if (vl_api_can_send_msg (reg)) { mp = vl_msg_api_alloc (sizeof (*mp)); clib_memcpy (mp, event, sizeof (*mp)); - vl_msg_api_send_shmem (q, (u8 *) & mp); + vl_api_send_msg (reg, (u8 *) mp); } else { @@ -2331,9 +2329,9 @@ wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) /* *INDENT-OFF* */ pool_foreach(reg, vpe_api_main.wc_ip4_arp_events_registrations, ({ - svm_queue_t *q; - q = vl_api_client_index_to_input_queue (reg->client_index); - if (q && q->cursize < q->maxsize) + vl_api_registration_t *vl_reg; + vl_reg = vl_api_client_index_to_registration (reg->client_index); + if (reg && vl_api_can_send_msg (vl_reg)) { vl_api_ip4_arp_event_t * event = vl_msg_api_alloc (sizeof *event); memset (event, 0, sizeof *event); @@ -2344,7 +2342,7 @@ wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) event->address = arp_events[i].ip4; event->sw_if_index = htonl(arp_events[i].sw_if_index); memcpy(event->new_mac, arp_events[i].mac, sizeof event->new_mac); - vl_msg_api_send_shmem (q, (u8 *) &event); + vl_api_send_msg (vl_reg, (u8 *) event); } })); /* *INDENT-ON* */ @@ -2370,9 +2368,9 @@ wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) /* *INDENT-OFF* */ pool_foreach(reg, vpe_api_main.wc_ip6_nd_events_registrations, ({ - svm_queue_t *q; - q = vl_api_client_index_to_input_queue (reg->client_index); - if (q && q->cursize < q->maxsize) + vl_api_registration_t *vl_reg; + vl_reg = vl_api_client_index_to_registration (reg->client_index); + if (vl_reg && vl_api_can_send_msg (vl_reg)) { vl_api_ip6_nd_event_t * event = vl_msg_api_alloc (sizeof *event); memset (event, 0, sizeof *event); @@ -2383,7 +2381,7 @@ wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) memcpy(event->address, nd_events[i].ip6.as_u8, sizeof event->address); event->sw_if_index = htonl(nd_events[i].sw_if_index); memcpy(event->new_mac, nd_events[i].mac, sizeof event->new_mac); - vl_msg_api_send_shmem (q, (u8 *) &event); + vl_api_send_msg (vl_reg, (u8 *) event); } })); /* *INDENT-ON* */ diff --git a/src/vnet/l2/l2_fib.c b/src/vnet/l2/l2_fib.c index 66bb8e3f3c7..55cffc8047c 100644 --- a/src/vnet/l2/l2_fib.c +++ b/src/vnet/l2/l2_fib.c @@ -962,12 +962,12 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only) u32 client = lm->client_pid; u32 cl_idx = lm->client_index; vl_api_l2_macs_event_t *mp = 0; - svm_queue_t *q = 0; + vl_api_registration_t *reg = 0; if (client) { mp = allocate_mac_evt_buf (client, cl_idx); - q = vl_api_client_index_to_input_queue (lm->client_index); + reg = vl_api_client_index_to_registration (lm->client_index); } for (i = 0; i < h->nbuckets; i++) @@ -1016,15 +1016,15 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only) if (PREDICT_FALSE (evt_idx >= fm->max_macs_in_event)) { /* event message full, send it and start a new one */ - if (q && (q->cursize < q->maxsize)) + if (reg && vl_api_can_send_msg (reg)) { mp->n_macs = htonl (evt_idx); - vl_msg_api_send_shmem (q, (u8 *) & mp); + vl_api_send_msg (reg, (u8 *) mp); mp = allocate_mac_evt_buf (client, cl_idx); } else { - if (q) + if (reg) clib_warning ("MAC event to pid %d queue stuffed!" " %d MAC entries lost", client, evt_idx); @@ -1101,14 +1101,14 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only) /* send any outstanding mac event message else free message buffer */ if (evt_idx) { - if (q && (q->cursize < q->maxsize)) + if (reg && vl_api_can_send_msg (reg)) { mp->n_macs = htonl (evt_idx); - vl_msg_api_send_shmem (q, (u8 *) & mp); + vl_api_send_msg (reg, (u8 *) mp); } else { - if (q) + if (reg) clib_warning ("MAC event to pid %d queue stuffed!" " %d MAC entries lost", client, evt_idx); vl_msg_api_free (mp); diff --git a/src/vnet/mfib/mfib_signal.c b/src/vnet/mfib/mfib_signal.c index 38e4bbabb3c..ce9a664c548 100644 --- a/src/vnet/mfib/mfib_signal.c +++ b/src/vnet/mfib/mfib_signal.c @@ -91,7 +91,7 @@ mfib_signal_lock_release (void) } int -mfib_signal_send_one (struct _svm_queue *q, +mfib_signal_send_one (struct vl_api_registration_ *reg, u32 context) { u32 li, si; @@ -121,7 +121,7 @@ mfib_signal_send_one (struct _svm_queue *q, ~MFIB_ITF_FLAG_SIGNAL_PRESENT); - vl_mfib_signal_send_one(q, context, mfs); + vl_mfib_signal_send_one(reg, context, mfs); /* * with the lock held, return the resoruces of the signals posted diff --git a/src/vnet/mfib/mfib_signal.h b/src/vnet/mfib/mfib_signal.h index 4dd60a6dace..f6609b3d8c1 100644 --- a/src/vnet/mfib/mfib_signal.h +++ b/src/vnet/mfib/mfib_signal.h @@ -47,12 +47,12 @@ extern void mfib_signal_remove_itf(const mfib_itf_t *mfi); extern void mfib_signal_module_init(void); -struct _svm_queue; +struct vl_api_registration_; -extern void vl_mfib_signal_send_one(struct _svm_queue *q, +extern void vl_mfib_signal_send_one(struct vl_api_registration_ *q, u32 context, const mfib_signal_t *mfs); -extern int mfib_signal_send_one(struct _svm_queue *q, +extern int mfib_signal_send_one(struct vl_api_registration_ *reg, u32 context); #endif diff --git a/src/vpp/stats/stats.c b/src/vpp/stats/stats.c index 4ac96dfa7e3..fe9ff1c5e1a 100644 --- a/src/vpp/stats/stats.c +++ b/src/vpp/stats/stats.c @@ -578,7 +578,7 @@ static void { vpe_client_registration_t *clients, client; stats_main_t *sm = &stats_main; - svm_queue_t *q, *q_prev = NULL; + vl_api_registration_t *reg, *reg_prev = NULL; vl_api_vnet_interface_combined_counters_t *mp_copy = NULL; u32 mp_size; int i; @@ -592,26 +592,26 @@ static void for (i = 0; i < vec_len (clients); i++) { client = clients[i]; - q = vl_api_client_index_to_input_queue (client.client_index); - if (q) + reg = vl_api_client_index_to_registration (client.client_index); + if (reg) { - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { mp_copy = vl_msg_api_alloc_as_if_client (mp_size); clib_memcpy (mp_copy, mp, mp_size); - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); mp = mp_copy; } - q_prev = q; + reg_prev = reg; } } #if STATS_DEBUG > 0 fformat (stdout, "%U\n", format_vnet_combined_counters, mp); #endif - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); } else { @@ -2142,7 +2142,7 @@ static void { vpe_client_registration_t *clients, client; stats_main_t *sm = &stats_main; - svm_queue_t *q, *q_prev = NULL; + vl_api_registration_t *reg, *reg_prev = NULL; vl_api_vnet_interface_simple_counters_t *mp_copy = NULL; u32 mp_size; int i; @@ -2156,17 +2156,17 @@ static void for (i = 0; i < vec_len (clients); i++) { client = clients[i]; - q = vl_api_client_index_to_input_queue (client.client_index); - if (q) + reg = vl_api_client_index_to_registration (client.client_index); + if (reg) { - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { mp_copy = vl_msg_api_alloc_as_if_client (mp_size); clib_memcpy (mp_copy, mp, mp_size); - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); mp = mp_copy; } - q_prev = q; + reg_prev = reg; } else { @@ -2181,9 +2181,9 @@ static void fformat (stdout, "%U\n", format_vnet_simple_counters, mp); #endif - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); } else { @@ -2195,7 +2195,7 @@ static void vl_api_vnet_ip4_fib_counters_t_handler (vl_api_vnet_ip4_fib_counters_t * mp) { stats_main_t *sm = &stats_main; - svm_queue_t *q, *q_prev = NULL; + vl_api_registration_t *reg, *reg_prev = NULL; vl_api_vnet_ip4_fib_counters_t *mp_copy = NULL; u32 mp_size; vpe_client_registration_t *clients, client; @@ -2210,17 +2210,17 @@ vl_api_vnet_ip4_fib_counters_t_handler (vl_api_vnet_ip4_fib_counters_t * mp) for (i = 0; i < vec_len (clients); i++) { client = clients[i]; - q = vl_api_client_index_to_input_queue (client.client_index); - if (q) + reg = vl_api_client_index_to_registration (client.client_index); + if (reg) { - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { mp_copy = vl_msg_api_alloc_as_if_client (mp_size); clib_memcpy (mp_copy, mp, mp_size); - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); mp = mp_copy; } - q_prev = q; + reg_prev = reg; } else { @@ -2230,9 +2230,9 @@ vl_api_vnet_ip4_fib_counters_t_handler (vl_api_vnet_ip4_fib_counters_t * mp) } } - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); } else { @@ -2244,7 +2244,7 @@ static void vl_api_vnet_ip4_nbr_counters_t_handler (vl_api_vnet_ip4_nbr_counters_t * mp) { stats_main_t *sm = &stats_main; - svm_queue_t *q, *q_prev = NULL; + vl_api_registration_t *reg, *reg_prev = NULL; vl_api_vnet_ip4_nbr_counters_t *mp_copy = NULL; u32 mp_size; vpe_client_registration_t *clients, client; @@ -2259,17 +2259,17 @@ vl_api_vnet_ip4_nbr_counters_t_handler (vl_api_vnet_ip4_nbr_counters_t * mp) for (i = 0; i < vec_len (clients); i++) { client = clients[i]; - q = vl_api_client_index_to_input_queue (client.client_index); - if (q) + reg = vl_api_client_index_to_registration (client.client_index); + if (reg) { - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { mp_copy = vl_msg_api_alloc_as_if_client (mp_size); clib_memcpy (mp_copy, mp, mp_size); - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); mp = mp_copy; } - q_prev = q; + reg_prev = reg; } else { @@ -2280,9 +2280,9 @@ vl_api_vnet_ip4_nbr_counters_t_handler (vl_api_vnet_ip4_nbr_counters_t * mp) } /* *INDENT-ON* */ - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); } else { @@ -2294,7 +2294,7 @@ static void vl_api_vnet_ip6_fib_counters_t_handler (vl_api_vnet_ip6_fib_counters_t * mp) { stats_main_t *sm = &stats_main; - svm_queue_t *q, *q_prev = NULL; + vl_api_registration_t *reg, *reg_prev = NULL; vl_api_vnet_ip6_fib_counters_t *mp_copy = NULL; u32 mp_size; vpe_client_registration_t *clients, client; @@ -2309,17 +2309,17 @@ vl_api_vnet_ip6_fib_counters_t_handler (vl_api_vnet_ip6_fib_counters_t * mp) for (i = 0; i < vec_len (clients); i++) { client = clients[i]; - q = vl_api_client_index_to_input_queue (client.client_index); - if (q) + reg = vl_api_client_index_to_registration (client.client_index); + if (reg) { - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { mp_copy = vl_msg_api_alloc_as_if_client (mp_size); clib_memcpy (mp_copy, mp, mp_size); - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); mp = mp_copy; } - q_prev = q; + reg_prev = reg; } else { @@ -2329,9 +2329,9 @@ vl_api_vnet_ip6_fib_counters_t_handler (vl_api_vnet_ip6_fib_counters_t * mp) } } /* *INDENT-ON* */ - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); } else { @@ -2343,7 +2343,7 @@ static void vl_api_vnet_ip6_nbr_counters_t_handler (vl_api_vnet_ip6_nbr_counters_t * mp) { stats_main_t *sm = &stats_main; - svm_queue_t *q, *q_prev = NULL; + vl_api_registration_t *reg, *reg_prev = NULL; vl_api_vnet_ip6_nbr_counters_t *mp_copy = NULL; u32 mp_size; vpe_client_registration_t *clients, client; @@ -2358,17 +2358,17 @@ vl_api_vnet_ip6_nbr_counters_t_handler (vl_api_vnet_ip6_nbr_counters_t * mp) for (i = 0; i < vec_len (clients); i++) { client = clients[i]; - q = vl_api_client_index_to_input_queue (client.client_index); - if (q) + reg = vl_api_client_index_to_registration (client.client_index); + if (reg) { - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { mp_copy = vl_msg_api_alloc_as_if_client (mp_size); clib_memcpy (mp_copy, mp, mp_size); - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); mp = mp_copy; } - q_prev = q; + reg_prev = reg; } else { @@ -2378,9 +2378,9 @@ vl_api_vnet_ip6_nbr_counters_t_handler (vl_api_vnet_ip6_nbr_counters_t * mp) } } /* *INDENT-ON* */ - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); } else { |