DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] ether: add support for vtune task tracing
@ 2017-06-19 17:18 ilia.kurakin
  2017-06-22  9:42 ` Ananyev, Konstantin
  2017-06-27 13:16 ` ilia.kurakin
  0 siblings, 2 replies; 22+ messages in thread
From: ilia.kurakin @ 2017-06-19 17:18 UTC (permalink / raw)
  To: dev; +Cc: Ilia Kurakin

From: Ilia Kurakin <ilia.kurakin@intel.com>

The patch adds tracing of loop iterations that yielded no packets in a DPDK
application. It is using ITT task API:
    https://software.intel.com/en-us/node/544206

We suppose the flow of using this tracing would assume the user has ITT lib
and header on his machine and re-build DPDK with additional make parameters:

    make EXTRA_CFLAGS=-I<path to ittnotify.h>
         EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"

Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>
---
 config/common_base             |  1 +
 lib/librte_ether/Makefile      |  1 +
 lib/librte_ether/rte_eth_itt.h | 69 ++++++++++++++++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.c  |  7 +++++
 lib/librte_ether/rte_ethdev.h  | 26 ++++++++++++++++
 5 files changed, 104 insertions(+)
 create mode 100644 lib/librte_ether/rte_eth_itt.h

diff --git a/config/common_base b/config/common_base
index f6aafd1..60d8b63 100644
--- a/config/common_base
+++ b/config/common_base
@@ -135,6 +135,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
 CONFIG_RTE_LIBRTE_IEEE1588=n
 CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
 CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
+CONFIG_RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS=n
 
 #
 # Turn off Tx preparation stage
diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile
index 93fdde1..c10153a 100644
--- a/lib/librte_ether/Makefile
+++ b/lib/librte_ether/Makefile
@@ -56,5 +56,6 @@ SYMLINK-y-include += rte_eth_ctrl.h
 SYMLINK-y-include += rte_dev_info.h
 SYMLINK-y-include += rte_flow.h
 SYMLINK-y-include += rte_flow_driver.h
+SYMLINK-${CONFIG_RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS}-include += rte_eth_itt.h
 
 include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/lib/librte_ether/rte_eth_itt.h b/lib/librte_ether/rte_eth_itt.h
new file mode 100644
index 0000000..e7984fb
--- /dev/null
+++ b/lib/librte_ether/rte_eth_itt.h
@@ -0,0 +1,69 @@
+#ifndef _RTE_ETH_ITT_H_
+#define _RTE_ETH_ITT_H_
+
+#include <ittnotify.h>
+#include <rte_config.h>
+
+#define ITT_MAX_NAME_LEN (100)
+
+/**
+ * Auxiliary ITT structure belonging to port and using to:
+ *   -  track queue state to determine whether it is wasting loop iterations
+ *   -  begin or end ITT task using task domain and name
+ */
+struct rte_eth_itt_aux_data {
+	/**
+	 * ITT domains for each queue.
+	 */
+	__itt_domain *wasted_iteration_itt_domains[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * ITT task names for each queue.
+	 */
+	__itt_string_handle *wasted_iteration_itt_handles[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * Flags indicating the queues state. Possible values:
+	 * 1 - queue is wasting iterations, 0 - otherwise.
+	 */
+	uint8_t queue_is_wasting_iterations[RTE_MAX_QUEUES_PER_PORT];
+};
+
+/**
+ * The pool of *rte_eth_itt_aux_data* structures.
+ */
+struct rte_eth_itt_aux_data itt_aux_data[RTE_MAX_ETHPORTS];
+
+/**
+ * Initialization of rte_eth_itt_aux_data for a given port.
+ * This function must be invoked when ethernet device is being configured.
+ * Result will be stored in the global array *itt_aux_data*.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param port_name
+ *  The name of the Ethernet device.
+ * @param queue_num
+ *  The number of queues on specified port.
+ */
+static inline void
+rte_eth_init_itt(uint8_t port_id, char *port_name, uint8_t queue_num) {
+	uint16_t q_id;
+	for (q_id = 0; q_id < queue_num; ++q_id) {
+		char domain_name[ITT_MAX_NAME_LEN];
+		snprintf(domain_name, sizeof(domain_name),
+			"RXBurst.WastedIterations.Port_%s.Queue_%d",
+			port_name, q_id);
+		itt_aux_data[port_id].wasted_iteration_itt_domains[q_id]
+			= __itt_domain_create(domain_name);
+
+		char task_name[ITT_MAX_NAME_LEN];
+		snprintf(task_name, sizeof(task_name),
+			"port id: %d; queue id: %d",
+			port_id, q_id);
+		itt_aux_data[port_id].wasted_iteration_itt_handles[q_id]
+			= __itt_string_handle_create(task_name);
+
+		itt_aux_data[port_id].queue_is_wasting_iterations[q_id] = 0;
+	}
+}
+
+#endif
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 81a45c0..9e5ac01 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -818,6 +818,13 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 		return diag;
 	}
 
+#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
+	/**
+	* See rte_eth_itt.h to find comments on code below.
+	*/
+	rte_eth_init_itt(port_id, dev->data->name, nb_rx_q);
+#endif
+
 	return 0;
 }
 
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index f6e6c74..4ba90d2 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -186,6 +186,10 @@ extern "C" {
 #include "rte_eth_ctrl.h"
 #include "rte_dev_info.h"
 
+#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
+#include "rte_eth_itt.h"
+#endif
+
 struct rte_mbuf;
 
 /**
@@ -2710,6 +2714,28 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
 	int16_t nb_rx = (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
 			rx_pkts, nb_pkts);
 
+#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
+	/**
+	* See rte_eth_itt.h to find comments on code below.
+	*/
+	if (unlikely(nb_rx == 0)) {
+		if (!itt_aux_data[port_id].queue_is_wasting_iterations[queue_id]) {
+			__itt_task_begin(
+				itt_aux_data[port_id].wasted_iteration_itt_domains[queue_id],
+				__itt_null, __itt_null,
+				itt_aux_data[port_id].wasted_iteration_itt_handles[queue_id]);
+			itt_aux_data[port_id].queue_is_wasting_iterations[queue_id] = 1;
+		}
+	}
+	else {
+		if (unlikely(itt_aux_data[port_id].queue_is_wasting_iterations[queue_id])) {
+			__itt_task_end(
+				itt_aux_data[port_id].wasted_iteration_itt_domains[queue_id]);
+			itt_aux_data[port_id].queue_is_wasting_iterations[queue_id] = 0;
+		}
+	}
+#endif
+
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
 	struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
 
-- 
2.7.4


--------------------------------------------------------------------
Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park,
17 Krylatskaya Str., Bldg 4, Moscow 121614,
Russian Federation

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH] ether: add support for vtune task tracing
  2017-06-19 17:18 [dpdk-dev] [PATCH] ether: add support for vtune task tracing ilia.kurakin
@ 2017-06-22  9:42 ` Ananyev, Konstantin
  2017-06-22 12:12   ` Kurakin, Ilia
  2017-06-27 13:16 ` ilia.kurakin
  1 sibling, 1 reply; 22+ messages in thread
From: Ananyev, Konstantin @ 2017-06-22  9:42 UTC (permalink / raw)
  To: Kurakin, Ilia, dev; +Cc: Kurakin, Ilia

Hi Ilia,

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of ilia.kurakin@intel.com
> Sent: Monday, June 19, 2017 6:18 PM
> To: dev@dpdk.org
> Cc: Kurakin, Ilia <ilia.kurakin@intel.com>
> Subject: [dpdk-dev] [PATCH] ether: add support for vtune task tracing
> 
> From: Ilia Kurakin <ilia.kurakin@intel.com>
> 
> The patch adds tracing of loop iterations that yielded no packets in a DPDK
> application. It is using ITT task API:
>     https://software.intel.com/en-us/node/544206
> 
> We suppose the flow of using this tracing would assume the user has ITT lib
> and header on his machine and re-build DPDK with additional make parameters:
> 
>     make EXTRA_CFLAGS=-I<path to ittnotify.h>
>          EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"

There are few things that worry me with that patch:
1. We add new config variable and add extra dependency here.
    Usually we try not to do that without really compelling reason.
2. We pollute rte_ethdev with the code that has nothing to do with
     it major functionality.

That makes me wonder why this vtune data collection has to be done
inside rx_burst() function?
 Why it can't be done on the application layer, i.e. straight after rx_burst()
is finished?
Something like:
n = rte_eth_rx_burst(port, queue, ....);
itt_rx_collect_data(port, queue, n, ....);
?

Or as alternative, user can install this vtune collection routine as
rx callback function.

Konstantin

> 
> Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>
> ---
>  config/common_base             |  1 +
>  lib/librte_ether/Makefile      |  1 +
>  lib/librte_ether/rte_eth_itt.h | 69 ++++++++++++++++++++++++++++++++++++++++++
>  lib/librte_ether/rte_ethdev.c  |  7 +++++
>  lib/librte_ether/rte_ethdev.h  | 26 ++++++++++++++++
>  5 files changed, 104 insertions(+)
>  create mode 100644 lib/librte_ether/rte_eth_itt.h
> 
> diff --git a/config/common_base b/config/common_base
> index f6aafd1..60d8b63 100644
> --- a/config/common_base
> +++ b/config/common_base
> @@ -135,6 +135,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
>  CONFIG_RTE_LIBRTE_IEEE1588=n
>  CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
>  CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
> +CONFIG_RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS=n
> 
>  #
>  # Turn off Tx preparation stage
> diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile
> index 93fdde1..c10153a 100644
> --- a/lib/librte_ether/Makefile
> +++ b/lib/librte_ether/Makefile
> @@ -56,5 +56,6 @@ SYMLINK-y-include += rte_eth_ctrl.h
>  SYMLINK-y-include += rte_dev_info.h
>  SYMLINK-y-include += rte_flow.h
>  SYMLINK-y-include += rte_flow_driver.h
> +SYMLINK-${CONFIG_RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS}-include += rte_eth_itt.h
> 
>  include $(RTE_SDK)/mk/rte.lib.mk
> diff --git a/lib/librte_ether/rte_eth_itt.h b/lib/librte_ether/rte_eth_itt.h
> new file mode 100644
> index 0000000..e7984fb
> --- /dev/null
> +++ b/lib/librte_ether/rte_eth_itt.h
> @@ -0,0 +1,69 @@
> +#ifndef _RTE_ETH_ITT_H_
> +#define _RTE_ETH_ITT_H_
> +
> +#include <ittnotify.h>
> +#include <rte_config.h>
> +
> +#define ITT_MAX_NAME_LEN (100)
> +
> +/**
> + * Auxiliary ITT structure belonging to port and using to:
> + *   -  track queue state to determine whether it is wasting loop iterations
> + *   -  begin or end ITT task using task domain and name
> + */
> +struct rte_eth_itt_aux_data {
> +	/**
> +	 * ITT domains for each queue.
> +	 */
> +	__itt_domain *wasted_iteration_itt_domains[RTE_MAX_QUEUES_PER_PORT];
> +	/**
> +	 * ITT task names for each queue.
> +	 */
> +	__itt_string_handle *wasted_iteration_itt_handles[RTE_MAX_QUEUES_PER_PORT];
> +	/**
> +	 * Flags indicating the queues state. Possible values:
> +	 * 1 - queue is wasting iterations, 0 - otherwise.
> +	 */
> +	uint8_t queue_is_wasting_iterations[RTE_MAX_QUEUES_PER_PORT];
> +};
> +
> +/**
> + * The pool of *rte_eth_itt_aux_data* structures.
> + */
> +struct rte_eth_itt_aux_data itt_aux_data[RTE_MAX_ETHPORTS];
> +
> +/**
> + * Initialization of rte_eth_itt_aux_data for a given port.
> + * This function must be invoked when ethernet device is being configured.
> + * Result will be stored in the global array *itt_aux_data*.
> + *
> + * @param port_id
> + *  The port identifier of the Ethernet device.
> + * @param port_name
> + *  The name of the Ethernet device.
> + * @param queue_num
> + *  The number of queues on specified port.
> + */
> +static inline void
> +rte_eth_init_itt(uint8_t port_id, char *port_name, uint8_t queue_num) {
> +	uint16_t q_id;
> +	for (q_id = 0; q_id < queue_num; ++q_id) {
> +		char domain_name[ITT_MAX_NAME_LEN];
> +		snprintf(domain_name, sizeof(domain_name),
> +			"RXBurst.WastedIterations.Port_%s.Queue_%d",
> +			port_name, q_id);
> +		itt_aux_data[port_id].wasted_iteration_itt_domains[q_id]
> +			= __itt_domain_create(domain_name);
> +
> +		char task_name[ITT_MAX_NAME_LEN];
> +		snprintf(task_name, sizeof(task_name),
> +			"port id: %d; queue id: %d",
> +			port_id, q_id);
> +		itt_aux_data[port_id].wasted_iteration_itt_handles[q_id]
> +			= __itt_string_handle_create(task_name);
> +
> +		itt_aux_data[port_id].queue_is_wasting_iterations[q_id] = 0;
> +	}
> +}
> +
> +#endif
> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
> index 81a45c0..9e5ac01 100644
> --- a/lib/librte_ether/rte_ethdev.c
> +++ b/lib/librte_ether/rte_ethdev.c
> @@ -818,6 +818,13 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
>  		return diag;
>  	}
> 
> +#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
> +	/**
> +	* See rte_eth_itt.h to find comments on code below.
> +	*/
> +	rte_eth_init_itt(port_id, dev->data->name, nb_rx_q);
> +#endif
> +
>  	return 0;
>  }
> 
> diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
> index f6e6c74..4ba90d2 100644
> --- a/lib/librte_ether/rte_ethdev.h
> +++ b/lib/librte_ether/rte_ethdev.h
> @@ -186,6 +186,10 @@ extern "C" {
>  #include "rte_eth_ctrl.h"
>  #include "rte_dev_info.h"
> 
> +#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
> +#include "rte_eth_itt.h"
> +#endif
> +
>  struct rte_mbuf;
> 
>  /**
> @@ -2710,6 +2714,28 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
>  	int16_t nb_rx = (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
>  			rx_pkts, nb_pkts);
> 
> +#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
> +	/**
> +	* See rte_eth_itt.h to find comments on code below.
> +	*/
> +	if (unlikely(nb_rx == 0)) {
> +		if (!itt_aux_data[port_id].queue_is_wasting_iterations[queue_id]) {
> +			__itt_task_begin(
> +				itt_aux_data[port_id].wasted_iteration_itt_domains[queue_id],
> +				__itt_null, __itt_null,
> +				itt_aux_data[port_id].wasted_iteration_itt_handles[queue_id]);
> +			itt_aux_data[port_id].queue_is_wasting_iterations[queue_id] = 1;
> +		}
> +	}
> +	else {
> +		if (unlikely(itt_aux_data[port_id].queue_is_wasting_iterations[queue_id])) {
> +			__itt_task_end(
> +				itt_aux_data[port_id].wasted_iteration_itt_domains[queue_id]);
> +			itt_aux_data[port_id].queue_is_wasting_iterations[queue_id] = 0;
> +		}
> +	}
> +#endif
> +
>  #ifdef RTE_ETHDEV_RXTX_CALLBACKS
>  	struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
> 
> --
> 2.7.4
> 
> 
> --------------------------------------------------------------------
> Joint Stock Company Intel A/O
> Registered legal address: Krylatsky Hills Business Park,
> 17 Krylatskaya Str., Bldg 4, Moscow 121614,
> Russian Federation
> 
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH] ether: add support for vtune task tracing
  2017-06-22  9:42 ` Ananyev, Konstantin
@ 2017-06-22 12:12   ` Kurakin, Ilia
  2017-06-22 16:46     ` Galanov, Dmitry
  0 siblings, 1 reply; 22+ messages in thread
From: Kurakin, Ilia @ 2017-06-22 12:12 UTC (permalink / raw)
  To: Ananyev, Konstantin, Galanov, Dmitry; +Cc: dev

Hi Konstantin,

Adding Dmitry to this thread

Ilia

-----Original Message-----
From: Ananyev, Konstantin 
Sent: Thursday, June 22, 2017 12:42 PM
To: Kurakin, Ilia <ilia.kurakin@intel.com>; dev@dpdk.org
Cc: Kurakin, Ilia <ilia.kurakin@intel.com>
Subject: RE: [dpdk-dev] [PATCH] ether: add support for vtune task tracing

Hi Ilia,

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of 
> ilia.kurakin@intel.com
> Sent: Monday, June 19, 2017 6:18 PM
> To: dev@dpdk.org
> Cc: Kurakin, Ilia <ilia.kurakin@intel.com>
> Subject: [dpdk-dev] [PATCH] ether: add support for vtune task tracing
> 
> From: Ilia Kurakin <ilia.kurakin@intel.com>
> 
> The patch adds tracing of loop iterations that yielded no packets in a 
> DPDK application. It is using ITT task API:
>     https://software.intel.com/en-us/node/544206
> 
> We suppose the flow of using this tracing would assume the user has 
> ITT lib and header on his machine and re-build DPDK with additional make parameters:
> 
>     make EXTRA_CFLAGS=-I<path to ittnotify.h>
>          EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"

There are few things that worry me with that patch:
1. We add new config variable and add extra dependency here.
    Usually we try not to do that without really compelling reason.
2. We pollute rte_ethdev with the code that has nothing to do with
     it major functionality.

That makes me wonder why this vtune data collection has to be done inside rx_burst() function?
 Why it can't be done on the application layer, i.e. straight after rx_burst() is finished?
Something like:
n = rte_eth_rx_burst(port, queue, ....); itt_rx_collect_data(port, queue, n, ....); ?

Or as alternative, user can install this vtune collection routine as rx callback function.

Konstantin

