Skip to contentSkip to conversation

Using shared mempools for zero-copy IO proxying

RFC PATCH In review Bruce Richardson 3 participants 8 messages Sep 22, 2023 – Feb 7, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Using shared mempools for zero-copy IO proxying

Following my talk at the recent DPDK Summit [1], here is an RFC patchset containing the prototypes I created which led to the talk. This patchset is simply to demonstrate:

* what is currently possible with DPDK in terms of zero-copy IPC
* where the big gaps, and general problem areas are
* what the performance is like doing zero-copy between processes
* how we may look to have new deployment models for DPDK apps.

This cover letter is quite long, as it covers how to run the demo app and use the drivers included in this set. I felt it more accessible this way than putting it in rst files in the patches. This patchset depends upon patchsets [2] and [3]

[1] https://dpdksummit2023.sched.com/event/1P9wU
[2] http://patches.dpdk.org/project/dpdk/list/?series=29536
[3] http://patches.dpdk.org/project/dpdk/list/?series=29538

Overview
--------

The patchset contains at a high level the following parts: a proxy application which performs packet IO and steers traffic on a per-queue basis to other applications which connect to it via unix sockets, and a set of drivers to be used by those applications so that they can (hopefully) receive packets from the proxy app without any changes to their own code. This all helps to demonstrate the feasibility of zero- copy packet transfer between independent DPDK apps.

