2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 #include <rte_table_hash.h>
19 #include <rte_version.h>
20 #include <rte_malloc.h>
22 #include "prox_malloc.h"
28 #include "hash_utils.h"
30 #include "prox_port_cfg.h"
32 #include "handle_qos.h"
33 #include "handle_qinq_encap4.h"
38 #include "stats_core.h"
40 void start_core_all(int task_id)
42 uint32_t cores[RTE_MAX_LCORE];
47 prox_core_to_str(tmp, sizeof(tmp), 0);
48 plog_info("Starting cores: %s\n", tmp);
51 while (prox_core_next(&lcore_id, 0) == 0) {
52 cores[cnt++] = lcore_id;
54 start_cores(cores, cnt, task_id);
57 void stop_core_all(int task_id)
59 uint32_t cores[RTE_MAX_LCORE];
64 prox_core_to_str(tmp, sizeof(tmp), 0);
65 plog_info("Stopping cores: %s\n", tmp);
68 while (prox_core_next(&lcore_id, 0) == 0) {
69 cores[cnt++] = lcore_id;
72 stop_cores(cores, cnt, task_id);
75 static void warn_inactive_cores(uint32_t *cores, int count, const char *prefix)
77 for (int i = 0; i < count; ++i) {
78 if (!prox_core_active(cores[i], 0)) {
79 plog_warn("%s %u: core is not active\n", prefix, cores[i]);
84 static inline int wait_command_handled(struct lcore_cfg *lconf)
86 uint64_t t1 = rte_rdtsc(), t2;
89 if (lconf->msg.type == LCONF_MSG_STOP)
92 while (lconf_is_req(lconf)) {
94 if (t2 - t1 > max_time * rte_get_tsc_hz()) {
95 // Failed to handle command ...
96 for (uint8_t task_id = 0; task_id < lconf->n_tasks_all; ++task_id) {
97 struct task_args *targs = &lconf->targs[task_id];
98 if (!(targs->flags & TASK_ARG_DROP)) {
99 plogx_err("Failed to handle command - task is in NO_DROP and might be stuck...\n");
103 plogx_err("Failed to handle command\n");
110 static inline void start_l3(struct task_args *targ)
112 if (!task_is_master(targ)) {
113 if ((targ->nb_txrings != 0) || (targ->nb_txports != 0)) {
114 if (targ->flags & TASK_ARG_L3)
115 task_start_l3(targ->tbase, targ);
120 void start_cores(uint32_t *cores, int count, int task_id)
122 int n_started_cores = 0;
123 uint32_t started_cores[RTE_MAX_LCORE];
124 struct task_args *targ;
126 warn_inactive_cores(cores, count, "Can't start core");
128 for (int i = 0; i < count; ++i) {
129 struct lcore_cfg *lconf = &lcore_cfg[cores[i]];
131 if (lconf->n_tasks_run != lconf->n_tasks_all) {
133 for (uint8_t tid = 0; tid < lconf->n_tasks_all; ++tid) {
134 targ = &lconf->targs[tid];
138 targ = &lconf->targs[task_id];
141 lconf->msg.type = LCONF_MSG_START;
142 lconf->msg.task_id = task_id;
143 lconf_set_req(lconf);
145 plog_info("Starting core %u (all tasks)\n", cores[i]);
147 plog_info("Starting core %u task %u\n", cores[i], task_id);
148 started_cores[n_started_cores++] = cores[i];
149 lconf->flags |= LCONF_FLAG_RUNNING;
150 rte_eal_remote_launch(lconf_run, NULL, cores[i]);
153 plog_warn("Core %u is already running all its tasks\n", cores[i]);
157 /* This function is blocking, so detect when each core has
158 consumed the message. */
159 for (int i = 0; i < n_started_cores; ++i) {
160 struct lcore_cfg *lconf = &lcore_cfg[started_cores[i]];
161 plog_info("Waiting for core %u to start...", started_cores[i]);
162 if (wait_command_handled(lconf) == -1) return;
167 void stop_cores(uint32_t *cores, int count, int task_id)
169 int n_stopped_cores = 0;
170 uint32_t stopped_cores[RTE_MAX_LCORE];
173 warn_inactive_cores(cores, count, "Can't stop core");
175 for (int i = 0; i < count; ++i) {
176 struct lcore_cfg *lconf = &lcore_cfg[cores[i]];
177 if (lconf->n_tasks_run) {
178 if (wait_command_handled(lconf) == -1) return;
180 lconf->msg.type = LCONF_MSG_STOP;
181 lconf->msg.task_id = task_id;
182 lconf_set_req(lconf);
183 stopped_cores[n_stopped_cores++] = cores[i];
187 for (int i = 0; i < n_stopped_cores; ++i) {
188 c = stopped_cores[i];
189 struct lcore_cfg *lconf = &lcore_cfg[c];
190 if (wait_command_handled(lconf) == -1) return;
192 if (lconf->n_tasks_run == 0) {
193 plog_info("All tasks stopped on core %u, waiting for core to stop...", c);
194 rte_eal_wait_lcore(c);
196 lconf->flags &= ~LCONF_FLAG_RUNNING;
199 plog_info("Stopped task %u on core %u\n", task_id, c);
210 static struct size_unit to_size_unit(uint64_t bytes)
212 struct size_unit ret;
214 if (bytes > 1 << 30) {
215 ret.val = bytes >> 30;
216 ret.frac = ((bytes - (ret.val << 30)) * 1000) / (1 << 30);
217 strcpy(ret.unit, "GB");
219 else if (bytes > 1 << 20) {
220 ret.val = bytes >> 20;
221 ret.frac = ((bytes - (ret.val << 20)) * 1000) / (1 << 20);
222 strcpy(ret.unit, "MB");
224 else if (bytes > 1 << 10) {
225 ret.val = bytes >> 10;
226 ret.frac = (bytes - (ret.val << 10)) * 1000 / (1 << 10);
227 strcpy(ret.unit, "KB");
232 strcpy(ret.unit, "B");
238 void cmd_mem_stats(void)
240 struct rte_malloc_socket_stats sock_stats;
244 for (uint32_t i = 0; i < RTE_MAX_NUMA_NODES; ++i) {
245 if (rte_malloc_get_socket_stats(i, &sock_stats) < 0 || sock_stats.heap_totalsz_bytes == 0)
248 plogx_info("Socket %u memory stats:\n", i);
249 su = to_size_unit(sock_stats.heap_totalsz_bytes);
250 plogx_info("\tHeap_size: %zu.%03zu %s\n", su.val, su.frac, su.unit);
251 su = to_size_unit(sock_stats.heap_freesz_bytes);
252 plogx_info("\tFree_size: %zu.%03zu %s\n", su.val, su.frac, su.unit);
253 su = to_size_unit(sock_stats.heap_allocsz_bytes);
254 plogx_info("\tAlloc_size: %zu.%03zu %s\n", su.val, su.frac, su.unit);
255 su = to_size_unit(sock_stats.greatest_free_size);
256 plogx_info("\tGreatest_free_size: %zu %s\n", su.val, su.unit);
257 plogx_info("\tAlloc_count: %u\n", sock_stats.alloc_count);
258 plogx_info("\tFree_count: %u\n", sock_stats.free_count);
262 void cmd_mem_layout(void)
264 const struct rte_memseg* memseg = rte_eal_get_physmem_layout();
266 plog_info("Memory layout:\n");
267 for (uint32_t i = 0; i < RTE_MAX_MEMSEG; i++) {
268 if (memseg[i].addr == NULL)
272 switch (memseg[i].hugepage_sz >> 20) {
283 plog_info("Segment %u: [%#lx-%#lx] at %p using %zu pages of %s\n",
286 memseg[i].phys_addr + memseg[i].len,
288 memseg[i].len/memseg[i].hugepage_sz, sz_str);
292 void cmd_dump(uint8_t lcore_id, uint8_t task_id, uint32_t nb_packets, struct input *input, int rx, int tx)
294 plog_info("dump %u %u %u\n", lcore_id, task_id, nb_packets);
295 if (lcore_id > RTE_MAX_LCORE) {
296 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
298 else if (task_id >= lcore_cfg[lcore_id].n_tasks_all) {
299 plog_warn("task_id too high, should be in [0, %u]\n", lcore_cfg[lcore_id].n_tasks_all - 1);
302 struct lcore_cfg *lconf = &lcore_cfg[lcore_id];
304 lconf->tasks_all[task_id]->aux->task_rt_dump.input = input;
306 if (wait_command_handled(lconf) == -1) return;
308 lconf->msg.type = LCONF_MSG_DUMP;
310 lconf->msg.type = LCONF_MSG_DUMP_RX;
312 lconf->msg.type = LCONF_MSG_DUMP_TX;
315 lconf->msg.task_id = task_id;
316 lconf->msg.val = nb_packets;
317 lconf_set_req(lconf);
320 if (lconf->n_tasks_run == 0) {
321 lconf_do_flags(lconf);
326 void cmd_trace(uint8_t lcore_id, uint8_t task_id, uint32_t nb_packets)
328 plog_info("trace %u %u %u\n", lcore_id, task_id, nb_packets);
329 if (lcore_id > RTE_MAX_LCORE) {
330 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
332 else if (task_id >= lcore_cfg[lcore_id].n_tasks_all) {
333 plog_warn("task_id too high, should be in [0, %u]\n", lcore_cfg[lcore_id].n_tasks_all - 1);
336 struct lcore_cfg *lconf = &lcore_cfg[lcore_id];
338 if (wait_command_handled(lconf) == -1) return;
340 lconf->msg.type = LCONF_MSG_TRACE;
341 lconf->msg.task_id = task_id;
342 lconf->msg.val = nb_packets;
343 lconf_set_req(lconf);
345 if (lconf->n_tasks_run == 0) {
346 lconf_do_flags(lconf);
351 void cmd_rx_bw_start(uint32_t lcore_id)
353 if (lcore_id > RTE_MAX_LCORE) {
354 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
355 } else if (lcore_cfg[lcore_id].flags & LCONF_FLAG_RX_BW_ACTIVE) {
356 plog_warn("rx bandwidt already on core %u\n", lcore_id);
359 struct lcore_cfg *lconf = &lcore_cfg[lcore_id];
361 if (wait_command_handled(lconf) == -1) return;
362 lconf->msg.type = LCONF_MSG_RX_BW_START;
363 lconf_set_req(lconf);
365 if (lconf->n_tasks_run == 0) {
366 lconf_do_flags(lconf);
371 void cmd_tx_bw_start(uint32_t lcore_id)
373 if (lcore_id > RTE_MAX_LCORE) {
374 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
375 } else if (lcore_cfg[lcore_id].flags & LCONF_FLAG_TX_BW_ACTIVE) {
376 plog_warn("tx bandwidth already running on core %u\n", lcore_id);
379 struct lcore_cfg *lconf = &lcore_cfg[lcore_id];
381 if (wait_command_handled(lconf) == -1) return;
382 lconf->msg.type = LCONF_MSG_TX_BW_START;
383 lconf_set_req(lconf);
385 if (lconf->n_tasks_run == 0) {
386 lconf_do_flags(lconf);
391 void cmd_rx_bw_stop(uint32_t lcore_id)
393 if (lcore_id > RTE_MAX_LCORE) {
394 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
395 } else if (!(lcore_cfg[lcore_id].flags & LCONF_FLAG_RX_BW_ACTIVE)) {
396 plog_warn("rx bandwidth not running on core %u\n", lcore_id);
399 struct lcore_cfg *lconf = &lcore_cfg[lcore_id];
401 if (wait_command_handled(lconf) == -1) return;
402 lconf->msg.type = LCONF_MSG_RX_BW_STOP;
403 lconf_set_req(lconf);
405 if (lconf->n_tasks_run == 0) {
406 lconf_do_flags(lconf);
411 void cmd_tx_bw_stop(uint32_t lcore_id)
413 if (lcore_id > RTE_MAX_LCORE) {
414 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
415 } else if (!(lcore_cfg[lcore_id].flags & LCONF_FLAG_TX_BW_ACTIVE)) {
416 plog_warn("tx bandwidth not running on core %u\n", lcore_id);
419 struct lcore_cfg *lconf = &lcore_cfg[lcore_id];
421 if (wait_command_handled(lconf) == -1) return;
422 lconf->msg.type = LCONF_MSG_TX_BW_STOP;
423 lconf_set_req(lconf);
425 if (lconf->n_tasks_run == 0) {
426 lconf_do_flags(lconf);
430 void cmd_rx_distr_start(uint32_t lcore_id)
432 if (lcore_id > RTE_MAX_LCORE) {
433 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
434 } else if (lcore_cfg[lcore_id].flags & LCONF_FLAG_RX_DISTR_ACTIVE) {
435 plog_warn("rx distribution already xrunning on core %u\n", lcore_id);
437 struct lcore_cfg *lconf = &lcore_cfg[lcore_id];
439 if (wait_command_handled(lconf) == -1) return;
440 lconf->msg.type = LCONF_MSG_RX_DISTR_START;
441 lconf_set_req(lconf);
443 if (lconf->n_tasks_run == 0) {
444 lconf_do_flags(lconf);
449 void cmd_tx_distr_start(uint32_t lcore_id)
451 if (lcore_id > RTE_MAX_LCORE) {
452 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
453 } else if (lcore_cfg[lcore_id].flags & LCONF_FLAG_TX_DISTR_ACTIVE) {
454 plog_warn("tx distribution already xrunning on core %u\n", lcore_id);
456 struct lcore_cfg *lconf = &lcore_cfg[lcore_id];
458 if (wait_command_handled(lconf) == -1) return;
459 lconf->msg.type = LCONF_MSG_TX_DISTR_START;
460 lconf_set_req(lconf);
462 if (lconf->n_tasks_run == 0) {
463 lconf_do_flags(lconf);
468 void cmd_rx_distr_stop(uint32_t lcore_id)
470 if (lcore_id > RTE_MAX_LCORE) {
471 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
472 } else if ((lcore_cfg[lcore_id].flags & LCONF_FLAG_RX_DISTR_ACTIVE) == 0) {
473 plog_warn("rx distribution not running on core %u\n", lcore_id);
475 struct lcore_cfg *lconf = &lcore_cfg[lcore_id];
477 if (wait_command_handled(lconf) == -1) return;
478 lconf->msg.type = LCONF_MSG_RX_DISTR_STOP;
479 lconf_set_req(lconf);
481 if (lconf->n_tasks_run == 0) {
482 lconf_do_flags(lconf);
487 void cmd_tx_distr_stop(uint32_t lcore_id)
489 if (lcore_id > RTE_MAX_LCORE) {
490 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
491 } else if ((lcore_cfg[lcore_id].flags & LCONF_FLAG_TX_DISTR_ACTIVE) == 0) {
492 plog_warn("tx distribution not running on core %u\n", lcore_id);
494 struct lcore_cfg *lconf = &lcore_cfg[lcore_id];
496 if (wait_command_handled(lconf) == -1) return;
497 lconf->msg.type = LCONF_MSG_TX_DISTR_STOP;
498 lconf_set_req(lconf);
500 if (lconf->n_tasks_run == 0) {
501 lconf_do_flags(lconf);
506 void cmd_rx_distr_rst(uint32_t lcore_id)
508 if (lcore_id > RTE_MAX_LCORE) {
509 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
511 struct lcore_cfg *lconf = &lcore_cfg[lcore_id];
513 if (wait_command_handled(lconf) == -1) return;
514 lconf->msg.type = LCONF_MSG_RX_DISTR_RESET;
515 lconf_set_req(lconf);
517 if (lconf->n_tasks_run == 0) {
518 lconf_do_flags(lconf);
523 void cmd_tx_distr_rst(uint32_t lcore_id)
525 if (lcore_id > RTE_MAX_LCORE) {
526 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
528 struct lcore_cfg *lconf = &lcore_cfg[lcore_id];
530 if (wait_command_handled(lconf) == -1) return;
531 lconf->msg.type = LCONF_MSG_TX_DISTR_RESET;
532 lconf_set_req(lconf);
534 if (lconf->n_tasks_run == 0) {
535 lconf_do_flags(lconf);
540 void cmd_rx_distr_show(uint32_t lcore_id)
542 if (lcore_id > RTE_MAX_LCORE) {
543 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
545 for (uint32_t i = 0; i < lcore_cfg[lcore_id].n_tasks_all; ++i) {
546 struct task_base *t = lcore_cfg[lcore_id].tasks_all[i];
547 plog_info("t[%u]: ", i);
548 for (uint32_t j = 0; j < sizeof(t->aux->rx_bucket)/sizeof(t->aux->rx_bucket[0]); ++j) {
549 plog_info("%u ", t->aux->rx_bucket[j]);
555 void cmd_tx_distr_show(uint32_t lcore_id)
557 if (lcore_id > RTE_MAX_LCORE) {
558 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
560 for (uint32_t i = 0; i < lcore_cfg[lcore_id].n_tasks_all; ++i) {
561 struct task_base *t = lcore_cfg[lcore_id].tasks_all[i];
562 uint64_t tot = 0, avg = 0;
563 for (uint32_t j = 0; j < sizeof(t->aux->tx_bucket)/sizeof(t->aux->tx_bucket[0]); ++j) {
564 tot += t->aux->tx_bucket[j];
565 avg += j * t->aux->tx_bucket[j];
570 plog_info("t[%u]: %lu: ", i, avg);
571 for (uint32_t j = 0; j < sizeof(t->aux->tx_bucket)/sizeof(t->aux->tx_bucket[0]); ++j) {
572 plog_info("%u ", t->aux->tx_bucket[j]);
579 void cmd_ringinfo_all(void)
581 struct lcore_cfg *lconf;
582 uint32_t lcore_id = -1;
584 while(prox_core_next(&lcore_id, 0) == 0) {
585 lconf = &lcore_cfg[lcore_id];
586 for (uint8_t task_id = 0; task_id < lconf->n_tasks_all; ++task_id) {
587 cmd_ringinfo(lcore_id, task_id);
592 void cmd_ringinfo(uint8_t lcore_id, uint8_t task_id)
594 struct lcore_cfg *lconf;
595 struct rte_ring *ring;
596 struct task_args* targ;
599 if (!prox_core_active(lcore_id, 0)) {
600 plog_info("lcore %u is not active\n", lcore_id);
603 lconf = &lcore_cfg[lcore_id];
604 if (task_id >= lconf->n_tasks_all) {
605 plog_warn("Invalid task index %u: lcore %u has %u tasks\n", task_id, lcore_id, lconf->n_tasks_all);
609 targ = &lconf->targs[task_id];
610 plog_info("Core %u task %u: %u rings\n", lcore_id, task_id, targ->nb_rxrings);
611 for (uint8_t i = 0; i < targ->nb_rxrings; ++i) {
612 ring = targ->rx_rings[i];
613 #if RTE_VERSION < RTE_VERSION_NUM(17,5,0,1)
614 count = ring->prod.mask + 1;
616 count = ring->mask + 1;
618 plog_info("\tRing %u:\n", i);
619 plog_info("\t\tFlags: %s,%s\n", ring->flags & RING_F_SP_ENQ? "sp":"mp", ring->flags & RING_F_SC_DEQ? "sc":"mc");
620 plog_info("\t\tMemory size: %zu bytes\n", rte_ring_get_memsize(count));
621 plog_info("\t\tOccupied: %u/%u\n", rte_ring_count(ring), count);
625 void cmd_port_up(uint8_t port_id)
629 if (!port_is_active(port_id)) {
633 if ((err = rte_eth_dev_set_link_up(port_id)) == 0) {
634 plog_info("Bringing port %d up\n", port_id);
637 plog_warn("Failed to bring port %d up with error %d\n", port_id, err);
641 void cmd_port_down(uint8_t port_id)
645 if (!port_is_active(port_id)) {
649 if ((err = rte_eth_dev_set_link_down(port_id)) == 0) {
650 plog_info("Bringing port %d down\n", port_id);
653 plog_warn("Failed to bring port %d down with error %d\n", port_id, err);
657 void cmd_xstats(uint8_t port_id)
659 #if RTE_VERSION >= RTE_VERSION_NUM(16,7,0,0)
661 struct rte_eth_xstat *eth_xstat = NULL; // id and value
662 struct rte_eth_xstat_name *eth_xstat_name = NULL; // only names
663 struct prox_port_cfg* port_cfg = &prox_port_cfg[port_id];
666 n_xstats = rte_eth_xstats_get(port_id, NULL, 0);
667 eth_xstat_name = prox_zmalloc(n_xstats * sizeof(*eth_xstat_name), port_cfg->socket);
668 PROX_ASSERT(eth_xstat_name);
669 rc = rte_eth_xstats_get_names(port_id, eth_xstat_name, n_xstats);
670 if ((rc < 0) || (rc > n_xstats)) {
672 plog_warn("Failed to get xstats_names on port %d with error %d\n", port_id, rc);
673 } else if (rc > n_xstats) {
674 plog_warn("Failed to get xstats_names on port %d: too many xstats (%d)\n", port_id, rc);
678 eth_xstat = prox_zmalloc(n_xstats * sizeof(*eth_xstat), port_cfg->socket);
679 PROX_ASSERT(eth_xstat);
680 rc = rte_eth_xstats_get(port_id, eth_xstat, n_xstats);
681 if ((rc < 0) || (rc > n_xstats)) {
683 plog_warn("Failed to get xstats on port %d with error %d\n", port_id, rc);
684 } else if (rc > n_xstats) {
685 plog_warn("Failed to get xstats on port %d: too many xstats (%d)\n", port_id, rc);
688 for (int i=0;i<rc;i++) {
689 plog_info("%s: %ld\n", eth_xstat_name[i].name, eth_xstat[i].value);
693 prox_free(eth_xstat_name);
695 prox_free(eth_xstat);
697 #if RTE_VERSION >= RTE_VERSION_NUM(2,1,0,0)
699 struct rte_eth_xstats *eth_xstats;
700 struct prox_port_cfg* port_cfg = &prox_port_cfg[port_id];
703 n_xstats = rte_eth_xstats_get(port_id, NULL, 0);
704 eth_xstats = prox_zmalloc(n_xstats * sizeof(*eth_xstats), port_cfg->socket);
705 PROX_ASSERT(eth_xstats);
706 rc = rte_eth_xstats_get(port_id, eth_xstats, n_xstats);
707 if ((rc < 0) || (rc > n_xstats)) {
709 plog_warn("Failed to get xstats on port %d with error %d\n", port_id, rc);
710 } else if (rc > n_xstats) {
711 plog_warn("Failed to get xstats on port %d: too many xstats (%d)\n", port_id, rc);
714 for (int i=0;i<rc;i++) {
715 plog_info("%s: %ld\n", eth_xstats[i].name, eth_xstats[i].value);
719 prox_free(eth_xstats);
721 plog_warn("Failed to get xstats, xstats are not supported in this version of dpdk\n");
726 void cmd_portinfo(int port_id, char *dst, size_t max_len)
728 char *end = dst + max_len;
732 uint8_t max_port_idx = prox_last_port_active() + 1;
734 for (uint8_t port_id = 0; port_id < max_port_idx; ++port_id) {
735 if (!prox_port_cfg[port_id].active) {
738 struct prox_port_cfg* port_cfg = &prox_port_cfg[port_id];
740 dst += snprintf(dst, end - dst,
741 "%2d:%10s; "MAC_BYTES_FMT"; %s\n",
744 MAC_BYTES(port_cfg->eth_addr.addr_bytes),
750 if (!port_is_active(port_id)) {
754 struct prox_port_cfg* port_cfg = &prox_port_cfg[port_id];
756 dst += snprintf(dst, end - dst, "Port info for port %u\n", port_id);
757 dst += snprintf(dst, end - dst, "\tName: %s\n", port_cfg->name);
758 dst += snprintf(dst, end - dst, "\tDriver: %s\n", port_cfg->driver_name);
759 dst += snprintf(dst, end - dst, "\tMac address: "MAC_BYTES_FMT"\n", MAC_BYTES(port_cfg->eth_addr.addr_bytes));
760 dst += snprintf(dst, end - dst, "\tLink speed: %u Mbps\n", port_cfg->link_speed);
761 dst += snprintf(dst, end - dst, "\tLink status: %s\n", port_cfg->link_up? "up" : "down");
762 dst += snprintf(dst, end - dst, "\tSocket: %u\n", port_cfg->socket);
763 dst += snprintf(dst, end - dst, "\tPCI address: %s\n", port_cfg->pci_addr);
764 dst += snprintf(dst, end - dst, "\tPromiscuous: %s\n", port_cfg->promiscuous? "yes" : "no");
765 dst += snprintf(dst, end - dst, "\tNumber of RX/TX descriptors: %u/%u\n", port_cfg->n_rxd, port_cfg->n_txd);
766 dst += snprintf(dst, end - dst, "\tNumber of RX/TX queues: %u/%u (max: %u/%u)\n", port_cfg->n_rxq, port_cfg->n_txq, port_cfg->max_rxq, port_cfg->max_txq);
767 dst += snprintf(dst, end - dst, "\tMemory pools:\n");
769 for (uint8_t i = 0; i < 32; ++i) {
770 if (port_cfg->pool[i]) {
771 dst += snprintf(dst, end - dst, "\t\tname: %s (%p)\n",
772 port_cfg->pool[i]->name, port_cfg->pool[i]);
777 void cmd_read_reg(uint8_t port_id, unsigned int id)
779 unsigned int val, rc;
780 if (!port_is_active(port_id)) {
783 rc = read_reg(port_id, id, &val);
785 plog_warn("Failed to read register %d on port %d\n", id, port_id);
788 plog_info("Register 0x%08X : %08X \n", id, val);
792 void cmd_reset_port(uint8_t portid)
795 if (!prox_port_cfg[portid].active) {
796 plog_info("port not active \n");
799 rte_eth_dev_stop(portid);
800 rc = rte_eth_dev_start(portid);
802 plog_warn("Failed to restart port %d\n", portid);
805 void cmd_write_reg(uint8_t port_id, unsigned int id, unsigned int val)
807 if (!port_is_active(port_id)) {
811 plog_info("writing 0x%08X %08X\n", id, val);
812 write_reg(port_id, id, val);
815 void cmd_set_vlan_offload(uint8_t port_id, unsigned int val)
817 if (!port_is_active(port_id)) {
821 plog_info("setting vlan offload to %d\n", val);
822 if (val & ~(ETH_VLAN_STRIP_OFFLOAD | ETH_VLAN_FILTER_OFFLOAD | ETH_VLAN_EXTEND_OFFLOAD)) {
823 plog_info("wrong vlan offload value\n");
825 int ret = rte_eth_dev_set_vlan_offload(port_id, val);
826 plog_info("rte_eth_dev_set_vlan_offload return %d\n", ret);
829 void cmd_set_vlan_filter(uint8_t port_id, unsigned int id, unsigned int val)
831 if (!port_is_active(port_id)) {
835 plog_info("setting vln filter for vlan %d to %d\n", id, val);
836 int ret = rte_eth_dev_vlan_filter(port_id, id, val);
837 plog_info("rte_eth_dev_vlan_filter return %d\n", ret);
840 void cmd_thread_info(uint8_t lcore_id, uint8_t task_id)
842 plog_info("thread_info %u %u \n", lcore_id, task_id);
843 if (lcore_id > RTE_MAX_LCORE) {
844 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
846 if (!prox_core_active(lcore_id, 0)) {
847 plog_warn("lcore %u is not active\n", lcore_id);
850 if (task_id >= lcore_cfg[lcore_id].n_tasks_all) {
851 plog_warn("task_id too high, should be in [0, %u]\n", lcore_cfg[lcore_id].n_tasks_all - 1);
854 if (strcmp(lcore_cfg[lcore_id].targs[task_id].task_init->mode_str, "qos") == 0) {
855 struct task_base *task;
857 task = lcore_cfg[lcore_id].tasks_all[task_id];
858 plog_info("core %d, task %d: %d mbufs stored in QoS\n", lcore_id, task_id,
859 task_qos_n_pkts_buffered(task));
861 #ifdef ENABLE_EXTRA_USER_STATISTICS
863 else if (lcore_cfg[lcore_id].targs[task_id].mode == QINQ_ENCAP4) {
864 struct task_qinq_encap4 *task;
865 task = (struct task_qinq_encap4 *)(lcore_cfg[lcore_id].tasks_all[task_id]);
866 for (int i=0;i<task->n_users;i++) {
867 if (task->stats_per_user[i])
868 plog_info("User %d: %d packets\n", i, task->stats_per_user[i]);
873 // Only QoS thread info so far
874 plog_err("core %d, task %d: not a qos core (%p)\n", lcore_id, task_id, lcore_cfg[lcore_id].thread_x);
878 void cmd_rx_tx_info(void)
880 uint32_t lcore_id = -1;
881 while(prox_core_next(&lcore_id, 0) == 0) {
882 for (uint8_t task_id = 0; task_id < lcore_cfg[lcore_id].n_tasks_all; ++task_id) {
883 struct task_args *targ = &lcore_cfg[lcore_id].targs[task_id];
885 plog_info("Core %u:", lcore_id);
886 if (targ->rx_port_queue[0].port != OUT_DISCARD) {
887 for (int i = 0; i < targ->nb_rxports; i++) {
888 plog_info(" RX port %u (queue %u)", targ->rx_port_queue[i].port, targ->rx_port_queue[i].queue);
892 for (uint8_t j = 0; j < targ->nb_rxrings; ++j) {
893 plog_info(" RX ring[%u,%u] %p", task_id, j, targ->rx_rings[j]);
897 for (uint8_t j = 0; j < targ->nb_txports; ++j) {
898 plog_info(" TX port %u (queue %u)", targ->tx_port_queue[j].port,
899 targ->tx_port_queue[j].queue);
902 for (uint8_t j = 0; j < targ->nb_txrings; ++j) {
903 plog_info(" TX ring %p", targ->tx_rings[j]);
910 void cmd_get_cache_class(uint32_t lcore_id, uint32_t *set)
912 uint64_t tmp_rmid = 0;
913 cqm_assoc_read(lcore_id, &tmp_rmid);
914 *set = (uint32_t)(tmp_rmid >> 32);
917 void cmd_get_cache_class_mask(uint32_t lcore_id, uint32_t set, uint32_t *val)
919 cat_get_class_mask(lcore_id, set, val);
922 void cmd_set_cache_class_mask(uint32_t lcore_id, uint32_t set, uint32_t val)
924 cat_set_class_mask(lcore_id, set, val);
925 lcore_cfg[lcore_id].cache_set = set;
927 while(prox_core_next(&id, 0) == 0) {
928 if ((lcore_cfg[id].cache_set == set) && (rte_lcore_to_socket_id(id) == rte_lcore_to_socket_id(lcore_id))) {
929 plog_info("Updating mask for core %d to %d\n", id, set);
930 stats_update_cache_mask(id, val);
935 void cmd_set_cache_class(uint32_t lcore_id, uint32_t set)
937 uint64_t tmp_rmid = 0;
939 cqm_assoc_read(lcore_id, &tmp_rmid);
940 cqm_assoc(lcore_id, (tmp_rmid & 0xffffffff) | ((set * 1L) << 32));
941 cat_get_class_mask(lcore_id, set, &val);
942 stats_update_cache_mask(lcore_id, val);
945 void cmd_cache_reset(void)
947 uint8_t sockets[MAX_SOCKETS] = {0};
948 uint8_t cores[MAX_SOCKETS] = {0};
949 uint32_t mask = (1 << cat_get_num_ways()) - 1;
950 uint32_t lcore_id = -1, socket_id;
951 while(prox_core_next(&lcore_id, 0) == 0) {
952 cqm_assoc(lcore_id, 0);
953 socket_id = rte_lcore_to_socket_id(lcore_id);
954 if (socket_id < MAX_SOCKETS) {
955 sockets[socket_id] = 1;
956 cores[socket_id] = lcore_id;
958 stats_update_cache_mask(lcore_id, mask);
959 plog_info("Setting core %d to cache mask %x\n", lcore_id, mask);
960 lcore_cfg[lcore_id].cache_set = 0;
962 for (uint32_t s = 0; s < MAX_SOCKETS; s++) {
964 cat_reset_cache(cores[s]);
966 stats_lcore_assoc_rmid();
969 int bypass_task(uint32_t lcore_id, uint32_t task_id)
971 struct lcore_cfg *lconf = &lcore_cfg[lcore_id];
972 struct task_args *targ, *starg, *dtarg;
973 struct rte_ring *ring = NULL;
975 if (task_id >= lconf->n_tasks_all)
978 targ = &lconf->targs[task_id];
979 if (targ->nb_txrings == 1) {
980 plog_info("Task has %d receive and 1 transmmit ring and can be bypassed, %d precedent tasks\n", targ->nb_rxrings, targ->n_prev_tasks);
982 for (unsigned int i = 0; i < targ->n_prev_tasks; i++) {
983 starg = targ->prev_tasks[i];
984 for (unsigned int j = 0; j < starg->nb_txrings; j++) {
985 for (unsigned int k = 0; k < targ->nb_rxrings; k++) {
986 if (starg->tx_rings[j] == targ->rx_rings[k]) {
987 plog_info("bypassing ring %p and connecting it to %p\n", starg->tx_rings[j], targ->tx_rings[0]);
988 starg->tx_rings[j] = targ->tx_rings[0];
989 struct task_base *tbase = starg->tbase;
990 tbase->tx_params_sw.tx_rings[j] = starg->tx_rings[j];
996 plog_info("Task has %d receive and %d transmit ring and cannot be bypassed\n", targ->nb_rxrings, targ->nb_txrings);
1003 int reconnect_task(uint32_t lcore_id, uint32_t task_id)
1005 struct lcore_cfg *lconf = &lcore_cfg[lcore_id];
1006 struct task_args *targ, *starg, *dtarg = NULL;
1007 struct rte_ring *ring = NULL;
1009 if (task_id >= lconf->n_tasks_all)
1012 targ = &lconf->targs[task_id];
1013 if (targ->nb_txrings == 1) {
1015 for (unsigned int i = 0; i < targ->n_prev_tasks; i++) {
1016 starg = targ->prev_tasks[i];
1017 for (unsigned int j = 0; j < starg->nb_txrings; j++) {
1018 if (starg->tx_rings[j] == targ->tx_rings[0]) {
1019 if (targ->n_prev_tasks == targ->nb_rxrings) {
1020 starg->tx_rings[j] = targ->rx_rings[i];
1021 struct task_base *tbase = starg->tbase;
1022 tbase->tx_params_sw.tx_rings[j] = starg->tx_rings[j];
1023 plog_info("Task has %d receive and 1 transmmit ring and can be reconnected, %d precedent tasks\n", targ->nb_rxrings, targ->n_prev_tasks);
1024 } else if (targ->nb_rxrings == 1) {
1025 starg->tx_rings[j] = targ->rx_rings[0];
1026 struct task_base *tbase = starg->tbase;
1027 tbase->tx_params_sw.tx_rings[j] = starg->tx_rings[j];
1028 plog_info("Task has %d receive and 1 transmmit ring and ring %p can be reconnected, %d precedent tasks\n", targ->nb_rxrings, starg->tx_rings[j], targ->n_prev_tasks);
1030 plog_err("Unexpected configuration: %d precedent tasks, %d rx rings\n", targ->n_prev_tasks, targ->nb_rxrings);
1036 plog_info("Task has %d receive and %d transmit ring and cannot be bypassed\n", targ->nb_rxrings, targ->nb_txrings);