> 
> Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>
> ---
>  config/common_base             |  1 +
>  lib/librte_ether/Makefile      |  1 +
>  lib/librte_ether/rte_eth_itt.h | 69 
> ++++++++++++++++++++++++++++++++++++++++++
>  lib/librte_ether/rte_ethdev.c  |  7 +++++  
> lib/librte_ether/rte_ethdev.h  | 26 ++++++++++++++++
>  5 files changed, 104 insertions(+)
>  create mode 100644 lib/librte_ether/rte_eth_itt.h
> 
> diff --git a/config/common_base b/config/common_base index 
> f6aafd1..60d8b63 100644
> --- a/config/common_base
> +++ b/config/common_base
> @@ -135,6 +135,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
>  CONFIG_RTE_LIBRTE_IEEE1588=n
>  CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
>  CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
> +CONFIG_RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS=n
> 
>  #
>  # Turn off Tx preparation stage
> diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile 
> index 93fdde1..c10153a 100644
> --- a/lib/librte_ether/Makefile
> +++ b/lib/librte_ether/Makefile
> @@ -56,5 +56,6 @@ SYMLINK-y-include += rte_eth_ctrl.h  
> SYMLINK-y-include += rte_dev_info.h  SYMLINK-y-include += rte_flow.h  
> SYMLINK-y-include += rte_flow_driver.h
> +SYMLINK-${CONFIG_RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS}-include += 
> +rte_eth_itt.h
> 
>  include $(RTE_SDK)/mk/rte.lib.mk
> diff --git a/lib/librte_ether/rte_eth_itt.h 
> b/lib/librte_ether/rte_eth_itt.h new file mode 100644 index 
> 0000000..e7984fb
> --- /dev/null
> +++ b/lib/librte_ether/rte_eth_itt.h
> @@ -0,0 +1,69 @@
> +#ifndef _RTE_ETH_ITT_H_
> +#define _RTE_ETH_ITT_H_
> +
> +#include <ittnotify.h>
> +#include <rte_config.h>
> +
> +#define ITT_MAX_NAME_LEN (100)
> +
> +/**
> + * Auxiliary ITT structure belonging to port and using to:
> + *   -  track queue state to determine whether it is wasting loop iterations
> + *   -  begin or end ITT task using task domain and name
> + */
> +struct rte_eth_itt_aux_data {
> +	/**
> +	 * ITT domains for each queue.
> +	 */
> +	__itt_domain *wasted_iteration_itt_domains[RTE_MAX_QUEUES_PER_PORT];
> +	/**
> +	 * ITT task names for each queue.
> +	 */
> +	__itt_string_handle *wasted_iteration_itt_handles[RTE_MAX_QUEUES_PER_PORT];
> +	/**
> +	 * Flags indicating the queues state. Possible values:
> +	 * 1 - queue is wasting iterations, 0 - otherwise.
> +	 */
> +	uint8_t queue_is_wasting_iterations[RTE_MAX_QUEUES_PER_PORT];
> +};
> +
> +/**
> + * The pool of *rte_eth_itt_aux_data* structures.
> + */
> +struct rte_eth_itt_aux_data itt_aux_data[RTE_MAX_ETHPORTS];
> +
> +/**
> + * Initialization of rte_eth_itt_aux_data for a given port.
> + * This function must be invoked when ethernet device is being configured.
> + * Result will be stored in the global array *itt_aux_data*.
> + *
> + * @param port_id
> + *  The port identifier of the Ethernet device.
> + * @param port_name
> + *  The name of the Ethernet device.
> + * @param queue_num
> + *  The number of queues on specified port.
> + */
> +static inline void
> +rte_eth_init_itt(uint8_t port_id, char *port_name, uint8_t queue_num) {
> +	uint16_t q_id;
> +	for (q_id = 0; q_id < queue_num; ++q_id) {
> +		char domain_name[ITT_MAX_NAME_LEN];
> +		snprintf(domain_name, sizeof(domain_name),
> +			"RXBurst.WastedIterations.Port_%s.Queue_%d",
> +			port_name, q_id);
> +		itt_aux_data[port_id].wasted_iteration_itt_domains[q_id]
> +			= __itt_domain_create(domain_name);
> +
> +		char task_name[ITT_MAX_NAME_LEN];
> +		snprintf(task_name, sizeof(task_name),
> +			"port id: %d; queue id: %d",
> +			port_id, q_id);
> +		itt_aux_data[port_id].wasted_iteration_itt_handles[q_id]
> +			= __itt_string_handle_create(task_name);
> +
> +		itt_aux_data[port_id].queue_is_wasting_iterations[q_id] = 0;
> +	}
> +}
> +
> +#endif
> diff --git a/lib/librte_ether/rte_ethdev.c 
> b/lib/librte_ether/rte_ethdev.c index 81a45c0..9e5ac01 100644
> --- a/lib/librte_ether/rte_ethdev.c
> +++ b/lib/librte_ether/rte_ethdev.c
> @@ -818,6 +818,13 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
>  		return diag;
>  	}
> 
> +#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
> +	/**
> +	* See rte_eth_itt.h to find comments on code below.
> +	*/
> +	rte_eth_init_itt(port_id, dev->data->name, nb_rx_q); #endif
> +
>  	return 0;
>  }
> 
> diff --git a/lib/librte_ether/rte_ethdev.h 
> b/lib/librte_ether/rte_ethdev.h index f6e6c74..4ba90d2 100644
> --- a/lib/librte_ether/rte_ethdev.h
> +++ b/lib/librte_ether/rte_ethdev.h
> @@ -186,6 +186,10 @@ extern "C" {
>  #include "rte_eth_ctrl.h"
>  #include "rte_dev_info.h"
> 
> +#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
> +#include "rte_eth_itt.h"
> +#endif
> +
>  struct rte_mbuf;
> 
>  /**
> @@ -2710,6 +2714,28 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
>  	int16_t nb_rx = (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
>  			rx_pkts, nb_pkts);
> 
> +#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
> +	/**
> +	* See rte_eth_itt.h to find comments on code below.
> +	*/
> +	if (unlikely(nb_rx == 0)) {
> +		if (!itt_aux_data[port_id].queue_is_wasting_iterations[queue_id]) {
> +			__itt_task_begin(
> +				itt_aux_data[port_id].wasted_iteration_itt_domains[queue_id],
> +				__itt_null, __itt_null,
> +				itt_aux_data[port_id].wasted_iteration_itt_handles[queue_id]);
> +			itt_aux_data[port_id].queue_is_wasting_iterations[queue_id] = 1;
> +		}
> +	}
> +	else {
> +		if (unlikely(itt_aux_data[port_id].queue_is_wasting_iterations[queue_id])) {
> +			__itt_task_end(
> +				itt_aux_data[port_id].wasted_iteration_itt_domains[queue_id]);
> +			itt_aux_data[port_id].queue_is_wasting_iterations[queue_id] = 0;
> +		}
> +	}
> +#endif
> +
>  #ifdef RTE_ETHDEV_RXTX_CALLBACKS
>  	struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
> 
> --
> 2.7.4
> 
> 
> --------------------------------------------------------------------
> Joint Stock Company Intel A/O
> Registered legal address: Krylatsky Hills Business Park,
> 17 Krylatskaya Str., Bldg 4, Moscow 121614, Russian Federation
> 
> This e-mail and any attachments may contain confidential material for 
> the sole use of the intended recipient(s). Any review or distribution 
> by others is strictly prohibited. If you are not the intended 
> recipient, please contact the sender and delete all copies.


--------------------------------------------------------------------
Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park,
17 Krylatskaya Str., Bldg 4, Moscow 121614,
Russian Federation

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH] ether: add support for vtune task tracing
  2017-06-22 12:12   ` Kurakin, Ilia
@ 2017-06-22 16:46     ` Galanov, Dmitry
  0 siblings, 0 replies; 22+ messages in thread
From: Galanov, Dmitry @ 2017-06-22 16:46 UTC (permalink / raw)
  To: Kurakin, Ilia, Ananyev, Konstantin; +Cc: dev

Hi Konstantin,
We are planning to use Intel ITT https://software.intel.com/en-us/node/544195  for tracing wasted cycle iterations.
The dependency on that library will only be required if user decides to enable that tracing by setting that in CONFIG_RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS=y. We currently assume in this case user has itt libraries on his machine, otherwise we should somehow include it with DPDK in the form of sources or prebuilt binaries.
We are using ITT because it gives better than simple txt trace performance, compression and is already used in various Intel's open-sourced products (TBB, OpenCL)
Asking a user to modify code of application is inconvenient because we should somehow educate them to do it that is decreasing chances that users will try this functionality. It's much easier if a user gets wasted cycle tracing just by recompiling the source code with an option.

Thanks, Dmitry

-----Original Message-----
From: Kurakin, Ilia 
Sent: Thursday, June 22, 2017 3:13 PM
To: Ananyev, Konstantin <konstantin.ananyev@intel.com>; Galanov, Dmitry <dmitry.galanov@intel.com>
Cc: dev@dpdk.org
Subject: RE: [dpdk-dev] [PATCH] ether: add support for vtune task tracing

Hi Konstantin,

Adding Dmitry to this thread

Ilia

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, June 22, 2017 12:42 PM
To: Kurakin, Ilia <ilia.kurakin@intel.com>; dev@dpdk.org\
Cc: Kurakin, Ilia <ilia.kurakin@intel.com>
Subject: RE: [dpdk-dev] [PATCH] ether: add support for vtune task tracing

Hi Ilia,

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of 
> ilia.kurakin@intel.com
> Sent: Monday, June 19, 2017 6:18 PM
> To: dev@dpdk.org
> Cc: Kurakin, Ilia <ilia.kurakin@intel.com>
> Subject: [dpdk-dev] [PATCH] ether: add support for vtune task tracing
> 
> From: Ilia Kurakin <ilia.kurakin@intel.com>
> 
> The patch adds tracing of loop iterations that yielded no packets in a 
> DPDK application. It is using ITT task API:
>     https://software.intel.com/en-us/node/544206
> 
> We suppose the flow of using this tracing would assume the user has 
> ITT lib and header on his machine and re-build DPDK with additional make parameters:
> 
>     make EXTRA_CFLAGS=-I<path to ittnotify.h>
>          EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"

There are few things that worry me with that patch:
1. We add new config variable and add extra dependency here.
    Usually we try not to do that without really compelling reason.
2. We pollute rte_ethdev with the code that has nothing to do with
     it major functionality.

That makes me wonder why this vtune data collection has to be done inside rx_burst() function?
 Why it can't be done on the application layer, i.e. straight after rx_burst() is finished?
Something like:
n = rte_eth_rx_burst(port, queue, ....); itt_rx_collect_data(port, queue, n, ....); ?

Or as alternative, user can install this vtune collection routine as rx callback function.

Konstantin

> 
> Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>
> ---
>  config/common_base             |  1 +
>  lib/librte_ether/Makefile      |  1 +
>  lib/librte_ether/rte_eth_itt.h | 69
> ++++++++++++++++++++++++++++++++++++++++++
>  lib/librte_ether/rte_ethdev.c  |  7 +++++ 
> lib/librte_ether/rte_ethdev.h  | 26 ++++++++++++++++
>  5 files changed, 104 insertions(+)
>  create mode 100644 lib/librte_ether/rte_eth_itt.h
> 
> diff --git a/config/common_base b/config/common_base index
> f6aafd1..60d8b63 100644
> --- a/config/common_base
> +++ b/config/common_base
> @@ -135,6 +135,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
>  CONFIG_RTE_LIBRTE_IEEE1588=n
>  CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
>  CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
> +CONFIG_RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS=n
> 
>  #
>  # Turn off Tx preparation stage
> diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile 
> index 93fdde1..c10153a 100644
> --- a/lib/librte_ether/Makefile
> +++ b/lib/librte_ether/Makefile
> @@ -56,5 +56,6 @@ SYMLINK-y-include += rte_eth_ctrl.h 
> SYMLINK-y-include += rte_dev_info.h  SYMLINK-y-include += rte_flow.h 
> SYMLINK-y-include += rte_flow_driver.h
> +SYMLINK-${CONFIG_RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS}-include += 
> +rte_eth_itt.h
> 
>  include $(RTE_SDK)/mk/rte.lib.mk
> diff --git a/lib/librte_ether/rte_eth_itt.h 
> b/lib/librte_ether/rte_eth_itt.h new file mode 100644 index 
> 0000000..e7984fb
> --- /dev/null
> +++ b/lib/librte_ether/rte_eth_itt.h
> @@ -0,0 +1,69 @@
> +#ifndef _RTE_ETH_ITT_H_
> +#define _RTE_ETH_ITT_H_
> +
> +#include <ittnotify.h>
> +#include <rte_config.h>
> +
> +#define ITT_MAX_NAME_LEN (100)
> +
> +/**
> + * Auxiliary ITT structure belonging to port and using to:
> + *   -  track queue state to determine whether it is wasting loop iterations
> + *   -  begin or end ITT task using task domain and name
> + */
> +struct rte_eth_itt_aux_data {
> +	/**
> +	 * ITT domains for each queue.
> +	 */
> +	__itt_domain *wasted_iteration_itt_domains[RTE_MAX_QUEUES_PER_PORT];
> +	/**
> +	 * ITT task names for each queue.
> +	 */
> +	__itt_string_handle *wasted_iteration_itt_handles[RTE_MAX_QUEUES_PER_PORT];
> +	/**
> +	 * Flags indicating the queues state. Possible values:
> +	 * 1 - queue is wasting iterations, 0 - otherwise.
> +	 */
> +	uint8_t queue_is_wasting_iterations[RTE_MAX_QUEUES_PER_PORT];
> +};
> +
> +/**
> + * The pool of *rte_eth_itt_aux_data* structures.
> + */
> +struct rte_eth_itt_aux_data itt_aux_data[RTE_MAX_ETHPORTS];
> +
> +/**
> + * Initialization of rte_eth_itt_aux_data for a given port.
> + * This function must be invoked when ethernet device is being configured.
> + * Result will be stored in the global array *itt_aux_data*.
> + *
> + * @param port_id
> + *  The port identifier of the Ethernet device.
> + * @param port_name
> + *  The name of the Ethernet device.
> + * @param queue_num
> + *  The number of queues on specified port.
> + */
> +static inline void
> +rte_eth_init_itt(uint8_t port_id, char *port_name, uint8_t queue_num) {
> +	uint16_t q_id;
> +	for (q_id = 0; q_id < queue_num; ++q_id) {
> +		char domain_name[ITT_MAX_NAME_LEN];
> +		snprintf(domain_name, sizeof(domain_name),
> +			"RXBurst.WastedIterations.Port_%s.Queue_%d",
> +			port_name, q_id);
> +		itt_aux_data[port_id].wasted_iteration_itt_domains[q_id]
> +			= __itt_domain_create(domain_name);
> +
> +		char task_name[ITT_MAX_NAME_LEN];
> +		snprintf(task_name, sizeof(task_name),
> +			"port id: %d; queue id: %d",
> +			port_id, q_id);
> +		itt_aux_data[port_id].wasted_iteration_itt_handles[q_id]
> +			= __itt_string_handle_create(task_name);
> +
> +		itt_aux_data[port_id].queue_is_wasting_iterations[q_id] = 0;
> +	}
> +}
> +
> +#endif
> diff --git a/lib/librte_ether/rte_ethdev.c 
> b/lib/librte_ether/rte_ethdev.c index 81a45c0..9e5ac01 100644
> --- a/lib/librte_ether/rte_ethdev.c
> +++ b/lib/librte_ether/rte_ethdev.c
> @@ -818,6 +818,13 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
>  		return diag;
>  	}
> 
> +#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
> +	/**
> +	* See rte_eth_itt.h to find comments on code below.
> +	*/
> +	rte_eth_init_itt(port_id, dev->data->name, nb_rx_q); #endif
> +
>  	return 0;
>  }
> 
> diff --git a/lib/librte_ether/rte_ethdev.h 
> b/lib/librte_ether/rte_ethdev.h index f6e6c74..4ba90d2 100644
> --- a/lib/librte_ether/rte_ethdev.h
> +++ b/lib/librte_ether/rte_ethdev.h
> @@ -186,6 +186,10 @@ extern "C" {
>  #include "rte_eth_ctrl.h"
>  #include "rte_dev_info.h"
> 
> +#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
> +#include "rte_eth_itt.h"
> +#endif
> +
>  struct rte_mbuf;
> 
>  /**
> @@ -2710,6 +2714,28 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
>  	int16_t nb_rx = (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
>  			rx_pkts, nb_pkts);
> 
> +#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
> +	/**
> +	* See rte_eth_itt.h to find comments on code below.
> +	*/
> +	if (unlikely(nb_rx == 0)) {
> +		if (!itt_aux_data[port_id].queue_is_wasting_iterations[queue_id]) {
> +			__itt_task_begin(
> +				itt_aux_data[port_id].wasted_iteration_itt_domains[queue_id],
> +				__itt_null, __itt_null,
> +				itt_aux_data[port_id].wasted_iteration_itt_handles[queue_id]);
> +			itt_aux_data[port_id].queue_is_wasting_iterations[queue_id] = 1;
> +		}
> +	}
> +	else {
> +		if (unlikely(itt_aux_data[port_id].queue_is_wasting_iterations[queue_id])) {
> +			__itt_task_end(
> +				itt_aux_data[port_id].wasted_iteration_itt_domains[queue_id]);
> +			itt_aux_data[port_id].queue_is_wasting_iterations[queue_id] = 0;
> +		}
> +	}
> +#endif
> +
>  #ifdef RTE_ETHDEV_RXTX_CALLBACKS
>  	struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
> 
> --
> 2.7.4
> 
> 
> --------------------------------------------------------------------
> Joint Stock Company Intel A/O
> Registered legal address: Krylatsky Hills Business Park,
> 17 Krylatskaya Str., Bldg 4, Moscow 121614, Russian Federation
> 
> This e-mail and any attachments may contain confidential material for 
> the sole use of the intended recipient(s). Any review or distribution 
> by others is strictly prohibited. If you are not the intended 
> recipient, please contact the sender and delete all copies.


--------------------------------------------------------------------
Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park,
17 Krylatskaya Str., Bldg 4, Moscow 121614,
Russian Federation

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH] ether: add support for vtune task tracing
  2017-06-19 17:18 [dpdk-dev] [PATCH] ether: add support for vtune task tracing ilia.kurakin
  2017-06-22  9:42 ` Ananyev, Konstantin
@ 2017-06-27 13:16 ` ilia.kurakin
  2017-06-30  3:30   ` Jerin Jacob
  2017-07-06 16:42   ` [dpdk-dev] [PATCH v2] " ilia.kurakin
  1 sibling, 2 replies; 22+ messages in thread
From: ilia.kurakin @ 2017-06-27 13:16 UTC (permalink / raw)
  To: dev; +Cc: konstantin.ananyev, keith.wiles, dmitry.galanov, Ilia Kurakin

From: Ilia Kurakin <ilia.kurakin@intel.com>

The patch adds tracing of loop iterations that yielded no packets in a DPDK
application. It is using ITT task API:
    https://software.intel.com/en-us/node/544206

We suppose the flow of using this tracing would assume the user has ITT lib
and header on machine and re-build DPDK with additional make parameters:

    make EXTRA_CFLAGS=-I<path to ittnotify.h>
         EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"

Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>
---
 config/common_base             |   1 +
 lib/librte_ether/Makefile      |   1 +
 lib/librte_ether/rte_eth_itt.h | 102 +++++++++++++++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.c  |   5 ++
 lib/librte_ether/rte_ethdev.h  |  23 ++++++++++
 5 files changed, 132 insertions(+)
 create mode 100644 lib/librte_ether/rte_eth_itt.h

diff --git a/config/common_base b/config/common_base
index f6aafd1..60d8b63 100644
--- a/config/common_base
+++ b/config/common_base
@@ -135,6 +135,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
 CONFIG_RTE_LIBRTE_IEEE1588=n
 CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
 CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
+CONFIG_RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS=n
 
 #
 # Turn off Tx preparation stage
diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile
index 93fdde1..c10153a 100644
--- a/lib/librte_ether/Makefile
+++ b/lib/librte_ether/Makefile
@@ -56,5 +56,6 @@ SYMLINK-y-include += rte_eth_ctrl.h
 SYMLINK-y-include += rte_dev_info.h
 SYMLINK-y-include += rte_flow.h
 SYMLINK-y-include += rte_flow_driver.h
+SYMLINK-${CONFIG_RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS}-include += rte_eth_itt.h
 
 include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/lib/librte_ether/rte_eth_itt.h b/lib/librte_ether/rte_eth_itt.h
new file mode 100644
index 0000000..e661782
--- /dev/null
+++ b/lib/librte_ether/rte_eth_itt.h
@@ -0,0 +1,102 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_ETH_ITT_H_
+#define _RTE_ETH_ITT_H_
+
+#include <ittnotify.h>
+#include <rte_config.h>
+
+#define ITT_MAX_NAME_LEN (100)
+
+/**
+ * Auxiliary ITT structure belonging to port and using to:
+ *   -  track queue state to determine whether it is wasting loop iterations
+ *   -  begin or end ITT task using task domain and name
+ */
+struct rte_eth_itt_aux_data {
+	/**
+	 * ITT domains for each queue.
+	 */
+	__itt_domain *wasted_iter_domains[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * ITT task names for each queue.
+	 */
+	__itt_string_handle *wasted_iter_handles[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * Flags indicating the queues state. Possible values:
+	 * 1 - queue is wasting iterations, 0 - otherwise.
+	 */
+	uint8_t queue_is_wasting_iters[RTE_MAX_QUEUES_PER_PORT];
+};
+
+/**
+ * The pool of *rte_eth_itt_aux_data* structures.
+ */
+struct rte_eth_itt_aux_data itt_aux_data[RTE_MAX_ETHPORTS];
+
+/**
+ * Initialization of rte_eth_itt_aux_data for a given port.
+ * This function must be invoked when ethernet device is being configured.
+ * Result will be stored in the global array *itt_aux_data*.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param port_name
+ *  The name of the Ethernet device.
+ * @param queue_num
+ *  The number of queues on specified port.
+ */
+static inline void
+rte_eth_init_itt(uint8_t port_id, char *port_name, uint8_t queue_num) {
+	uint16_t q_id;
+	for (q_id = 0; q_id < queue_num; ++q_id) {
+		char domain_name[ITT_MAX_NAME_LEN];
+		snprintf(domain_name, sizeof(domain_name),
+			"RXBurst.WastedIterations.Port_%s.Queue_%d",
+			port_name, q_id);
+		itt_aux_data[port_id].wasted_iter_domains[q_id]
+			= __itt_domain_create(domain_name);
+
+		char task_name[ITT_MAX_NAME_LEN];
+		snprintf(task_name, sizeof(task_name),
+			"port id: %d; queue id: %d",
+			port_id, q_id);
+		itt_aux_data[port_id].wasted_iter_handles[q_id]
+			= __itt_string_handle_create(task_name);
+
+		itt_aux_data[port_id].queue_is_wasting_iters[q_id] = 0;
+	}
+}
+
+#endif
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 81a45c0..ebaaf99 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -818,6 +818,11 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 		return diag;
 	}
 
+#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
+	/* See rte_eth_itt.h to find comments on code below. */
+	rte_eth_init_itt(port_id, dev->data->name, nb_rx_q);
+#endif
+
 	return 0;
 }
 
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index f6e6c74..ee7cc42 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -186,6 +186,10 @@ extern "C" {
 #include "rte_eth_ctrl.h"
 #include "rte_dev_info.h"
 
+#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
+#include "rte_eth_itt.h"
+#endif
+
 struct rte_mbuf;
 
 /**
@@ -2710,6 +2714,25 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
 	int16_t nb_rx = (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
 			rx_pkts, nb_pkts);
 
+#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
+	/* See rte_eth_itt.h to find comments on code below. */
+	if (unlikely(nb_rx == 0)) {
+		if (!itt_aux_data[port_id].queue_is_wasting_iters[queue_id]) {
+			__itt_task_begin(
+				itt_aux_data[port_id].wasted_iter_domains[queue_id],
+				__itt_null, __itt_null,
+				itt_aux_data[port_id].wasted_iter_handles[queue_id]);
+			itt_aux_data[port_id].queue_is_wasting_iters[queue_id] = 1;
+		}
+	} else {
+		if (unlikely(itt_aux_data[port_id].queue_is_wasting_iters[queue_id])) {
+			__itt_task_end(
+				itt_aux_data[port_id].wasted_iter_domains[queue_id]);
+			itt_aux_data[port_id].queue_is_wasting_iters[queue_id] = 0;
+		}
+	}
+#endif
+
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
 	struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
 
-- 
2.7.4


--------------------------------------------------------------------
Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park,
17 Krylatskaya Str., Bldg 4, Moscow 121614,
Russian Federation

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH] ether: add support for vtune task tracing
  2017-06-27 13:16 ` ilia.kurakin
@ 2017-06-30  3:30   ` Jerin Jacob
  2017-06-30 10:13     ` Ananyev, Konstantin
  2017-07-06 16:42   ` [dpdk-dev] [PATCH v2] " ilia.kurakin
  1 sibling, 1 reply; 22+ messages in thread
