New upstream version 18.11-rc1
[deb_dpdk.git] / lib / librte_ethdev / ethdev_profile.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 Intel Corporation
3  */
4
5 #include "ethdev_profile.h"
6
7 /**
8  * This conditional block enables Ethernet device profiling with
9  * Intel (R) VTune (TM) Amplifier.
10  */
11 #ifdef RTE_ETHDEV_PROFILE_WITH_VTUNE
12
13 /**
14  * Hook callback to trace rte_eth_rx_burst() calls.
15  */
16 uint16_t
17 profile_hook_rx_burst_cb(
18         __rte_unused uint16_t port_id, __rte_unused uint16_t queue_id,
19         __rte_unused struct rte_mbuf *pkts[], uint16_t nb_pkts,
20         __rte_unused uint16_t max_pkts, __rte_unused void *user_param)
21 {
22         return nb_pkts;
23 }
24
25 /**
26  * Setting profiling rx callback for a given Ethernet device.
27  * This function must be invoked when ethernet device is being configured.
28  *
29  * @param port_id
30  *  The port identifier of the Ethernet device.
31  * @param rx_queue_num
32  *  The number of RX queues on specified port.
33  *
34  * @return
35  *  - On success, zero.
36  *  - On failure, a negative value.
37  */
38 static inline int
39 vtune_profile_rx_init(uint16_t port_id, uint8_t rx_queue_num)
40 {
41         uint16_t q_id;
42
43         for (q_id = 0; q_id < rx_queue_num; ++q_id) {
44                 if (!rte_eth_add_rx_callback(
45                         port_id, q_id, profile_hook_rx_burst_cb, NULL)) {
46                         return -rte_errno;
47                 }
48         }
49
50         return 0;
51 }
52 #endif /* RTE_ETHDEV_PROFILE_WITH_VTUNE */
53
54 int
55 __rte_eth_dev_profile_init(__rte_unused uint16_t port_id,
56         __rte_unused struct rte_eth_dev *dev)
57 {
58 #ifdef RTE_ETHDEV_PROFILE_WITH_VTUNE
59         return vtune_profile_rx_init(port_id, dev->data->nb_rx_queues);
60 #endif
61         return 0;
62 }