The drivers are:
* a bus driver, which makes the connection to the proxy app via the unix socket. Thereafter it accepts the shared memory from the proxy and maps it into the running process for use for buffers and rings etc. It also handled communication with the proxy app on behalf of the other two drivers
* a mempool driver, which simply manages a set of buffers on the basis of offsets within the shared memory area rather than using pointers. The big downside of its use is that it assumes all the objects stored in the mempool are mbufs. (As described in my talk, this is a big issue where I'm not sure we have a good solution available right now to resolve it)
* an ethernet driver, which creates an rx and tx ring in shared memory for use in communicating with the proxy app. All buffers sent/received are converted to offsets within the shared memory area.

The proxy app itself implements all the other logic - mostly inside datapath.c - to allow the connecting app to run. When an app connects to the unix socket, the proxy app uses memfd to create a hugepage block to be passed through to the "guest" app, and then sends/receives the messages from the drivers until the app connection is up and running to handle traffic. [Ideally, this IPC over unix socket mechanism should probably be generalized into a library used by the app, but for now it's just built-in]. As stated above, the steering of traffic is done per-queue, that is, each app connects to a specific socket corresponding to a NIC queue. For demo purposes, the traffic to the queues is just distributed using RSS, but obviously it would be possible to use e.g. rte_flow to do more interesting distribution in future.

Running the Apps
----------------

To get things all working just do a DPDK build as normal. Then run the io-proxy app. It only takes a single parameter of the core number to use. For example, on my system I run it on lcore 25:

	./build/app/dpdk-io-proxy 25

The sockets to be created and how they map to ports/queues is controlled via commandline, but a startup script can be provided, which just needs to be in the current directory and name "dpdk-io-proxy.cmds". Patch 5 of this set contains an example setup that I use. Therefore it's recommended that you run the proxy app from a directory containing that file. If so, the proxy app will use two ports and create two queues on each, mapping them to 4 unix socket files in /tmp. (Each socket is created in its own directory to simplify use with docker containers as described below in next section).

No traffic is handled by the app until other end-user apps connect to it. Testpmd works as that second "guest" app without any changes to it. To run multiple testpmd instances, each taking traffic from a unique RX queue and forwarding it back, the following sequence of commands can be used [in this case, doing forwarding on cores 26 through 29, and using the 4 unix sockets configured using the startup file referenced above].

	./build/app/dpdk-testpmd -l 24,26 --no-huge -m1 --no-shconf \
		-a sock:/tmp/socket_0_0/sock  -- --forward-mode=macswap
	./build/app/dpdk-testpmd -l 24,27 --no-huge -m1 --no-shconf \
		-a sock:/tmp/socket_0_1/sock  -- --forward-mode=macswap
	./build/app/dpdk-testpmd -l 24,28 --no-huge -m1 --no-shconf \
		-a sock:/tmp/socket_1_0/sock  -- --forward-mode=macswap
	./build/app/dpdk-testpmd -l 24,29 --no-huge -m1 --no-shconf \
		-a sock:/tmp/socket_1_1/sock  -- --forward-mode=macswap

NOTE:
* the "--no-huge -m1" is present to guarantee that no regular DPDK hugepage memory is being used by the app. It's all coming from the proxy app's memfd
* the "--no-shconf" parameter is necessary just to avoid us needing to specify a unix file-prefix for each instance
* the forwarding type to be used is optional, macswap is chosen just to have some work done inside testpmd to prove it can touch the packet payload, not just the mbuf header.

Using with docker containers
----------------------------

The testpmd instances run above can also be run within a docker container. Using a dockerfile like below we can run testpmd in a container getting the packets in a zero-copy manner from the io-proxy running on the host.

   # syntax=docker/dockerfile:1-labs
   FROM alpine
   RUN apk add --update alpine-sdk \
           py3-elftools meson ninja \
           bsd-compat-headers \
           linux-headers \
           numactl-dev \
           bash
   ADD . dpdk
   WORKDIR dpdk
   RUN rm -rf build
   RUN meson setup -Denable_drivers=*/shared_mem -Ddisable_libs=* \
        -Denable_apps=test-pmd -Dtests=false build
   RUN ninja -v -C build
   ENTRYPOINT ["/dpdk/build/app/dpdk-testpmd"]

To access the proxy, all the container needs is access to the unix socket on the filesystem. Since in the example startup script each socket is placed in its own directory we can use "--volume" parameter to give each instance it's own unique unix socket, and therefore proxied NIC RX/TX queue. To run four testpmd instances as above, just in containers the following commands can be used - assuming the dockerfile above is built to an image called "testpmd".

	docker run -it --volume=/tmp/socket_0_0:/run testpmd \
		-l 24,26 --no-huge -a sock:/run/sock -- \
		--no-mlockall --forward-mode=macswap
	docker run -it --volume=/tmp/socket_0_1:/run testpmd \
		-l 24,27 --no-huge -a sock:/run/sock -- \
		--no-mlockall --forward-mode=macswap
	docker run -it --volume=/tmp/socket_1_0:/run testpmd \
		-l 24,28 --no-huge -a sock:/run/sock -- \
		--no-mlockall --forward-mode=macswap
	docker run -it --volume=/tmp/socket_1_1:/run testpmd \
		-l 24,29 --no-huge -a sock:/run/sock -- \
		--no-mlockall --forward-mode=macswap

NOTE: since these docker testpmd instances don't access IO or allocate hugepages directly, they should be runable without extra privileges, so long as they can connect to the unix socket.

Additional info
---------------

* Stats are available via app commandline
* By default (#define in code), the proxy app only uses 2 queues per port, so you can't configure more than that via cmdline
* Any ports used by the proxy script must support queue reconfiguration at runtime without stopping the port.
* When a "guest" process connected to a socket terminates, all shared memory used by that process is detroyed and a new memfd created on reconnect.
* The above setups using testpmd are the only ways in which this app and drivers have been tested. I would be hopeful that other apps would work too, but there are quite a few limitations (see my DPDK summit talk for some more details on those).

Congratulations on reading this far! :-)
All comments/feedback on this welcome.

Bruce Richardson (5):
bus: new driver to accept shared memory over unix socket
mempool: driver for mempools of mbufs on shared memory
net: new ethdev driver to communicate using shared mem
app: add IO proxy app using shared memory interfaces app/io-proxy: add startup commands

 app/io-proxy/command_fns.c                 | 160 ++++++
 app/io-proxy/commands.list                 |   6 +
 app/io-proxy/datapath.c                    | 595 +++++++++++++++++++++
 app/io-proxy/datapath.h                    |  37 ++
 app/io-proxy/datapath_mp.c                 |  78 +++
 app/io-proxy/dpdk-io-proxy.cmds            |   6 +
 app/io-proxy/main.c                        |  71 +++
 app/io-proxy/meson.build                   |  12 +
 app/meson.build                            |   1 +
 drivers/bus/meson.build                    |   1 +
 drivers/bus/shared_mem/meson.build         |  11 +
 drivers/bus/shared_mem/shared_mem_bus.c    | 323 +++++++++++
 drivers/bus/shared_mem/shared_mem_bus.h    |  75 +++
 drivers/bus/shared_mem/version.map         |  11 +
 drivers/mempool/meson.build                |   1 +
 drivers/mempool/shared_mem/meson.build     |  10 +
 drivers/mempool/shared_mem/shared_mem_mp.c |  94 ++++
 drivers/net/meson.build                    |   1 +
 drivers/net/shared_mem/meson.build         |  11 +
 drivers/net/shared_mem/shared_mem_eth.c    | 295 ++++++++++
 20 files changed, 1799 insertions(+)
 create mode 100644 app/io-proxy/command_fns.c
 create mode 100644 app/io-proxy/commands.list
 create mode 100644 app/io-proxy/datapath.c
 create mode 100644 app/io-proxy/datapath.h
 create mode 100644 app/io-proxy/datapath_mp.c
 create mode 100644 app/io-proxy/dpdk-io-proxy.cmds
 create mode 100644 app/io-proxy/main.c
 create mode 100644 app/io-proxy/meson.build
 create mode 100644 drivers/bus/shared_mem/meson.build
 create mode 100644 drivers/bus/shared_mem/shared_mem_bus.c
 create mode 100644 drivers/bus/shared_mem/shared_mem_bus.h
 create mode 100644 drivers/bus/shared_mem/version.map
 create mode 100644 drivers/mempool/shared_mem/meson.build
 create mode 100644 drivers/mempool/shared_mem/shared_mem_mp.c
 create mode 100644 drivers/net/shared_mem/meson.build
 create mode 100644 drivers/net/shared_mem/shared_mem_eth.c

--
2.39.2

#1 lore raw

RFC PATCH 1/5 bus: new driver to accept shared memory over unix socket

Add a new driver to DPDK which supports taking in memory e.g. hugepage memory via a unix socket connection and maps it into the DPDK process replacing the current socket memory as the default memory for use by future requests.

---
 drivers/bus/meson.build                 |   1 +
 drivers/bus/shared_mem/meson.build      |  11 +
 drivers/bus/shared_mem/shared_mem_bus.c | 323 ++++++++++++++++++++++++
 drivers/bus/shared_mem/shared_mem_bus.h |  75 ++++++
 drivers/bus/shared_mem/version.map      |  11 +
 5 files changed, 421 insertions(+)
 create mode 100644 drivers/bus/shared_mem/meson.build
 create mode 100644 drivers/bus/shared_mem/shared_mem_bus.c
 create mode 100644 drivers/bus/shared_mem/shared_mem_bus.h
 create mode 100644 drivers/bus/shared_mem/version.map
drivers/bus/meson.build +1 -0
index a78b4283bf..0e64959d1a 100644
@@ -9,6 +9,7 @@ drivers = [
         'ifpga',
         'pci',
         'platform',
+        'shared_mem',
         'vdev',
         'vmbus',
 ]
drivers/bus/shared_mem/meson.build new file +11 -0
new file mode 100644
index 0000000000..1fa21f3a09
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2023 Intel Corporation
+
+if is_windows
+    build = false
+    reason = 'not supported on Windows'
+endif
+
+sources = files('shared_mem_bus.c')
+require_iova_in_mbuf = false
+deps += ['mbuf', 'net']
drivers/bus/shared_mem/shared_mem_bus.c new file +323 -0

323 lines not on this page · raw message

drivers/bus/shared_mem/shared_mem_bus.h new file +75 -0

75 lines not on this page · raw message

drivers/bus/shared_mem/version.map new file +11 -0
new file mode 100644
index 0000000000..2af82689b1
@@ -0,0 +1,11 @@
+INTERNAL {
+	global:
+
+	shared_mem_register_driver;
+	rte_shm_bus_get_mem_offset;
+	rte_shm_bus_get_mem_ptr;
+	rte_shm_bus_recv_message;
+	rte_shm_bus_send_message;
+
+	local: *;
+};
Signature · 1 line
2.39.2
#2 lore raw

Re: [RFC PATCH 1/5] bus: new driver to accept shared memory over unix socket

Quoted 7 lines · Bruce Richardson

Add a new driver to DPDK which supports taking in memory e.g. hugepage memory via a unix socket connection and maps it into the DPDK process replacing the current socket memory as the default memory for use by future requests.

Thanks Bruce for this work. IMO, This will open up a lot of use cases like CPU based offload on different process.

drivers/bus/shared_mem/shared_mem_bus.h line 22

Quoted 11 lines
drivers/bus/shared_mem/shared_mem_bus.h new file +11 -0
+
+enum shared_mem_msg_type {
+       MSG_TYPE_ACK = 0,
+       MSG_TYPE_MMAP_BASE_ADDR,
+       MSG_TYPE_MEMPOOL_OFFSET,
+       MSG_TYPE_RX_RING_OFFSET,
+       MSG_TYPE_TX_RING_OFFSET,
+       MSG_TYPE_START,
+       MSG_TYPE_GET_MAC,
+       MSG_TYPE_REPORT_MAC,
+};

In order to cater to different use cases, IMO, drivers/bus/shared_mem/ should be generic and act only
as transport for communicating with other process. That would translate to the following
1) drivers/bus/shared_mem/ provides means to register message type and its callback
2) The consumers(drivers/mempool/shared_mem and drivers/net/sharedmem) register the
the callback. Definition the callback and message type should be in consumer.