From: Jerin Jacob @ 2017-06-30  3:30 UTC (permalink / raw)
  To: ilia.kurakin; +Cc: dev, konstantin.ananyev, keith.wiles, dmitry.galanov

-----Original Message-----
> Date: Tue, 27 Jun 2017 16:16:01 +0300
> From: ilia.kurakin@intel.com
> To: dev@dpdk.org
> CC: konstantin.ananyev@intel.com, keith.wiles@intel.com,
>  dmitry.galanov@intel.com, Ilia Kurakin <ilia.kurakin@intel.com>
> Subject: [dpdk-dev] [PATCH] ether: add support for vtune task tracing
> X-Mailer: git-send-email 2.7.4
> 
> From: Ilia Kurakin <ilia.kurakin@intel.com>
> 
> diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
> index f6e6c74..ee7cc42 100644
> --- a/lib/librte_ether/rte_ethdev.h
> +++ b/lib/librte_ether/rte_ethdev.h
> @@ -186,6 +186,10 @@ extern "C" {
>  #include "rte_eth_ctrl.h"
>  #include "rte_dev_info.h"
>  
> +#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
> +#include "rte_eth_itt.h"
> +#endif
> +
>  struct rte_mbuf;
>  
>  /**
> @@ -2710,6 +2714,25 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
>  	int16_t nb_rx = (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
>  			rx_pkts, nb_pkts);
>  
> +#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS

If we give the generic name like above then the solution should be generic
and it should not be tightly coupled with itt.

Different architectures may have different profiling tools like x86 has
itt or it is possible to have generic perf based plugin in future.

Considering the above points, IMO, we can not add code in
rte_eth_rx_burst() for each profiling variants. I think, this code can
go in lib/librte_ether/rte_ethdev_profile.c and based on specific
conditional compilation flag(something like RTE_ETHDEV_TRACE_ITT_WASTED_RX_ITERATIONS)
it can register a rx callback.
or any other scheme without directly modifying rte_eth_rx_burst() for
itt based profiling.


> +	/* See rte_eth_itt.h to find comments on code below. */
> +	if (unlikely(nb_rx == 0)) {
> +		if (!itt_aux_data[port_id].queue_is_wasting_iters[queue_id]) {
> +			__itt_task_begin(
> +				itt_aux_data[port_id].wasted_iter_domains[queue_id],
> +				__itt_null, __itt_null,
> +				itt_aux_data[port_id].wasted_iter_handles[queue_id]);
> +			itt_aux_data[port_id].queue_is_wasting_iters[queue_id] = 1;
> +		}
> +	} else {
> +		if (unlikely(itt_aux_data[port_id].queue_is_wasting_iters[queue_id])) {
> +			__itt_task_end(
> +				itt_aux_data[port_id].wasted_iter_domains[queue_id]);
> +			itt_aux_data[port_id].queue_is_wasting_iters[queue_id] = 0;
> +		}
> +	}
> +#endif
> +
>  #ifdef RTE_ETHDEV_RXTX_CALLBACKS
>  	struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
>  
> -- 
> 2.7.4
> 
> 
> --------------------------------------------------------------------
> Joint Stock Company Intel A/O
> Registered legal address: Krylatsky Hills Business Park,
> 17 Krylatskaya Str., Bldg 4, Moscow 121614,
> Russian Federation
> 
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.
> 

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH] ether: add support for vtune task tracing
  2017-06-30  3:30   ` Jerin Jacob
@ 2017-06-30 10:13     ` Ananyev, Konstantin
  0 siblings, 0 replies; 22+ messages in thread
From: Ananyev, Konstantin @ 2017-06-30 10:13 UTC (permalink / raw)
  To: Jerin Jacob, Kurakin, Ilia; +Cc: dev, Wiles, Keith, Galanov, Dmitry



> -----Original Message-----
> From: Jerin Jacob [mailto:jerin.jacob@caviumnetworks.com]
> Sent: Friday, June 30, 2017 4:31 AM
> To: Kurakin, Ilia <ilia.kurakin@intel.com>
> Cc: dev@dpdk.org; Ananyev, Konstantin <konstantin.ananyev@intel.com>; Wiles, Keith <keith.wiles@intel.com>; Galanov, Dmitry
> <dmitry.galanov@intel.com>
> Subject: Re: [dpdk-dev] [PATCH] ether: add support for vtune task tracing
> 
> -----Original Message-----
> > Date: Tue, 27 Jun 2017 16:16:01 +0300
> > From: ilia.kurakin@intel.com
> > To: dev@dpdk.org
> > CC: konstantin.ananyev@intel.com, keith.wiles@intel.com,
> >  dmitry.galanov@intel.com, Ilia Kurakin <ilia.kurakin@intel.com>
> > Subject: [dpdk-dev] [PATCH] ether: add support for vtune task tracing
> > X-Mailer: git-send-email 2.7.4
> >
> > From: Ilia Kurakin <ilia.kurakin@intel.com>
> >
> > diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
> > index f6e6c74..ee7cc42 100644
> > --- a/lib/librte_ether/rte_ethdev.h
> > +++ b/lib/librte_ether/rte_ethdev.h
> > @@ -186,6 +186,10 @@ extern "C" {
> >  #include "rte_eth_ctrl.h"
> >  #include "rte_dev_info.h"
> >
> > +#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
> > +#include "rte_eth_itt.h"
> > +#endif
> > +
> >  struct rte_mbuf;
> >
> >  /**
> > @@ -2710,6 +2714,25 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
> >  	int16_t nb_rx = (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
> >  			rx_pkts, nb_pkts);
> >
> > +#ifdef RTE_ETHDEV_TRACE_WASTED_RX_ITERATIONS
> 
> If we give the generic name like above then the solution should be generic
> and it should not be tightly coupled with itt.
> 
> Different architectures may have different profiling tools like x86 has
> itt or it is possible to have generic perf based plugin in future.
> 
> Considering the above points, IMO, we can not add code in
> rte_eth_rx_burst() for each profiling variants. 

+ 1

>I think, this code can
> go in lib/librte_ether/rte_ethdev_profile.c and based on specific
> conditional compilation flag(something like RTE_ETHDEV_TRACE_ITT_WASTED_RX_ITERATIONS)
> it can register a rx callback.
> or any other scheme without directly modifying rte_eth_rx_burst() for
> itt based profiling.

Or might be even better to have some wrapper function/macro on top of rx_burst():
rx_burst_profle(...) or so.
Then user can either replace rx_burst() with rx_burst_profile() by conditional compilation,
or just call rx_burst_profile() directly.

Konstantin

> 
> 
> > +	/* See rte_eth_itt.h to find comments on code below. */
> > +	if (unlikely(nb_rx == 0)) {
> > +		if (!itt_aux_data[port_id].queue_is_wasting_iters[queue_id]) {
> > +			__itt_task_begin(
> > +				itt_aux_data[port_id].wasted_iter_domains[queue_id],
> > +				__itt_null, __itt_null,
> > +				itt_aux_data[port_id].wasted_iter_handles[queue_id]);
> > +			itt_aux_data[port_id].queue_is_wasting_iters[queue_id] = 1;
> > +		}
> > +	} else {
> > +		if (unlikely(itt_aux_data[port_id].queue_is_wasting_iters[queue_id])) {
> > +			__itt_task_end(
> > +				itt_aux_data[port_id].wasted_iter_domains[queue_id]);
> > +			itt_aux_data[port_id].queue_is_wasting_iters[queue_id] = 0;
> > +		}
> > +	}
> > +#endif
> > +
> >  #ifdef RTE_ETHDEV_RXTX_CALLBACKS
> >  	struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
> >
> > --
> > 2.7.4
> >
> >
> > --------------------------------------------------------------------
> > Joint Stock Company Intel A/O
> > Registered legal address: Krylatsky Hills Business Park,
> > 17 Krylatskaya Str., Bldg 4, Moscow 121614,
> > Russian Federation
> >
> > This e-mail and any attachments may contain confidential material for
> > the sole use of the intended recipient(s). Any review or distribution
> > by others is strictly prohibited. If you are not the intended
> > recipient, please contact the sender and delete all copies.
> >

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH v2] ether: add support for vtune task tracing
  2017-06-27 13:16 ` ilia.kurakin
  2017-06-30  3:30   ` Jerin Jacob
@ 2017-07-06 16:42   ` ilia.kurakin
  2017-07-10 12:30     ` Jerin Jacob
                       ` (2 more replies)
  1 sibling, 3 replies; 22+ messages in thread
From: ilia.kurakin @ 2017-07-06 16:42 UTC (permalink / raw)
  To: dev
  Cc: jerin.jacob, konstantin.ananyev, keith.wiles, dmitry.galanov,
	Ilia Kurakin

From: Ilia Kurakin <ilia.kurakin@intel.com>

The patch adds tracing of loop iterations that yielded no packets in a DPDK
application. It is using ITT task API:
    https://software.intel.com/en-us/node/544206

We suppose the flow of using this tracing would assume the user has ITT lib
and header on machine and re-build DPDK with additional make parameters:

    make EXTRA_CFLAGS=-I<path to ittnotify.h>
         EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"

Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>

---

-V2 change:
    ITT tasks collection is moved to rx callback


 config/common_base                    |   1 +
 lib/librte_ether/Makefile             |   2 +
 lib/librte_ether/rte_ethdev.c         |   9 +++
 lib/librte_ether/rte_ethdev_profile.h | 137 ++++++++++++++++++++++++++++++++++
 4 files changed, 149 insertions(+)
 create mode 100644 lib/librte_ether/rte_ethdev_profile.h

diff --git a/config/common_base b/config/common_base
index 660588a..8795a95 100644
--- a/config/common_base
+++ b/config/common_base
@@ -136,6 +136,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
 CONFIG_RTE_LIBRTE_IEEE1588=n
 CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
 CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
+CONFIG_RTE_ETHDEV_TRACE_ITT_WASTED_RX_ITERATIONS=n
 
 #
 # Turn off Tx preparation stage
diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile
index 93fdde1..4d4017f 100644
--- a/lib/librte_ether/Makefile
+++ b/lib/librte_ether/Makefile
@@ -56,5 +56,7 @@ SYMLINK-y-include += rte_eth_ctrl.h
 SYMLINK-y-include += rte_dev_info.h
 SYMLINK-y-include += rte_flow.h
 SYMLINK-y-include += rte_flow_driver.h
+SYMLINK-${CONFIG_RTE_ETHDEV_TRACE_ITT_WASTED_RX_ITERATIONS}-include \
+	+= rte_ethdev_profile.h
 
 include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 957ae2a..a99eeea 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -68,6 +68,10 @@
 #include "rte_ether.h"
 #include "rte_ethdev.h"
 
+#ifdef RTE_ETHDEV_TRACE_ITT_WASTED_RX_ITERATIONS
+#include "rte_ethdev_profile.h"
+#endif
+
 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
 static struct rte_eth_dev_data *rte_eth_dev_data;
@@ -825,6 +829,11 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 		return diag;
 	}
 
+#ifdef RTE_ETHDEV_TRACE_ITT_WASTED_RX_ITERATIONS
+	/* See rte_ethdev_profile.h to find comments on code below. */
+	rte_eth_init_itt(port_id, dev->data->name, nb_rx_q);
+#endif
+
 	return 0;
 }
 
diff --git a/lib/librte_ether/rte_ethdev_profile.h b/lib/librte_ether/rte_ethdev_profile.h
new file mode 100644
index 0000000..95d49e9
--- /dev/null
+++ b/lib/librte_ether/rte_ethdev_profile.h
@@ -0,0 +1,137 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_ETHDEV_PROFILE_H_
+#define _RTE_ETHDEV_PROFILE_H_
+
+#include <rte_config.h>
+#include <rte_ethdev.h>
+#include <ittnotify.h>
+
+#define ITT_MAX_NAME_LEN (100)
+
+/**
+ * Auxiliary ITT structure belonging to port and using to:
+ *   -  track queue state to determine whether it is wasting loop iterations
+ *   -  begin or end ITT task using task domain and name
+ */
+struct rte_eth_itt_aux_data {
+	/**
+	 * ITT domains for each queue.
+	 */
+	__itt_domain *wasted_iter_domains[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * ITT task names for each queue.
+	 */
+	__itt_string_handle *wasted_iter_handles[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * Flags indicating the queues state. Possible values:
+	 * 1 - queue is wasting iterations, 0 - otherwise.
+	 */
+	uint8_t queue_is_wasting_iters[RTE_MAX_QUEUES_PER_PORT];
+};
+
+/**
+ * The pool of *rte_eth_itt_aux_data* structures.
+ */
+struct rte_eth_itt_aux_data itt_aux_data[RTE_MAX_ETHPORTS];
+
+
+/**
+ * This callback function manages ITT tasks collection on given port and queue.
+ * It must be registered with rte_eth_add_rx_callback() to be called from
+ * rte_eth_rx_burst(). To find more comments see rte_rx_callback_fn function
+ * type declaration.
+ */
+static uint16_t
+collect_itt_rx_burst_cb(uint8_t port_id, uint16_t queue_id,
+	__rte_unused struct rte_mbuf *pkts[], uint16_t nb_pkts,
+	__rte_unused uint16_t max_pkts, __rte_unused void *user_param)
+{
+	if (unlikely(nb_pkts == 0)) {
+		if (!itt_aux_data[port_id].queue_is_wasting_iters[queue_id]) {
+			__itt_task_begin(
+				itt_aux_data[port_id].wasted_iter_domains[queue_id],
+				__itt_null, __itt_null,
+				itt_aux_data[port_id].wasted_iter_handles[queue_id]);
+			itt_aux_data[port_id].queue_is_wasting_iters[queue_id] = 1;
+		}
+	} else {
+		if (unlikely(itt_aux_data[port_id].queue_is_wasting_iters[queue_id])) {
+			__itt_task_end(
+				itt_aux_data[port_id].wasted_iter_domains[queue_id]);
+			itt_aux_data[port_id].queue_is_wasting_iters[queue_id] = 0;
+		}
+	}
+	return nb_pkts;
+}
+
+/**
+ * Initialization of rte_eth_itt_aux_data for a given port.
+ * This function must be invoked when ethernet device is being configured.
+ * Result will be stored in the global array *itt_aux_data*.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param port_name
+ *  The name of the Ethernet device.
+ * @param queue_num
+ *  The number of queues on specified port.
+ */
+static inline void
+rte_eth_init_itt(uint8_t port_id, char *port_name, uint8_t queue_num)
+{
+	uint16_t q_id;
+	for (q_id = 0; q_id < queue_num; ++q_id) {
+		char domain_name[ITT_MAX_NAME_LEN];
+		snprintf(domain_name, sizeof(domain_name),
+			"RXBurst.WastedIterations.Port_%s.Queue_%d",
+			port_name, q_id);
+		itt_aux_data[port_id].wasted_iter_domains[q_id]
+			= __itt_domain_create(domain_name);
+
+		char task_name[ITT_MAX_NAME_LEN];
+		snprintf(task_name, sizeof(task_name),
+			"port id: %d; queue id: %d",
+			port_id, q_id);
+		itt_aux_data[port_id].wasted_iter_handles[q_id]
+			= __itt_string_handle_create(task_name);
+
+		itt_aux_data[port_id].queue_is_wasting_iters[q_id] = 0;
+
+		rte_eth_add_rx_callback(
+			port_id, q_id, collect_itt_rx_burst_cb, NULL);
+	}
+}
+
+#endif
-- 
2.7.4


--------------------------------------------------------------------
Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park,
17 Krylatskaya Str., Bldg 4, Moscow 121614,
Russian Federation

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH v2] ether: add support for vtune task tracing
  2017-07-06 16:42   ` [dpdk-dev] [PATCH v2] " ilia.kurakin
