doc: add patch dependency syntax to contributing guide
[dpdk.git] / lib / librte_graph / graph.c
index 7a77cb5..7224b00 100644 (file)
@@ -18,7 +18,6 @@
 static struct graph_head graph_list = STAILQ_HEAD_INITIALIZER(graph_list);
 static rte_spinlock_t graph_lock = RTE_SPINLOCK_INITIALIZER;
 static rte_graph_t graph_id;
-int rte_graph_logtype;
 
 #define GRAPH_ID_CHECK(id) ID_CHECK(id, graph_id)
 
@@ -473,15 +472,110 @@ __rte_node_stream_alloc(struct rte_graph *graph, struct rte_node *node)
        node->realloc_count++;
 }
 
+void __rte_noinline
+__rte_node_stream_alloc_size(struct rte_graph *graph, struct rte_node *node,
+                            uint16_t req_size)
+{
+       uint16_t size = node->size;
+
+       RTE_VERIFY(size != UINT16_MAX);
+       /* Allocate double amount of size to avoid immediate realloc */
+       size = RTE_MIN(UINT16_MAX, RTE_MAX(RTE_GRAPH_BURST_SIZE, req_size * 2));
+       node->objs = rte_realloc_socket(node->objs, size * sizeof(void *),
+                                       RTE_CACHE_LINE_SIZE, graph->socket);
+       RTE_VERIFY(node->objs);
+       node->size = size;
+       node->realloc_count++;
+}
+
+static int
+graph_to_dot(FILE *f, struct graph *graph)
+{
+       const char *src_edge_color = " [color=blue]\n";
+       const char *edge_color = "\n";
+       struct graph_node *graph_node;
+       char *node_name;
+       rte_edge_t i;
+       int rc;
+
+       rc = fprintf(f, "Digraph %s {\n\trankdir=LR;\n", graph->name);
+       if (rc < 0)
+               goto end;
+
+       STAILQ_FOREACH(graph_node, &graph->node_list, next) {
+               node_name = graph_node->node->name;
+               for (i = 0; i < graph_node->node->nb_edges; i++) {
+                       rc = fprintf(f, "\t\"%s\"->\"%s\"%s", node_name,
+                                    graph_node->adjacency_list[i]->node->name,
+                                    graph_node->node->flags & RTE_NODE_SOURCE_F
+                                            ? src_edge_color
+                                            : edge_color);
+                       if (rc < 0)
+                               goto end;
+               }
+       }
+       rc = fprintf(f, "}\n");
+       if (rc < 0)
+               goto end;
+
+       return 0;
+end:
+       rte_errno = EBADF;
+       return -rte_errno;
+}
+
+int
+rte_graph_export(const char *name, FILE *f)
+{
+       struct graph *graph;
+       int rc = ENOENT;
+
+       STAILQ_FOREACH(graph, &graph_list, next) {
+               if (strncmp(graph->name, name, RTE_GRAPH_NAMESIZE) == 0) {
+                       rc = graph_to_dot(f, graph);
+                       goto end;
+               }
+       }
+end:
+       return -rc;
+}
+
+static void
+graph_scan_dump(FILE *f, rte_graph_t id, bool all)
+{
+       struct graph *graph;
+
+       RTE_VERIFY(f);
+       GRAPH_ID_CHECK(id);
+
+       STAILQ_FOREACH(graph, &graph_list, next) {
+               if (all == true) {
+                       graph_dump(f, graph);
+               } else if (graph->id == id) {
+                       graph_dump(f, graph);
+                       return;
+               }
+       }
+fail:
+       return;
+}
+
+void
+rte_graph_dump(FILE *f, rte_graph_t id)
+{
+       graph_scan_dump(f, id, false);
+}
+
+void
+rte_graph_list_dump(FILE *f)
+{
+       graph_scan_dump(f, 0, true);
+}
+
 rte_graph_t
 rte_graph_max_count(void)
 {
        return graph_id;
 }
 
-RTE_INIT(rte_graph_init_log)
-{
-       rte_graph_logtype = rte_log_register("lib.graph");
-       if (rte_graph_logtype >= 0)
-               rte_log_set_level(rte_graph_logtype, RTE_LOG_INFO);
-}
+RTE_LOG_REGISTER(rte_graph_logtype, lib.graph, INFO);