Also, We may change the bus/sharedmem to bus/socket or so, to limit the scope of bus
driver as communion mechanism to talk to different process. That way there can different DPDK driver
can based on socket bus in the future.

#3 lore raw

RFC PATCH 2/5 mempool: driver for mempools of mbufs on shared memory

In reply to Bruce Richardson

This mempool driver can be used with the shared_mem bus driver to create a pool of shared mbufs on a shared memory segment.

---
 drivers/mempool/meson.build                |  1 +
 drivers/mempool/shared_mem/meson.build     | 10 +++
 drivers/mempool/shared_mem/shared_mem_mp.c | 94 ++++++++++++++++++++++
 3 files changed, 105 insertions(+)
 create mode 100644 drivers/mempool/shared_mem/meson.build
 create mode 100644 drivers/mempool/shared_mem/shared_mem_mp.c
drivers/mempool/meson.build +1 -0
index dc88812585..4326bd0ea3 100644
@@ -8,6 +8,7 @@ drivers = [
         'dpaa2',
         'octeontx',
         'ring',
+        'shared_mem',
         'stack',
 ]
 
drivers/mempool/shared_mem/meson.build new file +10 -0
new file mode 100644
index 0000000000..ee740ccdc9
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2023 Intel Corporation
+
+if is_windows
+    build = false
+    reason = 'not supported on Windows'
+endif
+sources = files('shared_mem_mp.c')
+require_iova_in_mbuf = false
+deps += ['stack', 'bus_shared_mem']
drivers/mempool/shared_mem/shared_mem_mp.c new file +94 -0