@ 2017-07-10 12:30     ` Jerin Jacob
  2017-07-11 17:24     ` [dpdk-dev] [PATCH v3] The patch adds tracing of loop iterations that yielded no packets in a DPDK application. It is using ITT task API: https://software.intel.com/en-us/node/544206 ilia.kurakin
  2017-07-11 17:48     ` [dpdk-dev] [PATCH v3] ether: add support for vtune task tracing ilia.kurakin
  2 siblings, 0 replies; 22+ messages in thread
From: Jerin Jacob @ 2017-07-10 12:30 UTC (permalink / raw)
  To: ilia.kurakin; +Cc: dev, konstantin.ananyev, keith.wiles, dmitry.galanov

-----Original Message-----
> Date: Thu, 6 Jul 2017 19:42:52 +0300
> From: ilia.kurakin@intel.com
> To: dev@dpdk.org
> CC: jerin.jacob@caviumnetworks.com, konstantin.ananyev@intel.com,
>  keith.wiles@intel.com, dmitry.galanov@intel.com, Ilia Kurakin
>  <ilia.kurakin@intel.com>
> Subject: [PATCH v2] ether: add support for vtune task tracing
> X-Mailer: git-send-email 2.7.4
> 
> From: Ilia Kurakin <ilia.kurakin@intel.com>
> 
> The patch adds tracing of loop iterations that yielded no packets in a DPDK
> application. It is using ITT task API:
>     https://software.intel.com/en-us/node/544206
> 
> We suppose the flow of using this tracing would assume the user has ITT lib
> and header on machine and re-build DPDK with additional make parameters:
> 
>     make EXTRA_CFLAGS=-I<path to ittnotify.h>
>          EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"
> 
> Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>
> 
> ---
> 
> -V2 change:
>     ITT tasks collection is moved to rx callback
> 
> 
>  config/common_base                    |   1 +
>  lib/librte_ether/Makefile             |   2 +
>  lib/librte_ether/rte_ethdev.c         |   9 +++
>  lib/librte_ether/rte_ethdev_profile.h | 137 ++++++++++++++++++++++++++++++++++

Please create rte_ethdev_profile.c for the actual source code.

>  4 files changed, 149 insertions(+)
>  create mode 100644 lib/librte_ether/rte_ethdev_profile.h
> 
> diff --git a/config/common_base b/config/common_base
> index 660588a..8795a95 100644
> --- a/config/common_base
> +++ b/config/common_base
> @@ -136,6 +136,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
>  CONFIG_RTE_LIBRTE_IEEE1588=n
>  CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
>  CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
> +CONFIG_RTE_ETHDEV_TRACE_ITT_WASTED_RX_ITERATIONS=n

Should we change to CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
as its going to under rte_ethdev_profile.c

>  
>  #
>  # Turn off Tx preparation stage
> diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile
> index 93fdde1..4d4017f 100644
> --- a/lib/librte_ether/Makefile
> +++ b/lib/librte_ether/Makefile
> @@ -56,5 +56,7 @@ SYMLINK-y-include += rte_eth_ctrl.h
>  SYMLINK-y-include += rte_dev_info.h
>  SYMLINK-y-include += rte_flow.h
>  SYMLINK-y-include += rte_flow_driver.h
> +SYMLINK-${CONFIG_RTE_ETHDEV_TRACE_ITT_WASTED_RX_ITERATIONS}-include \
> +	+= rte_ethdev_profile.h

With your current scheme,  you don't need to expose this header to
application as application is not directly including it.

One option is, Wherever there is reference to this header file in ethdev library, you
can update the CFLAGS in lib/librte_ether/Makefile

>  
>  include $(RTE_SDK)/mk/rte.lib.mk
> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
> index 957ae2a..a99eeea 100644
> --- a/lib/librte_ether/rte_ethdev.c
> +++ b/lib/librte_ether/rte_ethdev.c
> @@ -68,6 +68,10 @@
>  #include "rte_ether.h"
>  #include "rte_ethdev.h"
>  
> +#ifdef RTE_ETHDEV_TRACE_ITT_WASTED_RX_ITERATIONS

You can avoid conditional compilation here by including
rte_ethdev_profile.h always and ifdef in the rte_ethdev_profile.c
source code. With that scheme, rte_ethdev.c will be clean.

> +#include "rte_ethdev_profile.h"
> +#endif
> +
>  static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
>  struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
>  static struct rte_eth_dev_data *rte_eth_dev_data;
> @@ -825,6 +829,11 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
>  		return diag;
>  	}
>  
> +#ifdef RTE_ETHDEV_TRACE_ITT_WASTED_RX_ITERATIONS

Same as above.

Call a generic function from here say(rte_eth_rx_profile_init()) and
add ifdef in rte_ethdev_profile.c

> +	/* See rte_ethdev_profile.h to find comments on code below. */
> +	rte_eth_init_itt(port_id, dev->data->name, nb_rx_q);
> +#endif
> +
>  	return 0;
>  }
>  

Other than the above comments, it looks good to me.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH v3] The patch adds tracing of loop iterations that yielded no packets in a DPDK application. It is using ITT task API: https://software.intel.com/en-us/node/544206
  2017-07-06 16:42   ` [dpdk-dev] [PATCH v2] " ilia.kurakin
  2017-07-10 12:30     ` Jerin Jacob
@ 2017-07-11 17:24     ` ilia.kurakin
  2017-07-11 17:48     ` [dpdk-dev] [PATCH v3] ether: add support for vtune task tracing ilia.kurakin
  2 siblings, 0 replies; 22+ messages in thread
From: ilia.kurakin @ 2017-07-11 17:24 UTC (permalink / raw)
  To: dev
  Cc: jerin.jacob, konstantin.ananyev, keith.wiles, dmitry.galanov,
	Ilia Kurakin

From: Ilia Kurakin <ilia.kurakin@intel.com>

We suppose the flow of using this tracing would assume the user has ITT lib
and header on machine and re-build DPDK with additional make parameters:

    make EXTRA_CFLAGS=-I<path to ittnotify.h>
         EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"

Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>

---

-V2 change:
    ITT tasks collection is moved to rx callback

-V3 change:
    rte_ethdev_profile.c created, all profile specific code moved there.

    Added generic profile function


 config/common_base                    |   1 +
 lib/librte_ether/Makefile             |   1 +
 lib/librte_ether/rte_ethdev.c         |   4 +
 lib/librte_ether/rte_ethdev_profile.c | 150 ++++++++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev_profile.h |  51 ++++++++++++
 5 files changed, 207 insertions(+)
 create mode 100644 lib/librte_ether/rte_ethdev_profile.c
 create mode 100644 lib/librte_ether/rte_ethdev_profile.h

diff --git a/config/common_base b/config/common_base
index 8ae6e92..dda51db 100644
--- a/config/common_base
+++ b/config/common_base
@@ -136,6 +136,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
 CONFIG_RTE_LIBRTE_IEEE1588=n
 CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
 CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
+CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS=n
 
 #
 # Turn off Tx preparation stage
diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile
index 93fdde1..3c86ec6 100644
--- a/lib/librte_ether/Makefile
+++ b/lib/librte_ether/Makefile
@@ -45,6 +45,7 @@ LIBABIVER := 6
 
 SRCS-y += rte_ethdev.c
 SRCS-y += rte_flow.c
+SRCS-y += rte_ethdev_profile.c
 
 #
 # Export include files
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 76179fd..f4ec119 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -67,6 +67,7 @@
 
 #include "rte_ether.h"
 #include "rte_ethdev.h"
+#include "rte_ethdev_profile.h"
 
 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
@@ -825,6 +826,9 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 		return diag;
 	}
 
+	/* See rte_ethdev_profile.h to find comments on code below. */
+	rte_eth_rx_profile_init(port_id, dev);
+
 	return 0;
 }
 
diff --git a/lib/librte_ether/rte_ethdev_profile.c b/lib/librte_ether/rte_ethdev_profile.c
new file mode 100644
index 0000000..029fbba
--- /dev/null
+++ b/lib/librte_ether/rte_ethdev_profile.c
@@ -0,0 +1,150 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "rte_ethdev_profile.h"
+
+/**
+ * This conditional block is responsible for RX queues profiling using the
+ * Instrumentation and Tracing Technology (ITT) API, employed by the
+ * Intel VTune TM Amplifier.
+ */
+#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
+
+#include <rte_config.h>
+#include <ittnotify.h>
+
+#define ITT_MAX_NAME_LEN (100)
+
+/**
+ * Auxiliary ITT structure belonging to port and using to:
+ *   -  track queue state to determine whether it is wasting loop iterations
+ *   -  begin or end ITT task using task domain and name
+ */
+struct rte_eth_itt_aux_data {
+	/**
+	 * ITT domains for each queue.
+	 */
+	__itt_domain *wasted_iter_domains[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * ITT task names for each queue.
+	 */
+	__itt_string_handle *wasted_iter_handles[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * Flags indicating the queues state. Possible values:
+	 * 1 - queue is wasting iterations, 0 - otherwise.
+	 */
+	uint8_t queue_is_wasting_iters[RTE_MAX_QUEUES_PER_PORT];
+};
+
+/**
+ * The pool of *rte_eth_itt_aux_data* structures.
+ */
+struct rte_eth_itt_aux_data itt_aux_data[RTE_MAX_ETHPORTS];
+
+
+/**
+ * This callback function manages ITT tasks collection on given port and queue.
+ * It must be registered with rte_eth_add_rx_callback() to be called from
+ * rte_eth_rx_burst(). To find more comments see rte_rx_callback_fn function
+ * type declaration.
+ */
+static uint16_t
+collect_itt_rx_burst_cb(uint8_t port_id, uint16_t queue_id,
+	__rte_unused struct rte_mbuf *pkts[], uint16_t nb_pkts,
+	__rte_unused uint16_t max_pkts, __rte_unused void *user_param)
+{
+	if (unlikely(nb_pkts == 0)) {
+		if (!itt_aux_data[port_id].queue_is_wasting_iters[queue_id]) {
+			__itt_task_begin(
+				itt_aux_data[port_id].wasted_iter_domains[queue_id],
+				__itt_null, __itt_null,
+				itt_aux_data[port_id].wasted_iter_handles[queue_id]);
+			itt_aux_data[port_id].queue_is_wasting_iters[queue_id] = 1;
+		}
+	} else {
+		if (unlikely(itt_aux_data[port_id].queue_is_wasting_iters[queue_id])) {
+			__itt_task_end(
+				itt_aux_data[port_id].wasted_iter_domains[queue_id]);
+			itt_aux_data[port_id].queue_is_wasting_iters[queue_id] = 0;
+		}
+	}
+	return nb_pkts;
+}
+
+/**
+ * Initialization of rte_eth_itt_aux_data for a given port.
+ * This function must be invoked when ethernet device is being configured.
+ * Result will be stored in the global array *itt_aux_data*.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param port_name
+ *  The name of the Ethernet device.
+ * @param rx_queue_num
+ *  The number of RX queues on specified port.
+ */
+static inline void
+rte_eth_init_itt(uint8_t port_id, char *port_name, uint8_t rx_queue_num)
+{
+	uint16_t q_id;
+	for (q_id = 0; q_id < rx_queue_num; ++q_id) {
+		char domain_name[ITT_MAX_NAME_LEN];
+		snprintf(domain_name, sizeof(domain_name),
+			"RXBurst.WastedIterations.Port_%s.Queue_%d",
+			port_name, q_id);
+		itt_aux_data[port_id].wasted_iter_domains[q_id]
+			= __itt_domain_create(domain_name);
+
+		char task_name[ITT_MAX_NAME_LEN];
+		snprintf(task_name, sizeof(task_name),
+			"port id: %d; queue id: %d",
+			port_id, q_id);
+		itt_aux_data[port_id].wasted_iter_handles[q_id]
+			= __itt_string_handle_create(task_name);
+
+		itt_aux_data[port_id].queue_is_wasting_iters[q_id] = 0;
+
+		rte_eth_add_rx_callback(
+			port_id, q_id, collect_itt_rx_burst_cb, NULL);
+	}
+}
+#endif /* RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS */
+
+void
+rte_eth_rx_profile_init(__rte_unused uint8_t port_id,
+	__rte_unused struct rte_eth_dev *dev)
+{
+#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
+	rte_eth_init_itt(port_id, dev->data->name, dev->data->nb_rx_queues);
+#endif
+}
diff --git a/lib/librte_ether/rte_ethdev_profile.h b/lib/librte_ether/rte_ethdev_profile.h
new file mode 100644
index 0000000..503f136
--- /dev/null
+++ b/lib/librte_ether/rte_ethdev_profile.h
@@ -0,0 +1,51 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_ETHDEV_PROFILE_H_
+#define _RTE_ETHDEV_PROFILE_H_
+
+#include "rte_ethdev.h"
+
+/**
+ * Initialization of profiling RX queues for Ethernet device. Implementation of
+ * this function depends on chosen profiling method, defined in configs.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param dev
+ *  Pointer to struct rte_eth_dev corresponding to given port_id.
+*/
+void
+rte_eth_rx_profile_init(uint8_t port_id, struct rte_eth_dev *dev);
+
+#endif
-- 
2.7.4


--------------------------------------------------------------------
Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park,
17 Krylatskaya Str., Bldg 4, Moscow 121614,
Russian Federation

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH v3] ether: add support for vtune task tracing
  2017-07-06 16:42   ` [dpdk-dev] [PATCH v2] " ilia.kurakin
  2017-07-10 12:30     ` Jerin Jacob
  2017-07-11 17:24     ` [dpdk-dev] [PATCH v3] The patch adds tracing of loop iterations that yielded no packets in a DPDK application. It is using ITT task API: https://software.intel.com/en-us/node/544206 ilia.kurakin
@ 2017-07-11 17:48     ` ilia.kurakin
  2017-07-14  5:45       ` Jerin Jacob
  2017-07-17 17:15       ` [dpdk-dev] [PATCH v4] " ilia.kurakin
  2 siblings, 2 replies; 22+ messages in thread
From: ilia.kurakin @ 2017-07-11 17:48 UTC (permalink / raw)
  To: dev
  Cc: jerin.jacob, konstantin.ananyev, keith.wiles, dmitry.galanov,
	Ilia Kurakin

From: Ilia Kurakin <ilia.kurakin@intel.com>

The patch adds tracing of loop iterations that yielded no packets in a DPDK
application. It is using ITT task API:
    https://software.intel.com/en-us/node/544206

We suppose the flow of using this tracing would assume the user has ITT lib
and header on machine and re-build DPDK with additional make parameters:

    make EXTRA_CFLAGS=-I<path to ittnotify.h>
         EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"

Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>

---

-V2 change:
    ITT tasks collection is moved to rx callback

-V3 change:
    rte_ethdev_profile.c created, all profile specific code moved there.

    Added generic profile function


 config/common_base                    |   1 +
 lib/librte_ether/Makefile             |   1 +
 lib/librte_ether/rte_ethdev.c         |   4 +
 lib/librte_ether/rte_ethdev_profile.c | 150 ++++++++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev_profile.h |  51 ++++++++++++
 5 files changed, 207 insertions(+)
 create mode 100644 lib/librte_ether/rte_ethdev_profile.c
 create mode 100644 lib/librte_ether/rte_ethdev_profile.h

diff --git a/config/common_base b/config/common_base
index 8ae6e92..dda51db 100644
--- a/config/common_base
+++ b/config/common_base
@@ -136,6 +136,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
 CONFIG_RTE_LIBRTE_IEEE1588=n
 CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
 CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
+CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS=n
 
 #
 # Turn off Tx preparation stage
diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile
index 93fdde1..3c86ec6 100644
--- a/lib/librte_ether/Makefile
+++ b/lib/librte_ether/Makefile
@@ -45,6 +45,7 @@ LIBABIVER := 6
 
 SRCS-y += rte_ethdev.c
 SRCS-y += rte_flow.c
+SRCS-y += rte_ethdev_profile.c
 
 #
 # Export include files
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 76179fd..f4ec119 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -67,6 +67,7 @@
 
 #include "rte_ether.h"
 #include "rte_ethdev.h"
+#include "rte_ethdev_profile.h"
 
 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
@@ -825,6 +826,9 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 		return diag;
 	}
 
+	/* See rte_ethdev_profile.h to find comments on code below. */
+	rte_eth_rx_profile_init(port_id, dev);
+
 	return 0;
 }
 
diff --git a/lib/librte_ether/rte_ethdev_profile.c b/lib/librte_ether/rte_ethdev_profile.c
new file mode 100644
index 0000000..029fbba
--- /dev/null
+++ b/lib/librte_ether/rte_ethdev_profile.c
@@ -0,0 +1,150 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "rte_ethdev_profile.h"
+
+/**
+ * This conditional block is responsible for RX queues profiling using the
+ * Instrumentation and Tracing Technology (ITT) API, employed by the
+ * Intel VTune TM Amplifier.
+ */
+#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
+
+#include <rte_config.h>
+#include <ittnotify.h>
+
+#define ITT_MAX_NAME_LEN (100)
+
+/**
+ * Auxiliary ITT structure belonging to port and using to:
+ *   -  track queue state to determine whether it is wasting loop iterations
+ *   -  begin or end ITT task using task domain and name
+ */
+struct rte_eth_itt_aux_data {
+	/**
+	 * ITT domains for each queue.
+	 */
+	__itt_domain *wasted_iter_domains[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * ITT task names for each queue.
+	 */
+	__itt_string_handle *wasted_iter_handles[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * Flags indicating the queues state. Possible values:
+	 * 1 - queue is wasting iterations, 0 - otherwise.
+	 */
+	uint8_t queue_is_wasting_iters[RTE_MAX_QUEUES_PER_PORT];
+};
+
+/**
+ * The pool of *rte_eth_itt_aux_data* structures.
+ */
+struct rte_eth_itt_aux_data itt_aux_data[RTE_MAX_ETHPORTS];
+
+
+/**
+ * This callback function manages ITT tasks collection on given port and queue.
+ * It must be registered with rte_eth_add_rx_callback() to be called from
+ * rte_eth_rx_burst(). To find more comments see rte_rx_callback_fn function
+ * type declaration.
+ */
+static uint16_t
+collect_itt_rx_burst_cb(uint8_t port_id, uint16_t queue_id,
+	__rte_unused struct rte_mbuf *pkts[], uint16_t nb_pkts,
+	__rte_unused uint16_t max_pkts, __rte_unused void *user_param)
+{
+	if (unlikely(nb_pkts == 0)) {
+		if (!itt_aux_data[port_id].queue_is_wasting_iters[queue_id]) {
+			__itt_task_begin(
+				itt_aux_data[port_id].wasted_iter_domains[queue_id],
+				__itt_null, __itt_null,
+				itt_aux_data[port_id].wasted_iter_handles[queue_id]);
+			itt_aux_data[port_id].queue_is_wasting_iters[queue_id] = 1;
+		}
+	} else {
+		if (unlikely(itt_aux_data[port_id].queue_is_wasting_iters[queue_id])) {
+			__itt_task_end(
+				itt_aux_data[port_id].wasted_iter_domains[queue_id]);
+			itt_aux_data[port_id].queue_is_wasting_iters[queue_id] = 0;
+		}
+	}
+	return nb_pkts;
+}
+
+/**
+ * Initialization of rte_eth_itt_aux_data for a given port.
+ * This function must be invoked when ethernet device is being configured.
+ * Result will be stored in the global array *itt_aux_data*.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param port_name
+ *  The name of the Ethernet device.
+ * @param rx_queue_num
+ *  The number of RX queues on specified port.
+ */
+static inline void
+rte_eth_init_itt(uint8_t port_id, char *port_name, uint8_t rx_queue_num)
+{
+	uint16_t q_id;
+	for (q_id = 0; q_id < rx_queue_num; ++q_id) {
+		char domain_name[ITT_MAX_NAME_LEN];
+		snprintf(domain_name, sizeof(domain_name),
+			"RXBurst.WastedIterations.Port_%s.Queue_%d",
+			port_name, q_id);
+		itt_aux_data[port_id].wasted_iter_domains[q_id]
+			= __itt_domain_create(domain_name);
+
+		char task_name[ITT_MAX_NAME_LEN];
+		snprintf(task_name, sizeof(task_name),
+			"port id: %d; queue id: %d",
+			port_id, q_id);
+		itt_aux_data[port_id].wasted_iter_handles[q_id]
+			= __itt_string_handle_create(task_name);
+
+		itt_aux_data[port_id].queue_is_wasting_iters[q_id] = 0;
+
+		rte_eth_add_rx_callback(
+			port_id, q_id, collect_itt_rx_burst_cb, NULL);
+	}
+}
+#endif /* RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS */
+
+void
+rte_eth_rx_profile_init(__rte_unused uint8_t port_id,
+	__rte_unused struct rte_eth_dev *dev)
+{
+#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
+	rte_eth_init_itt(port_id, dev->data->name, dev->data->nb_rx_queues);
+#endif
+}
diff --git a/lib/librte_ether/rte_ethdev_profile.h b/lib/librte_ether/rte_ethdev_profile.h
new file mode 100644
index 0000000..7f1fc25
--- /dev/null
+++ b/lib/librte_ether/rte_ethdev_profile.h
@@ -0,0 +1,51 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_ETHDEV_PROFILE_H_
+#define _RTE_ETHDEV_PROFILE_H_
+
+#include "rte_ethdev.h"
+
+/**
+ * Initialization of profiling RX queues for Ethernet device. Implementation of
+ * this function depends on chosen profiling method, defined in configs.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param dev
+ *  Pointer to struct rte_eth_dev corresponding to given port_id.
+ */
+void
+rte_eth_rx_profile_init(uint8_t port_id, struct rte_eth_dev *dev);
+
+#endif
-- 
2.7.4


--------------------------------------------------------------------
Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park,
17 Krylatskaya Str., Bldg 4, Moscow 121614,
Russian Federation

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH v3] ether: add support for vtune task tracing
  2017-07-11 17:48     ` [dpdk-dev] [PATCH v3] ether: add support for vtune task tracing ilia.kurakin
@ 2017-07-14  5:45       ` Jerin Jacob
  2017-07-17 17:15       ` [dpdk-dev] [PATCH v4] " ilia.kurakin
  1 sibling, 0 replies; 22+ messages in thread
From: Jerin Jacob @ 2017-07-14  5:45 UTC (permalink / raw)
  To: ilia.kurakin; +Cc: dev, konstantin.ananyev, keith.wiles, dmitry.galanov


