xref: /dpdk/lib/graph/graph_stats.c (revision 06c047b6)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(C) 2020 Marvell International Ltd.
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #include <fnmatch.h>
699a2dd95SBruce Richardson #include <stdbool.h>
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson #include <rte_common.h>
999a2dd95SBruce Richardson #include <rte_errno.h>
1099a2dd95SBruce Richardson #include <rte_malloc.h>
1199a2dd95SBruce Richardson 
1299a2dd95SBruce Richardson #include "graph_private.h"
1399a2dd95SBruce Richardson 
1499a2dd95SBruce Richardson /* Capture all graphs of cluster */
1599a2dd95SBruce Richardson struct cluster {
1699a2dd95SBruce Richardson 	rte_graph_t nb_graphs;
1799a2dd95SBruce Richardson 	rte_graph_t size;
1899a2dd95SBruce Richardson 
1999a2dd95SBruce Richardson 	struct graph **graphs;
2099a2dd95SBruce Richardson };
2199a2dd95SBruce Richardson 
2299a2dd95SBruce Richardson /* Capture same node ID across cluster  */
2399a2dd95SBruce Richardson struct cluster_node {
2499a2dd95SBruce Richardson 	struct rte_graph_cluster_node_stats stat;
2599a2dd95SBruce Richardson 	rte_node_t nb_nodes;
2699a2dd95SBruce Richardson 
2799a2dd95SBruce Richardson 	struct rte_node *nodes[];
2899a2dd95SBruce Richardson };
2999a2dd95SBruce Richardson 
3099a2dd95SBruce Richardson struct rte_graph_cluster_stats {
3199a2dd95SBruce Richardson 	/* Header */
3299a2dd95SBruce Richardson 	rte_graph_cluster_stats_cb_t fn;
3399a2dd95SBruce Richardson 	uint32_t cluster_node_size; /* Size of struct cluster_node */
3499a2dd95SBruce Richardson 	rte_node_t max_nodes;
3599a2dd95SBruce Richardson 	int socket_id;
3699a2dd95SBruce Richardson 	void *cookie;
3799a2dd95SBruce Richardson 	size_t sz;
3899a2dd95SBruce Richardson 
3999a2dd95SBruce Richardson 	struct cluster_node clusters[];
4099a2dd95SBruce Richardson } __rte_cache_aligned;
4199a2dd95SBruce Richardson 
4299a2dd95SBruce Richardson #define boarder()                                                              \
4399a2dd95SBruce Richardson 	fprintf(f, "+-------------------------------+---------------+--------" \
4499a2dd95SBruce Richardson 		   "-------+---------------+---------------+---------------+-" \
4599a2dd95SBruce Richardson 		   "----------+\n")
4699a2dd95SBruce Richardson 
4799a2dd95SBruce Richardson static inline void
print_banner(FILE * f)4899a2dd95SBruce Richardson print_banner(FILE *f)
4999a2dd95SBruce Richardson {
5099a2dd95SBruce Richardson 	boarder();
5199a2dd95SBruce Richardson 	fprintf(f, "%-32s%-16s%-16s%-16s%-16s%-16s%-16s\n", "|Node", "|calls",
5299a2dd95SBruce Richardson 		"|objs", "|realloc_count", "|objs/call", "|objs/sec(10E6)",
5399a2dd95SBruce Richardson 		"|cycles/call|");
5499a2dd95SBruce Richardson 	boarder();
5599a2dd95SBruce Richardson }
5699a2dd95SBruce Richardson 
5799a2dd95SBruce Richardson static inline void
print_node(FILE * f,const struct rte_graph_cluster_node_stats * stat)5899a2dd95SBruce Richardson print_node(FILE *f, const struct rte_graph_cluster_node_stats *stat)
5999a2dd95SBruce Richardson {
6099a2dd95SBruce Richardson 	double objs_per_call, objs_per_sec, cycles_per_call, ts_per_hz;
6199a2dd95SBruce Richardson 	const uint64_t prev_calls = stat->prev_calls;
6299a2dd95SBruce Richardson 	const uint64_t prev_objs = stat->prev_objs;
6399a2dd95SBruce Richardson 	const uint64_t cycles = stat->cycles;
6499a2dd95SBruce Richardson 	const uint64_t calls = stat->calls;
6599a2dd95SBruce Richardson 	const uint64_t objs = stat->objs;
6699a2dd95SBruce Richardson 	uint64_t call_delta;
6799a2dd95SBruce Richardson 
6899a2dd95SBruce Richardson 	call_delta = calls - prev_calls;
6999a2dd95SBruce Richardson 	objs_per_call =
7099a2dd95SBruce Richardson 		call_delta ? (double)((objs - prev_objs) / call_delta) : 0;
7199a2dd95SBruce Richardson 	cycles_per_call =
7299a2dd95SBruce Richardson 		call_delta ? (double)((cycles - stat->prev_cycles) / call_delta)
7399a2dd95SBruce Richardson 			   : 0;
7499a2dd95SBruce Richardson 	ts_per_hz = (double)((stat->ts - stat->prev_ts) / stat->hz);
7599a2dd95SBruce Richardson 	objs_per_sec = ts_per_hz ? (objs - prev_objs) / ts_per_hz : 0;
7699a2dd95SBruce Richardson 	objs_per_sec /= 1000000;
7799a2dd95SBruce Richardson 
7899a2dd95SBruce Richardson 	fprintf(f,
7999a2dd95SBruce Richardson 		"|%-31s|%-15" PRIu64 "|%-15" PRIu64 "|%-15" PRIu64
8099a2dd95SBruce Richardson 		"|%-15.3f|%-15.6f|%-11.4f|\n",
8199a2dd95SBruce Richardson 		stat->name, calls, objs, stat->realloc_count, objs_per_call,
8299a2dd95SBruce Richardson 		objs_per_sec, cycles_per_call);
8399a2dd95SBruce Richardson }
8499a2dd95SBruce Richardson 
8599a2dd95SBruce Richardson static int
graph_cluster_stats_cb(bool is_first,bool is_last,void * cookie,const struct rte_graph_cluster_node_stats * stat)8699a2dd95SBruce Richardson graph_cluster_stats_cb(bool is_first, bool is_last, void *cookie,
8799a2dd95SBruce Richardson 		       const struct rte_graph_cluster_node_stats *stat)
8899a2dd95SBruce Richardson {
8999a2dd95SBruce Richardson 	FILE *f = cookie;
9099a2dd95SBruce Richardson 
9199a2dd95SBruce Richardson 	if (unlikely(is_first))
9299a2dd95SBruce Richardson 		print_banner(f);
9399a2dd95SBruce Richardson 	if (stat->objs)
9499a2dd95SBruce Richardson 		print_node(f, stat);
9599a2dd95SBruce Richardson 	if (unlikely(is_last))
9699a2dd95SBruce Richardson 		boarder();
9799a2dd95SBruce Richardson 
9899a2dd95SBruce Richardson 	return 0;
9999a2dd95SBruce Richardson };
10099a2dd95SBruce Richardson 
10199a2dd95SBruce Richardson static struct rte_graph_cluster_stats *
stats_mem_init(struct cluster * cluster,const struct rte_graph_cluster_stats_param * prm)10299a2dd95SBruce Richardson stats_mem_init(struct cluster *cluster,
10399a2dd95SBruce Richardson 	       const struct rte_graph_cluster_stats_param *prm)
10499a2dd95SBruce Richardson {
10599a2dd95SBruce Richardson 	size_t sz = sizeof(struct rte_graph_cluster_stats);
10699a2dd95SBruce Richardson 	struct rte_graph_cluster_stats *stats;
10799a2dd95SBruce Richardson 	rte_graph_cluster_stats_cb_t fn;
10899a2dd95SBruce Richardson 	int socket_id = prm->socket_id;
10999a2dd95SBruce Richardson 	uint32_t cluster_node_size;
11099a2dd95SBruce Richardson 
11199a2dd95SBruce Richardson 	/* Fix up callback */
11299a2dd95SBruce Richardson 	fn = prm->fn;
11399a2dd95SBruce Richardson 	if (fn == NULL)
11499a2dd95SBruce Richardson 		fn = graph_cluster_stats_cb;
11599a2dd95SBruce Richardson 
11699a2dd95SBruce Richardson 	cluster_node_size = sizeof(struct cluster_node);
11799a2dd95SBruce Richardson 	/* For a given cluster, max nodes will be the max number of graphs */
11899a2dd95SBruce Richardson 	cluster_node_size += cluster->nb_graphs * sizeof(struct rte_node *);
11999a2dd95SBruce Richardson 	cluster_node_size = RTE_ALIGN(cluster_node_size, RTE_CACHE_LINE_SIZE);
12099a2dd95SBruce Richardson 
12199a2dd95SBruce Richardson 	stats = realloc(NULL, sz);
12299a2dd95SBruce Richardson 	if (stats) {
123*2d2bf7deSHongbo Zheng 		memset(stats, 0, sz);
12499a2dd95SBruce Richardson 		stats->fn = fn;
12599a2dd95SBruce Richardson 		stats->cluster_node_size = cluster_node_size;
12699a2dd95SBruce Richardson 		stats->max_nodes = 0;
12799a2dd95SBruce Richardson 		stats->socket_id = socket_id;
12899a2dd95SBruce Richardson 		stats->cookie = prm->cookie;
12999a2dd95SBruce Richardson 		stats->sz = sz;
13099a2dd95SBruce Richardson 	}
13199a2dd95SBruce Richardson 
13299a2dd95SBruce Richardson 	return stats;
13399a2dd95SBruce Richardson }
13499a2dd95SBruce Richardson 
13599a2dd95SBruce Richardson static int
stats_mem_populate(struct rte_graph_cluster_stats ** stats_in,struct rte_graph * graph,struct graph_node * graph_node)13699a2dd95SBruce Richardson stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
13799a2dd95SBruce Richardson 		   struct rte_graph *graph, struct graph_node *graph_node)
13899a2dd95SBruce Richardson {
13999a2dd95SBruce Richardson 	struct rte_graph_cluster_stats *stats = *stats_in;
14099a2dd95SBruce Richardson 	rte_node_t id = graph_node->node->id;
14199a2dd95SBruce Richardson 	struct cluster_node *cluster;
14299a2dd95SBruce Richardson 	struct rte_node *node;
14399a2dd95SBruce Richardson 	rte_node_t count;
14499a2dd95SBruce Richardson 
14599a2dd95SBruce Richardson 	cluster = stats->clusters;
14699a2dd95SBruce Richardson 
14799a2dd95SBruce Richardson 	/* Iterate over cluster node array to find node ID match */
14899a2dd95SBruce Richardson 	for (count = 0; count < stats->max_nodes; count++) {
14999a2dd95SBruce Richardson 		/* Found an existing node in the reel */
15099a2dd95SBruce Richardson 		if (cluster->stat.id == id) {
15199a2dd95SBruce Richardson 			node = graph_node_id_to_ptr(graph, id);
15299a2dd95SBruce Richardson 			if (node == NULL)
15399a2dd95SBruce Richardson 				SET_ERR_JMP(
15499a2dd95SBruce Richardson 					ENOENT, err,
15599a2dd95SBruce Richardson 					"Failed to find node %s in graph %s",
15699a2dd95SBruce Richardson 					graph_node->node->name, graph->name);
15799a2dd95SBruce Richardson 
15899a2dd95SBruce Richardson 			cluster->nodes[cluster->nb_nodes++] = node;
15999a2dd95SBruce Richardson 			return 0;
16099a2dd95SBruce Richardson 		}
16199a2dd95SBruce Richardson 		cluster = RTE_PTR_ADD(cluster, stats->cluster_node_size);
16299a2dd95SBruce Richardson 	}
16399a2dd95SBruce Richardson 
16499a2dd95SBruce Richardson 	/* Hey, it is a new node, allocate space for it in the reel */
16599a2dd95SBruce Richardson 	stats = realloc(stats, stats->sz + stats->cluster_node_size);
16699a2dd95SBruce Richardson 	if (stats == NULL)
16799a2dd95SBruce Richardson 		SET_ERR_JMP(ENOMEM, err, "Realloc failed");
1683b47572fSHongbo Zheng 	*stats_in = NULL;
16999a2dd95SBruce Richardson 
17099a2dd95SBruce Richardson 	/* Clear the new struct cluster_node area */
17199a2dd95SBruce Richardson 	cluster = RTE_PTR_ADD(stats, stats->sz),
17299a2dd95SBruce Richardson 	memset(cluster, 0, stats->cluster_node_size);
17399a2dd95SBruce Richardson 	memcpy(cluster->stat.name, graph_node->node->name, RTE_NODE_NAMESIZE);
17499a2dd95SBruce Richardson 	cluster->stat.id = graph_node->node->id;
17599a2dd95SBruce Richardson 	cluster->stat.hz = rte_get_timer_hz();
17699a2dd95SBruce Richardson 	node = graph_node_id_to_ptr(graph, id);
17799a2dd95SBruce Richardson 	if (node == NULL)
1783b47572fSHongbo Zheng 		SET_ERR_JMP(ENOENT, free, "Failed to find node %s in graph %s",
17999a2dd95SBruce Richardson 			    graph_node->node->name, graph->name);
18099a2dd95SBruce Richardson 	cluster->nodes[cluster->nb_nodes++] = node;
18199a2dd95SBruce Richardson 
18299a2dd95SBruce Richardson 	stats->sz += stats->cluster_node_size;
18399a2dd95SBruce Richardson 	stats->max_nodes++;
18499a2dd95SBruce Richardson 	*stats_in = stats;
18599a2dd95SBruce Richardson 
18699a2dd95SBruce Richardson 	return 0;
1873b47572fSHongbo Zheng free:
1883b47572fSHongbo Zheng 	free(stats);
18999a2dd95SBruce Richardson err:
19099a2dd95SBruce Richardson 	return -rte_errno;
19199a2dd95SBruce Richardson }
19299a2dd95SBruce Richardson 
19399a2dd95SBruce Richardson static void
stats_mem_fini(struct rte_graph_cluster_stats * stats)19499a2dd95SBruce Richardson stats_mem_fini(struct rte_graph_cluster_stats *stats)
19599a2dd95SBruce Richardson {
19699a2dd95SBruce Richardson 	free(stats);
19799a2dd95SBruce Richardson }
19899a2dd95SBruce Richardson 
19999a2dd95SBruce Richardson static void
cluster_init(struct cluster * cluster)20099a2dd95SBruce Richardson cluster_init(struct cluster *cluster)
20199a2dd95SBruce Richardson {
20299a2dd95SBruce Richardson 	memset(cluster, 0, sizeof(*cluster));
20399a2dd95SBruce Richardson }
20499a2dd95SBruce Richardson 
20599a2dd95SBruce Richardson static int
cluster_add(struct cluster * cluster,struct graph * graph)20699a2dd95SBruce Richardson cluster_add(struct cluster *cluster, struct graph *graph)
20799a2dd95SBruce Richardson {
20899a2dd95SBruce Richardson 	rte_graph_t count;
20999a2dd95SBruce Richardson 	size_t sz;
21099a2dd95SBruce Richardson 
21199a2dd95SBruce Richardson 	/* Skip the if graph is already added to cluster */
21299a2dd95SBruce Richardson 	for (count = 0; count < cluster->nb_graphs; count++)
21399a2dd95SBruce Richardson 		if (cluster->graphs[count] == graph)
21499a2dd95SBruce Richardson 			return 0;
21599a2dd95SBruce Richardson 
21699a2dd95SBruce Richardson 	/* Expand the cluster if required to store graph objects */
21799a2dd95SBruce Richardson 	if (cluster->nb_graphs + 1 > cluster->size) {
21899a2dd95SBruce Richardson 		cluster->size = RTE_MAX(1, cluster->size * 2);
21999a2dd95SBruce Richardson 		sz = sizeof(struct graph *) * cluster->size;
22099a2dd95SBruce Richardson 		cluster->graphs = realloc(cluster->graphs, sz);
22199a2dd95SBruce Richardson 		if (cluster->graphs == NULL)
22299a2dd95SBruce Richardson 			SET_ERR_JMP(ENOMEM, free, "Failed to realloc");
22399a2dd95SBruce Richardson 	}
22499a2dd95SBruce Richardson 
22599a2dd95SBruce Richardson 	/* Add graph to cluster */
22699a2dd95SBruce Richardson 	cluster->graphs[cluster->nb_graphs++] = graph;
22799a2dd95SBruce Richardson 	return 0;
22899a2dd95SBruce Richardson 
22999a2dd95SBruce Richardson free:
23099a2dd95SBruce Richardson 	return -rte_errno;
23199a2dd95SBruce Richardson }
23299a2dd95SBruce Richardson 
23399a2dd95SBruce Richardson static void
cluster_fini(struct cluster * cluster)23499a2dd95SBruce Richardson cluster_fini(struct cluster *cluster)
23599a2dd95SBruce Richardson {
23699a2dd95SBruce Richardson 	free(cluster->graphs);
23799a2dd95SBruce Richardson }
23899a2dd95SBruce Richardson 
23999a2dd95SBruce Richardson static int
expand_pattern_to_cluster(struct cluster * cluster,const char * pattern)24099a2dd95SBruce Richardson expand_pattern_to_cluster(struct cluster *cluster, const char *pattern)
24199a2dd95SBruce Richardson {
24299a2dd95SBruce Richardson 	struct graph_head *graph_head = graph_list_head_get();
24399a2dd95SBruce Richardson 	struct graph *graph;
24499a2dd95SBruce Richardson 	bool found = false;
24599a2dd95SBruce Richardson 
24699a2dd95SBruce Richardson 	/* Check for pattern match */
24799a2dd95SBruce Richardson 	STAILQ_FOREACH(graph, graph_head, next) {
24899a2dd95SBruce Richardson 		if (fnmatch(pattern, graph->name, 0) == 0) {
24999a2dd95SBruce Richardson 			if (cluster_add(cluster, graph))
25099a2dd95SBruce Richardson 				goto fail;
25199a2dd95SBruce Richardson 			found = true;
25299a2dd95SBruce Richardson 		}
25399a2dd95SBruce Richardson 	}
25499a2dd95SBruce Richardson 	if (found == false)
25599a2dd95SBruce Richardson 		SET_ERR_JMP(EFAULT, fail, "Pattern %s graph not found",
25699a2dd95SBruce Richardson 			    pattern);
25799a2dd95SBruce Richardson 
25899a2dd95SBruce Richardson 	return 0;
25999a2dd95SBruce Richardson fail:
26099a2dd95SBruce Richardson 	return -rte_errno;
26199a2dd95SBruce Richardson }
26299a2dd95SBruce Richardson 
26399a2dd95SBruce Richardson struct rte_graph_cluster_stats *
rte_graph_cluster_stats_create(const struct rte_graph_cluster_stats_param * prm)26499a2dd95SBruce Richardson rte_graph_cluster_stats_create(const struct rte_graph_cluster_stats_param *prm)
26599a2dd95SBruce Richardson {
26699a2dd95SBruce Richardson 	struct rte_graph_cluster_stats *stats, *rc = NULL;
26799a2dd95SBruce Richardson 	struct graph_node *graph_node;
26899a2dd95SBruce Richardson 	struct cluster cluster;
26999a2dd95SBruce Richardson 	struct graph *graph;
27099a2dd95SBruce Richardson 	const char *pattern;
27199a2dd95SBruce Richardson 	rte_graph_t i;
27299a2dd95SBruce Richardson 
27399a2dd95SBruce Richardson 	/* Sanity checks */
27499a2dd95SBruce Richardson 	if (!rte_graph_has_stats_feature())
27599a2dd95SBruce Richardson 		SET_ERR_JMP(EINVAL, fail, "Stats feature is not enabled");
27699a2dd95SBruce Richardson 
27799a2dd95SBruce Richardson 	if (prm == NULL)
27899a2dd95SBruce Richardson 		SET_ERR_JMP(EINVAL, fail, "Invalid param");
27999a2dd95SBruce Richardson 
28099a2dd95SBruce Richardson 	if (prm->graph_patterns == NULL || prm->nb_graph_patterns == 0)
28199a2dd95SBruce Richardson 		SET_ERR_JMP(EINVAL, fail, "Invalid graph param");
28299a2dd95SBruce Richardson 
28399a2dd95SBruce Richardson 	cluster_init(&cluster);
28499a2dd95SBruce Richardson 
28599a2dd95SBruce Richardson 	graph_spinlock_lock();
28699a2dd95SBruce Richardson 	/* Expand graph pattern and add the graph to the cluster */
28799a2dd95SBruce Richardson 	for (i = 0; i < prm->nb_graph_patterns; i++) {
28899a2dd95SBruce Richardson 		pattern = prm->graph_patterns[i];
28999a2dd95SBruce Richardson 		if (expand_pattern_to_cluster(&cluster, pattern))
29099a2dd95SBruce Richardson 			goto bad_pattern;
29199a2dd95SBruce Richardson 	}
29299a2dd95SBruce Richardson 
29399a2dd95SBruce Richardson 	/* Alloc the stats memory */
29499a2dd95SBruce Richardson 	stats = stats_mem_init(&cluster, prm);
29599a2dd95SBruce Richardson 	if (stats == NULL)
29699a2dd95SBruce Richardson 		SET_ERR_JMP(ENOMEM, bad_pattern, "Failed alloc stats memory");
29799a2dd95SBruce Richardson 
29899a2dd95SBruce Richardson 	/* Iterate over M(Graph) x N (Nodes in graph) */
29999a2dd95SBruce Richardson 	for (i = 0; i < cluster.nb_graphs; i++) {
30099a2dd95SBruce Richardson 		graph = cluster.graphs[i];
30199a2dd95SBruce Richardson 		STAILQ_FOREACH(graph_node, &graph->node_list, next) {
30299a2dd95SBruce Richardson 			struct rte_graph *graph_fp = graph->graph;
30399a2dd95SBruce Richardson 			if (stats_mem_populate(&stats, graph_fp, graph_node))
30499a2dd95SBruce Richardson 				goto realloc_fail;
30599a2dd95SBruce Richardson 		}
30699a2dd95SBruce Richardson 	}
30799a2dd95SBruce Richardson 
30899a2dd95SBruce Richardson 	/* Finally copy to hugepage memory to avoid pressure on rte_realloc */
30999a2dd95SBruce Richardson 	rc = rte_malloc_socket(NULL, stats->sz, 0, stats->socket_id);
31099a2dd95SBruce Richardson 	if (rc)
31199a2dd95SBruce Richardson 		rte_memcpy(rc, stats, stats->sz);
31299a2dd95SBruce Richardson 	else
31399a2dd95SBruce Richardson 		SET_ERR_JMP(ENOMEM, realloc_fail, "rte_malloc failed");
31499a2dd95SBruce Richardson 
31599a2dd95SBruce Richardson realloc_fail:
31699a2dd95SBruce Richardson 	stats_mem_fini(stats);
31799a2dd95SBruce Richardson bad_pattern:
31899a2dd95SBruce Richardson 	graph_spinlock_unlock();
31999a2dd95SBruce Richardson 	cluster_fini(&cluster);
32099a2dd95SBruce Richardson fail:
32199a2dd95SBruce Richardson 	return rc;
32299a2dd95SBruce Richardson }
32399a2dd95SBruce Richardson 
32499a2dd95SBruce Richardson void
rte_graph_cluster_stats_destroy(struct rte_graph_cluster_stats * stat)32599a2dd95SBruce Richardson rte_graph_cluster_stats_destroy(struct rte_graph_cluster_stats *stat)
32699a2dd95SBruce Richardson {
32799a2dd95SBruce Richardson 	return rte_free(stat);
32899a2dd95SBruce Richardson }
32999a2dd95SBruce Richardson 
33099a2dd95SBruce Richardson static inline void
cluster_node_arregate_stats(struct cluster_node * cluster)33199a2dd95SBruce Richardson cluster_node_arregate_stats(struct cluster_node *cluster)
33299a2dd95SBruce Richardson {
33399a2dd95SBruce Richardson 	uint64_t calls = 0, cycles = 0, objs = 0, realloc_count = 0;
33499a2dd95SBruce Richardson 	struct rte_graph_cluster_node_stats *stat = &cluster->stat;
33599a2dd95SBruce Richardson 	struct rte_node *node;
33699a2dd95SBruce Richardson 	rte_node_t count;
33799a2dd95SBruce Richardson 
33899a2dd95SBruce Richardson 	for (count = 0; count < cluster->nb_nodes; count++) {
33999a2dd95SBruce Richardson 		node = cluster->nodes[count];
34099a2dd95SBruce Richardson 
34199a2dd95SBruce Richardson 		calls += node->total_calls;
34299a2dd95SBruce Richardson 		objs += node->total_objs;
34399a2dd95SBruce Richardson 		cycles += node->total_cycles;
34499a2dd95SBruce Richardson 		realloc_count += node->realloc_count;
34599a2dd95SBruce Richardson 	}
34699a2dd95SBruce Richardson 
34799a2dd95SBruce Richardson 	stat->calls = calls;
34899a2dd95SBruce Richardson 	stat->objs = objs;
34999a2dd95SBruce Richardson 	stat->cycles = cycles;
35099a2dd95SBruce Richardson 	stat->ts = rte_get_timer_cycles();
35199a2dd95SBruce Richardson 	stat->realloc_count = realloc_count;
35299a2dd95SBruce Richardson }
35399a2dd95SBruce Richardson 
35499a2dd95SBruce Richardson static inline void
cluster_node_store_prev_stats(struct cluster_node * cluster)35599a2dd95SBruce Richardson cluster_node_store_prev_stats(struct cluster_node *cluster)
35699a2dd95SBruce Richardson {
35799a2dd95SBruce Richardson 	struct rte_graph_cluster_node_stats *stat = &cluster->stat;
35899a2dd95SBruce Richardson 
35999a2dd95SBruce Richardson 	stat->prev_ts = stat->ts;
36099a2dd95SBruce Richardson 	stat->prev_calls = stat->calls;
36199a2dd95SBruce Richardson 	stat->prev_objs = stat->objs;
36299a2dd95SBruce Richardson 	stat->prev_cycles = stat->cycles;
36399a2dd95SBruce Richardson }
36499a2dd95SBruce Richardson 
36599a2dd95SBruce Richardson void
rte_graph_cluster_stats_get(struct rte_graph_cluster_stats * stat,bool skip_cb)36699a2dd95SBruce Richardson rte_graph_cluster_stats_get(struct rte_graph_cluster_stats *stat, bool skip_cb)
36799a2dd95SBruce Richardson {
36899a2dd95SBruce Richardson 	struct cluster_node *cluster;
36999a2dd95SBruce Richardson 	rte_node_t count;
37099a2dd95SBruce Richardson 	int rc = 0;
37199a2dd95SBruce Richardson 
37299a2dd95SBruce Richardson 	cluster = stat->clusters;
37399a2dd95SBruce Richardson 
37499a2dd95SBruce Richardson 	for (count = 0; count < stat->max_nodes; count++) {
37599a2dd95SBruce Richardson 		cluster_node_arregate_stats(cluster);
37699a2dd95SBruce Richardson 		if (!skip_cb)
37799a2dd95SBruce Richardson 			rc = stat->fn(!count, (count == stat->max_nodes - 1),
37899a2dd95SBruce Richardson 				      stat->cookie, &cluster->stat);
37999a2dd95SBruce Richardson 		cluster_node_store_prev_stats(cluster);
38099a2dd95SBruce Richardson 		if (rc)
38199a2dd95SBruce Richardson 			break;
38299a2dd95SBruce Richardson 		cluster = RTE_PTR_ADD(cluster, stat->cluster_node_size);
38399a2dd95SBruce Richardson 	}
38499a2dd95SBruce Richardson }
38599a2dd95SBruce Richardson 
38699a2dd95SBruce Richardson void
rte_graph_cluster_stats_reset(struct rte_graph_cluster_stats * stat)38799a2dd95SBruce Richardson rte_graph_cluster_stats_reset(struct rte_graph_cluster_stats *stat)
38899a2dd95SBruce Richardson {
38999a2dd95SBruce Richardson 	struct cluster_node *cluster;
39099a2dd95SBruce Richardson 	rte_node_t count;
39199a2dd95SBruce Richardson 
39299a2dd95SBruce Richardson 	cluster = stat->clusters;
39399a2dd95SBruce Richardson 
39499a2dd95SBruce Richardson 	for (count = 0; count < stat->max_nodes; count++) {
39599a2dd95SBruce Richardson 		struct rte_graph_cluster_node_stats *node = &cluster->stat;
39699a2dd95SBruce Richardson 
39799a2dd95SBruce Richardson 		node->ts = 0;
39899a2dd95SBruce Richardson 		node->calls = 0;
39999a2dd95SBruce Richardson 		node->objs = 0;
40099a2dd95SBruce Richardson 		node->cycles = 0;
40199a2dd95SBruce Richardson 		node->prev_ts = 0;
40299a2dd95SBruce Richardson 		node->prev_calls = 0;
40399a2dd95SBruce Richardson 		node->prev_objs = 0;
40499a2dd95SBruce Richardson 		node->prev_cycles = 0;
40599a2dd95SBruce Richardson 		node->realloc_count = 0;
40699a2dd95SBruce Richardson 		cluster = RTE_PTR_ADD(cluster, stat->cluster_node_size);
40799a2dd95SBruce Richardson 	}
40899a2dd95SBruce Richardson }
409