-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathgraph.c
More file actions
731 lines (632 loc) · 19.9 KB
/
Copy pathgraph.c
File metadata and controls
731 lines (632 loc) · 19.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2024 Robin Jarry
#include "graph.h"
#include "log.h"
#include "module.h"
#include "port.h"
#include "rxtx.h"
#include "vec.h"
#include "worker.h"
#include <gr_infra.h>
#include <gr_string.h>
#include <rte_build_config.h>
#include <rte_errno.h>
#include <rte_ethdev.h>
#include <rte_malloc.h>
#include <stdatomic.h>
#include <sys/queue.h>
#include <unistd.h>
LOG_TYPE("graph");
struct node_infos node_infos = STAILQ_HEAD_INITIALIZER(node_infos);
static vec const char **base_node_names;
static vec char **rx_node_names;
static vec char **tx_node_names;
static rte_node_t port_rx_node;
static rte_node_t port_tx_node;
static rte_node_t port_output_node;
static rte_edge_t port_output_invalid;
rte_edge_t gr_node_attach_parent(const char *parent, const char *node) {
rte_node_t parent_id;
rte_edge_t edge;
char **names;
if ((parent_id = rte_node_from_name(parent)) == RTE_NODE_ID_INVALID)
ABORT("'%s' parent node not found", parent);
edge = rte_node_edge_update(parent_id, RTE_EDGE_ID_INVALID, &node, 1);
if (edge == RTE_EDGE_ID_INVALID)
ABORT("rte_node_edge_update: %s", rte_strerror(rte_errno));
names = calloc(rte_node_edge_count(parent_id), sizeof(char *));
if (names == NULL)
ABORT("calloc(rte_node_edge_count('%s')) failed", parent);
if (rte_node_edge_get(parent_id, names) == RTE_EDGE_ID_INVALID)
ABORT("rte_node_edge_get('%s')) failed", parent);
for (edge = 0; edge < rte_node_edge_count(parent_id); edge++) {
if (strcmp(names[edge], node) == 0)
break;
}
free(names);
if (edge == rte_node_edge_count(parent_id))
ABORT("cannot find added edge");
LOG(DEBUG, "attach %s -> %s (edge=%u)", parent, node, edge);
return edge;
}
void worker_graph_free(struct worker *worker) {
int ret;
for (int i = 0; i < 2; i++) {
if (worker->graph[i] != NULL) {
if ((ret = rte_graph_destroy(worker->graph[i]->id)) < 0)
LOG(ERR, "rte_graph_destroy: %s", rte_strerror(-ret));
worker->graph[i] = NULL;
}
}
}
static struct iface_info_port *find_port(vec struct iface_info_port **ports, uint16_t port_id) {
struct iface_info_port *port = NULL;
vec_foreach (struct iface_info_port *p, ports) {
if (p->port_id == port_id) {
port = p;
break;
}
}
assert(port != NULL);
return port;
}
struct gr_graph_conf graph_conf = {
.rx_burst_max = 64,
.vector_max = 64,
.icmp_error_rate = 1000,
.arp_rate = 1000,
.icmp_rate = 1000,
};
static int
worker_graph_new(struct worker *worker, uint8_t index, vec struct iface_info_port **ports) {
vec const char **graph_nodes = NULL;
char graph_name[RTE_GRAPH_NAMESIZE];
char node_name[RTE_NODE_NAMESIZE];
vec char **rx_nodes = NULL;
struct iface_info_port *port;
struct queue_map *qmap;
struct rte_node *node;
uint16_t burst_size;
uint16_t graph_uid;
unsigned n_rxqs;
int ret = 0;
n_rxqs = 0;
vec_foreach_ref (qmap, worker->rxqs) {
if (ports != NULL && qmap->enabled)
n_rxqs++;
}
if (n_rxqs == 0) {
worker->graph[index] = NULL;
return 0;
}
// unique suffix for this graph
graph_uid = (worker->cpu_id << 1) | (0x1 & index);
snprintf(graph_name, sizeof(graph_name), "gr-%04x", graph_uid);
// generate graph nodes list
vec_foreach_ref (qmap, worker->rxqs) {
if (!qmap->enabled)
continue;
char *name = astrcat(NULL, RX_NODE_FMT, qmap->port_id, qmap->queue_id);
vec_add(rx_nodes, name);
vec_add(graph_nodes, name);
}
vec_extend(graph_nodes, base_node_names);
vec_extend(graph_nodes, tx_node_names);
// graph init
struct rte_graph_param params = {
.socket_id = rte_lcore_to_socket_id(worker->lcore_id),
.nb_node_patterns = vec_len(graph_nodes),
.node_patterns = graph_nodes,
};
if (rte_graph_create(graph_name, ¶ms) == RTE_GRAPH_ID_INVALID) {
if (rte_errno == 0)
rte_errno = EINVAL;
ret = -rte_errno;
goto out;
}
worker->graph[index] = rte_graph_lookup(graph_name);
// set rx nodes context data
vec_foreach_ref (qmap, worker->rxqs) {
if (!qmap->enabled)
continue;
snprintf(node_name, sizeof(node_name), RX_NODE_FMT, qmap->port_id, qmap->queue_id);
node = rte_graph_node_get_by_name(graph_name, node_name);
struct rx_node_ctx *ctx = rx_node_ctx(node);
port = find_port(ports, qmap->port_id);
ctx->iface = RTE_PTR_SUB(port, offsetof(struct iface, info));
ctx->rxq.port_id = qmap->port_id;
ctx->rxq.queue_id = qmap->queue_id;
burst_size = RTE_MAX(1u, graph_conf.vector_max / vec_len(rx_nodes));
ctx->burst_size = RTE_MIN(graph_conf.rx_burst_max, burst_size);
LOG(DEBUG,
"[CPU %d] <- port=%u rxq=%u burst_size=%u",
worker->cpu_id,
qmap->port_id,
qmap->queue_id,
ctx->burst_size);
// select the appropriate node process callback
if (ctx->iface->mode == GR_IFACE_MODE_BOND) {
// virtio driver supports Rx vlan stripping but requires help for L4 csum
if (port->virtio_offloads)
node->process = rx_bond_virtio_process;
else if (port->rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
node->process = rx_bond_offload_process;
else
node->process = rx_bond_process;
} else {
// virtio driver supports Rx vlan stripping but requires help for L4 csum
if (port->virtio_offloads)
node->process = rx_virtio_process;
else if (port->rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
node->process = rx_offload_process;
else
node->process = rx_process;
}
}
// initialize all tx nodes context to invalid ports and queues
vec_foreach (const char *name, tx_node_names) {
node = rte_graph_node_get_by_name(graph_name, name);
struct tx_node_ctx *ctx = tx_node_ctx(node);
ctx->txq.port_id = UINT16_MAX;
ctx->txq.queue_id = UINT16_MAX;
ctx->lock = NULL;
}
// initialize the port_output node context to point to the port_output_invalid edge
struct port_output_edges *out = rte_malloc(__func__, sizeof(*out), RTE_CACHE_LINE_SIZE);
if (out == NULL) {
ret = -ENOMEM;
goto out;
}
for (unsigned i = 0; i < ARRAY_DIM(out->edges); i++)
out->edges[i] = port_output_invalid;
vec_foreach_ref (qmap, worker->txqs) {
if (!qmap->enabled)
continue;
LOG(DEBUG,
"[CPU %d] -> port %u txq %u",
worker->cpu_id,
qmap->port_id,
qmap->queue_id);
// find the corresponding port_tx clone for this port-txq pair
snprintf(node_name, sizeof(node_name), TX_NODE_FMT, qmap->port_id, qmap->queue_id);
node = rte_graph_node_get_by_name(graph_name, node_name);
// and update its context data to correct values
struct tx_node_ctx *ctx = tx_node_ctx(node);
ctx->txq.port_id = qmap->port_id;
ctx->txq.queue_id = qmap->queue_id;
port = find_port(ports, qmap->port_id);
// set spinlock only if multiple workers share this TX queue
unsigned txq_users = 0;
struct worker *w = NULL;
STAILQ_FOREACH (w, &workers, next) {
vec_foreach_ref (struct queue_map *q, w->txqs) {
if (q->port_id == qmap->port_id && q->queue_id == qmap->queue_id)
txq_users++;
}
}
if (txq_users > 1) {
ctx->lock = &port->txq_locks[qmap->queue_id];
node->process = tx_shared_process;
LOG(WARNING,
"[CPU %d] port %s txq %u shared by %u workers",
worker->cpu_id,
port->devargs,
qmap->queue_id,
txq_users);
} else {
node->process = tx_process;
}
for (rte_edge_t edge = 0; edge < vec_len(tx_node_names); edge++) {
if (strcmp(tx_node_names[edge], node_name) == 0) {
// update the port_output context data to map this port to the
// correct edge
out->edges[ctx->txq.port_id] = edge;
break;
}
}
}
// finally, set the port_output context data
rte_graph_node_get_by_name(graph_name, "port_output")->ctx_ptr = out;
out:
vec_free(graph_nodes);
strvec_free(rx_nodes);
return errno_set(-ret);
}
int worker_graph_reload(struct worker *worker, vec struct iface_info_port **ports) {
unsigned next = !atomic_load(&worker->cur_config);
int ret;
if ((ret = worker_graph_new(worker, next, ports)) < 0)
return errno_log(-ret, "worker_graph_new");
// wait for datapath worker to pickup the config update
atomic_store(&worker->next_config, next);
worker_wakeup(worker);
for (unsigned i = 0; atomic_load(&worker->cur_config) != next; i++) {
if (i >= 10000) // 10000 * 500us -> 5s
return errno_log(ETIMEDOUT, "worker not responding to graph reload");
usleep(500);
}
// free old config
next = !next;
if (worker->graph[next] != NULL) {
if ((ret = rte_graph_destroy(worker->graph[next]->id)) < 0)
errno_log(-ret, "rte_graph_destroy");
worker->graph[next] = NULL;
}
return 0;
}
static char *ensure_queue_node(
rte_node_t base_node,
const char *name_fmt,
uint16_t port_id,
uint16_t queue_id,
vec char **old_list
) {
char *name = astrcat(NULL, name_fmt, port_id, queue_id);
assert(name != NULL);
// remove node from the old list so that only unused nodes remain
for (unsigned i = 0; i < vec_len(old_list); i++) {
if (strcmp(old_list[i], name) == 0) {
free(old_list[i]);
vec_del(old_list, i);
break;
}
}
if (rte_node_from_name(name) == RTE_NODE_ID_INVALID) {
// node does not exist yet, clone it from the base
rte_node_t node = rte_node_clone(base_node, strstr(name, "-") + 1);
assert(node != RTE_NODE_ID_INVALID);
}
return name;
}
static vec rte_node_t *worker_graph_nodes_add_missing(vec struct iface_info_port **ports) {
vec char **old_rx = vec_clone(rx_node_names);
vec char **old_tx = vec_clone(tx_node_names);
rte_node_t *unused_nodes = NULL;
rte_edge_t edge;
char *name;
vec_free(rx_node_names);
vec_free(tx_node_names);
// clone port_rx and port_tx to match all possible port-queue pairs
vec_foreach (struct iface_info_port *port, ports) {
for (uint16_t rxq = 0; rxq < port->n_rxq; rxq++) {
name = ensure_queue_node(
port_rx_node, RX_NODE_FMT, port->port_id, rxq, old_rx
);
vec_add(rx_node_names, name);
}
for (uint16_t txq = 0; txq < port->n_txq; txq++) {
name = ensure_queue_node(
port_tx_node, TX_NODE_FMT, port->port_id, txq, old_tx
);
vec_add(tx_node_names, name);
}
}
// update the port_output edges to allow reaching all possible port_tx clones
edge = rte_node_edge_update(
port_output_node, 0, (const char **)tx_node_names, vec_len(tx_node_names)
);
assert(edge != RTE_EDGE_ID_INVALID);
port_output_invalid = vec_len(tx_node_names);
// this error edge must be last
const char *invalid_port = "port_output_invalid";
edge = rte_node_edge_update(port_output_node, vec_len(tx_node_names), &invalid_port, 1);
assert(edge != RTE_EDGE_ID_INVALID);
edge = rte_node_edge_shrink(port_output_node, vec_len(tx_node_names) + 1);
assert(edge != RTE_EDGE_ID_INVALID);
// store all unused node_ids in a list to be returned to the caller
vec_foreach (name, old_rx)
vec_add(unused_nodes, rte_node_from_name(name));
vec_foreach (name, old_tx)
vec_add(unused_nodes, rte_node_from_name(name));
strvec_free(old_rx);
strvec_free(old_tx);
return unused_nodes;
}
int worker_graph_reload_all(vec struct iface_info_port **ports) {
struct worker *worker;
int ret;
vec rte_node_t *unused_nodes = worker_graph_nodes_add_missing(ports);
// stop all workers by switching them to NULL graphs
STAILQ_FOREACH (worker, &workers, next) {
if ((ret = worker_graph_reload(worker, NULL)) < 0)
return ret;
}
// create new graphs and start all workers
STAILQ_FOREACH (worker, &workers, next) {
if ((ret = worker_graph_reload(worker, ports)) < 0)
return ret;
}
// these port_rx and port_tx clones are now not referenced in any graph
// we can safely delete them
vec_foreach (rte_node_t node, unused_nodes)
rte_node_free(node);
vec_free(unused_nodes);
return 0;
}
const struct gr_node_info *gr_node_info_get(rte_node_t node_id) {
const struct gr_node_info *info;
STAILQ_FOREACH (info, &node_infos, next)
if (info->node->id == node_id)
return info;
return errno_set_null(ENOENT);
}
static struct api_out graph_dump(const void *request, struct api_ctx *) {
static const struct {
gr_node_type_t type;
const char *name;
} layers[] = {
{GR_NODE_T_L1, "L1"},
{GR_NODE_T_L2, "L2"},
{GR_NODE_T_L3, "L3"},
{GR_NODE_T_L4, "L4"},
};
const struct gr_graph_dump_req *req = request;
vec const char **seen_edges = NULL;
struct gr_node_info *info;
char **edges = NULL;
size_t buf_len = 0;
char *buf = NULL;
FILE *f = NULL;
if ((f = open_memstream(&buf, &buf_len)) == NULL)
return api_out(errno, 0, NULL);
if (fprintf(f, "digraph {\n") < 0)
goto err;
if (!req->by_layer) {
if (fprintf(f, "\trankdir=LR;\n") < 0)
goto err;
}
if (!req->compact || req->by_layer) {
if (fprintf(f, "\tnewrank=true;\n") < 0)
goto err;
}
if (fprintf(f, "\tnode [margin=0.02 fontsize=11 fontname=sans];\n") < 0)
goto err;
if (fprintf(f, "\tgraph [fontsize=11 fontname=sans compound=true style=dotted];\n") < 0)
goto err;
for (unsigned i = 0; i < ARRAY_DIM(layers); i++) {
if (req->by_layer) {
if (fprintf(f, "\tsubgraph \"cluster_%s\" {\n", layers[i].name) < 0)
goto err;
if (fprintf(f, "\t\tlabel=\"%s\";\n", layers[i].name) < 0)
goto err;
if (fprintf(f, "\t\tl%u [style=invis];\n", i + 1) < 0)
goto err;
}
STAILQ_FOREACH (info, &node_infos, next) {
rte_node_t node_id = rte_node_from_name(info->node->name);
unsigned nb_edges = rte_node_edge_count(node_id);
const char *name = info->node->name;
const char *attrs = "";
if (!(info->type & layers[i].type))
continue;
if (node_id == port_output_node)
nb_edges = info->node->nb_edges;
if (!req->full) {
if (nb_edges == 0)
continue;
if (strstr(name, "error"))
continue;
if (strcmp(name, "control_input") == 0)
continue;
if (strcmp(name, "control_output") == 0)
continue;
}
if (fprintf(f, "\t\t\"%s\"", name) < 0)
goto err;
if (info->node->flags & RTE_NODE_SOURCE_F) {
attrs = " [color=blue style=bold]";
if (fprintf(f, "%s", attrs) < 0)
goto err;
} else if (info->type & GR_NODE_T_CONTROL) {
attrs = " [color=dodgerblue shape=box margin=0.1]";
if (fprintf(f, "%s", attrs) < 0)
goto err;
} else if (nb_edges == 0) {
if (fprintf(f, " [fontcolor=darkorange shape=plain]") < 0)
goto err;
}
if (fprintf(f, ";\n") < 0)
goto err;
}
if (req->by_layer && fprintf(f, "\t}\n") < 0)
goto err;
}
if (req->by_layer) {
for (unsigned i = 1; i < ARRAY_DIM(layers); i++) {
if (fprintf(f, "\tl%u -> l%u [style=invis weight=10];\n", i, i + 1) < 0)
goto err;
}
}
STAILQ_FOREACH (info, &node_infos, next) {
rte_node_t node_id = rte_node_from_name(info->node->name);
unsigned nb_edges = rte_node_edge_count(node_id);
const char *name = info->node->name;
const char *attrs = "";
if (node_id == port_output_node)
nb_edges = info->node->nb_edges;
if (nb_edges == 0)
continue;
if (!req->full) {
if (strstr(name, "error"))
continue;
if (strcmp(name, "control_input") == 0)
continue;
if (strcmp(name, "control_output") == 0)
continue;
}
if (info->node->flags & RTE_NODE_SOURCE_F) {
if (req->by_layer)
attrs = " [color=blue style=bold constraint=false]";
else
attrs = " [color=blue style=bold]";
} else if (info->type & GR_NODE_T_CONTROL) {
if (req->by_layer)
attrs = " [color=dodgerblue constraint=false]";
else
attrs = " [color=dodgerblue]";
}
if ((edges = calloc(nb_edges, sizeof(char *))) == NULL)
goto err;
if (node_id == port_output_node) {
for (unsigned i = 0; i < nb_edges; i++)
edges[i] = (char *)info->node->next_nodes[i];
} else if (rte_node_edge_get(node_id, edges) == RTE_EDGE_ID_INVALID)
goto err;
for (unsigned i = 0; i < nb_edges; i++) {
const char *edge = edges[i];
const char *node_attrs = attrs;
rte_node_t id = rte_node_from_name(edge);
unsigned num = rte_node_edge_count(id);
if (!req->full) {
if (strstr(edge, "error"))
continue;
if (strcmp(edge, "control_input") == 0)
continue;
if (strcmp(edge, "control_output") == 0)
continue;
}
if (id == port_output_node) {
num = gr_node_info_get(id)->node->nb_edges;
}
if (num == 0) {
if (!req->full)
continue;
if (req->by_layer)
node_attrs = " [color=darkorange constraint=false]";
else
node_attrs = " [color=darkorange]";
}
vec_foreach (const char *e, seen_edges) {
if (strcmp(e, edge) == 0)
goto skip; // skip duplicate edges
}
vec_add(seen_edges, edge);
if (fprintf(f, "\t\"%s\" -> \"%s\"%s;\n", name, edge, node_attrs) < 0)
goto err;
skip:;
}
free(edges);
edges = NULL;
vec_free(seen_edges);
}
// terminate with nul character
if (fprintf(f, "}\n%c", '\0') < 0)
goto err;
fflush(f);
fclose(f);
return api_out(0, buf_len, buf);
err:
int errsave = errno;
fclose(f);
free(buf);
free(edges);
vec_free(seen_edges);
return api_out(errsave, 0, NULL);
}
static struct api_out graph_conf_get(const void * /*request*/, struct api_ctx *) {
struct gr_graph_conf *resp = malloc(sizeof(*resp));
if (resp == NULL)
return api_out(ENOMEM, 0, NULL);
*resp = graph_conf;
return api_out(0, sizeof(*resp), resp);
}
static struct api_out graph_conf_set(const void *request, struct api_ctx *) {
const struct gr_graph_conf_set_req *req = request;
vec struct iface_info_port **ports = NULL;
struct gr_graph_conf prev = graph_conf;
struct iface *iface = NULL;
int ret;
if (req->set_attrs & GR_GRAPH_SET_RX_BURST) {
if (req->rx_burst_max == 0)
return api_out(EDOM, 0, NULL);
if (req->rx_burst_max > RTE_GRAPH_BURST_SIZE)
return api_out(EOVERFLOW, 0, NULL);
graph_conf.rx_burst_max = req->rx_burst_max;
}
if (req->set_attrs & GR_GRAPH_SET_VECTOR) {
if (req->vector_max == 0)
return api_out(EDOM, 0, NULL);
if (req->vector_max > RTE_GRAPH_BURST_SIZE)
return api_out(EOVERFLOW, 0, NULL);
graph_conf.vector_max = req->vector_max;
}
if (req->set_attrs & GR_GRAPH_SET_ICMP_ERROR)
graph_conf.icmp_error_rate = req->icmp_error_rate;
if (req->set_attrs & GR_GRAPH_SET_ARP)
graph_conf.arp_rate = req->arp_rate;
if (req->set_attrs & GR_GRAPH_SET_ICMP)
graph_conf.icmp_rate = req->icmp_rate;
if (graph_conf.rx_burst_max == prev.rx_burst_max
&& graph_conf.vector_max == prev.vector_max)
return api_out(0, 0, NULL); // no change
while ((iface = iface_next(GR_IFACE_TYPE_PORT, iface)) != NULL) {
struct iface_info_port *port = iface_info_port(iface);
vec_add(ports, port);
}
LOG(NOTICE,
"vector_max=%u rx_burst_max=%u",
graph_conf.vector_max,
graph_conf.rx_burst_max);
ret = worker_graph_reload_all(ports);
if (ret < 0) {
graph_conf = prev;
worker_graph_reload_all(ports);
}
vec_free(ports);
return api_out(-ret, 0, NULL);
}
static void graph_init(struct event_base *) {
struct rte_node_register *reg;
struct gr_node_info *info;
// register nodes first
STAILQ_FOREACH (info, &node_infos, next) {
if (info->node == NULL)
ABORT("info->node == NULL");
reg = info->node;
reg->parent_id = RTE_NODE_ID_INVALID;
if (reg->xstats && reg->xstats->nb_xstats > GR_MAX_NODE_XSTATS)
ABORT("node %s has %u xstats (max %u)",
reg->name,
reg->xstats->nb_xstats,
GR_MAX_NODE_XSTATS);
reg->id = __rte_node_register(reg);
if (reg->id == RTE_NODE_ID_INVALID)
ABORT("__rte_node_register(%s): %s", reg->name, rte_strerror(rte_errno));
if (strcmp(reg->name, RX_NODE_BASE) == 0)
port_rx_node = reg->id;
else if (strcmp(reg->name, TX_NODE_BASE) == 0)
port_tx_node = reg->id;
else
vec_add(base_node_names, reg->name);
if (strcmp(reg->name, "port_output") == 0)
port_output_node = reg->id;
}
// then, invoke all registration callbacks where applicable
STAILQ_FOREACH (info, &node_infos, next) {
if (info->register_callback != NULL) {
info->register_callback();
}
}
}
static void graph_fini(struct event_base *) {
struct gr_node_info *info;
STAILQ_FOREACH (info, &node_infos, next) {
if (info->unregister_callback != NULL) {
info->unregister_callback();
}
}
vec_free(base_node_names);
strvec_free(rx_node_names);
strvec_free(tx_node_names);
}
static struct module graph_module = {
.name = "graph",
.init = graph_init,
.fini = graph_fini,
};
RTE_INIT(control_graph_init) {
api_handler(GR_GRAPH_DUMP, graph_dump);
api_handler(GR_GRAPH_CONF_GET, graph_conf_get);
api_handler(GR_GRAPH_CONF_SET, graph_conf_set);
module_register(&graph_module);
}