-----Original Message-----
> Date: Tue, 11 Jul 2017 20:48:06 +0300
> From: ilia.kurakin@intel.com
> To: dev@dpdk.org
> CC: jerin.jacob@caviumnetworks.com, konstantin.ananyev@intel.com,
>  keith.wiles@intel.com, dmitry.galanov@intel.com, Ilia Kurakin
>  <ilia.kurakin@intel.com>
> Subject: [PATCH v3] ether: add support for vtune task tracing
> X-Mailer: git-send-email 2.7.4
> 
> From: Ilia Kurakin <ilia.kurakin@intel.com>
> 
> The patch adds tracing of loop iterations that yielded no packets in a DPDK
> application. It is using ITT task API:
>     https://software.intel.com/en-us/node/544206
> 
> We suppose the flow of using this tracing would assume the user has ITT lib
> and header on machine and re-build DPDK with additional make parameters:
> 
>     make EXTRA_CFLAGS=-I<path to ittnotify.h>
>          EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"
> 

Plenty of checkpatch errors found in the patch. Verify the checkpatch
issues with ./devtools/checkpatches.sh

I think, this vtune tracing support deserves to added a section in
http://dpdk.org/doc/guides/prog_guide/profile_app.html


> Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>
> 
> ---
> 
> -V2 change:
>     ITT tasks collection is moved to rx callback
> 
> -V3 change:
>     rte_ethdev_profile.c created, all profile specific code moved there.
> 
>     Added generic profile function
> 
> 
>  config/common_base                    |   1 +
>  lib/librte_ether/Makefile             |   1 +
>  lib/librte_ether/rte_ethdev.c         |   4 +
>  lib/librte_ether/rte_ethdev_profile.c | 150 ++++++++++++++++++++++++++++++++++
>  lib/librte_ether/rte_ethdev_profile.h |  51 ++++++++++++
>  5 files changed, 207 insertions(+)
>  create mode 100644 lib/librte_ether/rte_ethdev_profile.c
>  create mode 100644 lib/librte_ether/rte_ethdev_profile.h
> 
> diff --git a/config/common_base b/config/common_base
> index 8ae6e92..dda51db 100644
> --- a/config/common_base
> +++ b/config/common_base
> @@ -136,6 +136,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
>  CONFIG_RTE_LIBRTE_IEEE1588=n
>  CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
>  CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
> +CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS=n
>  
>  #
>  # Turn off Tx preparation stage
> diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile
> index 93fdde1..3c86ec6 100644
> --- a/lib/librte_ether/Makefile
> +++ b/lib/librte_ether/Makefile
> @@ -45,6 +45,7 @@ LIBABIVER := 6
>  
>  SRCS-y += rte_ethdev.c
>  SRCS-y += rte_flow.c
> +SRCS-y += rte_ethdev_profile.c
>  
>  #
>  # Export include files
> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
> index 76179fd..f4ec119 100644
> --- a/lib/librte_ether/rte_ethdev.c
> +++ b/lib/librte_ether/rte_ethdev.c
> @@ -67,6 +67,7 @@
>  
>  #include "rte_ether.h"
>  #include "rte_ethdev.h"
> +#include "rte_ethdev_profile.h"
>  
>  static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
>  struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
> @@ -825,6 +826,9 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
>  		return diag;
>  	}
>  
> +	/* See rte_ethdev_profile.h to find comments on code below. */
> +	rte_eth_rx_profile_init(port_id, dev);

I prefer to change to rte_eth_profile_rx_init for better name space.

> +
>  	return 0;
>  }
>  
> diff --git a/lib/librte_ether/rte_ethdev_profile.c b/lib/librte_ether/rte_ethdev_profile.c
> new file mode 100644
> index 0000000..029fbba
> --- /dev/null
> +++ b/lib/librte_ether/rte_ethdev_profile.c
> @@ -0,0 +1,150 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
> + *   All rights reserved.
> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + *     * Redistributions of source code must retain the above copyright
> + *       notice, this list of conditions and the following disclaimer.
> + *     * Redistributions in binary form must reproduce the above copyright
> + *       notice, this list of conditions and the following disclaimer in
> + *       the documentation and/or other materials provided with the
> + *       distribution.
> + *     * Neither the name of Intel Corporation nor the names of its
> + *       contributors may be used to endorse or promote products derived
> + *       from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#include "rte_ethdev_profile.h"
> +
> +/**
> + * This conditional block is responsible for RX queues profiling using the
> + * Instrumentation and Tracing Technology (ITT) API, employed by the
> + * Intel VTune TM Amplifier.
> + */
> +#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
> +
> +#include <rte_config.h>

Shouldn't the rte_config.h moved up to bring
RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS definition.

> +#include <ittnotify.h>
> +
> +#define ITT_MAX_NAME_LEN (100)
> +
> +/**
> + * Auxiliary ITT structure belonging to port and using to:
> + *   -  track queue state to determine whether it is wasting loop iterations
> + *   -  begin or end ITT task using task domain and name
> + */
> +struct rte_eth_itt_aux_data {
> +	/**
> +	 * ITT domains for each queue.
> +	 */
> +	__itt_domain *wasted_iter_domains[RTE_MAX_QUEUES_PER_PORT];
> +	/**
> +	 * ITT task names for each queue.
> +	 */
> +	__itt_string_handle *wasted_iter_handles[RTE_MAX_QUEUES_PER_PORT];
> +	/**
> +	 * Flags indicating the queues state. Possible values:
> +	 * 1 - queue is wasting iterations, 0 - otherwise.
> +	 */
> +	uint8_t queue_is_wasting_iters[RTE_MAX_QUEUES_PER_PORT];
> +};
> +
> +/**
> + * The pool of *rte_eth_itt_aux_data* structures.
> + */
> +struct rte_eth_itt_aux_data itt_aux_data[RTE_MAX_ETHPORTS];
> +
> +
> +/**
> + * This callback function manages ITT tasks collection on given port and queue.
> + * It must be registered with rte_eth_add_rx_callback() to be called from
> + * rte_eth_rx_burst(). To find more comments see rte_rx_callback_fn function
> + * type declaration.
> + */
> +static uint16_t
> +collect_itt_rx_burst_cb(uint8_t port_id, uint16_t queue_id,
> +	__rte_unused struct rte_mbuf *pkts[], uint16_t nb_pkts,
> +	__rte_unused uint16_t max_pkts, __rte_unused void *user_param)
> +{
> +	if (unlikely(nb_pkts == 0)) {
> +		if (!itt_aux_data[port_id].queue_is_wasting_iters[queue_id]) {
> +			__itt_task_begin(
> +				itt_aux_data[port_id].wasted_iter_domains[queue_id],
> +				__itt_null, __itt_null,
> +				itt_aux_data[port_id].wasted_iter_handles[queue_id]);
> +			itt_aux_data[port_id].queue_is_wasting_iters[queue_id] = 1;
> +		}
> +	} else {
> +		if (unlikely(itt_aux_data[port_id].queue_is_wasting_iters[queue_id])) {
> +			__itt_task_end(
> +				itt_aux_data[port_id].wasted_iter_domains[queue_id]);
> +			itt_aux_data[port_id].queue_is_wasting_iters[queue_id] = 0;
> +		}
> +	}
> +	return nb_pkts;
> +}
> +
> +/**
> + * Initialization of rte_eth_itt_aux_data for a given port.
> + * This function must be invoked when ethernet device is being configured.
> + * Result will be stored in the global array *itt_aux_data*.
> + *
> + * @param port_id
> + *  The port identifier of the Ethernet device.
> + * @param port_name
> + *  The name of the Ethernet device.
> + * @param rx_queue_num
> + *  The number of RX queues on specified port.
> + */
> +static inline void
> +rte_eth_init_itt(uint8_t port_id, char *port_name, uint8_t rx_queue_num)
> +{
> +	uint16_t q_id;
> +	for (q_id = 0; q_id < rx_queue_num; ++q_id) {
> +		char domain_name[ITT_MAX_NAME_LEN];
> +		snprintf(domain_name, sizeof(domain_name),
> +			"RXBurst.WastedIterations.Port_%s.Queue_%d",
> +			port_name, q_id);
> +		itt_aux_data[port_id].wasted_iter_domains[q_id]
> +			= __itt_domain_create(domain_name);
> +
> +		char task_name[ITT_MAX_NAME_LEN];
> +		snprintf(task_name, sizeof(task_name),
> +			"port id: %d; queue id: %d",
> +			port_id, q_id);
> +		itt_aux_data[port_id].wasted_iter_handles[q_id]
> +			= __itt_string_handle_create(task_name);
> +
> +		itt_aux_data[port_id].queue_is_wasting_iters[q_id] = 0;
> +
> +		rte_eth_add_rx_callback(
> +			port_id, q_id, collect_itt_rx_burst_cb, NULL);
> +	}
> +}
> +#endif /* RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS */
> +
> +void
> +rte_eth_rx_profile_init(__rte_unused uint8_t port_id,
> +	__rte_unused struct rte_eth_dev *dev)
> +{
> +#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
> +	rte_eth_init_itt(port_id, dev->data->name, dev->data->nb_rx_queues);

You may not need to start with rte_ for location functions and i think,
it is better to reference rx in this function name.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH v4] ether: add support for vtune task tracing
  2017-07-11 17:48     ` [dpdk-dev] [PATCH v3] ether: add support for vtune task tracing ilia.kurakin
  2017-07-14  5:45       ` Jerin Jacob
@ 2017-07-17 17:15       ` ilia.kurakin
  2017-07-19  8:54         ` [dpdk-dev] [PATCH v5] " ilia.kurakin
  1 sibling, 1 reply; 22+ messages in thread
From: ilia.kurakin @ 2017-07-17 17:15 UTC (permalink / raw)
  To: dev
  Cc: jerin.jacob, konstantin.ananyev, keith.wiles, dmitry.galanov,
	Ilia Kurakin

From: Ilia Kurakin <ilia.kurakin@intel.com>

The patch adds tracing of loop iterations that yielded no packets in a DPDK
application. It is using ITT task API:
    https://software.intel.com/en-us/node/544206

We suppose the flow of using this tracing would assume the user has ITT lib
and header on machine and re-build DPDK with additional make parameters:

    make EXTRA_CFLAGS=-I<path to ittnotify.h>
         EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"

Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>

---

-V2 change:
    ITT tasks collection is moved to rx callback

-V3 change:
    rte_ethdev_profile.c created, all profile specific code moved there.

    Added generic profile function

-V4 change:
    checkpatch issues fixed

    Added documentation topic


 config/common_base                    |   1 +
 doc/guides/prog_guide/profile_app.rst |  31 +++++++
 lib/librte_ether/Makefile             |   1 +
 lib/librte_ether/rte_ethdev.c         |   4 +
 lib/librte_ether/rte_ethdev_profile.c | 156 ++++++++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev_profile.h |  52 ++++++++++++
 6 files changed, 245 insertions(+)
 create mode 100644 lib/librte_ether/rte_ethdev_profile.c
 create mode 100644 lib/librte_ether/rte_ethdev_profile.h

diff --git a/config/common_base b/config/common_base
index 8ae6e92..dda51db 100644
--- a/config/common_base
+++ b/config/common_base
@@ -136,6 +136,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
 CONFIG_RTE_LIBRTE_IEEE1588=n
 CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
 CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
+CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS=n
 
 #
 # Turn off Tx preparation stage
diff --git a/doc/guides/prog_guide/profile_app.rst b/doc/guides/prog_guide/profile_app.rst
index 54b546a..13b373c 100644
--- a/doc/guides/prog_guide/profile_app.rst
+++ b/doc/guides/prog_guide/profile_app.rst
@@ -59,6 +59,37 @@ Refer to the
 for details about application profiling.
 
 
+Profiling wasted iterations with ITT
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Iterations which yielded no RX packets (wasted loop iterations) can be analyzed
+using Intel VTune Amplifier. This profiling employs
+`Instrumentation and Tracing Technology (ITT) API
+<https://software.intel.com/en-us/node/544195>`_
+, enclosed to VTune, and requires no changes in a DPDK application.
+
+To trace wasted iterations on RX queues, first reconfigure DPDK with
+``CONFIG_RTE_ETHDEV_RXTX_CALLBACKS`` and
+``CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS`` enabled.
+
+Then rebuild DPDK, specifying paths to ITT header and library, which can be
+found in any VTune distribution in *include* and *lib* directories respectively:
+
+.. code-block:: console
+
+    make EXTRA_CFLAGS=-I<path to ittnotify.h> \
+         EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"
+
+Finally, to see wasted iterations in your performance analysis results, pick
+*"Analyze user tasks, events, and counters"* checkbox in VTune's
+*"Analysis Type"* tab when configuring analysis via VTune GUI. Alternatively,
+running VTune via command line, specify ``-knob enable-user-tasks=true`` option.
+
+Collected regions of wasted iterations will be marked on VTune's timeline
+as usual ITT tasks. These ITT tasks have predefined names, containing Ethernet
+device and RX queue identifiers.
+
+
 Profiling on ARM64
 ------------------
 
diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile
index db692ae..7224a11 100644
--- a/lib/librte_ether/Makefile
+++ b/lib/librte_ether/Makefile
@@ -46,6 +46,7 @@ LIBABIVER := 6
 SRCS-y += rte_ethdev.c
 SRCS-y += rte_flow.c
 SRCS-y += rte_tm.c
+SRCS-y += rte_ethdev_profile.c
 
 #
 # Export include files
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index a1b7447..2eba36e 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -67,6 +67,7 @@
 
 #include "rte_ether.h"
 #include "rte_ethdev.h"
+#include "rte_ethdev_profile.h"
 
 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
@@ -825,6 +826,9 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 		return diag;
 	}
 
+	/* See rte_ethdev_profile.h to find comments on code below. */
+	rte_eth_profile_rx_init(port_id, dev);
+
 	return 0;
 }
 
diff --git a/lib/librte_ether/rte_ethdev_profile.c b/lib/librte_ether/rte_ethdev_profile.c
new file mode 100644
index 0000000..8884175
--- /dev/null
+++ b/lib/librte_ether/rte_ethdev_profile.c
@@ -0,0 +1,156 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <rte_config.h>
+
+#include "rte_ethdev_profile.h"
+
+/**
+ * This conditional block enables RX queues profiling by tracking wasted
+ * iterations, i.e. iterations which yielded no RX packets. Profiling is
+ * performed using the Instrumentation and Tracing Technology (ITT) API,
+ * employed by the Intel VTune TM Amplifier.
+ */
+#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
+
+#include <ittnotify.h>
+
+#define ITT_MAX_NAME_LEN (100)
+
+/**
+ * Auxiliary ITT structure belonging to Ethernet devive and using to:
+ *   -  track RX queue state to determine whether it is wasting loop iterations
+ *   -  begin or end ITT task using task domain and task name (handle)
+ */
+struct itt_profile_rx_data {
+	/**
+	 * ITT domains for each queue.
+	 */
+	__itt_domain *domains[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * ITT task names for each queue.
+	 */
+	__itt_string_handle *handles[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * Flags indicating the queues state. Possible values:
+	 *   1 - queue is wasting iterations,
+	 *   0 - otherwise.
+	 */
+	uint8_t queue_state[RTE_MAX_QUEUES_PER_PORT];
+};
+
+/**
+ * The pool of *itt_profile_rx_data* structures.
+ */
+struct itt_profile_rx_data itt_rx_data[RTE_MAX_ETHPORTS];
+
+
+/**
+ * This callback function manages ITT tasks collection on given port and queue.
+ * It must be registered with rte_eth_add_rx_callback() to be called from
+ * rte_eth_rx_burst(). To find more comments see rte_rx_callback_fn function
+ * type declaration.
+ */
+static uint16_t
+collect_itt_rx_burst_cb(uint8_t port_id, uint16_t queue_id,
+	__rte_unused struct rte_mbuf *pkts[], uint16_t nb_pkts,
+	__rte_unused uint16_t max_pkts, __rte_unused void *user_param)
+{
+	if (unlikely(nb_pkts == 0)) {
+		if (!itt_rx_data[port_id].queue_state[queue_id]) {
+			__itt_task_begin(
+				itt_rx_data[port_id].domains[queue_id],
+				__itt_null, __itt_null,
+				itt_rx_data[port_id].handles[queue_id]);
+			itt_rx_data[port_id].queue_state[queue_id] = 1;
+		}
+	} else {
+		if (unlikely(itt_rx_data[port_id].queue_state[queue_id])) {
+			__itt_task_end(
+				itt_rx_data[port_id].domains[queue_id]);
+			itt_rx_data[port_id].queue_state[queue_id] = 0;
+		}
+	}
+	return nb_pkts;
+}
+
+/**
+ * Initialization of itt_profile_rx_data for a given Ethernet device.
+ * This function must be invoked when ethernet device is being configured.
+ * Result will be stored in the global array *itt_rx_data*.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param port_name
+ *  The name of the Ethernet device.
+ * @param rx_queue_num
+ *  The number of RX queues on specified port.
+ */
+static inline void
+itt_profile_rx_init(uint8_t port_id, char *port_name, uint8_t rx_queue_num)
+{
+	uint16_t q_id;
+
+	for (q_id = 0; q_id < rx_queue_num; ++q_id) {
+		char domain_name[ITT_MAX_NAME_LEN];
+
+		snprintf(domain_name, sizeof(domain_name),
+			"RXBurst.WastedIterations.Port_%s.Queue_%d",
+			port_name, q_id);
+		itt_rx_data[port_id].domains[q_id]
+			= __itt_domain_create(domain_name);
+
+		char task_name[ITT_MAX_NAME_LEN];
+
+		snprintf(task_name, sizeof(task_name),
+			"port id: %d; queue id: %d",
+			port_id, q_id);
+		itt_rx_data[port_id].handles[q_id]
+			= __itt_string_handle_create(task_name);
+
+		itt_rx_data[port_id].queue_state[q_id] = 0;
+
+		rte_eth_add_rx_callback(
+			port_id, q_id, collect_itt_rx_burst_cb, NULL);
+	}
+}
+#endif /* RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS */
+
+void
+rte_eth_profile_rx_init(__rte_unused uint8_t port_id,
+	__rte_unused struct rte_eth_dev *dev)
+{
+#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
+	itt_profile_rx_init(port_id, dev->data->name, dev->data->nb_rx_queues);
+#endif
+}
diff --git a/lib/librte_ether/rte_ethdev_profile.h b/lib/librte_ether/rte_ethdev_profile.h
new file mode 100644
index 0000000..1eb72bd
--- /dev/null
+++ b/lib/librte_ether/rte_ethdev_profile.h
@@ -0,0 +1,52 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_ETHDEV_PROFILE_H_
+#define _RTE_ETHDEV_PROFILE_H_
+
+#include "rte_ethdev.h"
+
+/**
+ * Initialization of profiling RX queues for the Ethernet device.
+ * Implementation of this function depends on chosen profiling method,
+ * defined in configs.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param dev
+ *  Pointer to struct rte_eth_dev corresponding to given port_id.
+ */
+void
+rte_eth_profile_rx_init(uint8_t port_id, struct rte_eth_dev *dev);
+
+#endif
-- 
2.7.4


--------------------------------------------------------------------
Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park,
17 Krylatskaya Str., Bldg 4, Moscow 121614,
Russian Federation

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH v5] ether: add support for vtune task tracing
  2017-07-17 17:15       ` [dpdk-dev] [PATCH v4] " ilia.kurakin
@ 2017-07-19  8:54         ` ilia.kurakin
  2017-07-24  9:27           ` Jerin Jacob
  2017-07-24 17:06           ` [dpdk-dev] [PATCH v6] " ilia.kurakin
  0 siblings, 2 replies; 22+ messages in thread
From: ilia.kurakin @ 2017-07-19  8:54 UTC (permalink / raw)
  To: dev
  Cc: jerin.jacob, konstantin.ananyev, keith.wiles, dmitry.galanov,
	Ilia Kurakin

From: Ilia Kurakin <ilia.kurakin@intel.com>

The patch adds tracing of loop iterations that yielded no packets in a DPDK
application. It is using ITT task API:
    https://software.intel.com/en-us/node/544206

We suppose the flow of using this tracing would assume the user has ITT lib
and header on machine and re-build DPDK with additional make parameters:

    make EXTRA_CFLAGS=-I<path to ittnotify.h>
         EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"

Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>

---

-V2 change:
    ITT tasks collection is moved to rx callback

-V3 change:
    rte_ethdev_profile.c created, all profile specific code moved there.

    Added generic profile function

-V4 change:
    checkpatch issues fixed

    Added documentation topic

-V5 change:
    Documentation fixes


 config/common_base                    |   1 +
 doc/guides/prog_guide/profile_app.rst |  34 ++++++++
 lib/librte_ether/Makefile             |   1 +
 lib/librte_ether/rte_ethdev.c         |   4 +
 lib/librte_ether/rte_ethdev_profile.c | 156 ++++++++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev_profile.h |  52 ++++++++++++
 6 files changed, 248 insertions(+)
 create mode 100644 lib/librte_ether/rte_ethdev_profile.c
 create mode 100644 lib/librte_ether/rte_ethdev_profile.h

diff --git a/config/common_base b/config/common_base
index 8ae6e92..dda51db 100644
--- a/config/common_base
+++ b/config/common_base
@@ -136,6 +136,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
 CONFIG_RTE_LIBRTE_IEEE1588=n
 CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
 CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
+CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS=n
 
 #
 # Turn off Tx preparation stage
diff --git a/doc/guides/prog_guide/profile_app.rst b/doc/guides/prog_guide/profile_app.rst
index 54b546a..590cb72 100644
--- a/doc/guides/prog_guide/profile_app.rst
+++ b/doc/guides/prog_guide/profile_app.rst
@@ -59,6 +59,40 @@ Refer to the
 for details about application profiling.
 
 
+Profiling wasted iterations with ITT
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Iterations that yielded no RX packets (wasted loop iterations) can be analyzed
+using Intel® VTune\ :sup:`TM` Amplifier. This profiling employs the
+`Instrumentation and Tracing Technology (ITT) API
+<https://software.intel.com/en-us/node/544195>`_
+feature of VTune Amplifier and requires only reconfiguring of DPDK library,
+no changes in a DPDK application are needed.
+
+To trace wasted iterations on RX queues, first reconfigure DPDK with
+``CONFIG_RTE_ETHDEV_RXTX_CALLBACKS`` and
+``CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS`` enabled.
+
+Then rebuild DPDK, specifying paths to the ITT header and library, which can
+be found in any VTune Amplifier distribution in the *include* and *lib*
+directories respectively:
+
+.. code-block:: console
+
+    make EXTRA_CFLAGS=-I<path to ittnotify.h> \
+         EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"
+
+Finally, to see wasted iterations in your performance analysis results,
+select the *"Analyze user tasks, events, and counters"* checkbox in the
+*"Analysis Type"* tab when configuring analysis via VTune Amplifier GUI.
+Alternatively, when running VTune Amplifier via command line, specify
+``-knob enable-user-tasks=true`` option.
+
+Collected regions of wasted iterations will be marked on VTune Amplifier's
+timeline as ITT tasks. These ITT tasks have predefined names, containing
+Ethernet device and RX queue identifiers.
+
+
 Profiling on ARM64
 ------------------
 
diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile
index db692ae..7224a11 100644
--- a/lib/librte_ether/Makefile
+++ b/lib/librte_ether/Makefile
@@ -46,6 +46,7 @@ LIBABIVER := 6
 SRCS-y += rte_ethdev.c
 SRCS-y += rte_flow.c
 SRCS-y += rte_tm.c
+SRCS-y += rte_ethdev_profile.c
 
 #
 # Export include files
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index a1b7447..2eba36e 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -67,6 +67,7 @@
 
 #include "rte_ether.h"
 #include "rte_ethdev.h"
+#include "rte_ethdev_profile.h"
 
 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
@@ -825,6 +826,9 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 		return diag;
 	}
 
