| 222 | } |
| 223 | |
| 224 | int |
| 225 | rte_latencystats_init(uint64_t app_samp_intvl, |
| 226 | rte_latency_stats_flow_type_fn user_cb) |
| 227 | { |
| 228 | unsigned int i; |
| 229 | uint16_t pid; |
| 230 | uint16_t qid; |
| 231 | struct rxtx_cbs *cbs = NULL; |
| 232 | const char *ptr_strings[NUM_LATENCY_STATS] = {0}; |
| 233 | const struct rte_memzone *mz = NULL; |
| 234 | const unsigned int flags = 0; |
| 235 | int ret; |
| 236 | |
| 237 | if (rte_memzone_lookup(MZ_RTE_LATENCY_STATS)) |
| 238 | return -EEXIST; |
| 239 | |
| 240 | /** Allocate stats in shared memory fo multi process support */ |
| 241 | mz = rte_memzone_reserve(MZ_RTE_LATENCY_STATS, sizeof(*glob_stats), |
| 242 | rte_socket_id(), flags); |
| 243 | if (mz == NULL) { |
| 244 | RTE_LOG(ERR, LATENCY_STATS, "Cannot reserve memory: %s:%d\n", |
| 245 | __func__, __LINE__); |
| 246 | return -ENOMEM; |
| 247 | } |
| 248 | |
| 249 | glob_stats = mz->addr; |
| 250 | rte_spinlock_init(&glob_stats->lock); |
| 251 | samp_intvl = app_samp_intvl * latencystat_cycles_per_ns(); |
| 252 | next_tsc = rte_rdtsc(); |
| 253 | |
| 254 | /** Register latency stats with stats library */ |
| 255 | for (i = 0; i < NUM_LATENCY_STATS; i++) |
| 256 | ptr_strings[i] = lat_stats_strings[i].name; |
| 257 | |
| 258 | latency_stats_index = rte_metrics_reg_names(ptr_strings, |
| 259 | NUM_LATENCY_STATS); |
| 260 | if (latency_stats_index < 0) { |
| 261 | RTE_LOG(DEBUG, LATENCY_STATS, |
| 262 | "Failed to register latency stats names\n"); |
| 263 | return -1; |
| 264 | } |
| 265 | |
| 266 | /* Register mbuf field and flag for Rx timestamp */ |
| 267 | ret = rte_mbuf_dyn_rx_timestamp_register(×tamp_dynfield_offset, |
| 268 | ×tamp_dynflag); |
| 269 | if (ret != 0) { |
| 270 | RTE_LOG(ERR, LATENCY_STATS, |
| 271 | "Cannot register mbuf field/flag for timestamp\n"); |
| 272 | return -rte_errno; |
| 273 | } |
| 274 | |
| 275 | /** Register Rx/Tx callbacks */ |
| 276 | RTE_ETH_FOREACH_DEV(pid) { |
| 277 | struct rte_eth_dev_info dev_info; |
| 278 | |
| 279 | ret = rte_eth_dev_info_get(pid, &dev_info); |
| 280 | if (ret != 0) { |
| 281 | RTE_LOG(INFO, LATENCY_STATS, |