X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvpp%2Fstats%2Fstats.c;h=31cfc336aca28d0ffe6db01a7620238db1517e45;hb=1ddbc0138b64486b8e51e5e12fcad21fba8b8b68;hp=bf0bc50cafc46e2371f8e8bd4d7b62d7ccd693fc;hpb=048a4e5a000017d0d632ebf02dcc23d9bf9ccf72;p=vpp.git diff --git a/src/vpp/stats/stats.c b/src/vpp/stats/stats.c index bf0bc50cafc..31cfc336aca 100644 --- a/src/vpp/stats/stats.c +++ b/src/vpp/stats/stats.c @@ -298,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]); } @@ -320,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 */ @@ -337,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++) @@ -364,6 +403,19 @@ 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. */ @@ -2288,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);