+	/* See rte_ethdev_profile.h to find comments on code below. */
+	rte_eth_profile_rx_init(port_id, dev);
+
 	return 0;
 }
 
diff --git a/lib/librte_ether/rte_ethdev_profile.c b/lib/librte_ether/rte_ethdev_profile.c
new file mode 100644
index 0000000..bb83c8a
--- /dev/null
+++ b/lib/librte_ether/rte_ethdev_profile.c
@@ -0,0 +1,156 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <rte_config.h>
+
+#include "rte_ethdev_profile.h"
+
+/**
+ * This conditional block enables RX queues profiling by tracking wasted
+ * iterations, i.e. iterations which yielded no RX packets. Profiling is
+ * performed using the Instrumentation and Tracing Technology (ITT) API,
+ * employed by the Intel (R) VTune (TM) Amplifier.
+ */
+#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
+
+#include <ittnotify.h>
+
+#define ITT_MAX_NAME_LEN (100)
+
+/**
+ * Auxiliary ITT structure belonging to Ethernet devive and using to:
+ *   -  track RX queue state to determine whether it is wasting loop iterations
+ *   -  begin or end ITT task using task domain and task name (handle)
+ */
+struct itt_profile_rx_data {
+	/**
+	 * ITT domains for each queue.
+	 */
+	__itt_domain *domains[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * ITT task names for each queue.
+	 */
+	__itt_string_handle *handles[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * Flags indicating the queues state. Possible values:
+	 *   1 - queue is wasting iterations,
+	 *   0 - otherwise.
+	 */
+	uint8_t queue_state[RTE_MAX_QUEUES_PER_PORT];
+};
+
+/**
+ * The pool of *itt_profile_rx_data* structures.
+ */
+struct itt_profile_rx_data itt_rx_data[RTE_MAX_ETHPORTS];
+
+
+/**
+ * This callback function manages ITT tasks collection on given port and queue.
+ * It must be registered with rte_eth_add_rx_callback() to be called from
+ * rte_eth_rx_burst(). To find more comments see rte_rx_callback_fn function
+ * type declaration.
+ */
+static uint16_t
+collect_itt_rx_burst_cb(uint8_t port_id, uint16_t queue_id,
+	__rte_unused struct rte_mbuf *pkts[], uint16_t nb_pkts,
+	__rte_unused uint16_t max_pkts, __rte_unused void *user_param)
+{
+	if (unlikely(nb_pkts == 0)) {
+		if (!itt_rx_data[port_id].queue_state[queue_id]) {
+			__itt_task_begin(
+				itt_rx_data[port_id].domains[queue_id],
+				__itt_null, __itt_null,
+				itt_rx_data[port_id].handles[queue_id]);
+			itt_rx_data[port_id].queue_state[queue_id] = 1;
+		}
+	} else {
+		if (unlikely(itt_rx_data[port_id].queue_state[queue_id])) {
+			__itt_task_end(
+				itt_rx_data[port_id].domains[queue_id]);
+			itt_rx_data[port_id].queue_state[queue_id] = 0;
+		}
+	}
+	return nb_pkts;
+}
+
+/**
+ * Initialization of itt_profile_rx_data for a given Ethernet device.
+ * This function must be invoked when ethernet device is being configured.
+ * Result will be stored in the global array *itt_rx_data*.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param port_name
+ *  The name of the Ethernet device.
+ * @param rx_queue_num
+ *  The number of RX queues on specified port.
+ */
+static inline void
+itt_profile_rx_init(uint8_t port_id, char *port_name, uint8_t rx_queue_num)
+{
+	uint16_t q_id;
+
+	for (q_id = 0; q_id < rx_queue_num; ++q_id) {
+		char domain_name[ITT_MAX_NAME_LEN];
+
+		snprintf(domain_name, sizeof(domain_name),
+			"RXBurst.WastedIterations.Port_%s.Queue_%d",
+			port_name, q_id);
+		itt_rx_data[port_id].domains[q_id]
+			= __itt_domain_create(domain_name);
+
+		char task_name[ITT_MAX_NAME_LEN];
+
+		snprintf(task_name, sizeof(task_name),
+			"port id: %d; queue id: %d",
+			port_id, q_id);
+		itt_rx_data[port_id].handles[q_id]
+			= __itt_string_handle_create(task_name);
+
+		itt_rx_data[port_id].queue_state[q_id] = 0;
+
+		rte_eth_add_rx_callback(
+			port_id, q_id, collect_itt_rx_burst_cb, NULL);
+	}
+}
+#endif /* RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS */
+
+void
+rte_eth_profile_rx_init(__rte_unused uint8_t port_id,
+	__rte_unused struct rte_eth_dev *dev)
+{
+#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
+	itt_profile_rx_init(port_id, dev->data->name, dev->data->nb_rx_queues);
+#endif
+}
diff --git a/lib/librte_ether/rte_ethdev_profile.h b/lib/librte_ether/rte_ethdev_profile.h
new file mode 100644
index 0000000..1eb72bd
--- /dev/null
+++ b/lib/librte_ether/rte_ethdev_profile.h
@@ -0,0 +1,52 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_ETHDEV_PROFILE_H_
+#define _RTE_ETHDEV_PROFILE_H_
+
+#include "rte_ethdev.h"
+
+/**
+ * Initialization of profiling RX queues for the Ethernet device.
+ * Implementation of this function depends on chosen profiling method,
+ * defined in configs.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param dev
+ *  Pointer to struct rte_eth_dev corresponding to given port_id.
+ */
+void
+rte_eth_profile_rx_init(uint8_t port_id, struct rte_eth_dev *dev);
+
+#endif
-- 
2.7.4


--------------------------------------------------------------------
Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park,
17 Krylatskaya Str., Bldg 4, Moscow 121614,
Russian Federation

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH v5] ether: add support for vtune task tracing
  2017-07-19  8:54         ` [dpdk-dev] [PATCH v5] " ilia.kurakin
@ 2017-07-24  9:27           ` Jerin Jacob
  2017-07-24 12:33             ` Kurakin, Ilia
  2017-09-22 10:19             ` Thomas Monjalon
  2017-07-24 17:06           ` [dpdk-dev] [PATCH v6] " ilia.kurakin
  1 sibling, 2 replies; 22+ messages in thread
From: Jerin Jacob @ 2017-07-24  9:27 UTC (permalink / raw)
  To: ilia.kurakin; +Cc: dev, konstantin.ananyev, keith.wiles, dmitry.galanov

-----Original Message-----
> Date: Wed, 19 Jul 2017 11:54:45 +0300
> From: ilia.kurakin@intel.com
> To: dev@dpdk.org
> CC: jerin.jacob@caviumnetworks.com, konstantin.ananyev@intel.com,
>  keith.wiles@intel.com, dmitry.galanov@intel.com, Ilia Kurakin
>  <ilia.kurakin@intel.com>
> Subject: [PATCH v5] ether: add support for vtune task tracing
> X-Mailer: git-send-email 2.7.4
> 
> From: Ilia Kurakin <ilia.kurakin@intel.com>
> 
> The patch adds tracing of loop iterations that yielded no packets in a DPDK
> application. It is using ITT task API:
>     https://software.intel.com/en-us/node/544206
> 
> We suppose the flow of using this tracing would assume the user has ITT lib
> and header on machine and re-build DPDK with additional make parameters:
> 
>     make EXTRA_CFLAGS=-I<path to ittnotify.h>
>          EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"
> 
> Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>

Found a checkpatch issue.

➜ [master][dpdk.org] $ ./devtools/checkpatches.sh 

### ether: add support for vtune task tracing

ERROR:SPACING: need consistent spacing around '*' (ctx:WxV)
#173: FILE: lib/librte_ether/rte_ethdev_profile.c:59:
+	__itt_domain *domains[RTE_MAX_QUEUES_PER_PORT];
 	             ^

ERROR:SPACING: need consistent spacing around '*' (ctx:WxV)
#177: FILE: lib/librte_ether/rte_ethdev_profile.c:63:
+	__itt_string_handle *handles[RTE_MAX_QUEUES_PER_PORT];
 	                    ^

total: 2 errors, 0 warnings, 278 lines checked

0/1 valid patch


> 
> ---
> 
> -V2 change:
>     ITT tasks collection is moved to rx callback
> 
> -V3 change:
>     rte_ethdev_profile.c created, all profile specific code moved there.
> 
>     Added generic profile function
> 
> -V4 change:
>     checkpatch issues fixed
> 
>     Added documentation topic
> 
> -V5 change:
>     Documentation fixes
> 
> 
>  config/common_base                    |   1 +
>  doc/guides/prog_guide/profile_app.rst |  34 ++++++++
>  lib/librte_ether/Makefile             |   1 +
>  lib/librte_ether/rte_ethdev.c         |   4 +
>  lib/librte_ether/rte_ethdev_profile.c | 156 ++++++++++++++++++++++++++++++++++
>  lib/librte_ether/rte_ethdev_profile.h |  52 ++++++++++++
>  6 files changed, 248 insertions(+)
>  create mode 100644 lib/librte_ether/rte_ethdev_profile.c
>  create mode 100644 lib/librte_ether/rte_ethdev_profile.h
> 
> diff --git a/config/common_base b/config/common_base
> index 8ae6e92..dda51db 100644
> --- a/config/common_base
> +++ b/config/common_base
> @@ -136,6 +136,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
>  CONFIG_RTE_LIBRTE_IEEE1588=n
>  CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
>  CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
> +CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS=n
>  
>  #
>  # Turn off Tx preparation stage
> diff --git a/doc/guides/prog_guide/profile_app.rst b/doc/guides/prog_guide/profile_app.rst
> index 54b546a..590cb72 100644
> --- a/doc/guides/prog_guide/profile_app.rst
> +++ b/doc/guides/prog_guide/profile_app.rst
> @@ -59,6 +59,40 @@ Refer to the
>  for details about application profiling.
>  
>  
> +Profiling wasted iterations with ITT
> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> +
> +Iterations that yielded no RX packets (wasted loop iterations) can be analyzed
> +using Intel® VTune\ :sup:`TM` Amplifier. This profiling employs the
> +`Instrumentation and Tracing Technology (ITT) API
> +<https://software.intel.com/en-us/node/544195>`_
> +feature of VTune Amplifier and requires only reconfiguring of DPDK library,
> +no changes in a DPDK application are needed.
> +
> +To trace wasted iterations on RX queues, first reconfigure DPDK with
> +``CONFIG_RTE_ETHDEV_RXTX_CALLBACKS`` and
> +``CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS`` enabled.
> +
> +Then rebuild DPDK, specifying paths to the ITT header and library, which can
> +be found in any VTune Amplifier distribution in the *include* and *lib*
> +directories respectively:
> +
> +.. code-block:: console
> +
> +    make EXTRA_CFLAGS=-I<path to ittnotify.h> \
> +         EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"
> +
> +Finally, to see wasted iterations in your performance analysis results,
> +select the *"Analyze user tasks, events, and counters"* checkbox in the
> +*"Analysis Type"* tab when configuring analysis via VTune Amplifier GUI.
> +Alternatively, when running VTune Amplifier via command line, specify
> +``-knob enable-user-tasks=true`` option.
> +
> +Collected regions of wasted iterations will be marked on VTune Amplifier's
> +timeline as ITT tasks. These ITT tasks have predefined names, containing
> +Ethernet device and RX queue identifiers.

Documentation changes could move to different patch for better review.

> diff --git a/lib/librte_ether/rte_ethdev_profile.h b/lib/librte_ether/rte_ethdev_profile.h
> new file mode 100644
> index 0000000..1eb72bd
> +/**
> + * Initialization of profiling RX queues for the Ethernet device.
> + * Implementation of this function depends on chosen profiling method,
> + * defined in configs.
> + *
> + * @param port_id
> + *  The port identifier of the Ethernet device.
> + * @param dev
> + *  Pointer to struct rte_eth_dev corresponding to given port_id.
> + */
> +void
> +rte_eth_profile_rx_init(uint8_t port_id, struct rte_eth_dev *dev);

better to prefix __ for internal function(i.e __rte_eth_profile_rx_init)

With above suggested changes:

Acked-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>


> +
> +#endif
> -- 
> 2.7.4
> 
> 
> --------------------------------------------------------------------
> Joint Stock Company Intel A/O
> Registered legal address: Krylatsky Hills Business Park,
> 17 Krylatskaya Str., Bldg 4, Moscow 121614,
> Russian Federation
> 
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.

Remove such notice when send to public mailing list.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH v5] ether: add support for vtune task tracing
  2017-07-24  9:27           ` Jerin Jacob
@ 2017-07-24 12:33             ` Kurakin, Ilia
  2017-09-22 10:19             ` Thomas Monjalon
  1 sibling, 0 replies; 22+ messages in thread
From: Kurakin, Ilia @ 2017-07-24 12:33 UTC (permalink / raw)
  To: Jerin Jacob; +Cc: dev, Ananyev, Konstantin, Wiles, Keith, Galanov, Dmitry

Hi Jerin,

Thank you for your comments.

> -----Original Message-----
> From: Jerin Jacob [mailto:jerin.jacob@caviumnetworks.com]
> Sent: Monday, July 24, 2017 12:28 PM
> To: Kurakin, Ilia <ilia.kurakin@intel.com>
> Cc: dev@dpdk.org; Ananyev, Konstantin <konstantin.ananyev@intel.com>;
> Wiles, Keith <keith.wiles@intel.com>; Galanov, Dmitry
> <dmitry.galanov@intel.com>
> Subject: Re: [PATCH v5] ether: add support for vtune task tracing
> 
> -----Original Message-----
> > Date: Wed, 19 Jul 2017 11:54:45 +0300
> > From: ilia.kurakin@intel.com
> > To: dev@dpdk.org
> > CC: jerin.jacob@caviumnetworks.com, konstantin.ananyev@intel.com,
> > keith.wiles@intel.com, dmitry.galanov@intel.com, Ilia Kurakin
> > <ilia.kurakin@intel.com>
> > Subject: [PATCH v5] ether: add support for vtune task tracing
> > X-Mailer: git-send-email 2.7.4
> >
> > From: Ilia Kurakin <ilia.kurakin@intel.com>
> >
> > The patch adds tracing of loop iterations that yielded no packets in a
> > DPDK application. It is using ITT task API:
> >     https://software.intel.com/en-us/node/544206
> >
> > We suppose the flow of using this tracing would assume the user has
> > ITT lib and header on machine and re-build DPDK with additional make
> parameters:
> >
> >     make EXTRA_CFLAGS=-I<path to ittnotify.h>
> >          EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"
> >
> > Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>
> 
> Found a checkpatch issue.
> 
> ➜ [master][dpdk.org] $ ./devtools/checkpatches.sh
> 
> ### ether: add support for vtune task tracing
> 
> ERROR:SPACING: need consistent spacing around '*' (ctx:WxV)
> #173: FILE: lib/librte_ether/rte_ethdev_profile.c:59:
> +	__itt_domain *domains[RTE_MAX_QUEUES_PER_PORT];
>  	             ^
> 
> ERROR:SPACING: need consistent spacing around '*' (ctx:WxV)
> #177: FILE: lib/librte_ether/rte_ethdev_profile.c:63:
> +	__itt_string_handle *handles[RTE_MAX_QUEUES_PER_PORT];
>  	                    ^
> 
> total: 2 errors, 0 warnings, 278 lines checked
> 
> 0/1 valid patch

I suppose this is a mistake in the checkpatch script, since here I use "*" as a pointer.
Probably the script considers "*" as multiplication sign.

> 
> 
> >
> > ---
> >
> > -V2 change:
> >     ITT tasks collection is moved to rx callback
> >
> > -V3 change:
> >     rte_ethdev_profile.c created, all profile specific code moved there.
> >
> >     Added generic profile function
> >
> > -V4 change:
> >     checkpatch issues fixed
> >
> >     Added documentation topic
> >
> > -V5 change:
> >     Documentation fixes
> >
> >
> >  config/common_base                    |   1 +
> >  doc/guides/prog_guide/profile_app.rst |  34 ++++++++
> >  lib/librte_ether/Makefile             |   1 +
> >  lib/librte_ether/rte_ethdev.c         |   4 +
> >  lib/librte_ether/rte_ethdev_profile.c | 156
> > ++++++++++++++++++++++++++++++++++
> >  lib/librte_ether/rte_ethdev_profile.h |  52 ++++++++++++
> >  6 files changed, 248 insertions(+)
> >  create mode 100644 lib/librte_ether/rte_ethdev_profile.c
> >  create mode 100644 lib/librte_ether/rte_ethdev_profile.h
> >
> > diff --git a/config/common_base b/config/common_base index
> > 8ae6e92..dda51db 100644
> > --- a/config/common_base
> > +++ b/config/common_base
> > @@ -136,6 +136,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
> >  CONFIG_RTE_LIBRTE_IEEE1588=n
> >  CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
> >  CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
> > +CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS=n
> >
> >  #
> >  # Turn off Tx preparation stage
> > diff --git a/doc/guides/prog_guide/profile_app.rst
> > b/doc/guides/prog_guide/profile_app.rst
> > index 54b546a..590cb72 100644
> > --- a/doc/guides/prog_guide/profile_app.rst
> > +++ b/doc/guides/prog_guide/profile_app.rst
> > @@ -59,6 +59,40 @@ Refer to the
> >  for details about application profiling.
> >
> >
> > +Profiling wasted iterations with ITT
> > +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > +
> > +Iterations that yielded no RX packets (wasted loop iterations) can be
> > +analyzed using Intel® VTune\ :sup:`TM` Amplifier. This profiling
> > +employs the `Instrumentation and Tracing Technology (ITT) API
> > +<https://software.intel.com/en-us/node/544195>`_
> > +feature of VTune Amplifier and requires only reconfiguring of DPDK
> > +library, no changes in a DPDK application are needed.
> > +
> > +To trace wasted iterations on RX queues, first reconfigure DPDK with
> > +``CONFIG_RTE_ETHDEV_RXTX_CALLBACKS`` and
> > +``CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS`` enabled.
> > +
> > +Then rebuild DPDK, specifying paths to the ITT header and library,
> > +which can be found in any VTune Amplifier distribution in the
> > +*include* and *lib* directories respectively:
> > +
> > +.. code-block:: console
> > +
> > +    make EXTRA_CFLAGS=-I<path to ittnotify.h> \
> > +         EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"
> > +
> > +Finally, to see wasted iterations in your performance analysis
> > +results, select the *"Analyze user tasks, events, and counters"*
> > +checkbox in the *"Analysis Type"* tab when configuring analysis via VTune
> Amplifier GUI.
> > +Alternatively, when running VTune Amplifier via command line, specify
> > +``-knob enable-user-tasks=true`` option.
> > +
> > +Collected regions of wasted iterations will be marked on VTune
> > +Amplifier's timeline as ITT tasks. These ITT tasks have predefined
> > +names, containing Ethernet device and RX queue identifiers.
> 
> Documentation changes could move to different patch for better review.
> 
> > diff --git a/lib/librte_ether/rte_ethdev_profile.h
> > b/lib/librte_ether/rte_ethdev_profile.h
> > new file mode 100644
> > index 0000000..1eb72bd
> > +/**
> > + * Initialization of profiling RX queues for the Ethernet device.
> > + * Implementation of this function depends on chosen profiling
> > +method,
> > + * defined in configs.
> > + *
> > + * @param port_id
> > + *  The port identifier of the Ethernet device.
> > + * @param dev
> > + *  Pointer to struct rte_eth_dev corresponding to given port_id.
> > + */
> > +void
> > +rte_eth_profile_rx_init(uint8_t port_id, struct rte_eth_dev *dev);
> 
> better to prefix __ for internal function(i.e __rte_eth_profile_rx_init)
> 
> With above suggested changes:
> 
> Acked-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
> 
> 
> > +
> > +#endif
> > --
> > 2.7.4
> >
> >
> > --------------------------------------------------------------------
> > Joint Stock Company Intel A/O
> > Registered legal address: Krylatsky Hills Business Park,
> > 17 Krylatskaya Str., Bldg 4, Moscow 121614, Russian Federation
> >
> > This e-mail and any attachments may contain confidential material for
> > the sole use of the intended recipient(s). Any review or distribution
> > by others is strictly prohibited. If you are not the intended
> > recipient, please contact the sender and delete all copies.
> 
> Remove such notice when send to public mailing list.


