]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/lib/librte_ethdev/ethdev_profile.c
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / spdk / dpdk / lib / librte_ethdev / ethdev_profile.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
3 */
4
5 #include "ethdev_profile.h"
6
7 /**
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.
12 */
13 #ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
14
15 #include <ittnotify.h>
16
17 #define ITT_MAX_NAME_LEN (100)
18
19 /**
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)
23 */
24 struct itt_profile_rx_data {
25 /**
26 * ITT domains for each queue.
27 */
28 __itt_domain *domains[RTE_MAX_QUEUES_PER_PORT];
29 /**
30 * ITT task names for each queue.
31 */
32 __itt_string_handle *handles[RTE_MAX_QUEUES_PER_PORT];
33 /**
34 * Flags indicating the queues state. Possible values:
35 * 1 - queue is wasting iterations,
36 * 0 - otherwise.
37 */
38 uint8_t queue_state[RTE_MAX_QUEUES_PER_PORT];
39 };
40
41 /**
42 * The pool of *itt_profile_rx_data* structures.
43 */
44 struct itt_profile_rx_data itt_rx_data[RTE_MAX_ETHPORTS];
45
46
47 /**
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
51 * type declaration.
52 */
53 static uint16_t
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)
57 {
58 if (unlikely(nb_pkts == 0)) {
59 if (!itt_rx_data[port_id].queue_state[queue_id]) {
60 __itt_task_begin(
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;
65 }
66 } else {
67 if (unlikely(itt_rx_data[port_id].queue_state[queue_id])) {
68 __itt_task_end(
69 itt_rx_data[port_id].domains[queue_id]);
70 itt_rx_data[port_id].queue_state[queue_id] = 0;
71 }
72 }
73 return nb_pkts;
74 }
75
76 /**
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*.
80 *
81 * @param port_id
82 * The port identifier of the Ethernet device.
83 * @param port_name
84 * The name of the Ethernet device.
85 * @param rx_queue_num
86 * The number of RX queues on specified port.
87 *
88 * @return
89 * - On success, zero.
90 * - On failure, a negative value.
91 */
92 static inline int
93 itt_profile_rx_init(uint16_t port_id, char *port_name, uint8_t rx_queue_num)
94 {
95 uint16_t q_id;
96
97 for (q_id = 0; q_id < rx_queue_num; ++q_id) {
98 char domain_name[ITT_MAX_NAME_LEN];
99
100 snprintf(domain_name, sizeof(domain_name),
101 "RXBurst.WastedIterations.Port_%s.Queue_%d",
102 port_name, q_id);
103 itt_rx_data[port_id].domains[q_id]
104 = __itt_domain_create(domain_name);
105
106 char task_name[ITT_MAX_NAME_LEN];
107
108 snprintf(task_name, sizeof(task_name),
109 "port id: %d; queue id: %d",
110 port_id, q_id);
111 itt_rx_data[port_id].handles[q_id]
112 = __itt_string_handle_create(task_name);
113
114 itt_rx_data[port_id].queue_state[q_id] = 0;
115
116 if (!rte_eth_add_rx_callback(
117 port_id, q_id, collect_itt_rx_burst_cb, NULL)) {
118 return -rte_errno;
119 }
120 }
121
122 return 0;
123 }
124 #endif /* RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS */
125
126 int
127 __rte_eth_profile_rx_init(__rte_unused uint16_t port_id,
128 __rte_unused struct rte_eth_dev *dev)
129 {
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);
133 #endif
134 return 0;
135 }