summaryrefslogtreecommitdiff
path: root/examples/skeleton
diff options
context:
space:
mode:
authorThomas Monjalon <thomas@monjalon.net>2018-04-05 17:33:20 +0200
committerThomas Monjalon <thomas@monjalon.net>2018-04-18 00:25:27 +0200
commit8728ccf37615904cf23fb8763895b05c9a3c6b0c (patch)
treeb6e895ec425d20d4933115f533da4be189be1f8a /examples/skeleton
parenta3d6026711d00183e308f1dd79933f6161840e04 (diff)
downloaddpdk-8728ccf37615904cf23fb8763895b05c9a3c6b0c.zip
dpdk-8728ccf37615904cf23fb8763895b05c9a3c6b0c.tar.gz
dpdk-8728ccf37615904cf23fb8763895b05c9a3c6b0c.tar.xz
fix ethdev ports enumeration
Some DPDK applications wrongly assume these requirements: - no hotplug, i.e. ports are never detached - all allocated ports are available to the application Such application iterates over ports by its own mean. The most common pattern is to request the port count and assume ports with index in the range [0..count[ can be used. There are three consequences when using such wrong design: - new ports having an index higher than the port count won't be seen - old ports being detached (RTE_ETH_DEV_UNUSED) can be seen as ghosts - failsafe sub-devices (RTE_ETH_DEV_DEFERRED) will be seen by the application Such mistake will be less common with growing hotplug awareness. All applications and examples inside this repository - except testpmd - must be fixed to use the iterator RTE_ETH_FOREACH_DEV. Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Diffstat (limited to 'examples/skeleton')
-rw-r--r--examples/skeleton/Makefile3
-rw-r--r--examples/skeleton/basicfwd.c7
-rw-r--r--examples/skeleton/meson.build1
3 files changed, 7 insertions, 4 deletions
diff --git a/examples/skeleton/Makefile b/examples/skeleton/Makefile
index bd980ec..a4a1860 100644
--- a/examples/skeleton/Makefile
+++ b/examples/skeleton/Makefile
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk)
LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk)
LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk)
+CFLAGS += -DALLOW_EXPERIMENTAL_API
+
build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -48,6 +50,7 @@ RTE_TARGET ?= x86_64-native-linuxapp-gcc
include $(RTE_SDK)/mk/rte.vars.mk
+CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += $(WERROR_FLAGS)
# workaround for a gcc bug with noreturn attribute
diff --git a/examples/skeleton/basicfwd.c b/examples/skeleton/basicfwd.c
index e62cc0a..11a9b57 100644
--- a/examples/skeleton/basicfwd.c
+++ b/examples/skeleton/basicfwd.c
@@ -106,14 +106,13 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool)
static __attribute__((noreturn)) void
lcore_main(void)
{
- const uint16_t nb_ports = rte_eth_dev_count();
uint16_t port;
/*
* Check that the port is on the same NUMA node as the polling thread
* for best performance.
*/
- for (port = 0; port < nb_ports; port++)
+ RTE_ETH_FOREACH_DEV(port)
if (rte_eth_dev_socket_id(port) > 0 &&
rte_eth_dev_socket_id(port) !=
(int)rte_socket_id())
@@ -130,7 +129,7 @@ lcore_main(void)
* Receive packets on a port and forward them on the paired
* port. The mapping is 0 -> 1, 1 -> 0, 2 -> 3, 3 -> 2, etc.
*/
- for (port = 0; port < nb_ports; port++) {
+ RTE_ETH_FOREACH_DEV(port) {
/* Get burst of RX packets, from first port of pair. */
struct rte_mbuf *bufs[BURST_SIZE];
@@ -186,7 +185,7 @@ main(int argc, char *argv[])
rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
/* Initialize all ports. */
- for (portid = 0; portid < nb_ports; portid++)
+ RTE_ETH_FOREACH_DEV(portid)
if (port_init(portid, mbuf_pool) != 0)
rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu16 "\n",
portid);
diff --git a/examples/skeleton/meson.build b/examples/skeleton/meson.build
index 9bb9ec3..ef46b18 100644
--- a/examples/skeleton/meson.build
+++ b/examples/skeleton/meson.build
@@ -6,6 +6,7 @@
# To build this example as a standalone application with an already-installed
# DPDK instance, use 'make'
+allow_experimental_apis = true
sources = files(
'basicfwd.c'
)