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 "ethdev_profile.h"
37 * This conditional block enables RX queues profiling by tracking wasted
38 * iterations, i.e. iterations which yielded no RX packets. Profiling is
39 * performed using the Instrumentation and Tracing Technology (ITT) API,
40 * employed by the Intel (R) VTune (TM) Amplifier.
42 #ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
44 #include <ittnotify.h>
46 #define ITT_MAX_NAME_LEN (100)
49 * Auxiliary ITT structure belonging to Ethernet device and using to:
50 * - track RX queue state to determine whether it is wasting loop iterations
51 * - begin or end ITT task using task domain and task name (handle)
53 struct itt_profile_rx_data {
55 * ITT domains for each queue.
57 __itt_domain *domains[RTE_MAX_QUEUES_PER_PORT];
59 * ITT task names for each queue.
61 __itt_string_handle *handles[RTE_MAX_QUEUES_PER_PORT];
63 * Flags indicating the queues state. Possible values:
64 * 1 - queue is wasting iterations,
67 uint8_t queue_state[RTE_MAX_QUEUES_PER_PORT];
71 * The pool of *itt_profile_rx_data* structures.
73 struct itt_profile_rx_data itt_rx_data[RTE_MAX_ETHPORTS];
77 * This callback function manages ITT tasks collection on given port and queue.
78 * It must be registered with rte_eth_add_rx_callback() to be called from
79 * rte_eth_rx_burst(). To find more comments see rte_rx_callback_fn function
83 collect_itt_rx_burst_cb(uint16_t port_id, uint16_t queue_id,
84 __rte_unused struct rte_mbuf *pkts[], uint16_t nb_pkts,
85 __rte_unused uint16_t max_pkts, __rte_unused void *user_param)
87 if (unlikely(nb_pkts == 0)) {
88 if (!itt_rx_data[port_id].queue_state[queue_id]) {
90 itt_rx_data[port_id].domains[queue_id],
91 __itt_null, __itt_null,
92 itt_rx_data[port_id].handles[queue_id]);
93 itt_rx_data[port_id].queue_state[queue_id] = 1;
96 if (unlikely(itt_rx_data[port_id].queue_state[queue_id])) {
98 itt_rx_data[port_id].domains[queue_id]);
99 itt_rx_data[port_id].queue_state[queue_id] = 0;
106 * Initialization of itt_profile_rx_data for a given Ethernet device.
107 * This function must be invoked when ethernet device is being configured.
108 * Result will be stored in the global array *itt_rx_data*.
111 * The port identifier of the Ethernet device.
113 * The name of the Ethernet device.
114 * @param rx_queue_num
115 * The number of RX queues on specified port.
118 * - On success, zero.
119 * - On failure, a negative value.
122 itt_profile_rx_init(uint16_t port_id, char *port_name, uint8_t rx_queue_num)
126 for (q_id = 0; q_id < rx_queue_num; ++q_id) {
127 char domain_name[ITT_MAX_NAME_LEN];
129 snprintf(domain_name, sizeof(domain_name),
130 "RXBurst.WastedIterations.Port_%s.Queue_%d",
132 itt_rx_data[port_id].domains[q_id]
133 = __itt_domain_create(domain_name);
135 char task_name[ITT_MAX_NAME_LEN];
137 snprintf(task_name, sizeof(task_name),
138 "port id: %d; queue id: %d",
140 itt_rx_data[port_id].handles[q_id]
141 = __itt_string_handle_create(task_name);
143 itt_rx_data[port_id].queue_state[q_id] = 0;
145 if (!rte_eth_add_rx_callback(
146 port_id, q_id, collect_itt_rx_burst_cb, NULL)) {
153 #endif /* RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS */
156 __rte_eth_profile_rx_init(__rte_unused uint16_t port_id,
157 __rte_unused struct rte_eth_dev *dev)
159 #ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
160 return itt_profile_rx_init(
161 port_id, dev->data->name, dev->data->nb_rx_queues);