94 lines not on this page · raw message

Signature · 1 line
2.39.2
#4 lore raw

RFC PATCH 3/5 net: new ethdev driver to communicate using shared mem

In reply to Bruce Richardson

This ethdev builds on the previous shared_mem bus driver and shared_mem mempool driver to provide an ethdev interface which can allow zero-copy I/O from one process to another.

---
 drivers/net/meson.build                 |   1 +
 drivers/net/shared_mem/meson.build      |  11 +
 drivers/net/shared_mem/shared_mem_eth.c | 295 ++++++++++++++++++++++++
 3 files changed, 307 insertions(+)
 create mode 100644 drivers/net/shared_mem/meson.build
 create mode 100644 drivers/net/shared_mem/shared_mem_eth.c
drivers/net/meson.build +1 -0
index bd38b533c5..505d208497 100644
@@ -53,6 +53,7 @@ drivers = [
         'qede',
         'ring',
         'sfc',
+        'shared_mem',
         'softnic',
         'tap',
         'thunderx',
drivers/net/shared_mem/meson.build new file +11 -0
new file mode 100644
index 0000000000..17d1b84454
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2023 Intel Corporation
+
+if is_windows
+    build = false
+    reason = 'not supported on Windows'
+endif
+
+sources = files('shared_mem_eth.c')
+deps += 'bus_shared_mem'
+require_iova_in_mbuf = false
drivers/net/shared_mem/shared_mem_eth.c new file +295 -0

295 lines not on this page · raw message

Signature · 1 line
2.39.2
#5 lore raw

RFC PATCH 4/5 app: add IO proxy app using shared memory interfaces

In reply to Bruce Richardson

This app uses the shared memory poll, and shared ethdev infrastructure to act as a zero-copy IO proxy to other applications. It has been tested and verified to work successfully proxying data to testpmd instances on the system, with those testpmd instances each being passed a unix socket to work with via the shared memory bus "-a sock:/path/to/sock..." parameter.

---
 app/io-proxy/command_fns.c | 160 ++++++++++
 app/io-proxy/commands.list |   6 +
 app/io-proxy/datapath.c    | 595 +++++++++++++++++++++++++++++++++++++
 app/io-proxy/datapath.h    |  37 +++
 app/io-proxy/datapath_mp.c |  78 +++++
 app/io-proxy/main.c        |  71 +++++
 app/io-proxy/meson.build   |  12 +
 app/meson.build            |   1 +
 8 files changed, 960 insertions(+)
 create mode 100644 app/io-proxy/command_fns.c
 create mode 100644 app/io-proxy/commands.list
 create mode 100644 app/io-proxy/datapath.c
 create mode 100644 app/io-proxy/datapath.h
 create mode 100644 app/io-proxy/datapath_mp.c
 create mode 100644 app/io-proxy/main.c
 create mode 100644 app/io-proxy/meson.build
app/io-proxy/command_fns.c new file +160 -0
new file mode 100644
index 0000000000..f48921e005
@@ -0,0 +1,160 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 Intel Corporation
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdbool.h>
+
+#include <rte_ethdev.h>
+
+#include "datapath.h"
+#include "commands.h"
+
+extern volatile bool quit;
+extern volatile bool running_startup_script;
+
+void
+cmd_add_socket_parsed(void *parsed_result, struct cmdline *cl __rte_unused,
+		void *data __rte_unused)
+{
+	struct cmd_add_socket_result *res = parsed_result;
+	uint64_t maxmem = 0;
+	char *endchar;
+
+	maxmem = strtoull(res->memsize, &endchar, 0);
+	switch (*endchar) {
+	case 'G': case 'g':
+		maxmem *= 1024;
+		/* fall-through */
+	case 'M': case 'm':
+		maxmem *= 1024;
+		/* fall-through */
+	case 'K': case 'k':
+		maxmem *= 1024;
+		break;
+	}
+	if (res->port >= MAX_PORTS_SUPPORTED) {
+		fprintf(stderr, "Port id out of range. Must be <%u\n", MAX_PORTS_SUPPORTED);
+		goto err;
+	}
+	if (res->queue >= MAX_QUEUES_SUPPORTED) {
+		fprintf(stderr, "Queue id out of range. Must be <%u\n", MAX_QUEUES_SUPPORTED);
+		goto err;
+	}
+	if (listen_unix_socket(res->path, maxmem, res->port, res->queue) != 0) {
+		fprintf(stderr, "error initializing socket: %s\n", res->path);
+		goto err;
+	}
+
+	printf("Created socket = %s with memsize = %s using port = %u, queue = %u\n",
+			res->path, res->memsize, res->port, res->queue);
+	return;
+
+err:
+	if (running_startup_script) {
+		quit = true;
+		/* wait for main thread to quit. Just spin here for condition which
+		 * will never actually come true, as main thread should just exit
+		 */
+		while (quit)
+			usleep(100);
+	}
+	/* if running interactively, do nothing on error except report it above */
+}
+
+void
+cmd_list_sockets_parsed(__rte_unused void *parsed_result,
+		__rte_unused struct cmdline *cl,
+		__rte_unused void *data)
+{
+	const char *path;
+	int sock;
+	uint64_t maxmem;
+	uint16_t port, queue;
+	bool connected;
+
+	for (int i = get_next_socket(0, &path, &sock, &maxmem, &port, &queue, &connected);
+			i < MAX_SOCKETS;
+			i = get_next_socket(i + 1, &path, &sock, &maxmem, &port,
+					&queue, &connected)) {
+		char memstr[32];
+		if (maxmem % (1UL << 30) == 0)
+			snprintf(memstr, sizeof(memstr), "%" PRIu64 "G", maxmem >> 30);
+		else if (maxmem % (1UL << 20) == 0)
+			snprintf(memstr, sizeof(memstr), "%" PRIu64 "M", maxmem >> 20);
+		else if (maxmem % (1UL << 10) == 0)
+			snprintf(memstr, sizeof(memstr), "%" PRIu64 "K", maxmem >> 10);
+		else
+			snprintf(memstr, sizeof(memstr), "%" PRIu64, maxmem);
+
+		printf("Socket %s [%s]: mem=%s, port=%u, queue=%u\n",
+				path, connected ? "connected" : "idle", memstr, port, queue);
+	}
+}
+
+void
+cmd_list_ports_parsed(__rte_unused void *parsed_result,
+		__rte_unused struct cmdline *cl,
+		__rte_unused void *data)
+{
+	for (int i = 0; i < rte_eth_dev_count_avail(); i++) {
+		struct rte_ether_addr addr;
+		int retval = rte_eth_macaddr_get(i, &addr);
+		if (retval != 0) {
+			printf("Port %d - MAC UNKNOWN\n", i);
+			continue;
+		}
+		printf("Port %d - "RTE_ETHER_ADDR_PRT_FMT"\n", i, RTE_ETHER_ADDR_BYTES(&addr));
+	}
+}
+
+void
+cmd_show_port_stats_parsed(__rte_unused void *parsed_result,
+		__rte_unused struct cmdline *cl,
+		__rte_unused void *data)
+{
+	for (int i = 0; i < rte_eth_dev_count_avail(); i++) {
+		struct rte_eth_stats stats = {0};
+		int retval = rte_eth_stats_get(i, &stats);
+		if (retval != 0) {
+			printf("Port %d - Cannot get stats\n", i);
+			continue;
+		}
+		printf("Port %d - ipkts: %"PRIu64", imissed: %"PRIu64
+				", ierrors: %"PRIu64", opkts: %"PRIu64"\n",
+				i, stats.ipackets, stats.imissed, stats.ierrors, stats.opackets);
+	}
+}
+
+void
+cmd_show_socket_stats_parsed(__rte_unused void *parsed_result,
+		__rte_unused struct cmdline *cl,
+		__rte_unused void *data)
+{
+	const char *path;
+	int sock;
+	uint64_t maxmem;
+	uint16_t port, queue;
+	bool connected;
+
+	for (int i = get_next_socket(0, &path, &sock, &maxmem, &port, &queue, &connected);
+			i < MAX_SOCKETS;
+			i = get_next_socket(i + 1, &path, &sock, &maxmem, &port,
+					&queue, &connected)) {
+		if (connected || dp_stats[i].rx != 0 || dp_stats[i].deq != 0)
+			printf("Socket %u [port %u, q %u]: RX %" PRIu64 ", Enq_drops %" PRIu64
+					", Deq %" PRIu64 ", TX_drops %" PRIu64 "\n",
+					i, i / MAX_QUEUES_SUPPORTED, i % MAX_QUEUES_SUPPORTED,
+					dp_stats[i].rx, dp_stats[i].enq_drop,
+					dp_stats[i].deq, dp_stats[i].tx_drop);
+
+	}
+}
+
+void
+cmd_quit_parsed(__rte_unused void *parsed_result, struct cmdline *cl,
+		__rte_unused void *data)
+{
+	cmdline_quit(cl);
+}
app/io-proxy/commands.list new file +6 -0
new file mode 100644
index 0000000000..9dab9bba28
@@ -0,0 +1,6 @@
+add socket <STRING>path <STRING>memsize <UINT16>port <UINT16>queue
+list sockets
+list ports
+show port stats
+show socket stats
+quit
app/io-proxy/datapath.c new file +595 -0

595 lines not on this page · raw message

app/io-proxy/datapath.h new file +37 -0
new file mode 100644
index 0000000000..ec5b395164
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 Intel Corporation
+ */
+#ifndef DATAPATH_H_INC
+#define DATAPATH_H_INC
+
+#include <stdint.h>
+
+#define MEMPOOL_OPS_NAME "proxy_mp"
+#define MAX_PORTS_SUPPORTED 8
+#define MAX_QUEUES_SUPPORTED 2
+#define MAX_SOCKETS (MAX_PORTS_SUPPORTED * MAX_QUEUES_SUPPORTED)
+
+struct rxtx_stats {
+	uint64_t rx;
+	uint64_t enq_drop;
+	uint64_t deq;
+	uint64_t tx_drop;
+};
+
+extern struct rxtx_stats dp_stats[MAX_SOCKETS];
+
+int check_mempool_ops(void);
+
+int datapath_init(const char *corelist);
+
+int listen_unix_socket(const char *path, uint64_t maxmem, uint16_t port, uint16_t qid);
+
+void handle_forwarding(void);
+
+unsigned int lcore_id(void);
+
+int get_next_socket(int start, const char **path, int *sock, uint64_t *maxmem,
+		uint16_t *port, uint16_t *queue, bool *connected);
+
+
+#endif
app/io-proxy/datapath_mp.c new file +78 -0

78 lines not on this page · raw message

app/io-proxy/main.c new file +71 -0

71 lines not on this page · raw message

app/io-proxy/meson.build new file +12 -0
new file mode 100644
index 0000000000..f03783b68f
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2023 Intel Corporation
+
+cmd_h = custom_target('commands_hdr',
+        output: 'commands.h',
+        input: files('commands.list'),
+        capture: true,
+        command: [cmdline_gen_cmd, '@INPUT@']
+)
+sources += files('datapath.c', 'datapath_mp.c', 'main.c', 'command_fns.c')
+sources += cmd_h
+deps += ['cmdline', 'ethdev', 'stack', 'bus_shared_mem']
app/meson.build +1 -0
index e4bf5c531c..27f69d883e 100644
@@ -18,6 +18,7 @@ apps = [
         'dumpcap',
         'pdump',
         'proc-info',
+        'io-proxy',
         'test-acl',
         'test-bbdev',
         'test-cmdline',
Signature · 1 line
2.39.2
#6 lore raw

RFC PATCH 5/5 app/io-proxy: add startup commands

In reply to Bruce Richardson

To make it easier to run the io-proxy, add a startup command line example to configure by default 4 sockets on two ports.

---
 app/io-proxy/dpdk-io-proxy.cmds | 6 ++++++
 1 file changed, 6 insertions(+)
 create mode 100644 app/io-proxy/dpdk-io-proxy.cmds
app/io-proxy/dpdk-io-proxy.cmds new file +6 -0
new file mode 100644
index 0000000000..515d598079
@@ -0,0 +1,6 @@
+add socket /tmp/socket_0_0/sock 2G 0 0
+add socket /tmp/socket_0_1/sock 2G 0 1
+add socket /tmp/socket_1_0/sock 2G 1 0
+add socket /tmp/socket_1_1/sock 2G 1 1
+list ports
+list sockets
Signature · 1 line
2.39.2
#7 lore raw
In reply to Bruce Richardson
Quoted 216 lines · On Fri, 22 Sep 2023 09:19:07 +0100 Bruce Richardson…

Following my talk at the recent DPDK Summit [1], here is an RFC patchset containing the prototypes I created which led to the talk. This patchset is simply to demonstrate:

* what is currently possible with DPDK in terms of zero-copy IPC
* where the big gaps, and general problem areas are
* what the performance is like doing zero-copy between processes
* how we may look to have new deployment models for DPDK apps.

This cover letter is quite long, as it covers how to run the demo app and use the drivers included in this set. I felt it more accessible this way than putting it in rst files in the patches. This patchset depends upon patchsets [2] and [3]

[1] https://dpdksummit2023.sched.com/event/1P9wU
[2] http://patches.dpdk.org/project/dpdk/list/?series=29536
[3] http://patches.dpdk.org/project/dpdk/list/?series=29538

Overview
--------

The patchset contains at a high level the following parts: a proxy application which performs packet IO and steers traffic on a per-queue basis to other applications which connect to it via unix sockets, and a set of drivers to be used by those applications so that they can (hopefully) receive packets from the proxy app without any changes to their own code. This all helps to demonstrate the feasibility of zero- copy packet transfer between independent DPDK apps.

The drivers are:
* a bus driver, which makes the connection to the proxy app via the unix socket. Thereafter it accepts the shared memory from the proxy and maps it into the running process for use for buffers and rings etc. It also handled communication with the proxy app on behalf of the other two drivers
* a mempool driver, which simply manages a set of buffers on the basis of offsets within the shared memory area rather than using pointers. The big downside of its use is that it assumes all the objects stored in the mempool are mbufs. (As described in my talk, this is a big issue where I'm not sure we have a good solution available right now to resolve it)
* an ethernet driver, which creates an rx and tx ring in shared memory for use in communicating with the proxy app. All buffers sent/received are converted to offsets within the shared memory area.

The proxy app itself implements all the other logic - mostly inside datapath.c - to allow the connecting app to run. When an app connects to the unix socket, the proxy app uses memfd to create a hugepage block to be passed through to the "guest" app, and then sends/receives the messages from the drivers until the app connection is up and running to handle traffic. [Ideally, this IPC over unix socket mechanism should probably be generalized into a library used by the app, but for now it's just built-in]. As stated above, the steering of traffic is done per-queue, that is, each app connects to a specific socket corresponding to a NIC queue. For demo purposes, the traffic to the queues is just distributed using RSS, but obviously it would be possible to use e.g. rte_flow to do more interesting distribution in future.

Running the Apps
----------------

To get things all working just do a DPDK build as normal. Then run the io-proxy app. It only takes a single parameter of the core number to use. For example, on my system I run it on lcore 25:

	./build/app/dpdk-io-proxy 25

The sockets to be created and how they map to ports/queues is controlled via commandline, but a startup script can be provided, which just needs to be in the current directory and name "dpdk-io-proxy.cmds". Patch 5 of this set contains an example setup that I use. Therefore it's recommended that you run the proxy app from a directory containing that file. If so, the proxy app will use two ports and create two queues on each, mapping them to 4 unix socket files in /tmp. (Each socket is created in its own directory to simplify use with docker containers as described below in next section).

No traffic is handled by the app until other end-user apps connect to it. Testpmd works as that second "guest" app without any changes to it. To run multiple testpmd instances, each taking traffic from a unique RX queue and forwarding it back, the following sequence of commands can be used [in this case, doing forwarding on cores 26 through 29, and using the 4 unix sockets configured using the startup file referenced above].

	./build/app/dpdk-testpmd -l 24,26 --no-huge -m1 --no-shconf \
		-a sock:/tmp/socket_0_0/sock  -- --forward-mode=macswap
	./build/app/dpdk-testpmd -l 24,27 --no-huge -m1 --no-shconf \
		-a sock:/tmp/socket_0_1/sock  -- --forward-mode=macswap
	./build/app/dpdk-testpmd -l 24,28 --no-huge -m1 --no-shconf \
		-a sock:/tmp/socket_1_0/sock  -- --forward-mode=macswap
	./build/app/dpdk-testpmd -l 24,29 --no-huge -m1 --no-shconf \
		-a sock:/tmp/socket_1_1/sock  -- --forward-mode=macswap

NOTE:
* the "--no-huge -m1" is present to guarantee that no regular DPDK hugepage memory is being used by the app. It's all coming from the proxy app's memfd
* the "--no-shconf" parameter is necessary just to avoid us needing to specify a unix file-prefix for each instance
* the forwarding type to be used is optional, macswap is chosen just to have some work done inside testpmd to prove it can touch the packet payload, not just the mbuf header.

Using with docker containers
----------------------------

The testpmd instances run above can also be run within a docker container. Using a dockerfile like below we can run testpmd in a container getting the packets in a zero-copy manner from the io-proxy running on the host.

   # syntax=docker/dockerfile:1-labs
   FROM alpine
   RUN apk add --update alpine-sdk \
           py3-elftools meson ninja \
           bsd-compat-headers \
           linux-headers \
           numactl-dev \
           bash
   ADD . dpdk
   WORKDIR dpdk
   RUN rm -rf build
   RUN meson setup -Denable_drivers=*/shared_mem -Ddisable_libs=* \
        -Denable_apps=test-pmd -Dtests=false build
   RUN ninja -v -C build
   ENTRYPOINT ["/dpdk/build/app/dpdk-testpmd"]

To access the proxy, all the container needs is access to the unix socket on the filesystem. Since in the example startup script each socket is placed in its own directory we can use "--volume" parameter to give each instance it's own unique unix socket, and therefore proxied NIC RX/TX queue. To run four testpmd instances as above, just in containers the following commands can be used - assuming the dockerfile above is built to an image called "testpmd".

	docker run -it --volume=/tmp/socket_0_0:/run testpmd \
		-l 24,26 --no-huge -a sock:/run/sock -- \
		--no-mlockall --forward-mode=macswap
	docker run -it --volume=/tmp/socket_0_1:/run testpmd \
		-l 24,27 --no-huge -a sock:/run/sock -- \
		--no-mlockall --forward-mode=macswap
	docker run -it --volume=/tmp/socket_1_0:/run testpmd \
		-l 24,28 --no-huge -a sock:/run/sock -- \
		--no-mlockall --forward-mode=macswap
	docker run -it --volume=/tmp/socket_1_1:/run testpmd \
		-l 24,29 --no-huge -a sock:/run/sock -- \
		--no-mlockall --forward-mode=macswap

NOTE: since these docker testpmd instances don't access IO or allocate hugepages directly, they should be runable without extra privileges, so long as they can connect to the unix socket.

Additional info
---------------

* Stats are available via app commandline
* By default (#define in code), the proxy app only uses 2 queues per port, so you can't configure more than that via cmdline
* Any ports used by the proxy script must support queue reconfiguration at runtime without stopping the port.
* When a "guest" process connected to a socket terminates, all shared memory used by that process is detroyed and a new memfd created on reconnect.
* The above setups using testpmd are the only ways in which this app and drivers have been tested. I would be hopeful that other apps would work too, but there are quite a few limitations (see my DPDK summit talk for some more details on those).

Congratulations on reading this far! :-)
All comments/feedback on this welcome.

Bruce Richardson (5):
bus: new driver to accept shared memory over unix socket
mempool: driver for mempools of mbufs on shared memory
net: new ethdev driver to communicate using shared mem
app: add IO proxy app using shared memory interfaces app/io-proxy: add startup commands

 app/io-proxy/command_fns.c                 | 160 ++++++
 app/io-proxy/commands.list                 |   6 +
 app/io-proxy/datapath.c                    | 595 +++++++++++++++++++++
 app/io-proxy/datapath.h                    |  37 ++
 app/io-proxy/datapath_mp.c                 |  78 +++
 app/io-proxy/dpdk-io-proxy.cmds            |   6 +
 app/io-proxy/main.c                        |  71 +++
 app/io-proxy/meson.build                   |  12 +
 app/meson.build                            |   1 +
 drivers/bus/meson.build                    |   1 +
 drivers/bus/shared_mem/meson.build         |  11 +
 drivers/bus/shared_mem/shared_mem_bus.c    | 323 +++++++++++
 drivers/bus/shared_mem/shared_mem_bus.h    |  75 +++
 drivers/bus/shared_mem/version.map         |  11 +
 drivers/mempool/meson.build                |   1 +
 drivers/mempool/shared_mem/meson.build     |  10 +
 drivers/mempool/shared_mem/shared_mem_mp.c |  94 ++++
 drivers/net/meson.build                    |   1 +
 drivers/net/shared_mem/meson.build         |  11 +
 drivers/net/shared_mem/shared_mem_eth.c    | 295 ++++++++++
 20 files changed, 1799 insertions(+)
 create mode 100644 app/io-proxy/command_fns.c
 create mode 100644 app/io-proxy/commands.list
 create mode 100644 app/io-proxy/datapath.c
 create mode 100644 app/io-proxy/datapath.h
 create mode 100644 app/io-proxy/datapath_mp.c
 create mode 100644 app/io-proxy/dpdk-io-proxy.cmds
 create mode 100644 app/io-proxy/main.c
 create mode 100644 app/io-proxy/meson.build
 create mode 100644 drivers/bus/shared_mem/meson.build
 create mode 100644 drivers/bus/shared_mem/shared_mem_bus.c
 create mode 100644 drivers/bus/shared_mem/shared_mem_bus.h
 create mode 100644 drivers/bus/shared_mem/version.map
 create mode 100644 drivers/mempool/shared_mem/meson.build
 create mode 100644 drivers/mempool/shared_mem/shared_mem_mp.c
 create mode 100644 drivers/net/shared_mem/meson.build
 create mode 100644 drivers/net/shared_mem/shared_mem_eth.c
Quoted 3 lines

--
2.39.2

This looked interesting but appears to be a dead end. No more work, and never clear how it was different from memif. Would need more documentation etc to be a real NIC. If there is still interest resubmit it.