/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2017 Intel Corporation
+ * Copyright(c) 2018 Intel Corporation
*/
#include <unistd.h>
#include <stdbool.h>
#include <math.h>
+#include <rte_string_fns.h>
#include <rte_mbuf.h>
#include <rte_log.h>
#include <rte_cycles.h>
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;
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;
}
uint16_t pid;
uint16_t qid;
struct rxtx_cbs *cbs = NULL;
- const uint16_t nb_ports = rte_eth_dev_count();
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;
}
/** Register Rx/Tx callbacks */
- for (pid = 0; pid < nb_ports; pid++) {
+ 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,
uint16_t qid;
int ret = 0;
struct rxtx_cbs *cbs = NULL;
- const uint16_t nb_ports = rte_eth_dev_count();
+ const struct rte_memzone *mz = NULL;
/** De register Rx/Tx callbacks */
- for (pid = 0; pid < nb_ports; pid++) {
+ 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);
}
}
+ /* free up the memzone */
+ mz = rte_memzone_lookup(MZ_RTE_LATENCY_STATS);
+ if (mz)
+ rte_memzone_free(mz);
+
return 0;
}
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;
}