--------------------------------------------------------------------
Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park,
17 Krylatskaya Str., Bldg 4, Moscow 121614,
Russian Federation

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH v6] ether: add support for vtune task tracing
  2017-07-19  8:54         ` [dpdk-dev] [PATCH v5] " ilia.kurakin
  2017-07-24  9:27           ` Jerin Jacob
@ 2017-07-24 17:06           ` ilia.kurakin
  2017-09-08 12:57             ` [dpdk-dev] [PATCH v7] " ilia.kurakin
  1 sibling, 1 reply; 22+ messages in thread
From: ilia.kurakin @ 2017-07-24 17:06 UTC (permalink / raw)
  To: dev
  Cc: jerin.jacob, konstantin.ananyev, keith.wiles, dmitry.galanov,
	Ilia Kurakin

From: Ilia Kurakin <ilia.kurakin@intel.com>

The patch adds tracing of loop iterations that yielded no packets in a DPDK
application. It is using ITT task API:
    https://software.intel.com/en-us/node/544206

We suppose the flow of using this tracing would assume the user has ITT lib
and header on machine and re-build DPDK with additional make parameters:

    make EXTRA_CFLAGS=-I<path to ittnotify.h>
         EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"

Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>
Acked-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>

---

-V2 change:
    ITT tasks collection is moved to rx callback

-V3 change:
    rte_ethdev_profile.c created, all profile specific code moved there.

    Added generic profile function

-V4 change:
    checkpatch issues fixed

    Added documentation topic

-V5 change:
    Documentation fixes

-v6 change:
    Documentation changes are moved to different patch


 config/common_base                    |   1 +
 lib/librte_ether/Makefile             |   1 +
 lib/librte_ether/rte_ethdev.c         |   4 +
 lib/librte_ether/rte_ethdev_profile.c | 156 ++++++++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev_profile.h |  52 ++++++++++++
 5 files changed, 214 insertions(+)
 create mode 100644 lib/librte_ether/rte_ethdev_profile.c
 create mode 100644 lib/librte_ether/rte_ethdev_profile.h

diff --git a/config/common_base b/config/common_base
index 7805605..7465b5c 100644
--- a/config/common_base
+++ b/config/common_base
@@ -136,6 +136,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
 CONFIG_RTE_LIBRTE_IEEE1588=n
 CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
 CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
+CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS=n
 
 #
 # Turn off Tx preparation stage
diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile
index db692ae..7224a11 100644
--- a/lib/librte_ether/Makefile
+++ b/lib/librte_ether/Makefile
@@ -46,6 +46,7 @@ LIBABIVER := 6
 SRCS-y += rte_ethdev.c
 SRCS-y += rte_flow.c
 SRCS-y += rte_tm.c
+SRCS-y += rte_ethdev_profile.c
 
 #
 # Export include files
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index d4ebb1b..fd3632a 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -67,6 +67,7 @@
 
 #include "rte_ether.h"
 #include "rte_ethdev.h"
+#include "rte_ethdev_profile.h"
 
 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
@@ -828,6 +829,9 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 		return diag;
 	}
 
+	/* See rte_ethdev_profile.h to find comments on code below. */
+	__rte_eth_profile_rx_init(port_id, dev);
+
 	return 0;
 }
 
diff --git a/lib/librte_ether/rte_ethdev_profile.c b/lib/librte_ether/rte_ethdev_profile.c
new file mode 100644
index 0000000..0e1b512
--- /dev/null
+++ b/lib/librte_ether/rte_ethdev_profile.c
@@ -0,0 +1,156 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <rte_config.h>
+
+#include "rte_ethdev_profile.h"
+
+/**
+ * This conditional block enables RX queues profiling by tracking wasted
+ * iterations, i.e. iterations which yielded no RX packets. Profiling is
+ * performed using the Instrumentation and Tracing Technology (ITT) API,
+ * employed by the Intel (R) VTune (TM) Amplifier.
+ */
+#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
+
+#include <ittnotify.h>
+
+#define ITT_MAX_NAME_LEN (100)
+
+/**
+ * Auxiliary ITT structure belonging to Ethernet device and using to:
+ *   -  track RX queue state to determine whether it is wasting loop iterations
+ *   -  begin or end ITT task using task domain and task name (handle)
+ */
+struct itt_profile_rx_data {
+	/**
+	 * ITT domains for each queue.
+	 */
+	__itt_domain *domains[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * ITT task names for each queue.
+	 */
+	__itt_string_handle *handles[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * Flags indicating the queues state. Possible values:
+	 *   1 - queue is wasting iterations,
+	 *   0 - otherwise.
+	 */
+	uint8_t queue_state[RTE_MAX_QUEUES_PER_PORT];
+};
+
+/**
+ * The pool of *itt_profile_rx_data* structures.
+ */
+struct itt_profile_rx_data itt_rx_data[RTE_MAX_ETHPORTS];
+
+
+/**
+ * This callback function manages ITT tasks collection on given port and queue.
+ * It must be registered with rte_eth_add_rx_callback() to be called from
+ * rte_eth_rx_burst(). To find more comments see rte_rx_callback_fn function
+ * type declaration.
+ */
+static uint16_t
+collect_itt_rx_burst_cb(uint8_t port_id, uint16_t queue_id,
+	__rte_unused struct rte_mbuf *pkts[], uint16_t nb_pkts,
+	__rte_unused uint16_t max_pkts, __rte_unused void *user_param)
+{
+	if (unlikely(nb_pkts == 0)) {
+		if (!itt_rx_data[port_id].queue_state[queue_id]) {
+			__itt_task_begin(
+				itt_rx_data[port_id].domains[queue_id],
+				__itt_null, __itt_null,
+				itt_rx_data[port_id].handles[queue_id]);
+			itt_rx_data[port_id].queue_state[queue_id] = 1;
+		}
+	} else {
+		if (unlikely(itt_rx_data[port_id].queue_state[queue_id])) {
+			__itt_task_end(
+				itt_rx_data[port_id].domains[queue_id]);
+			itt_rx_data[port_id].queue_state[queue_id] = 0;
+		}
+	}
+	return nb_pkts;
+}
+
+/**
+ * Initialization of itt_profile_rx_data for a given Ethernet device.
+ * This function must be invoked when ethernet device is being configured.
+ * Result will be stored in the global array *itt_rx_data*.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param port_name
+ *  The name of the Ethernet device.
+ * @param rx_queue_num
+ *  The number of RX queues on specified port.
+ */
+static inline void
+itt_profile_rx_init(uint8_t port_id, char *port_name, uint8_t rx_queue_num)
+{
+	uint16_t q_id;
+
+	for (q_id = 0; q_id < rx_queue_num; ++q_id) {
+		char domain_name[ITT_MAX_NAME_LEN];
+
+		snprintf(domain_name, sizeof(domain_name),
+			"RXBurst.WastedIterations.Port_%s.Queue_%d",
+			port_name, q_id);
+		itt_rx_data[port_id].domains[q_id]
+			= __itt_domain_create(domain_name);
+
+		char task_name[ITT_MAX_NAME_LEN];
+
+		snprintf(task_name, sizeof(task_name),
+			"port id: %d; queue id: %d",
+			port_id, q_id);
+		itt_rx_data[port_id].handles[q_id]
+			= __itt_string_handle_create(task_name);
+
+		itt_rx_data[port_id].queue_state[q_id] = 0;
+
+		rte_eth_add_rx_callback(
+			port_id, q_id, collect_itt_rx_burst_cb, NULL);
+	}
+}
+#endif /* RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS */
+
+void
+__rte_eth_profile_rx_init(__rte_unused uint8_t port_id,
+	__rte_unused struct rte_eth_dev *dev)
+{
+#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
+	itt_profile_rx_init(port_id, dev->data->name, dev->data->nb_rx_queues);
+#endif
+}
diff --git a/lib/librte_ether/rte_ethdev_profile.h b/lib/librte_ether/rte_ethdev_profile.h
new file mode 100644
index 0000000..eecec72
--- /dev/null
+++ b/lib/librte_ether/rte_ethdev_profile.h
@@ -0,0 +1,52 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_ETHDEV_PROFILE_H_
+#define _RTE_ETHDEV_PROFILE_H_
+
+#include "rte_ethdev.h"
+
+/**
+ * Initialization of profiling RX queues for the Ethernet device.
+ * Implementation of this function depends on chosen profiling method,
+ * defined in configs.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param dev
+ *  Pointer to struct rte_eth_dev corresponding to given port_id.
+ */
+void
+__rte_eth_profile_rx_init(uint8_t port_id, struct rte_eth_dev *dev);
+
+#endif
-- 
2.7.4


--------------------------------------------------------------------
Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park,
17 Krylatskaya Str., Bldg 4, Moscow 121614,
Russian Federation

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH v7] ether: add support for vtune task tracing
  2017-07-24 17:06           ` [dpdk-dev] [PATCH v6] " ilia.kurakin
@ 2017-09-08 12:57             ` ilia.kurakin
  2017-09-22 10:42               ` Thomas Monjalon
  2017-09-22 14:52               ` [dpdk-dev] [PATCH v8] " ilia.kurakin
  0 siblings, 2 replies; 22+ messages in thread
From: ilia.kurakin @ 2017-09-08 12:57 UTC (permalink / raw)
  To: dev; +Cc: thomas, jerin.jacob, keith.wiles, dmitry.galanov, Ilia Kurakin

From: Ilia Kurakin <ilia.kurakin@intel.com>

The patch simplifies DPDK applications analysis for developers which use
Intel® VTune Amplifier.

The empty cycles are such iterations that yielded no RX packets. As far as
DPDK is running in poll mode, wasting cycles is equal to wasting CPU time.
Tracing such iterations can identify that device is underutilized. Tracing
empty cycles becomes even more critical if a system uses a lot of Ethernet
ports.

The patch gives possibility to analyze empty cycles without changing
application code. All needs to be done is just to reconfigure and rebuild
the DPDK itself with CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
enbled. The important thing here is that this does not affect DPDK code.
The profiling code is not being compiled if user does not specify config flag.

The patch provides common way to inject RX queues profiling and VTune specific
implementation.


Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>

---

-V2 change:
    ITT tasks collection is moved to rx callback

-V3 change:
    rte_ethdev_profile.c created, all profile specific code moved there.

    Added generic profile function

-V4 change:
    checkpatch issues fixed

    Added documentation topic

-V5 change:
    Documentation fixes

-V6 change:
    Documentation changes are moved to different patch

-V7 change:
    Documentation and code changes are merged to a single patch.
    Added detailed description.


 config/common_base                    |   1 +
 doc/guides/prog_guide/profile_app.rst |  37 +++++++-
 lib/librte_ether/Makefile             |   1 +
 lib/librte_ether/rte_ethdev.c         |   4 +
 lib/librte_ether/rte_ethdev_profile.c | 156 ++++++++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev_profile.h |  52 ++++++++++++
 6 files changed, 250 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_ether/rte_ethdev_profile.c
 create mode 100644 lib/librte_ether/rte_ethdev_profile.h

diff --git a/config/common_base b/config/common_base
index 5e97a08..12f6be9 100644
--- a/config/common_base
+++ b/config/common_base
@@ -136,6 +136,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
 CONFIG_RTE_LIBRTE_IEEE1588=n
 CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
 CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
+CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS=n
 
 #
 # Turn off Tx preparation stage
diff --git a/doc/guides/prog_guide/profile_app.rst b/doc/guides/prog_guide/profile_app.rst
index 54b546a..ca1c91f 100644
--- a/doc/guides/prog_guide/profile_app.rst
+++ b/doc/guides/prog_guide/profile_app.rst
@@ -39,7 +39,8 @@ Profiling on x86
 ----------------
 
 Intel processors provide performance counters to monitor events.
-Some tools provided by Intel, such as VTune, can be used to profile and benchmark an application.
+Some tools provided by Intel, such as Intel® VTune™ Amplifier, can be used
+to profile and benchmark an application.
 See the *VTune Performance Analyzer Essentials* publication from Intel Press for more information.
 
 For a DPDK application, this can be done in a Linux* application environment only.
@@ -59,6 +60,40 @@ Refer to the
 for details about application profiling.
 
 
+Empty cycles tracing
+~~~~~~~~~~~~~~~~~~~~
+
+Iterations that yielded no RX packets (empty cycles, wasted iterations) can
+be analyzed using VTune Amplifier. This profiling employs the
+`Instrumentation and Tracing Technology (ITT) API
+<https://software.intel.com/en-us/node/544195>`_
+feature of VTune Amplifier and requires only reconfiguring the DPDK library,
+no changes in a DPDK application are needed.
+
+To trace wasted iterations on RX queues, first reconfigure DPDK with
+``CONFIG_RTE_ETHDEV_RXTX_CALLBACKS`` and
+``CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS`` enabled.
+
+Then rebuild DPDK, specifying paths to the ITT header and library, which can
+be found in any VTune Amplifier distribution in the *include* and *lib*
+directories respectively:
+
+.. code-block:: console
+
+    make EXTRA_CFLAGS=-I<path to ittnotify.h> \
+         EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"
+
+Finally, to see wasted iterations in your performance analysis results,
+select the *"Analyze user tasks, events, and counters"* checkbox in the
+*"Analysis Type"* tab when configuring analysis via VTune Amplifier GUI.
+Alternatively, when running VTune Amplifier via command line, specify
+``-knob enable-user-tasks=true`` option.
+
+Collected regions of wasted iterations will be marked on VTune Amplifier's
+timeline as ITT tasks. These ITT tasks have predefined names, containing
+Ethernet device and RX queue identifiers.
+
+
 Profiling on ARM64
 ------------------
 
diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile
index 27d9766..ac1622b 100644
--- a/lib/librte_ether/Makefile
+++ b/lib/librte_ether/Makefile
@@ -46,6 +46,7 @@ LIBABIVER := 6
 SRCS-y += rte_ethdev.c
 SRCS-y += rte_flow.c
 SRCS-y += rte_tm.c
+SRCS-y += rte_ethdev_profile.c
 
 #
 # Export include files
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 0597641..0f020b3 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -67,6 +67,7 @@
 
 #include "rte_ether.h"
 #include "rte_ethdev.h"
+#include "rte_ethdev_profile.h"
 
 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
@@ -819,6 +820,9 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 		return diag;
 	}
 
+	/* See rte_ethdev_profile.h to find comments on code below. */
+	__rte_eth_profile_rx_init(port_id, dev);
+
 	return 0;
 }
 
