Add a new rte_graph_cycle_stats_enable() function to control whether
rte_rdtsc() is called twice for each node visit in order to collect the
number of cycles spent in each node process callback.

The default value remains the same as before and is fixed by the compile
time value RTE_LIBRTE_GRAPH_STATS.

Signed-off-by: Robin Jarry <[email protected]>
---
 lib/graph/graph_populate.c          |  1 +
 lib/graph/rte_graph_worker_common.h | 18 ++++++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/lib/graph/graph_populate.c b/lib/graph/graph_populate.c
index 026daecb2122..e51e3b39e24a 100644
--- a/lib/graph/graph_populate.c
+++ b/lib/graph/graph_populate.c
@@ -64,6 +64,7 @@ graph_header_popluate(struct graph *_graph)
        graph->nb_nodes = _graph->node_count;
        graph->cir_start = RTE_PTR_ADD(graph, _graph->cir_start);
        graph->nodes_start = _graph->nodes_start;
+       graph->cycles_stats = rte_graph_has_stats_feature();
        graph->socket = _graph->socket;
        graph->id = _graph->id;
        memcpy(graph->name, _graph->name, RTE_GRAPH_NAMESIZE);
diff --git a/lib/graph/rte_graph_worker_common.h 
b/lib/graph/rte_graph_worker_common.h
index c87a6796a96e..4161fc4b02e7 100644
--- a/lib/graph/rte_graph_worker_common.h
+++ b/lib/graph/rte_graph_worker_common.h
@@ -56,7 +56,7 @@ struct __rte_cache_aligned rte_graph {
        rte_graph_off_t *cir_start;  /**< Pointer to circular buffer. */
        rte_graph_off_t nodes_start; /**< Offset at which node memory starts. */
        uint8_t model;               /**< graph model */
-       uint8_t reserved1;           /**< Reserved for future use. */
+       uint8_t cycles_stats;        /**< Reserved for future use. */
        uint16_t reserved2;          /**< Reserved for future use. */
        union {
                /* Fast schedule area for mcore dispatch model */
@@ -205,7 +205,7 @@ __rte_node_process(struct rte_graph *graph, struct rte_node 
*node)
        objs = node->objs;
        rte_prefetch0(objs);
 
-       if (rte_graph_has_stats_feature()) {
+       if (graph->cycles_stats) {
                start = rte_rdtsc();
                rc = node->process(graph, node, objs, node->idx);
                node->total_cycles += rte_rdtsc() - start;
@@ -560,6 +560,20 @@ rte_graph_model_is_valid(uint8_t model);
  */
 int rte_graph_worker_model_set(uint8_t model);
 
+/**
+ * Enable/disable collecting of TSC cycles for each node visit. The default
+ * value for all new or cloned graphs is equal to rte_graph_has_stats_feature()
+ * which is set to the RTE_LIBRTE_GRAPH_STATS compile time constant.
+ *
+ * @param enabled
+ *   Set to 1 to enable, 0 to disable.
+ */
+static inline void
+rte_graph_cycle_stats_enable(struct rte_graph *graph, uint8_t enabled)
+{
+       graph->cycles_stats = enabled;
+}
+
 /**
  * Get the graph worker model
  *
-- 
2.52.0

Reply via email to