X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvpp%2Fstats%2Fstats.c;h=31cfc336aca28d0ffe6db01a7620238db1517e45;hb=1ddbc0138b64486b8e51e5e12fcad21fba8b8b68;hp=5787b9e14e90422c15b9cc7c10d900d09d5fc560;hpb=871dc4287d8c05ff76106dba4f5f8654c24347fe;p=vpp.git diff --git a/src/vpp/stats/stats.c b/src/vpp/stats/stats.c index 5787b9e14e9..31cfc336aca 100644 --- a/src/vpp/stats/stats.c +++ b/src/vpp/stats/stats.c @@ -48,24 +48,25 @@ stats_main_t stats_main; #define foreach_stats_msg \ _(WANT_STATS, want_stats) \ _(VNET_INTERFACE_SIMPLE_COUNTERS, vnet_interface_simple_counters) \ -_(WANT_INTERFACE_SIMPLE_STATS, want_interface_simple_stats) \ +_(WANT_INTERFACE_SIMPLE_STATS, want_interface_simple_stats) \ _(VNET_INTERFACE_COMBINED_COUNTERS, vnet_interface_combined_counters) \ -_(WANT_INTERFACE_COMBINED_STATS, want_interface_combined_stats) \ +_(WANT_INTERFACE_COMBINED_STATS, want_interface_combined_stats) \ _(WANT_PER_INTERFACE_COMBINED_STATS, want_per_interface_combined_stats) \ -_(WANT_PER_INTERFACE_SIMPLE_STATS, want_per_interface_simple_stats) \ +_(WANT_PER_INTERFACE_SIMPLE_STATS, want_per_interface_simple_stats) \ _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \ -_(WANT_IP4_FIB_STATS, want_ip4_fib_stats) \ +_(WANT_IP4_FIB_STATS, want_ip4_fib_stats) \ _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \ -_(WANT_IP6_FIB_STATS, want_ip6_fib_stats) \ +_(WANT_IP6_FIB_STATS, want_ip6_fib_stats) \ _(WANT_IP4_MFIB_STATS, want_ip4_mfib_stats) \ _(WANT_IP6_MFIB_STATS, want_ip6_mfib_stats) \ _(VNET_IP4_NBR_COUNTERS, vnet_ip4_nbr_counters) \ -_(WANT_IP4_NBR_STATS, want_ip4_nbr_stats) \ -_(VNET_IP6_NBR_COUNTERS, vnet_ip6_nbr_counters) \ -_(WANT_IP6_NBR_STATS, want_ip6_nbr_stats) \ -_(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \ -_(STATS_GET_POLLER_DELAY, stats_get_poller_delay) \ -_(WANT_UDP_ENCAP_STATS, want_udp_encap_stats) +_(WANT_IP4_NBR_STATS, want_ip4_nbr_stats) \ +_(VNET_IP6_NBR_COUNTERS, vnet_ip6_nbr_counters) \ +_(WANT_IP6_NBR_STATS, want_ip6_nbr_stats) \ +_(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \ +_(STATS_GET_POLLER_DELAY, stats_get_poller_delay) \ +_(WANT_UDP_ENCAP_STATS, want_udp_encap_stats) \ +_(MAP_STATS_SEGMENT, map_stats_segment) #define vl_msg_name_crc_list #include @@ -297,6 +298,8 @@ set_client_for_stat (u32 reg, u32 item, vpe_client_registration_t * client) { pool_get (sm->stats_registrations[reg], registration); registration->item = item; + registration->client_hash = NULL; + registration->clients = NULL; hash_set (sm->stats_registration_hash[reg], item, registration - sm->stats_registrations[reg]); } @@ -319,13 +322,39 @@ set_client_for_stat (u32 reg, u32 item, vpe_client_registration_t * client) return 1; //At least one client is doing something ... poll } -int -clear_client_for_stat (u32 reg, u32 item, u32 client_index) +static void +clear_one_client (u32 reg_index, u32 reg, u32 item, u32 client_index) { stats_main_t *sm = &stats_main; vpe_client_stats_registration_t *registration; vpe_client_registration_t *client; uword *p; + + registration = pool_elt_at_index (sm->stats_registrations[reg], reg_index); + p = hash_get (registration->client_hash, client_index); + + if (p) + { + client = pool_elt_at_index (registration->clients, p[0]); + hash_unset (registration->client_hash, client->client_index); + pool_put (registration->clients, client); + + /* Now check if that was the last client for that item */ + if (0 == pool_elts (registration->clients)) + { + hash_unset (sm->stats_registration_hash[reg], item); + hash_free (registration->client_hash); + pool_free (registration->clients); + pool_put (sm->stats_registrations[reg], registration); + } + } +} + +int +clear_client_for_stat (u32 reg, u32 item, u32 client_index) +{ + stats_main_t *sm = &stats_main; + uword *p; int i, elts; /* Clear the client first */ @@ -336,24 +365,35 @@ clear_client_for_stat (u32 reg, u32 item, u32 client_index) goto exit; /* If there is, is our client_index one of them */ - registration = pool_elt_at_index (sm->stats_registrations[reg], p[0]); - p = hash_get (registration->client_hash, client_index); + clear_one_client (p[0], reg, item, client_index); - if (!p) - goto exit; +exit: + elts = 0; + /* Now check if that was the last item in any of the listened to stats */ + for (i = 0; i < STATS_REG_N_IDX; i++) + { + elts += pool_elts (sm->stats_registrations[i]); + } + return elts; +} - client = pool_elt_at_index (registration->clients, p[0]); - hash_unset (registration->client_hash, client->client_index); - pool_put (registration->clients, client); +static int +clear_client_for_all_stats (u32 client_index) +{ + stats_main_t *sm = &stats_main; + u32 reg_index, item, reg; + int i, elts; - /* Now check if that was the last client for that item */ - if (0 == pool_elts (registration->clients)) + /* *INDENT-OFF* */ + vec_foreach_index(reg, sm->stats_registration_hash) { - hash_unset (sm->stats_registration_hash[reg], item); - pool_put (sm->stats_registrations[reg], registration); + hash_foreach(item, reg_index, sm->stats_registration_hash[reg], + ({ + clear_one_client(reg_index, reg, item, client_index); + })); } + /* *INDENT-OFF* */ -exit: elts = 0; /* Now check if that was the last item in any of the listened to stats */ for (i = 0; i < STATS_REG_N_IDX; i++) @@ -363,6 +403,22 @@ exit: return elts; } +static clib_error_t * +want_stats_reaper (u32 client_index) +{ + stats_main_t *sm = &stats_main; + + sm->enable_poller = clear_client_for_all_stats (client_index); + + return (NULL); +} + +VL_MSG_API_REAPER_FUNCTION (want_stats_reaper); + + +/* + * Return a copy of the clients list. + */ vpe_client_registration_t * get_clients_for_stat (u32 reg, u32 item) { @@ -381,10 +437,13 @@ get_clients_for_stat (u32 reg, u32 item) registration = pool_elt_at_index (sm->stats_registrations[reg], p[0]); vec_reset_length (clients); - pool_foreach (client, registration->clients, ( - { - vec_add1 (clients, *client);} - )); + + /* *INDENT-OFF* */ + pool_foreach (client, registration->clients, + ({ + vec_add1 (clients, *client);} + )); + /* *INDENT-ON* */ return clients; } @@ -608,6 +667,7 @@ static void reg_prev = reg; } } + vec_free (clients); #if STATS_DEBUG > 0 fformat (stdout, "%U\n", format_vnet_combined_counters, mp); #endif @@ -2280,10 +2340,12 @@ stats_thread_fn (void *arg) ip46_fib_stats_delay (sm, sm->stats_poll_interval_in_seconds, 0 /* nsec */ ); + /* Always update stats segment data */ + do_stat_segment_updates (sm); + if (!(sm->enable_poller)) - { - continue; - } + continue; + if (pool_elts (sm->stats_registrations[IDX_PER_INTERFACE_COMBINED_COUNTERS])) do_combined_per_interface_counters (sm); @@ -2355,6 +2417,7 @@ static void continue; } } + vec_free (clients); #if STATS_DEBUG > 0 fformat (stdout, "%U\n", format_vnet_simple_counters, mp); @@ -2408,6 +2471,7 @@ vl_api_vnet_ip4_fib_counters_t_handler (vl_api_vnet_ip4_fib_counters_t * mp) continue; } } + vec_free (clients); if (reg_prev && vl_api_can_send_msg (reg_prev)) { @@ -2457,6 +2521,7 @@ vl_api_vnet_ip4_nbr_counters_t_handler (vl_api_vnet_ip4_nbr_counters_t * mp) continue; } } + vec_free (clients); /* *INDENT-ON* */ if (reg_prev && vl_api_can_send_msg (reg_prev)) @@ -2507,6 +2572,8 @@ vl_api_vnet_ip6_fib_counters_t_handler (vl_api_vnet_ip6_fib_counters_t * mp) continue; } } + vec_free (clients); + /* *INDENT-ON* */ if (reg_prev && vl_api_can_send_msg (reg_prev)) { @@ -2556,6 +2623,8 @@ vl_api_vnet_ip6_nbr_counters_t_handler (vl_api_vnet_ip6_nbr_counters_t * mp) continue; } } + vec_free (clients); + /* *INDENT-ON* */ if (reg_prev && vl_api_can_send_msg (reg_prev)) { @@ -2920,6 +2989,50 @@ stats_memclnt_delete_callback (u32 client_index) #define vl_api_vnet_ip4_nbr_counters_t_print vl_noop_handler #define vl_api_vnet_ip6_nbr_counters_t_endian vl_noop_handler #define vl_api_vnet_ip6_nbr_counters_t_print vl_noop_handler +#define vl_api_map_stats_segment_t_print vl_noop_handler + +static void +vl_api_map_stats_segment_t_handler (vl_api_map_stats_segment_t * mp) +{ + vl_api_map_stats_segment_reply_t *rmp; + stats_main_t *sm = &stats_main; + ssvm_private_t *ssvmp = &sm->stat_segment; + vl_api_registration_t *regp; + api_main_t *am = &api_main; + clib_file_t *cf; + vl_api_shm_elem_config_t *config = 0; + vl_shmem_hdr_t *shmem_hdr; + int rv = 0; + + regp = vl_api_client_index_to_registration (mp->client_index); + if (regp == 0) + { + clib_warning ("API client disconnected"); + return; + } + if (regp->registration_type != REGISTRATION_TYPE_SOCKET_SERVER) + rv = VNET_API_ERROR_INVALID_REGISTRATION; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + rmp->_vl_msg_id = htons (VL_API_MAP_STATS_SEGMENT_REPLY); + rmp->context = mp->context; + rmp->retval = htonl (rv); + + vl_api_send_msg (regp, (u8 *) rmp); + + if (rv != 0) + return; + + /* + * We need the reply message to make it out the back door + * before we send the magic fd message so force a flush + */ + cf = vl_api_registration_file (regp); + cf->write_function (cf); + + /* Send the magic "here's your sign (aka fd)" socket message */ + vl_sock_api_send_fd_msg (cf->file_descriptor, ssvmp->fd); +} static clib_error_t * stats_init (vlib_main_t * vm)