X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_latencystats%2Frte_latencystats.c;h=ba2fff3bcbb63a3f4db99b109bf71feff2994ca5;hb=9135705bb81df0b529821a121004c41f176995ff;hp=46c69bf058185d84200bca62f3fe77766416b52e;hpb=8728ccf37615904cf23fb8763895b05c9a3c6b0c;p=dpdk.git diff --git a/lib/librte_latencystats/rte_latencystats.c b/lib/librte_latencystats/rte_latencystats.c index 46c69bf058..ba2fff3bcb 100644 --- a/lib/librte_latencystats/rte_latencystats.c +++ b/lib/librte_latencystats/rte_latencystats.c @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2017 Intel Corporation + * Copyright(c) 2018 Intel Corporation */ #include @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -41,6 +42,7 @@ struct rte_latency_stats { float avg_latency; /**< Average latency in nano seconds */ float max_latency; /**< Maximum latency in nano seconds */ float jitter; /** Latency variation */ + rte_spinlock_t lock; /** Latency calculation lock */ }; static struct rte_latency_stats *glob_stats; @@ -125,8 +127,11 @@ add_time_stamps(uint16_t pid __rte_unused, for (i = 0; i < nb_pkts; i++) { diff_tsc = now - prev_tsc; timer_tsc += diff_tsc; - if (timer_tsc >= samp_intvl) { + + if ((pkts[i]->ol_flags & PKT_RX_TIMESTAMP) == 0 + && (timer_tsc >= samp_intvl)) { pkts[i]->timestamp = now; + pkts[i]->ol_flags |= PKT_RX_TIMESTAMP; timer_tsc = 0; } prev_tsc = now; @@ -156,10 +161,11 @@ calc_latency(uint16_t pid __rte_unused, now = rte_rdtsc(); for (i = 0; i < nb_pkts; i++) { - if (pkts[i]->timestamp) + if (pkts[i]->ol_flags & PKT_RX_TIMESTAMP) latency[cnt++] = now - pkts[i]->timestamp; } + rte_spinlock_lock(&glob_stats->lock); for (i = 0; i < cnt; i++) { /* * The jitter is calculated as statistical mean of interpacket @@ -189,6 +195,7 @@ calc_latency(uint16_t pid __rte_unused, alpha * (latency[i] - glob_stats->avg_latency); prev_latency = latency[i]; } + rte_spinlock_unlock(&glob_stats->lock); return nb_pkts; } @@ -204,6 +211,7 @@ rte_latencystats_init(uint64_t app_samp_intvl, const char *ptr_strings[NUM_LATENCY_STATS] = {0}; const struct rte_memzone *mz = NULL; const unsigned int flags = 0; + int ret; if (rte_memzone_lookup(MZ_RTE_LATENCY_STATS)) return -EEXIST; @@ -218,6 +226,7 @@ rte_latencystats_init(uint64_t app_samp_intvl, } glob_stats = mz->addr; + rte_spinlock_init(&glob_stats->lock); samp_intvl = app_samp_intvl * latencystat_cycles_per_ns(); /** Register latency stats with stats library */ @@ -235,7 +244,16 @@ rte_latencystats_init(uint64_t app_samp_intvl, /** Register Rx/Tx callbacks */ RTE_ETH_FOREACH_DEV(pid) { struct rte_eth_dev_info dev_info; - rte_eth_dev_info_get(pid, &dev_info); + + ret = rte_eth_dev_info_get(pid, &dev_info); + if (ret != 0) { + RTE_LOG(INFO, LATENCY_STATS, + "Error during getting device (port %u) info: %s\n", + pid, strerror(-ret)); + + continue; + } + for (qid = 0; qid < dev_info.nb_rx_queues; qid++) { cbs = &rx_cbs[pid][qid]; cbs->cb = rte_eth_add_first_rx_callback(pid, qid, @@ -265,11 +283,21 @@ rte_latencystats_uninit(void) uint16_t qid; int ret = 0; struct rxtx_cbs *cbs = NULL; + const struct rte_memzone *mz = NULL; /** De register Rx/Tx callbacks */ RTE_ETH_FOREACH_DEV(pid) { struct rte_eth_dev_info dev_info; - rte_eth_dev_info_get(pid, &dev_info); + + ret = rte_eth_dev_info_get(pid, &dev_info); + if (ret != 0) { + RTE_LOG(INFO, LATENCY_STATS, + "Error during getting device (port %u) info: %s\n", + pid, strerror(-ret)); + + continue; + } + for (qid = 0; qid < dev_info.nb_rx_queues; qid++) { cbs = &rx_cbs[pid][qid]; ret = rte_eth_remove_rx_callback(pid, qid, cbs->cb); @@ -288,6 +316,11 @@ rte_latencystats_uninit(void) } } + /* free up the memzone */ + mz = rte_memzone_lookup(MZ_RTE_LATENCY_STATS); + if (mz) + rte_memzone_free(mz); + return 0; } @@ -300,8 +333,8 @@ rte_latencystats_get_names(struct rte_metric_name *names, uint16_t size) return NUM_LATENCY_STATS; for (i = 0; i < NUM_LATENCY_STATS; i++) - snprintf(names[i].name, sizeof(names[i].name), - "%s", lat_stats_strings[i].name); + strlcpy(names[i].name, lat_stats_strings[i].name, + sizeof(names[i].name)); return NUM_LATENCY_STATS; }