1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
5 #include "ethdev_profile.h"
8 * This conditional block enables RX queues profiling by tracking wasted
9 * iterations, i.e. iterations which yielded no RX packets. Profiling is
10 * performed using the Instrumentation and Tracing Technology (ITT) API,
11 * employed by the Intel (R) VTune (TM) Amplifier.
13 #ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
15 #include <ittnotify.h>
17 #define ITT_MAX_NAME_LEN (100)
20 * Auxiliary ITT structure belonging to Ethernet device and using to:
21 * - track RX queue state to determine whether it is wasting loop iterations
22 * - begin or end ITT task using task domain and task name (handle)
24 struct itt_profile_rx_data {
26 * ITT domains for each queue.
28 __itt_domain *domains[RTE_MAX_QUEUES_PER_PORT];
30 * ITT task names for each queue.
32 __itt_string_handle *handles[RTE_MAX_QUEUES_PER_PORT];
34 * Flags indicating the queues state. Possible values:
35 * 1 - queue is wasting iterations,
38 uint8_t queue_state[RTE_MAX_QUEUES_PER_PORT];
42 * The pool of *itt_profile_rx_data* structures.
44 struct itt_profile_rx_data itt_rx_data[RTE_MAX_ETHPORTS];
48 * This callback function manages ITT tasks collection on given port and queue.
49 * It must be registered with rte_eth_add_rx_callback() to be called from
50 * rte_eth_rx_burst(). To find more comments see rte_rx_callback_fn function
54 collect_itt_rx_burst_cb(uint16_t port_id, uint16_t queue_id,
55 __rte_unused struct rte_mbuf *pkts[], uint16_t nb_pkts,
56 __rte_unused uint16_t max_pkts, __rte_unused void *user_param)
58 if (unlikely(nb_pkts == 0)) {
59 if (!itt_rx_data[port_id].queue_state[queue_id]) {
61 itt_rx_data[port_id].domains[queue_id],
62 __itt_null, __itt_null,
63 itt_rx_data[port_id].handles[queue_id]);
64 itt_rx_data[port_id].queue_state[queue_id] = 1;
67 if (unlikely(itt_rx_data[port_id].queue_state[queue_id])) {
69 itt_rx_data[port_id].domains[queue_id]);
70 itt_rx_data[port_id].queue_state[queue_id] = 0;
77 * Initialization of itt_profile_rx_data for a given Ethernet device.
78 * This function must be invoked when ethernet device is being configured.
79 * Result will be stored in the global array *itt_rx_data*.
82 * The port identifier of the Ethernet device.
84 * The name of the Ethernet device.
86 * The number of RX queues on specified port.
90 * - On failure, a negative value.
93 itt_profile_rx_init(uint16_t port_id, char *port_name, uint8_t rx_queue_num)
97 for (q_id = 0; q_id < rx_queue_num; ++q_id) {
98 char domain_name[ITT_MAX_NAME_LEN];
100 snprintf(domain_name, sizeof(domain_name),
101 "RXBurst.WastedIterations.Port_%s.Queue_%d",
103 itt_rx_data[port_id].domains[q_id]
104 = __itt_domain_create(domain_name);
106 char task_name[ITT_MAX_NAME_LEN];
108 snprintf(task_name, sizeof(task_name),
109 "port id: %d; queue id: %d",
111 itt_rx_data[port_id].handles[q_id]
112 = __itt_string_handle_create(task_name);
114 itt_rx_data[port_id].queue_state[q_id] = 0;
116 if (!rte_eth_add_rx_callback(
117 port_id, q_id, collect_itt_rx_burst_cb, NULL)) {
124 #endif /* RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS */
127 __rte_eth_profile_rx_init(__rte_unused uint16_t port_id,
128 __rte_unused struct rte_eth_dev *dev)
130 #ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
131 return itt_profile_rx_init(
132 port_id, dev->data->name, dev->data->nb_rx_queues);