* [spp] [PATCH 0/2] add vdev_test @ 2020-02-26 2:02 Itsuro Oda 2020-02-26 2:02 ` [spp] [PATCH 1/2] vdev_test: simple tool to perform packet forwarding for vdev Itsuro Oda ` (3 more replies) 0 siblings, 4 replies; 15+ messages in thread From: Itsuro Oda @ 2020-02-26 2:02 UTC (permalink / raw) To: spp, ferruh.yigit, yasufum.o vdev_test is a simple tool to perform packet forwarding for virtual ethernet devices. It is mainly to test pipe PMD because testpmd can not be secondary process but vdev_test can be. Itsuro Oda (2): vdev_test: simple tool to perform packet forwarding for vdev makefile: add to build vdev_test src/Makefile | 2 + src/vdev_test/Makefile | 25 ++++ src/vdev_test/vdev_test.c | 247 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 274 insertions(+) create mode 100644 src/vdev_test/Makefile create mode 100644 src/vdev_test/vdev_test.c -- 2.17.1 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [spp] [PATCH 1/2] vdev_test: simple tool to perform packet forwarding for vdev 2020-02-26 2:02 [spp] [PATCH 0/2] add vdev_test Itsuro Oda @ 2020-02-26 2:02 ` Itsuro Oda 2020-02-26 2:02 ` [spp] [PATCH 2/2] makefile: add to build vdev_test Itsuro Oda ` (2 subsequent siblings) 3 siblings, 0 replies; 15+ messages in thread From: Itsuro Oda @ 2020-02-26 2:02 UTC (permalink / raw) To: spp, ferruh.yigit, yasufum.o vdev_test is a simple tool to perform packet forwarding for virtual ethernet devices. It is mainly to test pipe PMD because testpmd can not be secondary process but vdev_test can be. Signed-off-by: Itsuro Oda <oda@valinux.co.jp> --- src/vdev_test/Makefile | 25 ++++ src/vdev_test/vdev_test.c | 247 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 272 insertions(+) create mode 100644 src/vdev_test/Makefile create mode 100644 src/vdev_test/vdev_test.c diff --git a/src/vdev_test/Makefile b/src/vdev_test/Makefile new file mode 100644 index 0000000..aabd9c4 --- /dev/null +++ b/src/vdev_test/Makefile @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2020 Nippon Telegraph and Telephone Corporation + +ifeq ($(RTE_SDK),) +$(error "Please define RTE_SDK environment variable") +endif + +# Default target, can be overridden by command line or environment +RTE_TARGET ?= x86_64-native-linuxapp-gcc + +include $(RTE_SDK)/mk/rte.vars.mk + +# binary name +APP = vdev_test + +# all source are stored in SRCS-y +SRCS-y := vdev_test.c + +CFLAGS += -O3 +CFLAGS += $(WERROR_FLAGS) + +SPP_DRIVERS_DIR = $(BASE_OUTPUT)/src/drivers +EXTRA_LDLIBS = -L$(SPP_DRIVERS_DIR)/vhost -L$(SPP_DRIVERS_DIR)/pipe --whole-archive -lrte_pmd_spp_vhost -lrte_pmd_spp_pipe --no-whole-archive + +include $(RTE_SDK)/mk/rte.extapp.mk diff --git a/src/vdev_test/vdev_test.c b/src/vdev_test/vdev_test.c new file mode 100644 index 0000000..f7eb507 --- /dev/null +++ b/src/vdev_test/vdev_test.c @@ -0,0 +1,247 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation + */ + +#include <getopt.h> +#include <signal.h> +#include <stdint.h> +#include <inttypes.h> +#include <unistd.h> +#include <stdio.h> +#include <sys/time.h> + +#include <rte_eal.h> +#include <rte_ethdev.h> +#include <rte_ether.h> +#include <rte_cycles.h> +#include <rte_lcore.h> +#include <rte_mbuf.h> +#include <rte_eth_ring.h> +#include <rte_bus_vdev.h> + +#define RING_SIZE 128 +#define BURST_SIZE 32 +#define NUM_MBUFS 8191 +#define MBUF_CACHE_SIZE 512 + +#define PKTMBUF_POOL_NAME "MProc_pktmbuf_pool" + +static int tx_first = 0; +static char *device; +static char *devargs = NULL; +static int force_quit; + +static struct option lopts[] = { + {"send", no_argument, &tx_first, 1}, + {"create", required_argument, NULL, 'c'}, + {NULL, 0, 0, 0} +}; + +static const struct rte_eth_conf port_conf_default = { + .rxmode = { .max_rx_pkt_len = RTE_ETHER_MAX_LEN } +}; + +static int +parse_args(int argc, char *argv[]) +{ + int c; + + while ((c = getopt_long(argc, argv, "", lopts, NULL)) != -1) { + switch (c) { + case 0: + /* long option */ + break; + case 'c': + /* --create */ + devargs = optarg; + break; + default: + /* invalid option */ + return -1; + } + } + + if (optind != argc - 1) { + return -1; + } + + device = argv[optind]; + + return 0; +} + +static void +signal_handler(int signum) +{ + printf("signel %d recieved\n", signum); + force_quit = 1; +} + +int +main(int argc, char *argv[]) +{ + int ret; + uint16_t port_id; + uint16_t nb_ports; + struct rte_mempool *mbuf_pool = NULL; + struct rte_mbuf *m; + uint16_t nb_tx; + struct rte_mbuf *bufs[BURST_SIZE]; + uint16_t nb_rx; + struct rte_eth_conf port_conf = port_conf_default; + struct rte_eth_stats stats; + struct timeval t0, t1; + long total; + uint16_t buf; + int i; + + ret = rte_eal_init(argc, argv); + if (ret < 0) { + rte_exit(EXIT_FAILURE, "EAL initialization failed\n"); + } + argc -= ret; + argv += ret; + + ret = parse_args(argc, argv); + if (ret < 0) { + rte_exit(EXIT_FAILURE, + "usage: vdev_test <eal options> -- " + "[--send] [--create devargs] vdev\n"); + } + printf("device: %s tx_first: %d devargs: %s\n", device, tx_first, devargs); + + if (strncmp("spp_pipe", device, 8) == 0) { + if (rte_eal_process_type() != RTE_PROC_SECONDARY) { + rte_exit(EXIT_FAILURE, "must be secondary\n"); + } + } + + if (devargs) { + /* --create */ + ret = rte_eth_dev_get_port_by_name(device, &port_id); + if (ret == 0) { + rte_exit(EXIT_FAILURE, + "%s already exists.\n", device); + } + for (i = 0; i < 3; i++) { + ret = rte_eal_hotplug_add("vdev", device, devargs); + if (ret == 0) + break; + sleep(1); + } + if (ret < 0) { + pause(); + rte_exit(EXIT_FAILURE, + "%s %s create failed.\n", device, devargs); + } + } + + ret = rte_eth_dev_get_port_by_name(device, &port_id); + if (ret < 0) { + rte_exit(EXIT_FAILURE, "device not found\n"); + } + printf("port_id: %u\n", (unsigned)port_id); + + nb_ports = rte_eth_dev_count_avail(); + /* just infomation */ + printf("num port: %u\n", (unsigned)nb_ports); + + if (rte_eal_process_type() == RTE_PROC_SECONDARY) { + mbuf_pool = rte_mempool_lookup(PKTMBUF_POOL_NAME); + } else { + mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS, + MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, + rte_socket_id()); + } + if (mbuf_pool == NULL) { + rte_exit(EXIT_FAILURE, "Cannot get mbuf pool\n"); + } + + if (strncmp("virtio_user", device, 11) == 0) { + port_conf.intr_conf.lsc = 1; + } + ret = rte_eth_dev_configure(port_id, 1, 1, &port_conf); + if (ret != 0) { + rte_exit(EXIT_FAILURE, "rte_eth_dev_configure failed\n"); + } + + ret = rte_eth_rx_queue_setup(port_id, 0, RING_SIZE, + rte_eth_dev_socket_id(port_id), NULL, mbuf_pool); + if (ret < 0) { + rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup failed\n"); + } + + ret = rte_eth_tx_queue_setup(port_id, 0, RING_SIZE, + rte_eth_dev_socket_id(port_id), NULL); + if (ret < 0) { + rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup failed\n"); + } + + ret = rte_eth_dev_start(port_id); + if (ret < 0) { + rte_exit(EXIT_FAILURE, "rte_eth_dev_start failed\n"); + } + + force_quit = 0; + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); + + if (tx_first) { + /* send a packet */ + m = rte_pktmbuf_alloc(mbuf_pool); + if (m == NULL) { + fprintf(stderr, "rte_pktmbuf_alloc failed\n"); + goto out; + } + if (rte_pktmbuf_append(m, RTE_ETHER_MIN_LEN) == NULL) { + fprintf(stderr, "rte_pktmbuf_append failed\n"); + goto out; + } + + nb_tx = rte_eth_tx_burst(port_id, 0, &m, 1); + if (nb_tx != 1) { + fprintf(stderr, "can not send a packet\n"); + rte_pktmbuf_free(m); + goto out; + } + printf("send a packet\n"); + gettimeofday(&t0, NULL); + } + + /* recieve and send a packet */ + while (!force_quit) { + nb_rx = rte_eth_rx_burst(port_id, 0, bufs, BURST_SIZE); + if (nb_rx > 0) { + nb_tx = rte_eth_tx_burst(port_id, 0, bufs, nb_rx); + for (buf = nb_tx; buf < nb_rx; buf++) { + rte_pktmbuf_free(bufs[buf]); + } + } + } + + gettimeofday(&t1, NULL); + + ret = rte_eth_stats_get(port_id, &stats); + if (ret == 0) { + printf("ipackets: %lu\n", stats.ipackets); + printf("opackets: %lu\n", stats.opackets); + printf("ierrors: %lu\n", stats.ierrors); + printf("oerrors: %lu\n", stats.oerrors); + if (tx_first) { + total = (t1.tv_sec - t0.tv_sec) * 1000000 \ + + t1.tv_usec - t0.tv_usec; + printf("%ld us: %.2f packet/s\n", total, + (double)stats.ipackets / total * 1000000); + } + } + +out: + rte_eth_dev_stop(port_id); + rte_eth_dev_close(port_id); + + if (devargs) { + rte_eal_hotplug_remove("vdev", device); + } + + return 0; +} -- 2.17.1 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [spp] [PATCH 2/2] makefile: add to build vdev_test 2020-02-26 2:02 [spp] [PATCH 0/2] add vdev_test Itsuro Oda 2020-02-26 2:02 ` [spp] [PATCH 1/2] vdev_test: simple tool to perform packet forwarding for vdev Itsuro Oda @ 2020-02-26 2:02 ` Itsuro Oda 2020-02-27 4:25 ` [spp] [PATCH v2 0/3] add vdev_test Itsuro Oda 2020-03-02 0:00 ` [spp] [PATCH v3 0/3] add vdev_test Itsuro Oda 3 siblings, 0 replies; 15+ messages in thread From: Itsuro Oda @ 2020-02-26 2:02 UTC (permalink / raw) To: spp, ferruh.yigit, yasufum.o This patch adds to build vdev_test. Signed-off-by: Itsuro Oda <oda@valinux.co.jp> --- src/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Makefile b/src/Makefile index 72a0910..48106d5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -43,6 +43,7 @@ DEPDIRS-nfv := drivers DEPDIRS-vf := drivers DEPDIRS-mirror := drivers DEPDIRS-pcap := drivers +DEPDIRS-vdev_test := drivers DIRS-y += drivers DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += primary @@ -50,5 +51,6 @@ DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += nfv DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += vf DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += mirror DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += pcap +DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += vdev_test include $(RTE_SDK)/mk/rte.extsubdir.mk -- 2.17.1 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [spp] [PATCH v2 0/3] add vdev_test 2020-02-26 2:02 [spp] [PATCH 0/2] add vdev_test Itsuro Oda 2020-02-26 2:02 ` [spp] [PATCH 1/2] vdev_test: simple tool to perform packet forwarding for vdev Itsuro Oda 2020-02-26 2:02 ` [spp] [PATCH 2/2] makefile: add to build vdev_test Itsuro Oda @ 2020-02-27 4:25 ` Itsuro Oda 2020-02-27 4:25 ` [spp] [PATCH v2 1/3] vdev_test: simple tool to perform packet forwarding for vdev Itsuro Oda ` (2 more replies) 2020-03-02 0:00 ` [spp] [PATCH v3 0/3] add vdev_test Itsuro Oda 3 siblings, 3 replies; 15+ messages in thread From: Itsuro Oda @ 2020-02-27 4:25 UTC (permalink / raw) To: spp, ferruh.yigit, yasufum.o vdev_test is a simple tool to perform packet forwarding for virtual ethernet devices. It is mainly to test pipe PMD because testpmd can not be secondary process but vdev_test can be. --- v2: * move directory src to tools. Itsuro Oda (3): vdev_test: simple tool to perform packet forwarding for vdev tools: add Makefile for vdev_test makefile: add make of tools directory GNUmakefile | 5 + tools/Makefile | 15 +++ tools/vdev_test/Makefile | 25 ++++ tools/vdev_test/vdev_test.c | 247 ++++++++++++++++++++++++++++++++++++ 4 files changed, 292 insertions(+) create mode 100644 tools/Makefile create mode 100644 tools/vdev_test/Makefile create mode 100644 tools/vdev_test/vdev_test.c -- 2.17.1 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [spp] [PATCH v2 1/3] vdev_test: simple tool to perform packet forwarding for vdev 2020-02-27 4:25 ` [spp] [PATCH v2 0/3] add vdev_test Itsuro Oda @ 2020-02-27 4:25 ` Itsuro Oda 2020-02-28 8:32 ` Yasufumi Ogawa 2020-02-27 4:25 ` [spp] [PATCH v2 2/3] tools: add Makefile for vdev_test Itsuro Oda 2020-02-27 4:25 ` [spp] [PATCH v2 3/3] makefile: add make of tools directory Itsuro Oda 2 siblings, 1 reply; 15+ messages in thread From: Itsuro Oda @ 2020-02-27 4:25 UTC (permalink / raw) To: spp, ferruh.yigit, yasufum.o vdev_test is a simple tool to perform packet forwarding for virtual ethernet devices. It is mainly to test pipe PMD because testpmd can not be secondary process but vdev_test can be. Signed-off-by: Itsuro Oda <oda@valinux.co.jp> --- tools/vdev_test/Makefile | 25 ++++ tools/vdev_test/vdev_test.c | 247 ++++++++++++++++++++++++++++++++++++ 2 files changed, 272 insertions(+) create mode 100644 tools/vdev_test/Makefile create mode 100644 tools/vdev_test/vdev_test.c diff --git a/tools/vdev_test/Makefile b/tools/vdev_test/Makefile new file mode 100644 index 0000000..aabd9c4 --- /dev/null +++ b/tools/vdev_test/Makefile @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2020 Nippon Telegraph and Telephone Corporation + +ifeq ($(RTE_SDK),) +$(error "Please define RTE_SDK environment variable") +endif + +# Default target, can be overridden by command line or environment +RTE_TARGET ?= x86_64-native-linuxapp-gcc + +include $(RTE_SDK)/mk/rte.vars.mk + +# binary name +APP = vdev_test + +# all source are stored in SRCS-y +SRCS-y := vdev_test.c + +CFLAGS += -O3 +CFLAGS += $(WERROR_FLAGS) + +SPP_DRIVERS_DIR = $(BASE_OUTPUT)/src/drivers +EXTRA_LDLIBS = -L$(SPP_DRIVERS_DIR)/vhost -L$(SPP_DRIVERS_DIR)/pipe --whole-archive -lrte_pmd_spp_vhost -lrte_pmd_spp_pipe --no-whole-archive + +include $(RTE_SDK)/mk/rte.extapp.mk diff --git a/tools/vdev_test/vdev_test.c b/tools/vdev_test/vdev_test.c new file mode 100644 index 0000000..f7eb507 --- /dev/null +++ b/tools/vdev_test/vdev_test.c @@ -0,0 +1,247 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation + */ + +#include <getopt.h> +#include <signal.h> +#include <stdint.h> +#include <inttypes.h> +#include <unistd.h> +#include <stdio.h> +#include <sys/time.h> + +#include <rte_eal.h> +#include <rte_ethdev.h> +#include <rte_ether.h> +#include <rte_cycles.h> +#include <rte_lcore.h> +#include <rte_mbuf.h> +#include <rte_eth_ring.h> +#include <rte_bus_vdev.h> + +#define RING_SIZE 128 +#define BURST_SIZE 32 +#define NUM_MBUFS 8191 +#define MBUF_CACHE_SIZE 512 + +#define PKTMBUF_POOL_NAME "MProc_pktmbuf_pool" + +static int tx_first = 0; +static char *device; +static char *devargs = NULL; +static int force_quit; + +static struct option lopts[] = { + {"send", no_argument, &tx_first, 1}, + {"create", required_argument, NULL, 'c'}, + {NULL, 0, 0, 0} +}; + +static const struct rte_eth_conf port_conf_default = { + .rxmode = { .max_rx_pkt_len = RTE_ETHER_MAX_LEN } +}; + +static int +parse_args(int argc, char *argv[]) +{ + int c; + + while ((c = getopt_long(argc, argv, "", lopts, NULL)) != -1) { + switch (c) { + case 0: + /* long option */ + break; + case 'c': + /* --create */ + devargs = optarg; + break; + default: + /* invalid option */ + return -1; + } + } + + if (optind != argc - 1) { + return -1; + } + + device = argv[optind]; + + return 0; +} + +static void +signal_handler(int signum) +{ + printf("signel %d recieved\n", signum); + force_quit = 1; +} + +int +main(int argc, char *argv[]) +{ + int ret; + uint16_t port_id; + uint16_t nb_ports; + struct rte_mempool *mbuf_pool = NULL; + struct rte_mbuf *m; + uint16_t nb_tx; + struct rte_mbuf *bufs[BURST_SIZE]; + uint16_t nb_rx; + struct rte_eth_conf port_conf = port_conf_default; + struct rte_eth_stats stats; + struct timeval t0, t1; + long total; + uint16_t buf; + int i; + + ret = rte_eal_init(argc, argv); + if (ret < 0) { + rte_exit(EXIT_FAILURE, "EAL initialization failed\n"); + } + argc -= ret; + argv += ret; + + ret = parse_args(argc, argv); + if (ret < 0) { + rte_exit(EXIT_FAILURE, + "usage: vdev_test <eal options> -- " + "[--send] [--create devargs] vdev\n"); + } + printf("device: %s tx_first: %d devargs: %s\n", device, tx_first, devargs); + + if (strncmp("spp_pipe", device, 8) == 0) { + if (rte_eal_process_type() != RTE_PROC_SECONDARY) { + rte_exit(EXIT_FAILURE, "must be secondary\n"); + } + } + + if (devargs) { + /* --create */ + ret = rte_eth_dev_get_port_by_name(device, &port_id); + if (ret == 0) { + rte_exit(EXIT_FAILURE, + "%s already exists.\n", device); + } + for (i = 0; i < 3; i++) { + ret = rte_eal_hotplug_add("vdev", device, devargs); + if (ret == 0) + break; + sleep(1); + } + if (ret < 0) { + pause(); + rte_exit(EXIT_FAILURE, + "%s %s create failed.\n", device, devargs); + } + } + + ret = rte_eth_dev_get_port_by_name(device, &port_id); + if (ret < 0) { + rte_exit(EXIT_FAILURE, "device not found\n"); + } + printf("port_id: %u\n", (unsigned)port_id); + + nb_ports = rte_eth_dev_count_avail(); + /* just infomation */ + printf("num port: %u\n", (unsigned)nb_ports); + + if (rte_eal_process_type() == RTE_PROC_SECONDARY) { + mbuf_pool = rte_mempool_lookup(PKTMBUF_POOL_NAME); + } else { + mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS, + MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, + rte_socket_id()); + } + if (mbuf_pool == NULL) { + rte_exit(EXIT_FAILURE, "Cannot get mbuf pool\n"); + } + + if (strncmp("virtio_user", device, 11) == 0) { + port_conf.intr_conf.lsc = 1; + } + ret = rte_eth_dev_configure(port_id, 1, 1, &port_conf); + if (ret != 0) { + rte_exit(EXIT_FAILURE, "rte_eth_dev_configure failed\n"); + } + + ret = rte_eth_rx_queue_setup(port_id, 0, RING_SIZE, + rte_eth_dev_socket_id(port_id), NULL, mbuf_pool); + if (ret < 0) { + rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup failed\n"); + } + + ret = rte_eth_tx_queue_setup(port_id, 0, RING_SIZE, + rte_eth_dev_socket_id(port_id), NULL); + if (ret < 0) { + rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup failed\n"); + } + + ret = rte_eth_dev_start(port_id); + if (ret < 0) { + rte_exit(EXIT_FAILURE, "rte_eth_dev_start failed\n"); + } + + force_quit = 0; + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); + + if (tx_first) { + /* send a packet */ + m = rte_pktmbuf_alloc(mbuf_pool); + if (m == NULL) { + fprintf(stderr, "rte_pktmbuf_alloc failed\n"); + goto out; + } + if (rte_pktmbuf_append(m, RTE_ETHER_MIN_LEN) == NULL) { + fprintf(stderr, "rte_pktmbuf_append failed\n"); + goto out; + } + + nb_tx = rte_eth_tx_burst(port_id, 0, &m, 1); + if (nb_tx != 1) { + fprintf(stderr, "can not send a packet\n"); + rte_pktmbuf_free(m); + goto out; + } + printf("send a packet\n"); + gettimeofday(&t0, NULL); + } + + /* recieve and send a packet */ + while (!force_quit) { + nb_rx = rte_eth_rx_burst(port_id, 0, bufs, BURST_SIZE); + if (nb_rx > 0) { + nb_tx = rte_eth_tx_burst(port_id, 0, bufs, nb_rx); + for (buf = nb_tx; buf < nb_rx; buf++) { + rte_pktmbuf_free(bufs[buf]); + } + } + } + + gettimeofday(&t1, NULL); + + ret = rte_eth_stats_get(port_id, &stats); + if (ret == 0) { + printf("ipackets: %lu\n", stats.ipackets); + printf("opackets: %lu\n", stats.opackets); + printf("ierrors: %lu\n", stats.ierrors); + printf("oerrors: %lu\n", stats.oerrors); + if (tx_first) { + total = (t1.tv_sec - t0.tv_sec) * 1000000 \ + + t1.tv_usec - t0.tv_usec; + printf("%ld us: %.2f packet/s\n", total, + (double)stats.ipackets / total * 1000000); + } + } + +out: + rte_eth_dev_stop(port_id); + rte_eth_dev_close(port_id); + + if (devargs) { + rte_eal_hotplug_remove("vdev", device); + } + + return 0; +} -- 2.17.1 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [spp] [PATCH v2 1/3] vdev_test: simple tool to perform packet forwarding for vdev 2020-02-27 4:25 ` [spp] [PATCH v2 1/3] vdev_test: simple tool to perform packet forwarding for vdev Itsuro Oda @ 2020-02-28 8:32 ` Yasufumi Ogawa 0 siblings, 0 replies; 15+ messages in thread From: Yasufumi Ogawa @ 2020-02-28 8:32 UTC (permalink / raw) To: Itsuro Oda; +Cc: spp, ferruh.yigit This is the second one. $ checkpatches.sh patches/0013-vdev_test-simple-tool-to-perform-packet-forwarding-f.patch ### [PATCH 13/15] vdev_test: simple tool to perform packet forwarding for vdev ERROR:INITIALISED_STATIC: do not initialise statics to 0 #85: FILE: tools/vdev_test/vdev_test.c:29: +static int tx_first = 0; ERROR:INITIALISED_STATIC: do not initialise statics to NULL #87: FILE: tools/vdev_test/vdev_test.c:31: +static char *devargs = NULL; ERROR:CODE_INDENT: code indent should use tabs where possible #103: FILE: tools/vdev_test/vdev_test.c:47: + int c;$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #103: FILE: tools/vdev_test/vdev_test.c:47: + int c;$ ERROR:CODE_INDENT: code indent should use tabs where possible #105: FILE: tools/vdev_test/vdev_test.c:49: + while ((c = getopt_long(argc, argv, "", lopts, NULL)) != -1) {$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #105: FILE: tools/vdev_test/vdev_test.c:49: + while ((c = getopt_long(argc, argv, "", lopts, NULL)) != -1) {$ ERROR:CODE_INDENT: code indent should use tabs where possible #106: FILE: tools/vdev_test/vdev_test.c:50: + switch (c) {$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #106: FILE: tools/vdev_test/vdev_test.c:50: + switch (c) {$ ERROR:CODE_INDENT: code indent should use tabs where possible #107: FILE: tools/vdev_test/vdev_test.c:51: + case 0:$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #107: FILE: tools/vdev_test/vdev_test.c:51: + case 0:$ ERROR:CODE_INDENT: code indent should use tabs where possible #108: FILE: tools/vdev_test/vdev_test.c:52: + /* long option */$ ERROR:CODE_INDENT: code indent should use tabs where possible #109: FILE: tools/vdev_test/vdev_test.c:53: + break;$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #109: FILE: tools/vdev_test/vdev_test.c:53: + break;$ ERROR:CODE_INDENT: code indent should use tabs where possible #114: FILE: tools/vdev_test/vdev_test.c:58: + default:$ ERROR:CODE_INDENT: code indent should use tabs where possible #115: FILE: tools/vdev_test/vdev_test.c:59: + /* invalid option */$ ERROR:CODE_INDENT: code indent should use tabs where possible #117: FILE: tools/vdev_test/vdev_test.c:61: + }$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #117: FILE: tools/vdev_test/vdev_test.c:61: + }$ ERROR:CODE_INDENT: code indent should use tabs where possible #118: FILE: tools/vdev_test/vdev_test.c:62: + }$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #118: FILE: tools/vdev_test/vdev_test.c:62: + }$ WARNING:BRACES: braces {} are not necessary for single statement blocks #120: FILE: tools/vdev_test/vdev_test.c:64: + if (optind != argc - 1) { + return -1; + } ERROR:CODE_INDENT: code indent should use tabs where possible #126: FILE: tools/vdev_test/vdev_test.c:70: + return 0;$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #126: FILE: tools/vdev_test/vdev_test.c:70: + return 0;$ ERROR:CODE_INDENT: code indent should use tabs where possible #143: FILE: tools/vdev_test/vdev_test.c:87: + struct rte_mbuf *m;$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #143: FILE: tools/vdev_test/vdev_test.c:87: + struct rte_mbuf *m;$ WARNING:BRACES: braces {} are not necessary for single statement blocks #155: FILE: tools/vdev_test/vdev_test.c:99: + if (ret < 0) { + rte_exit(EXIT_FAILURE, "EAL initialization failed\n"); + } WARNING:LONG_LINE: line over 80 characters #167: FILE: tools/vdev_test/vdev_test.c:111: + printf("device: %s tx_first: %d devargs: %s\n", device, tx_first, devargs); WARNING:BRACES: braces {} are not necessary for single statement blocks #170: FILE: tools/vdev_test/vdev_test.c:114: + if (rte_eal_process_type() != RTE_PROC_SECONDARY) { + rte_exit(EXIT_FAILURE, "must be secondary\n"); + } WARNING:BRACES: braces {} are not necessary for single statement blocks #196: FILE: tools/vdev_test/vdev_test.c:140: + if (ret < 0) { + rte_exit(EXIT_FAILURE, "device not found\n"); + } WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #199: FILE: tools/vdev_test/vdev_test.c:143: + printf("port_id: %u\n", (unsigned)port_id); ERROR:CODE_INDENT: code indent should use tabs where possible #201: FILE: tools/vdev_test/vdev_test.c:145: + nb_ports = rte_eth_dev_count_avail();$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #201: FILE: tools/vdev_test/vdev_test.c:145: + nb_ports = rte_eth_dev_count_avail();$ ERROR:CODE_INDENT: code indent should use tabs where possible #203: FILE: tools/vdev_test/vdev_test.c:147: + printf("num port: %u\n", (unsigned)nb_ports);$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #203: FILE: tools/vdev_test/vdev_test.c:147: + printf("num port: %u\n", (unsigned)nb_ports);$ WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #203: FILE: tools/vdev_test/vdev_test.c:147: + printf("num port: %u\n", (unsigned)nb_ports); ERROR:CODE_INDENT: code indent should use tabs where possible #208: FILE: tools/vdev_test/vdev_test.c:152: + mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS,$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #208: FILE: tools/vdev_test/vdev_test.c:152: + mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS,$ ERROR:CODE_INDENT: code indent should use tabs where possible #209: FILE: tools/vdev_test/vdev_test.c:153: + MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE,$ WARNING:LEADING_SPACE: please, no spaces at the start of a line #209: FILE: tools/vdev_test/vdev_test.c:153: + MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE,$ WARNING:BRACES: braces {} are not necessary for single statement blocks #212: FILE: tools/vdev_test/vdev_test.c:156: + if (mbuf_pool == NULL) { + rte_exit(EXIT_FAILURE, "Cannot get mbuf pool\n"); + } WARNING:BRACES: braces {} are not necessary for single statement blocks #216: FILE: tools/vdev_test/vdev_test.c:160: + if (strncmp("virtio_user", device, 11) == 0) { + port_conf.intr_conf.lsc = 1; + } WARNING:BRACES: braces {} are not necessary for single statement blocks #220: FILE: tools/vdev_test/vdev_test.c:164: + if (ret != 0) { + rte_exit(EXIT_FAILURE, "rte_eth_dev_configure failed\n"); + } WARNING:BRACES: braces {} are not necessary for single statement blocks #226: FILE: tools/vdev_test/vdev_test.c:170: + if (ret < 0) { + rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup failed\n"); + } WARNING:BRACES: braces {} are not necessary for single statement blocks #232: FILE: tools/vdev_test/vdev_test.c:176: + if (ret < 0) { + rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup failed\n"); + } WARNING:BRACES: braces {} are not necessary for single statement blocks #237: FILE: tools/vdev_test/vdev_test.c:181: + if (ret < 0) { + rte_exit(EXIT_FAILURE, "rte_eth_dev_start failed\n"); + } WARNING:BRACES: braces {} are not necessary for single statement blocks #272: FILE: tools/vdev_test/vdev_test.c:216: + for (buf = nb_tx; buf < nb_rx; buf++) { + rte_pktmbuf_free(bufs[buf]); + } WARNING:LINE_CONTINUATIONS: Avoid unnecessary line continuations #287: FILE: tools/vdev_test/vdev_test.c:231: + total = (t1.tv_sec - t0.tv_sec) * 1000000 \ WARNING:BRACES: braces {} are not necessary for single statement blocks #298: FILE: tools/vdev_test/vdev_test.c:242: + if (devargs) { + rte_eal_hotplug_remove("vdev", device); + } total: 18 errors, 29 warnings, 272 lines checked 0/1 valid patch On 2020/02/27 13:25, Itsuro Oda wrote: > vdev_test is a simple tool to perform packet forwarding for > virtual ethernet devices. It is mainly to test pipe PMD > because testpmd can not be secondary process but vdev_test > can be. > > Signed-off-by: Itsuro Oda <oda@valinux.co.jp> > --- > tools/vdev_test/Makefile | 25 ++++ > tools/vdev_test/vdev_test.c | 247 ++++++++++++++++++++++++++++++++++++ > 2 files changed, 272 insertions(+) > create mode 100644 tools/vdev_test/Makefile > create mode 100644 tools/vdev_test/vdev_test.c > > diff --git a/tools/vdev_test/Makefile b/tools/vdev_test/Makefile > new file mode 100644 > index 0000000..aabd9c4 > --- /dev/null > +++ b/tools/vdev_test/Makefile > @@ -0,0 +1,25 @@ > +# SPDX-License-Identifier: BSD-3-Clause > +# Copyright(c) 2020 Nippon Telegraph and Telephone Corporation > + > +ifeq ($(RTE_SDK),) > +$(error "Please define RTE_SDK environment variable") > +endif > + > +# Default target, can be overridden by command line or environment > +RTE_TARGET ?= x86_64-native-linuxapp-gcc > + > +include $(RTE_SDK)/mk/rte.vars.mk > + > +# binary name > +APP = vdev_test > + > +# all source are stored in SRCS-y > +SRCS-y := vdev_test.c > + > +CFLAGS += -O3 > +CFLAGS += $(WERROR_FLAGS) > + > +SPP_DRIVERS_DIR = $(BASE_OUTPUT)/src/drivers > +EXTRA_LDLIBS = -L$(SPP_DRIVERS_DIR)/vhost -L$(SPP_DRIVERS_DIR)/pipe --whole-archive -lrte_pmd_spp_vhost -lrte_pmd_spp_pipe --no-whole-archive > + > +include $(RTE_SDK)/mk/rte.extapp.mk > diff --git a/tools/vdev_test/vdev_test.c b/tools/vdev_test/vdev_test.c > new file mode 100644 > index 0000000..f7eb507 > --- /dev/null > +++ b/tools/vdev_test/vdev_test.c > @@ -0,0 +1,247 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation > + */ > + > +#include <getopt.h> > +#include <signal.h> > +#include <stdint.h> > +#include <inttypes.h> > +#include <unistd.h> > +#include <stdio.h> > +#include <sys/time.h> > + > +#include <rte_eal.h> > +#include <rte_ethdev.h> > +#include <rte_ether.h> > +#include <rte_cycles.h> > +#include <rte_lcore.h> > +#include <rte_mbuf.h> > +#include <rte_eth_ring.h> > +#include <rte_bus_vdev.h> > + > +#define RING_SIZE 128 > +#define BURST_SIZE 32 > +#define NUM_MBUFS 8191 > +#define MBUF_CACHE_SIZE 512 > + > +#define PKTMBUF_POOL_NAME "MProc_pktmbuf_pool" > + > +static int tx_first = 0; > +static char *device; > +static char *devargs = NULL; > +static int force_quit; > + > +static struct option lopts[] = { > + {"send", no_argument, &tx_first, 1}, > + {"create", required_argument, NULL, 'c'}, > + {NULL, 0, 0, 0} > +}; > + > +static const struct rte_eth_conf port_conf_default = { > + .rxmode = { .max_rx_pkt_len = RTE_ETHER_MAX_LEN } > +}; > + > +static int > +parse_args(int argc, char *argv[]) > +{ > + int c; > + > + while ((c = getopt_long(argc, argv, "", lopts, NULL)) != -1) { > + switch (c) { > + case 0: > + /* long option */ > + break; > + case 'c': > + /* --create */ > + devargs = optarg; > + break; > + default: > + /* invalid option */ > + return -1; > + } > + } > + > + if (optind != argc - 1) { > + return -1; > + } > + > + device = argv[optind]; > + > + return 0; > +} > + > +static void > +signal_handler(int signum) > +{ > + printf("signel %d recieved\n", signum); > + force_quit = 1; > +} > + > +int > +main(int argc, char *argv[]) > +{ > + int ret; > + uint16_t port_id; > + uint16_t nb_ports; > + struct rte_mempool *mbuf_pool = NULL; > + struct rte_mbuf *m; > + uint16_t nb_tx; > + struct rte_mbuf *bufs[BURST_SIZE]; > + uint16_t nb_rx; > + struct rte_eth_conf port_conf = port_conf_default; > + struct rte_eth_stats stats; > + struct timeval t0, t1; > + long total; > + uint16_t buf; > + int i; > + > + ret = rte_eal_init(argc, argv); > + if (ret < 0) { > + rte_exit(EXIT_FAILURE, "EAL initialization failed\n"); > + } > + argc -= ret; > + argv += ret; > + > + ret = parse_args(argc, argv); > + if (ret < 0) { > + rte_exit(EXIT_FAILURE, > + "usage: vdev_test <eal options> -- " > + "[--send] [--create devargs] vdev\n"); > + } > + printf("device: %s tx_first: %d devargs: %s\n", device, tx_first, devargs); > + > + if (strncmp("spp_pipe", device, 8) == 0) { > + if (rte_eal_process_type() != RTE_PROC_SECONDARY) { > + rte_exit(EXIT_FAILURE, "must be secondary\n"); > + } > + } > + > + if (devargs) { > + /* --create */ > + ret = rte_eth_dev_get_port_by_name(device, &port_id); > + if (ret == 0) { > + rte_exit(EXIT_FAILURE, > + "%s already exists.\n", device); > + } > + for (i = 0; i < 3; i++) { > + ret = rte_eal_hotplug_add("vdev", device, devargs); > + if (ret == 0) > + break; > + sleep(1); > + } > + if (ret < 0) { > + pause(); > + rte_exit(EXIT_FAILURE, > + "%s %s create failed.\n", device, devargs); > + } > + } > + > + ret = rte_eth_dev_get_port_by_name(device, &port_id); > + if (ret < 0) { > + rte_exit(EXIT_FAILURE, "device not found\n"); > + } > + printf("port_id: %u\n", (unsigned)port_id); > + > + nb_ports = rte_eth_dev_count_avail(); > + /* just infomation */ > + printf("num port: %u\n", (unsigned)nb_ports); > + > + if (rte_eal_process_type() == RTE_PROC_SECONDARY) { > + mbuf_pool = rte_mempool_lookup(PKTMBUF_POOL_NAME); > + } else { > + mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS, > + MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, > + rte_socket_id()); > + } > + if (mbuf_pool == NULL) { > + rte_exit(EXIT_FAILURE, "Cannot get mbuf pool\n"); > + } > + > + if (strncmp("virtio_user", device, 11) == 0) { > + port_conf.intr_conf.lsc = 1; > + } > + ret = rte_eth_dev_configure(port_id, 1, 1, &port_conf); > + if (ret != 0) { > + rte_exit(EXIT_FAILURE, "rte_eth_dev_configure failed\n"); > + } > + > + ret = rte_eth_rx_queue_setup(port_id, 0, RING_SIZE, > + rte_eth_dev_socket_id(port_id), NULL, mbuf_pool); > + if (ret < 0) { > + rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup failed\n"); > + } > + > + ret = rte_eth_tx_queue_setup(port_id, 0, RING_SIZE, > + rte_eth_dev_socket_id(port_id), NULL); > + if (ret < 0) { > + rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup failed\n"); > + } > + > + ret = rte_eth_dev_start(port_id); > + if (ret < 0) { > + rte_exit(EXIT_FAILURE, "rte_eth_dev_start failed\n"); > + } > + > + force_quit = 0; > + signal(SIGINT, signal_handler); > + signal(SIGTERM, signal_handler); > + > + if (tx_first) { > + /* send a packet */ > + m = rte_pktmbuf_alloc(mbuf_pool); > + if (m == NULL) { > + fprintf(stderr, "rte_pktmbuf_alloc failed\n"); > + goto out; > + } > + if (rte_pktmbuf_append(m, RTE_ETHER_MIN_LEN) == NULL) { > + fprintf(stderr, "rte_pktmbuf_append failed\n"); > + goto out; > + } > + > + nb_tx = rte_eth_tx_burst(port_id, 0, &m, 1); > + if (nb_tx != 1) { > + fprintf(stderr, "can not send a packet\n"); > + rte_pktmbuf_free(m); > + goto out; > + } > + printf("send a packet\n"); > + gettimeofday(&t0, NULL); > + } > + > + /* recieve and send a packet */ > + while (!force_quit) { > + nb_rx = rte_eth_rx_burst(port_id, 0, bufs, BURST_SIZE); > + if (nb_rx > 0) { > + nb_tx = rte_eth_tx_burst(port_id, 0, bufs, nb_rx); > + for (buf = nb_tx; buf < nb_rx; buf++) { > + rte_pktmbuf_free(bufs[buf]); > + } > + } > + } > + > + gettimeofday(&t1, NULL); > + > + ret = rte_eth_stats_get(port_id, &stats); > + if (ret == 0) { > + printf("ipackets: %lu\n", stats.ipackets); > + printf("opackets: %lu\n", stats.opackets); > + printf("ierrors: %lu\n", stats.ierrors); > + printf("oerrors: %lu\n", stats.oerrors); > + if (tx_first) { > + total = (t1.tv_sec - t0.tv_sec) * 1000000 \ > + + t1.tv_usec - t0.tv_usec; > + printf("%ld us: %.2f packet/s\n", total, > + (double)stats.ipackets / total * 1000000); > + } > + } > + > +out: > + rte_eth_dev_stop(port_id); > + rte_eth_dev_close(port_id); > + > + if (devargs) { > + rte_eal_hotplug_remove("vdev", device); > + } > + > + return 0; > +} > ^ permalink raw reply [flat|nested] 15+ messages in thread
* [spp] [PATCH v2 2/3] tools: add Makefile for vdev_test 2020-02-27 4:25 ` [spp] [PATCH v2 0/3] add vdev_test Itsuro Oda 2020-02-27 4:25 ` [spp] [PATCH v2 1/3] vdev_test: simple tool to perform packet forwarding for vdev Itsuro Oda @ 2020-02-27 4:25 ` Itsuro Oda 2020-02-27 4:25 ` [spp] [PATCH v2 3/3] makefile: add make of tools directory Itsuro Oda 2 siblings, 0 replies; 15+ messages in thread From: Itsuro Oda @ 2020-02-27 4:25 UTC (permalink / raw) To: spp, ferruh.yigit, yasufum.o This patch adds Makefile of tools to build vdev_test. Signed-off-by: Itsuro Oda <oda@valinux.co.jp> --- tools/Makefile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tools/Makefile diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 0000000..40c1310 --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2020 Nippon Telegraph and Telephone Corporation + +ifeq ($(RTE_SDK),) +$(error "Please define RTE_SDK environment variable") +endif + +# Default target, can be overriden by command line or environment +RTE_TARGET ?= x86_64-native-linuxapp-gcc + +include $(RTE_SDK)/mk/rte.vars.mk + +DIRS-y += vdev_test + +include $(RTE_SDK)/mk/rte.extsubdir.mk -- 2.17.1 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [spp] [PATCH v2 3/3] makefile: add make of tools directory 2020-02-27 4:25 ` [spp] [PATCH v2 0/3] add vdev_test Itsuro Oda 2020-02-27 4:25 ` [spp] [PATCH v2 1/3] vdev_test: simple tool to perform packet forwarding for vdev Itsuro Oda 2020-02-27 4:25 ` [spp] [PATCH v2 2/3] tools: add Makefile for vdev_test Itsuro Oda @ 2020-02-27 4:25 ` Itsuro Oda 2 siblings, 0 replies; 15+ messages in thread From: Itsuro Oda @ 2020-02-27 4:25 UTC (permalink / raw) To: spp, ferruh.yigit, yasufum.o This patch adds make of tools directory to build vdev_test. Signed-off-by: Itsuro Oda <oda@valinux.co.jp> --- GNUmakefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/GNUmakefile b/GNUmakefile index 9c0cea9..e44a31f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -9,7 +9,10 @@ RTE_TARGET ?= x86_64-native-linuxapp-gcc include $(RTE_SDK)/mk/rte.vars.mk +DEPDIRS-tools := src + DIRS-y += src +DIRS-y += tools include $(RTE_SDK)/mk/rte.extsubdir.mk endif @@ -39,6 +42,8 @@ _dist-clean: rm -f $(wildcard src/*/*/*.pyc) rm -rf $(wildcard src/*/__pycache__) rm -rf $(wildcard src/*/*/__pycache__) + rm -rf $(wildcard tools/vdev_test/build) + rm -rf $(wildcard tools/vdev_test/$(RTE_TARGET)) .PHONY: doc doc: doc-all -- 2.17.1 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [spp] [PATCH v3 0/3] add vdev_test 2020-02-26 2:02 [spp] [PATCH 0/2] add vdev_test Itsuro Oda ` (2 preceding siblings ...) 2020-02-27 4:25 ` [spp] [PATCH v2 0/3] add vdev_test Itsuro Oda @ 2020-03-02 0:00 ` Itsuro Oda 2020-03-02 0:00 ` [spp] [PATCH v3 1/3] vdev_test: simple tool to perform packet forwarding for vdev Itsuro Oda ` (4 more replies) 3 siblings, 5 replies; 15+ messages in thread From: Itsuro Oda @ 2020-03-02 0:00 UTC (permalink / raw) To: spp, ferruh.yigit, yasufum.o vdev_test is a simple tool to perform packet forwarding for virtual ethernet devices. It is mainly to test pipe PMD because testpmd can not be secondary process but vdev_test can be. --- v3: * fix checkpatches.sh errors. v2: * move directory src to tools. Itsuro Oda (3): vdev_test: simple tool to perform packet forwarding for vdev tools: add Makefile for vdev_test makefile: add make of tools directory GNUmakefile | 5 + tools/Makefile | 15 +++ tools/vdev_test/Makefile | 25 ++++ tools/vdev_test/vdev_test.c | 235 ++++++++++++++++++++++++++++++++++++ 4 files changed, 280 insertions(+) create mode 100644 tools/Makefile create mode 100644 tools/vdev_test/Makefile create mode 100644 tools/vdev_test/vdev_test.c -- 2.17.1 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [spp] [PATCH v3 1/3] vdev_test: simple tool to perform packet forwarding for vdev 2020-03-02 0:00 ` [spp] [PATCH v3 0/3] add vdev_test Itsuro Oda @ 2020-03-02 0:00 ` Itsuro Oda 2020-03-02 0:00 ` [spp] [PATCH v3 2/3] tools: add Makefile for vdev_test Itsuro Oda ` (3 subsequent siblings) 4 siblings, 0 replies; 15+ messages in thread From: Itsuro Oda @ 2020-03-02 0:00 UTC (permalink / raw) To: spp, ferruh.yigit, yasufum.o vdev_test is a simple tool to perform packet forwarding for virtual ethernet devices. It is mainly to test pipe PMD because testpmd can not be secondary process but vdev_test can be. Signed-off-by: Itsuro Oda <oda@valinux.co.jp> --- tools/vdev_test/Makefile | 25 ++++ tools/vdev_test/vdev_test.c | 235 ++++++++++++++++++++++++++++++++++++ 2 files changed, 260 insertions(+) create mode 100644 tools/vdev_test/Makefile create mode 100644 tools/vdev_test/vdev_test.c diff --git a/tools/vdev_test/Makefile b/tools/vdev_test/Makefile new file mode 100644 index 0000000..aabd9c4 --- /dev/null +++ b/tools/vdev_test/Makefile @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2020 Nippon Telegraph and Telephone Corporation + +ifeq ($(RTE_SDK),) +$(error "Please define RTE_SDK environment variable") +endif + +# Default target, can be overridden by command line or environment +RTE_TARGET ?= x86_64-native-linuxapp-gcc + +include $(RTE_SDK)/mk/rte.vars.mk + +# binary name +APP = vdev_test + +# all source are stored in SRCS-y +SRCS-y := vdev_test.c + +CFLAGS += -O3 +CFLAGS += $(WERROR_FLAGS) + +SPP_DRIVERS_DIR = $(BASE_OUTPUT)/src/drivers +EXTRA_LDLIBS = -L$(SPP_DRIVERS_DIR)/vhost -L$(SPP_DRIVERS_DIR)/pipe --whole-archive -lrte_pmd_spp_vhost -lrte_pmd_spp_pipe --no-whole-archive + +include $(RTE_SDK)/mk/rte.extapp.mk diff --git a/tools/vdev_test/vdev_test.c b/tools/vdev_test/vdev_test.c new file mode 100644 index 0000000..138b67c --- /dev/null +++ b/tools/vdev_test/vdev_test.c @@ -0,0 +1,235 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation + */ + +#include <getopt.h> +#include <signal.h> +#include <stdint.h> +#include <inttypes.h> +#include <unistd.h> +#include <stdio.h> +#include <sys/time.h> + +#include <rte_eal.h> +#include <rte_ethdev.h> +#include <rte_ether.h> +#include <rte_cycles.h> +#include <rte_lcore.h> +#include <rte_mbuf.h> +#include <rte_eth_ring.h> +#include <rte_bus_vdev.h> + +#define RING_SIZE 128 +#define BURST_SIZE 32 +#define NUM_MBUFS 8191 +#define MBUF_CACHE_SIZE 512 + +#define PKTMBUF_POOL_NAME "MProc_pktmbuf_pool" + +static int tx_first; +static char *device; +static char *devargs; +static int force_quit; + +static struct option lopts[] = { + {"send", no_argument, &tx_first, 1}, + {"create", required_argument, NULL, 'c'}, + {NULL, 0, 0, 0} +}; + +static const struct rte_eth_conf port_conf_default = { + .rxmode = { .max_rx_pkt_len = RTE_ETHER_MAX_LEN } +}; + +static int +parse_args(int argc, char *argv[]) +{ + int c; + + while ((c = getopt_long(argc, argv, "", lopts, NULL)) != -1) { + switch (c) { + case 0: + /* long option */ + break; + case 'c': + /* --create */ + devargs = optarg; + break; + default: + /* invalid option */ + return -1; + } + } + + if (optind != argc - 1) + return -1; + + device = argv[optind]; + + return 0; +} + +static void +signal_handler(int signum) +{ + printf("signel %d received\n", signum); + force_quit = 1; +} + +int +main(int argc, char *argv[]) +{ + int ret; + uint16_t port_id; + uint16_t nb_ports; + struct rte_mempool *mbuf_pool = NULL; + struct rte_mbuf *m; + uint16_t nb_tx; + struct rte_mbuf *bufs[BURST_SIZE]; + uint16_t nb_rx; + struct rte_eth_conf port_conf = port_conf_default; + struct rte_eth_stats stats; + struct timeval t0, t1; + long total; + uint16_t buf; + int i; + + ret = rte_eal_init(argc, argv); + if (ret < 0) + rte_exit(EXIT_FAILURE, "EAL initialization failed\n"); + argc -= ret; + argv += ret; + + ret = parse_args(argc, argv); + if (ret < 0) { + rte_exit(EXIT_FAILURE, + "usage: vdev_test <eal options> -- " + "[--send] [--create devargs] vdev\n"); + } + printf("device: %s tx_first: %d devargs: %s\n", device, + tx_first, devargs); + + if (strncmp("spp_pipe", device, 8) == 0) { + if (rte_eal_process_type() != RTE_PROC_SECONDARY) + rte_exit(EXIT_FAILURE, "must be secondary\n"); + } + + if (devargs) { + /* --create */ + ret = rte_eth_dev_get_port_by_name(device, &port_id); + if (ret == 0) + rte_exit(EXIT_FAILURE, + "%s already exists.\n", device); + for (i = 0; i < 3; i++) { + ret = rte_eal_hotplug_add("vdev", device, devargs); + if (ret == 0) + break; + sleep(1); + } + if (ret < 0) + rte_exit(EXIT_FAILURE, + "%s %s create failed.\n", device, devargs); + } + + ret = rte_eth_dev_get_port_by_name(device, &port_id); + if (ret < 0) + rte_exit(EXIT_FAILURE, "device not found\n"); + + printf("port_id: %u\n", (unsigned int)port_id); + + nb_ports = rte_eth_dev_count_avail(); + /* just information */ + printf("num port: %u\n", (unsigned int)nb_ports); + + if (rte_eal_process_type() == RTE_PROC_SECONDARY) { + mbuf_pool = rte_mempool_lookup(PKTMBUF_POOL_NAME); + } else { + mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS, + MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, + rte_socket_id()); + } + if (mbuf_pool == NULL) + rte_exit(EXIT_FAILURE, "Cannot get mbuf pool\n"); + + if (strncmp("virtio_user", device, 11) == 0) + port_conf.intr_conf.lsc = 1; + + ret = rte_eth_dev_configure(port_id, 1, 1, &port_conf); + if (ret != 0) + rte_exit(EXIT_FAILURE, "rte_eth_dev_configure failed\n"); + + ret = rte_eth_rx_queue_setup(port_id, 0, RING_SIZE, + rte_eth_dev_socket_id(port_id), NULL, mbuf_pool); + if (ret < 0) + rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup failed\n"); + + ret = rte_eth_tx_queue_setup(port_id, 0, RING_SIZE, + rte_eth_dev_socket_id(port_id), NULL); + if (ret < 0) + rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup failed\n"); + + ret = rte_eth_dev_start(port_id); + if (ret < 0) + rte_exit(EXIT_FAILURE, "rte_eth_dev_start failed\n"); + + force_quit = 0; + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); + + if (tx_first) { + /* send a packet */ + m = rte_pktmbuf_alloc(mbuf_pool); + if (m == NULL) { + fprintf(stderr, "rte_pktmbuf_alloc failed\n"); + goto out; + } + if (rte_pktmbuf_append(m, RTE_ETHER_MIN_LEN) == NULL) { + fprintf(stderr, "rte_pktmbuf_append failed\n"); + goto out; + } + + nb_tx = rte_eth_tx_burst(port_id, 0, &m, 1); + if (nb_tx != 1) { + fprintf(stderr, "can not send a packet\n"); + rte_pktmbuf_free(m); + goto out; + } + printf("send a packet\n"); + gettimeofday(&t0, NULL); + } + + /* receive and send a packet */ + while (!force_quit) { + nb_rx = rte_eth_rx_burst(port_id, 0, bufs, BURST_SIZE); + if (nb_rx > 0) { + nb_tx = rte_eth_tx_burst(port_id, 0, bufs, nb_rx); + for (buf = nb_tx; buf < nb_rx; buf++) + rte_pktmbuf_free(bufs[buf]); + } + } + + gettimeofday(&t1, NULL); + + ret = rte_eth_stats_get(port_id, &stats); + if (ret == 0) { + printf("ipackets: %lu\n", stats.ipackets); + printf("opackets: %lu\n", stats.opackets); + printf("ierrors: %lu\n", stats.ierrors); + printf("oerrors: %lu\n", stats.oerrors); + if (tx_first) { + total = (t1.tv_sec - t0.tv_sec) * 1000000 + + t1.tv_usec - t0.tv_usec; + printf("%ld us: %.2f packet/s\n", total, + (double)stats.ipackets / total * 1000000); + } + } + +out: + rte_eth_dev_stop(port_id); + rte_eth_dev_close(port_id); + + if (devargs) + rte_eal_hotplug_remove("vdev", device); + + return 0; +} -- 2.17.1 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [spp] [PATCH v3 2/3] tools: add Makefile for vdev_test 2020-03-02 0:00 ` [spp] [PATCH v3 0/3] add vdev_test Itsuro Oda 2020-03-02 0:00 ` [spp] [PATCH v3 1/3] vdev_test: simple tool to perform packet forwarding for vdev Itsuro Oda @ 2020-03-02 0:00 ` Itsuro Oda 2020-03-02 0:00 ` [spp] [PATCH v3 3/3] makefile: add make of tools directory Itsuro Oda ` (2 subsequent siblings) 4 siblings, 0 replies; 15+ messages in thread From: Itsuro Oda @ 2020-03-02 0:00 UTC (permalink / raw) To: spp, ferruh.yigit, yasufum.o This patch adds Makefile of tools to build vdev_test. Signed-off-by: Itsuro Oda <oda@valinux.co.jp> --- tools/Makefile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tools/Makefile diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 0000000..40c1310 --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2020 Nippon Telegraph and Telephone Corporation + +ifeq ($(RTE_SDK),) +$(error "Please define RTE_SDK environment variable") +endif + +# Default target, can be overriden by command line or environment +RTE_TARGET ?= x86_64-native-linuxapp-gcc + +include $(RTE_SDK)/mk/rte.vars.mk + +DIRS-y += vdev_test + +include $(RTE_SDK)/mk/rte.extsubdir.mk -- 2.17.1 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [spp] [PATCH v3 3/3] makefile: add make of tools directory 2020-03-02 0:00 ` [spp] [PATCH v3 0/3] add vdev_test Itsuro Oda 2020-03-02 0:00 ` [spp] [PATCH v3 1/3] vdev_test: simple tool to perform packet forwarding for vdev Itsuro Oda 2020-03-02 0:00 ` [spp] [PATCH v3 2/3] tools: add Makefile for vdev_test Itsuro Oda @ 2020-03-02 0:00 ` Itsuro Oda 2020-03-05 1:25 ` [spp] [PATCH v3 0/3] add vdev_test Yasufumi Ogawa 2020-03-11 1:25 ` Itsuro ODA 4 siblings, 0 replies; 15+ messages in thread From: Itsuro Oda @ 2020-03-02 0:00 UTC (permalink / raw) To: spp, ferruh.yigit, yasufum.o This patch adds make of tools directory to build vdev_test. Signed-off-by: Itsuro Oda <oda@valinux.co.jp> --- GNUmakefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/GNUmakefile b/GNUmakefile index 9c0cea9..e44a31f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -9,7 +9,10 @@ RTE_TARGET ?= x86_64-native-linuxapp-gcc include $(RTE_SDK)/mk/rte.vars.mk +DEPDIRS-tools := src + DIRS-y += src +DIRS-y += tools include $(RTE_SDK)/mk/rte.extsubdir.mk endif @@ -39,6 +42,8 @@ _dist-clean: rm -f $(wildcard src/*/*/*.pyc) rm -rf $(wildcard src/*/__pycache__) rm -rf $(wildcard src/*/*/__pycache__) + rm -rf $(wildcard tools/vdev_test/build) + rm -rf $(wildcard tools/vdev_test/$(RTE_TARGET)) .PHONY: doc doc: doc-all -- 2.17.1 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [spp] [PATCH v3 0/3] add vdev_test 2020-03-02 0:00 ` [spp] [PATCH v3 0/3] add vdev_test Itsuro Oda ` (2 preceding siblings ...) 2020-03-02 0:00 ` [spp] [PATCH v3 3/3] makefile: add make of tools directory Itsuro Oda @ 2020-03-05 1:25 ` Yasufumi Ogawa 2020-03-11 1:25 ` Itsuro ODA 4 siblings, 0 replies; 15+ messages in thread From: Yasufumi Ogawa @ 2020-03-05 1:25 UTC (permalink / raw) To: Itsuro Oda; +Cc: spp, ferruh.yigit > vdev_test is a simple tool to perform packet forwarding for > virtual ethernet devices. It is mainly to test pipe PMD > because testpmd can not be secondary process but vdev_test > can be. Applied, thanks. > > --- > v3: > * fix checkpatches.sh errors. > > v2: > * move directory src to tools. > > Itsuro Oda (3): > vdev_test: simple tool to perform packet forwarding for vdev > tools: add Makefile for vdev_test > makefile: add make of tools directory > > GNUmakefile | 5 + > tools/Makefile | 15 +++ > tools/vdev_test/Makefile | 25 ++++ > tools/vdev_test/vdev_test.c | 235 ++++++++++++++++++++++++++++++++++++ > 4 files changed, 280 insertions(+) > create mode 100644 tools/Makefile > create mode 100644 tools/vdev_test/Makefile > create mode 100644 tools/vdev_test/vdev_test.c > ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [spp] [PATCH v3 0/3] add vdev_test 2020-03-02 0:00 ` [spp] [PATCH v3 0/3] add vdev_test Itsuro Oda ` (3 preceding siblings ...) 2020-03-05 1:25 ` [spp] [PATCH v3 0/3] add vdev_test Yasufumi Ogawa @ 2020-03-11 1:25 ` Itsuro ODA 2020-03-13 0:44 ` Yasufumi Ogawa 4 siblings, 1 reply; 15+ messages in thread From: Itsuro ODA @ 2020-03-11 1:25 UTC (permalink / raw) To: yasufum.o; +Cc: spp, ferruh.yigit Hi Yasufumi, >> vdev_test is a simple tool to perform packet forwarding for >> virtual ethernet devices. It is mainly to test pipe PMD >> because testpmd can not be secondary process but vdev_test >> can be. >Applied, thanks. I received "Applied" on 5th March but git has not been update yet. When is it going to update ? Thanks. -- Itsuro ODA <oda@valinux.co.jp> ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [spp] [PATCH v3 0/3] add vdev_test 2020-03-11 1:25 ` Itsuro ODA @ 2020-03-13 0:44 ` Yasufumi Ogawa 0 siblings, 0 replies; 15+ messages in thread From: Yasufumi Ogawa @ 2020-03-13 0:44 UTC (permalink / raw) To: Itsuro ODA; +Cc: spp, ferruh.yigit > Hi Yasufumi, > >>> vdev_test is a simple tool to perform packet forwarding for >>> virtual ethernet devices. It is mainly to test pipe PMD >>> because testpmd can not be secondary process but vdev_test >>> can be. >> Applied, thanks. > > I received "Applied" on 5th March but git has not been > update yet. When is it going to update ? I'll merge all patches in waiting list after HIdeyuki's update. Thanks > > Thanks. > ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2020-03-13 0:44 UTC | newest] Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-02-26 2:02 [spp] [PATCH 0/2] add vdev_test Itsuro Oda 2020-02-26 2:02 ` [spp] [PATCH 1/2] vdev_test: simple tool to perform packet forwarding for vdev Itsuro Oda 2020-02-26 2:02 ` [spp] [PATCH 2/2] makefile: add to build vdev_test Itsuro Oda 2020-02-27 4:25 ` [spp] [PATCH v2 0/3] add vdev_test Itsuro Oda 2020-02-27 4:25 ` [spp] [PATCH v2 1/3] vdev_test: simple tool to perform packet forwarding for vdev Itsuro Oda 2020-02-28 8:32 ` Yasufumi Ogawa 2020-02-27 4:25 ` [spp] [PATCH v2 2/3] tools: add Makefile for vdev_test Itsuro Oda 2020-02-27 4:25 ` [spp] [PATCH v2 3/3] makefile: add make of tools directory Itsuro Oda 2020-03-02 0:00 ` [spp] [PATCH v3 0/3] add vdev_test Itsuro Oda 2020-03-02 0:00 ` [spp] [PATCH v3 1/3] vdev_test: simple tool to perform packet forwarding for vdev Itsuro Oda 2020-03-02 0:00 ` [spp] [PATCH v3 2/3] tools: add Makefile for vdev_test Itsuro Oda 2020-03-02 0:00 ` [spp] [PATCH v3 3/3] makefile: add make of tools directory Itsuro Oda 2020-03-05 1:25 ` [spp] [PATCH v3 0/3] add vdev_test Yasufumi Ogawa 2020-03-11 1:25 ` Itsuro ODA 2020-03-13 0:44 ` Yasufumi Ogawa
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).