4 * Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <rte_config.h>
36 #include "ethdev_profile.h"
39 * This conditional block enables RX queues profiling by tracking wasted
40 * iterations, i.e. iterations which yielded no RX packets. Profiling is
41 * performed using the Instrumentation and Tracing Technology (ITT) API,
42 * employed by the Intel (R) VTune (TM) Amplifier.
44 #ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
46 #include <ittnotify.h>
48 #define ITT_MAX_NAME_LEN (100)
51 * Auxiliary ITT structure belonging to Ethernet device and using to:
52 * - track RX queue state to determine whether it is wasting loop iterations
53 * - begin or end ITT task using task domain and task name (handle)
55 struct itt_profile_rx_data {
57 * ITT domains for each queue.
59 __itt_domain *domains[RTE_MAX_QUEUES_PER_PORT];
61 * ITT task names for each queue.
63 __itt_string_handle *handles[RTE_MAX_QUEUES_PER_PORT];
65 * Flags indicating the queues state. Possible values:
66 * 1 - queue is wasting iterations,
69 uint8_t queue_state[RTE_MAX_QUEUES_PER_PORT];
73 * The pool of *itt_profile_rx_data* structures.
75 struct itt_profile_rx_data itt_rx_data[RTE_MAX_ETHPORTS];
79 * This callback function manages ITT tasks collection on given port and queue.
80 * It must be registered with rte_eth_add_rx_callback() to be called from
81 * rte_eth_rx_burst(). To find more comments see rte_rx_callback_fn function
85 collect_itt_rx_burst_cb(uint16_t port_id, uint16_t queue_id,
86 __rte_unused struct rte_mbuf *pkts[], uint16_t nb_pkts,
87 __rte_unused uint16_t max_pkts, __rte_unused void *user_param)
89 if (unlikely(nb_pkts == 0)) {
90 if (!itt_rx_data[port_id].queue_state[queue_id]) {
92 itt_rx_data[port_id].domains[queue_id],
93 __itt_null, __itt_null,
94 itt_rx_data[port_id].handles[queue_id]);
95 itt_rx_data[port_id].queue_state[queue_id] = 1;
98 if (unlikely(itt_rx_data[port_id].queue_state[queue_id])) {
100 itt_rx_data[port_id].domains[queue_id]);
101 itt_rx_data[port_id].queue_state[queue_id] = 0;
108 * Initialization of itt_profile_rx_data for a given Ethernet device.
109 * This function must be invoked when ethernet device is being configured.
110 * Result will be stored in the global array *itt_rx_data*.
113 * The port identifier of the Ethernet device.
115 * The name of the Ethernet device.
116 * @param rx_queue_num
117 * The number of RX queues on specified port.
120 * - On success, zero.
121 * - On failure, a negative value.
124 itt_profile_rx_init(uint16_t port_id, char *port_name, uint8_t rx_queue_num)
128 for (q_id = 0; q_id < rx_queue_num; ++q_id) {
129 char domain_name[ITT_MAX_NAME_LEN];
131 snprintf(domain_name, sizeof(domain_name),
132 "RXBurst.WastedIterations.Port_%s.Queue_%d",
134 itt_rx_data[port_id].domains[q_id]
135 = __itt_domain_create(domain_name);
137 char task_name[ITT_MAX_NAME_LEN];
139 snprintf(task_name, sizeof(task_name),
140 "port id: %d; queue id: %d",
142 itt_rx_data[port_id].handles[q_id]
143 = __itt_string_handle_create(task_name);
145 itt_rx_data[port_id].queue_state[q_id] = 0;
147 if (!rte_eth_add_rx_callback(
148 port_id, q_id, collect_itt_rx_burst_cb, NULL)) {
155 #endif /* RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS */
158 __rte_eth_profile_rx_init(__rte_unused uint16_t port_id,
159 __rte_unused struct rte_eth_dev *dev)
161 #ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
162 return itt_profile_rx_init(
163 port_id, dev->data->name, dev->data->nb_rx_queues);