| 323 | } |
| 324 | |
| 325 | struct rte_graph_cluster_stats * |
| 326 | rte_graph_cluster_stats_create(const struct rte_graph_cluster_stats_param *prm) |
| 327 | { |
| 328 | struct rte_graph_cluster_stats *stats, *rc = NULL; |
| 329 | struct graph_node *graph_node; |
| 330 | struct cluster cluster; |
| 331 | struct graph *graph; |
| 332 | const char *pattern; |
| 333 | rte_graph_t i; |
| 334 | |
| 335 | /* Sanity checks */ |
| 336 | if (!rte_graph_has_stats_feature()) |
| 337 | SET_ERR_JMP(EINVAL, fail, "Stats feature is not enabled"); |
| 338 | |
| 339 | if (prm == NULL) |
| 340 | SET_ERR_JMP(EINVAL, fail, "Invalid param"); |
| 341 | |
| 342 | if (prm->graph_patterns == NULL || prm->nb_graph_patterns == 0) |
| 343 | SET_ERR_JMP(EINVAL, fail, "Invalid graph param"); |
| 344 | |
| 345 | cluster_init(&cluster); |
| 346 | |
| 347 | graph_spinlock_lock(); |
| 348 | /* Expand graph pattern and add the graph to the cluster */ |
| 349 | for (i = 0; i < prm->nb_graph_patterns; i++) { |
| 350 | pattern = prm->graph_patterns[i]; |
| 351 | if (expand_pattern_to_cluster(&cluster, pattern)) |
| 352 | goto bad_pattern; |
| 353 | } |
| 354 | |
| 355 | /* Alloc the stats memory */ |
| 356 | stats = stats_mem_init(&cluster, prm); |
| 357 | if (stats == NULL) |
| 358 | SET_ERR_JMP(ENOMEM, bad_pattern, "Failed alloc stats memory"); |
| 359 | |
| 360 | /* Iterate over M(Graph) x N (Nodes in graph) */ |
| 361 | for (i = 0; i < cluster.nb_graphs; i++) { |
| 362 | graph = cluster.graphs[i]; |
| 363 | STAILQ_FOREACH(graph_node, &graph->node_list, next) { |
| 364 | struct rte_graph *graph_fp = graph->graph; |
| 365 | if (stats_mem_populate(&stats, graph_fp, graph_node)) |
| 366 | goto realloc_fail; |
| 367 | } |
| 368 | if (graph->graph->model == RTE_GRAPH_MODEL_MCORE_DISPATCH) |
| 369 | stats->dispatch = true; |
| 370 | } |
| 371 | |
| 372 | /* Finally copy to hugepage memory to avoid pressure on rte_realloc */ |
| 373 | rc = rte_malloc_socket(NULL, stats->sz, 0, stats->socket_id); |
| 374 | if (rc) |
| 375 | rte_memcpy(rc, stats, stats->sz); |
| 376 | else |
| 377 | SET_ERR_JMP(ENOMEM, realloc_fail, "rte_malloc failed"); |
| 378 | |
| 379 | realloc_fail: |
| 380 | stats_mem_fini(stats); |
| 381 | bad_pattern: |
| 382 | graph_spinlock_unlock(); |