diff --git a/lib/librte_ether/rte_ethdev_profile.c b/lib/librte_ether/rte_ethdev_profile.c
new file mode 100644
index 0000000..2dee75e
--- /dev/null
+++ b/lib/librte_ether/rte_ethdev_profile.c
@@ -0,0 +1,156 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <rte_config.h>
+
+#include "rte_ethdev_profile.h"
+
+/**
+ * This conditional block enables RX queues profiling by tracking wasted
+ * iterations, i.e. iterations which yielded no RX packets. Profiling is
+ * performed using the Instrumentation and Tracing Technology (ITT) API,
+ * employed by the Intel (R) VTune (TM) Amplifier.
+ */
+#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
+
+#include <ittnotify.h>
+
+#define ITT_MAX_NAME_LEN (100)
+
+/**
+ * Auxiliary ITT structure belonging to Ethernet device and using to:
+ *   -  track RX queue state to determine whether it is wasting loop iterations
+ *   -  begin or end ITT task using task domain and task name (handle)
+ */
+struct itt_profile_rx_data {
+	/**
+	 * ITT domains for each queue.
+	 */
+	__itt_domain *domains[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * ITT task names for each queue.
+	 */
+	__itt_string_handle *handles[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * Flags indicating the queues state. Possible values:
+	 *   1 - queue is wasting iterations,
+	 *   0 - otherwise.
+	 */
+	uint8_t queue_state[RTE_MAX_QUEUES_PER_PORT];
+};
+
+/**
+ * The pool of *itt_profile_rx_data* structures.
+ */
+struct itt_profile_rx_data itt_rx_data[RTE_MAX_ETHPORTS];
+
+
+/**
+ * This callback function manages ITT tasks collection on given port and queue.
+ * It must be registered with rte_eth_add_rx_callback() to be called from
+ * rte_eth_rx_burst(). To find more comments see rte_rx_callback_fn function
+ * type declaration.
+ */
+static uint16_t
+collect_itt_rx_burst_cb(uint8_t port_id, uint16_t queue_id,
+	__rte_unused struct rte_mbuf *pkts[], uint16_t nb_pkts,
+	__rte_unused uint16_t max_pkts, __rte_unused void *user_param)
+{
+	if (unlikely(nb_pkts == 0)) {
+		if (!itt_rx_data[port_id].queue_state[queue_id]) {
+			__itt_task_begin(
+				itt_rx_data[port_id].domains[queue_id],
+				__itt_null, __itt_null,
+				itt_rx_data[port_id].handles[queue_id]);
+			itt_rx_data[port_id].queue_state[queue_id] = 1;
+		}
+	} else {
+		if (unlikely(itt_rx_data[port_id].queue_state[queue_id])) {
+			__itt_task_end(
+				itt_rx_data[port_id].domains[queue_id]);
+			itt_rx_data[port_id].queue_state[queue_id] = 0;
+		}
+	}
+	return nb_pkts;
+}
+
+/**
+ * Initialization of itt_profile_rx_data for a given Ethernet device.
+ * This function must be invoked when ethernet device is being configured.
+ * Result will be stored in the global array *itt_rx_data*.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param port_name
+ *  The name of the Ethernet device.
+ * @param rx_queue_num
+ *  The number of RX queues on specified port.
+ */
+static inline void
+itt_profile_rx_init(uint8_t port_id, char *port_name, uint8_t rx_queue_num)
+{
+	uint16_t q_id;
+
+	for (q_id = 0; q_id < rx_queue_num; ++q_id) {
+		char domain_name[ITT_MAX_NAME_LEN];
+
+		snprintf(domain_name, sizeof(domain_name),
+			"RXBurst.WastedIterations.Port_%s.Queue_%d",
+			port_name, q_id);
+		itt_rx_data[port_id].domains[q_id]
+			= __itt_domain_create(domain_name);
+
+		char task_name[ITT_MAX_NAME_LEN];
+
+		snprintf(task_name, sizeof(task_name),
+			"port id: %d; queue id: %d",
+			port_id, q_id);
+		itt_rx_data[port_id].handles[q_id]
+			= __itt_string_handle_create(task_name);
+
+		itt_rx_data[port_id].queue_state[q_id] = 0;
+
+		rte_eth_add_rx_callback(
+			port_id, q_id, collect_itt_rx_burst_cb, NULL);
+	}
+}
+#endif /* RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS */
+
+void
+__rte_eth_profile_rx_init(__rte_unused uint8_t port_id,
+	__rte_unused struct rte_eth_dev *dev)
+{
+#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
+	itt_profile_rx_init(port_id, dev->data->name, dev->data->nb_rx_queues);
+#endif
+}
diff --git a/lib/librte_ether/rte_ethdev_profile.h b/lib/librte_ether/rte_ethdev_profile.h
new file mode 100644
index 0000000..eecec72
--- /dev/null
+++ b/lib/librte_ether/rte_ethdev_profile.h
@@ -0,0 +1,52 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_ETHDEV_PROFILE_H_
+#define _RTE_ETHDEV_PROFILE_H_
+
+#include "rte_ethdev.h"
+
+/**
+ * Initialization of profiling RX queues for the Ethernet device.
+ * Implementation of this function depends on chosen profiling method,
+ * defined in configs.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param dev
+ *  Pointer to struct rte_eth_dev corresponding to given port_id.
+ */
+void
+__rte_eth_profile_rx_init(uint8_t port_id, struct rte_eth_dev *dev);
+
+#endif
-- 
2.9.3

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH v5] ether: add support for vtune task tracing
  2017-07-24  9:27           ` Jerin Jacob
  2017-07-24 12:33             ` Kurakin, Ilia
@ 2017-09-22 10:19             ` Thomas Monjalon
  1 sibling, 0 replies; 22+ messages in thread
From: Thomas Monjalon @ 2017-09-22 10:19 UTC (permalink / raw)
  To: Jerin Jacob
  Cc: dev, ilia.kurakin, konstantin.ananyev, keith.wiles, dmitry.galanov

24/07/2017 11:27, Jerin Jacob:
> Documentation changes could move to different patch for better review.

Sorry for late reply,
I think it is better to have doc with code in the same patch.
I will merge them when applying.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH v7] ether: add support for vtune task tracing
  2017-09-08 12:57             ` [dpdk-dev] [PATCH v7] " ilia.kurakin
@ 2017-09-22 10:42               ` Thomas Monjalon
  2017-09-22 14:52               ` [dpdk-dev] [PATCH v8] " ilia.kurakin
  1 sibling, 0 replies; 22+ messages in thread
From: Thomas Monjalon @ 2017-09-22 10:42 UTC (permalink / raw)
  To: ilia.kurakin; +Cc: dev, jerin.jacob, keith.wiles, dmitry.galanov

08/09/2017 14:57, ilia.kurakin@intel.com:
> +	/* See rte_ethdev_profile.h to find comments on code below. */
> +	__rte_eth_profile_rx_init(port_id, dev);

We can find easily where the function is defined.
Please replace this comment by something like that:
/* Initialize Rx profiling if enabled at compilation time. */

Why not checking an error code for this initialization?
If we enable it, we expect the application to abort if
the profiling does not work.


> --- /dev/null
> +++ b/lib/librte_ether/rte_ethdev_profile.h

This file is internal so it should not appear in doxygen index.
Please remove rte_ prefix from the filename to blacklist it from
doxygen point of view.
You can apply the same change to the .c file for consistency.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [dpdk-dev] [PATCH v8] ether: add support for vtune task tracing
  2017-09-08 12:57             ` [dpdk-dev] [PATCH v7] " ilia.kurakin
  2017-09-22 10:42               ` Thomas Monjalon
@ 2017-09-22 14:52               ` ilia.kurakin
  2017-09-22 17:04                 ` Thomas Monjalon
  1 sibling, 1 reply; 22+ messages in thread
From: ilia.kurakin @ 2017-09-22 14:52 UTC (permalink / raw)
  To: dev; +Cc: thomas, jerin.jacob, keith.wiles, dmitry.galanov, Ilia Kurakin

From: Ilia Kurakin <ilia.kurakin@intel.com>

The patch simplifies DPDK applications analysis for developers which use
Intel® VTune Amplifier.

The empty cycles are such iterations that yielded no RX packets. As far as
DPDK is running in poll mode, wasting cycles is equal to wasting CPU time.
Tracing such iterations can identify that device is underutilized. Tracing
empty cycles becomes even more critical if a system uses a lot of Ethernet
ports.

The patch gives possibility to analyze empty cycles without changing
application code. All needs to be done is just to reconfigure and rebuild
the DPDK itself with CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
enbled. The important thing here is that this does not affect DPDK code.
The profiling code is not being compiled if user does not specify config
flag.

The patch provides common way to inject RX queues profiling and VTune
specific implementation.

Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>

---

-V2 change:
    ITT tasks collection is moved to rx callback

-V3 change:
    rte_ethdev_profile.c created, all profile specific code moved there.

    Added generic profile function

-V4 change:
    checkpatch issues fixed

    Added documentation topic

-V5 change:
    Documentation fixes

-V6 change:
    Documentation changes are moved to different patch

-V7 change:
    Documentation and code changes are merged to a single patch.
    Added detailed description.

-V8 change:
    Added return code handling for Rx queues profiling init.


 config/common_base                    |   1 +
 doc/guides/prog_guide/profile_app.rst |  37 +++++++-
 lib/librte_ether/Makefile             |   1 +
 lib/librte_ether/ethdev_profile.c     | 166 ++++++++++++++++++++++++++++++++++
 lib/librte_ether/ethdev_profile.h     |  56 ++++++++++++
 lib/librte_ether/rte_ethdev.c         |  11 +++
 6 files changed, 271 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_ether/ethdev_profile.c
 create mode 100644 lib/librte_ether/ethdev_profile.h

diff --git a/config/common_base b/config/common_base
index 5e97a08..12f6be9 100644
--- a/config/common_base
+++ b/config/common_base
@@ -136,6 +136,7 @@ CONFIG_RTE_MAX_QUEUES_PER_PORT=1024
 CONFIG_RTE_LIBRTE_IEEE1588=n
 CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS=16
 CONFIG_RTE_ETHDEV_RXTX_CALLBACKS=y
+CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS=n
 
 #
 # Turn off Tx preparation stage
diff --git a/doc/guides/prog_guide/profile_app.rst b/doc/guides/prog_guide/profile_app.rst
index 54b546a..ca1c91f 100644
--- a/doc/guides/prog_guide/profile_app.rst
+++ b/doc/guides/prog_guide/profile_app.rst
@@ -39,7 +39,8 @@ Profiling on x86
 ----------------
 
 Intel processors provide performance counters to monitor events.
-Some tools provided by Intel, such as VTune, can be used to profile and benchmark an application.
+Some tools provided by Intel, such as Intel® VTune™ Amplifier, can be used
+to profile and benchmark an application.
 See the *VTune Performance Analyzer Essentials* publication from Intel Press for more information.
 
 For a DPDK application, this can be done in a Linux* application environment only.
@@ -59,6 +60,40 @@ Refer to the
 for details about application profiling.
 
 
+Empty cycles tracing
+~~~~~~~~~~~~~~~~~~~~
+
+Iterations that yielded no RX packets (empty cycles, wasted iterations) can
+be analyzed using VTune Amplifier. This profiling employs the
+`Instrumentation and Tracing Technology (ITT) API
+<https://software.intel.com/en-us/node/544195>`_
+feature of VTune Amplifier and requires only reconfiguring the DPDK library,
+no changes in a DPDK application are needed.
+
+To trace wasted iterations on RX queues, first reconfigure DPDK with
+``CONFIG_RTE_ETHDEV_RXTX_CALLBACKS`` and
+``CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS`` enabled.
+
+Then rebuild DPDK, specifying paths to the ITT header and library, which can
+be found in any VTune Amplifier distribution in the *include* and *lib*
+directories respectively:
+
+.. code-block:: console
+
+    make EXTRA_CFLAGS=-I<path to ittnotify.h> \
+         EXTRA_LDLIBS="-L<path to libittnotify.a> -littnotify"
+
+Finally, to see wasted iterations in your performance analysis results,
+select the *"Analyze user tasks, events, and counters"* checkbox in the
+*"Analysis Type"* tab when configuring analysis via VTune Amplifier GUI.
+Alternatively, when running VTune Amplifier via command line, specify
+``-knob enable-user-tasks=true`` option.
+
+Collected regions of wasted iterations will be marked on VTune Amplifier's
+timeline as ITT tasks. These ITT tasks have predefined names, containing
+Ethernet device and RX queue identifiers.
+
+
 Profiling on ARM64
 ------------------
 
diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile
index 27d9766..5f65d05 100644
--- a/lib/librte_ether/Makefile
+++ b/lib/librte_ether/Makefile
@@ -46,6 +46,7 @@ LIBABIVER := 6
 SRCS-y += rte_ethdev.c
 SRCS-y += rte_flow.c
 SRCS-y += rte_tm.c
+SRCS-y += ethdev_profile.c
 
 #
 # Export include files
diff --git a/lib/librte_ether/ethdev_profile.c b/lib/librte_ether/ethdev_profile.c
new file mode 100644
index 0000000..13c48a8
--- /dev/null
+++ b/lib/librte_ether/ethdev_profile.c
@@ -0,0 +1,166 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <rte_config.h>
+
+#include "ethdev_profile.h"
+
+/**
+ * This conditional block enables RX queues profiling by tracking wasted
+ * iterations, i.e. iterations which yielded no RX packets. Profiling is
+ * performed using the Instrumentation and Tracing Technology (ITT) API,
+ * employed by the Intel (R) VTune (TM) Amplifier.
+ */
+#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
+
+#include <ittnotify.h>
+
+#define ITT_MAX_NAME_LEN (100)
+
+/**
+ * Auxiliary ITT structure belonging to Ethernet device and using to:
+ *   -  track RX queue state to determine whether it is wasting loop iterations
+ *   -  begin or end ITT task using task domain and task name (handle)
+ */
+struct itt_profile_rx_data {
+	/**
+	 * ITT domains for each queue.
+	 */
+	__itt_domain *domains[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * ITT task names for each queue.
+	 */
+	__itt_string_handle *handles[RTE_MAX_QUEUES_PER_PORT];
+	/**
+	 * Flags indicating the queues state. Possible values:
+	 *   1 - queue is wasting iterations,
+	 *   0 - otherwise.
+	 */
+	uint8_t queue_state[RTE_MAX_QUEUES_PER_PORT];
+};
+
+/**
+ * The pool of *itt_profile_rx_data* structures.
+ */
+struct itt_profile_rx_data itt_rx_data[RTE_MAX_ETHPORTS];
+
+
+/**
+ * This callback function manages ITT tasks collection on given port and queue.
+ * It must be registered with rte_eth_add_rx_callback() to be called from
+ * rte_eth_rx_burst(). To find more comments see rte_rx_callback_fn function
+ * type declaration.
+ */
+static uint16_t
+collect_itt_rx_burst_cb(uint8_t port_id, uint16_t queue_id,
+	__rte_unused struct rte_mbuf *pkts[], uint16_t nb_pkts,
+	__rte_unused uint16_t max_pkts, __rte_unused void *user_param)
+{
+	if (unlikely(nb_pkts == 0)) {
+		if (!itt_rx_data[port_id].queue_state[queue_id]) {
+			__itt_task_begin(
+				itt_rx_data[port_id].domains[queue_id],
+				__itt_null, __itt_null,
+				itt_rx_data[port_id].handles[queue_id]);
+			itt_rx_data[port_id].queue_state[queue_id] = 1;
+		}
+	} else {
+		if (unlikely(itt_rx_data[port_id].queue_state[queue_id])) {
+			__itt_task_end(
+				itt_rx_data[port_id].domains[queue_id]);
+			itt_rx_data[port_id].queue_state[queue_id] = 0;
+		}
+	}
+	return nb_pkts;
+}
+
+/**
+ * Initialization of itt_profile_rx_data for a given Ethernet device.
+ * This function must be invoked when ethernet device is being configured.
+ * Result will be stored in the global array *itt_rx_data*.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param port_name
+ *  The name of the Ethernet device.
+ * @param rx_queue_num
+ *  The number of RX queues on specified port.
+ *
+ * @return
+ *  - On success, zero.
+ *  - On failure, a negative value.
+ */
+static inline int
+itt_profile_rx_init(uint8_t port_id, char *port_name, uint8_t rx_queue_num)
+{
+	uint16_t q_id;
+
+	for (q_id = 0; q_id < rx_queue_num; ++q_id) {
+		char domain_name[ITT_MAX_NAME_LEN];
+
+		snprintf(domain_name, sizeof(domain_name),
+			"RXBurst.WastedIterations.Port_%s.Queue_%d",
+			port_name, q_id);
+		itt_rx_data[port_id].domains[q_id]
+			= __itt_domain_create(domain_name);
+
+		char task_name[ITT_MAX_NAME_LEN];
+
+		snprintf(task_name, sizeof(task_name),
+			"port id: %d; queue id: %d",
+			port_id, q_id);
+		itt_rx_data[port_id].handles[q_id]
+			= __itt_string_handle_create(task_name);
+
+		itt_rx_data[port_id].queue_state[q_id] = 0;
+
+		if (!rte_eth_add_rx_callback(
+			port_id, q_id, collect_itt_rx_burst_cb, NULL)) {
+			return -rte_errno;
+		}
+	}
+
+	return 0;
+}
+#endif /* RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS */
+
+int
+__rte_eth_profile_rx_init(__rte_unused uint8_t port_id,
+	__rte_unused struct rte_eth_dev *dev)
+{
+#ifdef RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
+	return itt_profile_rx_init(
+		port_id, dev->data->name, dev->data->nb_rx_queues);
+#endif
+	return 0;
+}
diff --git a/lib/librte_ether/ethdev_profile.h b/lib/librte_ether/ethdev_profile.h
new file mode 100644
index 0000000..32f103e
--- /dev/null
+++ b/lib/librte_ether/ethdev_profile.h
@@ -0,0 +1,56 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_ETHDEV_PROFILE_H_
+#define _RTE_ETHDEV_PROFILE_H_
+
+#include "rte_ethdev.h"
+
+/**
+ * Initialization of profiling RX queues for the Ethernet device.
+ * Implementation of this function depends on chosen profiling method,
+ * defined in configs.
+ *
+ * @param port_id
+ *  The port identifier of the Ethernet device.
+ * @param dev
+ *  Pointer to struct rte_eth_dev corresponding to given port_id.
+ *
+ * @return
+ *  - On success, zero.
+ *  - On failure, a negative value.
+ */
+int
+__rte_eth_profile_rx_init(uint8_t port_id, struct rte_eth_dev *dev);
+
+#endif
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index a88916f..1849a3b 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -67,6 +67,7 @@
 
 #include "rte_ether.h"
 #include "rte_ethdev.h"
+#include "ethdev_profile.h"
 
 static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
@@ -819,6 +820,16 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 		return diag;
 	}
 
+	/* Initialize Rx profiling if enabled at compilation time. */
+	diag = __rte_eth_profile_rx_init(port_id, dev);
+	if (diag != 0) {
+		RTE_PMD_DEBUG_TRACE("port%d __rte_eth_profile_rx_init = %d\n",
+				port_id, diag);
+		rte_eth_dev_rx_queue_config(dev, 0);
+		rte_eth_dev_tx_queue_config(dev, 0);
+		return diag;
+	}
+
 	return 0;
 }
 
-- 
2.9.3

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [dpdk-dev] [PATCH v8] ether: add support for vtune task tracing
  2017-09-22 14:52               ` [dpdk-dev] [PATCH v8] " ilia.kurakin
@ 2017-09-22 17:04                 ` Thomas Monjalon
  0 siblings, 0 replies; 22+ messages in thread
From: Thomas Monjalon @ 2017-09-22 17:04 UTC (permalink / raw)
  To: ilia.kurakin; +Cc: dev, jerin.jacob, keith.wiles, dmitry.galanov

22/09/2017 16:52, ilia.kurakin@intel.com:
> From: Ilia Kurakin <ilia.kurakin@intel.com>
> 
> The patch simplifies DPDK applications analysis for developers which use
> Intel® VTune Amplifier.
> 
> The empty cycles are such iterations that yielded no RX packets. As far as
> DPDK is running in poll mode, wasting cycles is equal to wasting CPU time.
> Tracing such iterations can identify that device is underutilized. Tracing
> empty cycles becomes even more critical if a system uses a lot of Ethernet
> ports.
> 
> The patch gives possibility to analyze empty cycles without changing
> application code. All needs to be done is just to reconfigure and rebuild
> the DPDK itself with CONFIG_RTE_ETHDEV_PROFILE_ITT_WASTED_RX_ITERATIONS
> enbled. The important thing here is that this does not affect DPDK code.
> The profiling code is not being compiled if user does not specify config
> flag.
> 
> The patch provides common way to inject RX queues profiling and VTune
> specific implementation.
> 
> Signed-off-by: Ilia Kurakin <ilia.kurakin@intel.com>

Applied with previous Ack from Jerin, thanks

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2017-09-22 17:04 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-19 17:18 [dpdk-dev] [PATCH] ether: add support for vtune task tracing ilia.kurakin
2017-06-22  9:42 ` Ananyev, Konstantin
2017-06-22 12:12   ` Kurakin, Ilia
2017-06-22 16:46     ` Galanov, Dmitry
2017-06-27 13:16 ` ilia.kurakin
2017-06-30  3:30   ` Jerin Jacob
2017-06-30 10:13     ` Ananyev, Konstantin
2017-07-06 16:42   ` [dpdk-dev] [PATCH v2] " ilia.kurakin
2017-07-10 12:30     ` Jerin Jacob
2017-07-11 17:24     ` [dpdk-dev] [PATCH v3] The patch adds tracing of loop iterations that yielded no packets in a DPDK application. It is using ITT task API: https://software.intel.com/en-us/node/544206 ilia.kurakin
2017-07-11 17:48     ` [dpdk-dev] [PATCH v3] ether: add support for vtune task tracing ilia.kurakin
2017-07-14  5:45       ` Jerin Jacob
2017-07-17 17:15       ` [dpdk-dev] [PATCH v4] " ilia.kurakin
2017-07-19  8:54         ` [dpdk-dev] [PATCH v5] " ilia.kurakin
2017-07-24  9:27           ` Jerin Jacob
2017-07-24 12:33             ` Kurakin, Ilia
2017-09-22 10:19             ` Thomas Monjalon
2017-07-24 17:06           ` [dpdk-dev] [PATCH v6] " ilia.kurakin
2017-09-08 12:57             ` [dpdk-dev] [PATCH v7] " ilia.kurakin
2017-09-22 10:42               ` Thomas Monjalon
2017-09-22 14:52               ` [dpdk-dev] [PATCH v8] " ilia.kurakin
2017-09-22 17:04                 ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).