Skip to contentSkip to conversation

liburing: add api for napi busy poll timeout

RFC PATCH Superseded Stefan Roesch 2 participants 12 messages Nov 3, 2022 – Nov 7, 2022

Subsystems (3)

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

cover liburing: add api for napi busy poll timeout

This adds two new api's to set and clear the napi busy poll timeout. The two new functions are called:
- io_uring_register_busy_poll_timeout and
- io_uring_unregister_busy_poll_timeout.

The patch series also contains the documentation for the two new functions and two test programs. The client program is called napi-busy-poll-client and the server program napi-busy-poll-server. The client measures the roundtrip times of requests.

There is also a kernel patch "io-uring: support napi busy poll" to enable this feature on the kernel side.

Stefan Roesch (3):
liburing: add api to set napi busy poll timeout
liburing: add documentation for new napi busy polling
liburing: add test programs for napi busy poll

 man/io_uring_register_napi.3    |  35 +++
 man/io_uring_unregister_napi.3  |  26 ++
 src/include/liburing.h          |   3 +
 src/include/liburing/io_uring.h |   4 +
 src/register.c                  |  12 +
 test/Makefile                   |   2 +
 test/napi-busy-poll-client.c    | 419 ++++++++++++++++++++++++++++++++
 test/napi-busy-poll-server.c    | 371 ++++++++++++++++++++++++++++
 8 files changed, 872 insertions(+)
 create mode 100644 man/io_uring_register_napi.3
 create mode 100644 man/io_uring_unregister_napi.3
 create mode 100644 test/napi-busy-poll-client.c
 create mode 100644 test/napi-busy-poll-server.c

base-commit: 4915f2af869876d892a1f591ee2c21be21c6fc5c

Signature · 1 line
2.30.2
#7 lore raw

RFC PATCH 3/3 liburing: add test programs for napi busy poll

This adds two test programs to test the napi busy poll functionality. It consists of a client program and a server program. To get a napi id, the client and the server program need to be run on different hosts.

To test the napi busy poll timeout, the -t needs to be specified. A reasonable value for the busy poll timeout is 100. By specifying the busy poll timeout on the server and the client the best results are accomplished.

---
 test/Makefile                |   2 +
 test/napi-busy-poll-client.c | 419 +++++++++++++++++++++++++++++++++++
 test/napi-busy-poll-server.c | 371 +++++++++++++++++++++++++++++++
 3 files changed, 792 insertions(+)
 create mode 100644 test/napi-busy-poll-client.c
 create mode 100644 test/napi-busy-poll-server.c
test/Makefile +2 -0
index e14eb51..3a54571 100644
@@ -104,6 +104,8 @@ test_srcs := \
 	mkdir.c \
 	msg-ring.c \
 	multicqes_drain.c \
+	napi-busy-poll-client.c \
+	napi-busy-poll-server.c \
 	nolibc.c \
 	nop-all-sizes.c \
 	nop.c \
test/napi-busy-poll-client.c new file +419 -0

419 lines not on this page · raw message

test/napi-busy-poll-server.c new file +371 -0

371 lines not on this page · raw message

Signature · 1 line
2.30.2
#1 lore raw

RFC PATCH 1/3 liburing: add api to set napi busy poll timeout

In reply to Stefan Roesch

This adds the two functions to register and unregister the napi busy poll timeout:
- io_uring_register_busy_poll_timeout
- io_uring_unregister_busy_poll_timeout

---
 src/include/liburing.h          |  3 +++
 src/include/liburing/io_uring.h |  4 ++++
 src/register.c                  | 12 ++++++++++++
 3 files changed, 19 insertions(+)
src/include/liburing.h +3 -0
index 12a703f..ef2510e 100644
@@ -235,6 +235,9 @@ int io_uring_register_sync_cancel(struct io_uring *ring,
 int io_uring_register_file_alloc_range(struct io_uring *ring,
 					unsigned off, unsigned len);
 
+int io_uring_register_busy_poll_timeout(struct io_uring *ring, unsigned int to);
+int io_uring_unregister_busy_poll_timeout(struct io_uring *ring);
+
 int io_uring_get_events(struct io_uring *ring);
 int io_uring_submit_and_get_events(struct io_uring *ring);
 
src/include/liburing/io_uring.h +4 -0
index a3e0920..0919d9e 100644
@@ -499,6 +499,10 @@ enum {
 	/* register a range of fixed file slots for automatic slot allocation */
 	IORING_REGISTER_FILE_ALLOC_RANGE	= 25,
 
+	/* set/clear busy poll timeout */
+	IORING_REGISTER_NAPI_BUSY_POLL_TIMEOUT	= 26,
+	IORING_UNREGISTER_NAPI_BUSY_POLL_TIMEOUT= 27,
+
 	/* this goes last */
 	IORING_REGISTER_LAST
 };
src/register.c +12 -0
index e849825..c18e072 100644
@@ -367,3 +367,15 @@ int io_uring_register_file_alloc_range(struct io_uring *ring,
 				       IORING_REGISTER_FILE_ALLOC_RANGE, &range,
 				       0);
 }
+
+int io_uring_register_busy_poll_timeout(struct io_uring *ring, unsigned int to)
+{
+	return __sys_io_uring_register(ring->ring_fd,
+				IORING_REGISTER_NAPI_BUSY_POLL_TIMEOUT, NULL, to);
+}
+
+int io_uring_unregister_busy_poll_timeout(struct io_uring *ring)
+{
+	return __sys_io_uring_register(ring->ring_fd,
+				IORING_UNREGISTER_NAPI_BUSY_POLL_TIMEOUT, NULL, 0);
+}
Signature · 1 line
2.30.2
#6 lore raw

RFC PATCH 2/3 liburing: add documentation for new napi busy polling

In reply to Stefan Roesch

This adds two man pages for the two new functions:
- io_uring_register_busy_poll_timeout
- io_uring_unregister_busy_poll_timeout

---
 man/io_uring_register_napi.3   | 35 ++++++++++++++++++++++++++++++++++
 man/io_uring_unregister_napi.3 | 26 +++++++++++++++++++++++++
 2 files changed, 61 insertions(+)
 create mode 100644 man/io_uring_register_napi.3
 create mode 100644 man/io_uring_unregister_napi.3
man/io_uring_register_napi.3 new file +35 -0
new file mode 100644
index 0000000..2063b5c
@@ -0,0 +1,35 @@
+.\" Copyright (C) 2022 Stefan Roesch <[email protected]>
+.\"
+.\" SPDX-License-Identifier: LGPL-2.0-or-later
+.\"
+.TH io_uring_register_busy_poll_timeout 3 "November 1, 2022" "liburing-2.3" "liburing Manual"
+.SH NAME
+io_uring_register_busy_poll_timeout \- register NAPI busy poll timeout
+.SH SYNOPSIS
+.nf
+.B #include <liburing.h>
+.PP
+.BI "int io_uring_register_busy_poll_timeout(struct io_uring *" ring ","
+.BI "                                        unsigned int " timeout)
+.PP
+.fi
+.SH DESCRIPTION
+.PP
+The
+.BR io_uring_register_busy_poll_timeout (3)
+function registers the NAPI busy poll
+.I timeout
+for subsequent operations.
+
+Registering a NAPI busy poll timeout is a requirement to be able to use
+NAPI busy polling. The other way to enable NAPI busy polling is to set the
+proc setting /proc/sys/net/core/busy_poll.
+
+NAPI busy poll can reduce the network roundtrip time.
+
+
+.SH RETURN VALUE
+On success
+.BR io_uring_register_busy_poll_timeout (3)
+return 0. On failure they return
+.BR -errno .
man/io_uring_unregister_napi.3 new file +26 -0
new file mode 100644
index 0000000..f294ab3
@@ -0,0 +1,26 @@
+.\" Copyright (C) 2022 Stefan Roesch <[email protected]>
+.\"
+.\" SPDX-License-Identifier: LGPL-2.0-or-later
+.\"
+.TH io_uring_unregister_busy_poll_timeout 3 "November 1, 2022" "liburing-2.3" "liburing Manual"
+.SH NAME
+io_uring_unregister_busy_poll_timeout \- register NAPI busy poll timeout
+.SH SYNOPSIS
+.nf
+.B #include <liburing.h>
+.PP
+.BI "int io_uring_register_busy_poll_timeout(struct io_uring *" ring ")
+.PP
+.fi
+.SH DESCRIPTION
+.PP
+The
+.BR io_uring_unregister_busy_poll_timeout (3)
+function unregisters the NAPI busy poll
+for subsequent operations.
+
+.SH RETURN VALUE
+On success
+.BR io_uring_unregister_busy_poll_timeout (3)
+return 0. On failure they return
+.BR -errno .
Signature · 1 line
2.30.2
#2 lore raw

Re: [RFC PATCH v1 1/3] liburing: add api to set napi busy poll timeout

In reply to Stefan Roesch
Quoted 17 lines · Stefan Roesch

This adds the two functions to register and unregister the napi busy poll timeout:
- io_uring_register_busy_poll_timeout
- io_uring_unregister_busy_poll_timeout

---
  src/include/liburing.h          |  3 +++
  src/include/liburing/io_uring.h |  4 ++++
  src/register.c                  | 12 ++++++++++++
  3 files changed, 19 insertions(+)
src/include/liburing.h +0 -0
index 12a703f..ef2510e 100644

src/include/liburing.h int io_uring_register_sync_cancel(struct io_uring *ring, · line 240

Quoted 6 lines
src/include/liburing.h +3 -0
@@ -235,6 +235,9 @@ int io_uring_register_sync_cancel(struct io_uring *ring,
  int io_uring_register_file_alloc_range(struct io_uring *ring,
  					unsigned off, unsigned len);
 
+int io_uring_register_busy_poll_timeout(struct io_uring *ring, unsigned int to);
+int io_uring_unregister_busy_poll_timeout(struct io_uring *ring);
+

If you export a non inline function, you should also update the liburing.map file.

Signature · 1 line
Ammar Faizi
#8 lore raw

Re: [RFC PATCH v1 3/3] liburing: add test programs for napi busy poll

In reply to Stefan Roesch

test/napi-busy-poll-client.c line 69

Quoted 9 lines · Stefan Roesch
test/napi-busy-poll-client.c new file +9 -0
+struct option longopts[] =
+{
+        {"address"  , 1, NULL, 'a'},
+        {"busy"     , 0, NULL, 'b'},
+        {"help"     , 0, NULL, 'h'},
+        {"num_pings", 1, NULL, 'n'},
+        {"port"     , 1, NULL, 'p'},
+        {"sqpoll"   , 0, NULL, 's'},
+	{"timeout"  , 1, NULL, 't'},

Inconsistent indentation.

test/napi-busy-poll-client.c line 322

Quoted 5 lines
test/napi-busy-poll-client.c new file +5 -0
+	if (strlen(opt.addr) == 0) {
+		fprintf(stderr, "address option is mandatory\n");
+		printUsage(argv[0]);
+		exit(-1);
+	}

Don't use integer literal like 0 or -1 as the exit code in tests, use the exit code protocol:

T_EXIT_PASS
T_EXIT_FAIL
T_EXIT_SKIP

They are defined in test/helpers.h.

Signature · 1 line
Ammar Faizi
#4 lore raw

Re: [RFC PATCH v1 1/3] liburing: add api to set napi busy poll timeout

In reply to Stefan Roesch
Quoted 6 lines · Stefan Roesch

This adds the two functions to register and unregister the napi busy poll timeout:
- io_uring_register_busy_poll_timeout
- io_uring_unregister_busy_poll_timeout

Also, please update the CHANGELOG file if you add a new feature. Create a new entry for liburing-2.4 release.

Ref: https://github.com/axboe/liburing/discussions/696#discussioncomment-3962770

Signature · 1 line
Ammar Faizi
#10 lore raw

Re: [RFC PATCH v1 3/3] liburing: add test programs for napi busy poll

In reply to Stefan Roesch

test/napi-busy-poll-client.c line 120

Quoted 4 lines · Stefan Roesch
test/napi-busy-poll-client.c new file +4 -0
+void *encodeUserData(char type, int fd)
+{
+	return (void *)((uint32_t)fd | ((__u64)type << 56));
+}

This breaks 32-bit build.

i686-linux-gnu-gcc -Werror -D_GNU_SOURCE -D__SANE_USERSPACE_TYPES__ -I../src/include/ -include ../config-host.h -g -O3 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-sign-compare -Wstringop-overflow=0 -Warray-bounds=0 -DLIBURING_BUILD_TEST -o napi-busy-poll-client.t napi-busy-poll-client.c helpers.o -L../src/ -luring -lpthread napi-busy-poll-client.c: In function ‘encodeUserData’:
napi-busy-poll-client.c:119:16: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]

    119 |         return (void *)((uint32_t)fd | ((__u64)type << 56));
        |                ^

cc1: all warnings being treated as errors

Signature · 1 line
Ammar Faizi
#3 lore raw

Re: [RFC PATCH v1 1/3] liburing: add api to set napi busy poll timeout

In reply to Ammar Faizi
Quoted 17 lines · Ammar Faizi
Quoted 16 lines · Stefan Roesch

This adds the two functions to register and unregister the napi busy poll timeout:
- io_uring_register_busy_poll_timeout
- io_uring_unregister_busy_poll_timeout

---
  src/include/liburing.h          |  3 +++
  src/include/liburing/io_uring.h |  4 ++++
  src/register.c                  | 12 ++++++++++++
  3 files changed, 19 insertions(+)
src/include/liburing.h +0 -0
index 12a703f..ef2510e 100644
@@ -235,6 +235,9 @@ int io_uring_register_sync_cancel(struct io_uring *ring,
  int io_uring_register_file_alloc_range(struct io_uring *ring,
Quoted 8 lines

src/include/liburing.h int io_uring_register_sync_cancel(struct io_uring *ring, · line 240

Quoted 5 lines
src/include/liburing.h +2 -0
  					unsigned off, unsigned len);
  +int io_uring_register_busy_poll_timeout(struct io_uring *ring, unsigned int
 to);
+int io_uring_unregister_busy_poll_timeout(struct io_uring *ring);
+

If you export a non inline function, you should also update the liburing.map file.

In version 2 of the patch, the file liburing.map is updated.

#5 lore raw

Re: [RFC PATCH v1 1/3] liburing: add api to set napi busy poll timeout

In reply to Ammar Faizi
Quoted 10 lines · Ammar Faizi
Quoted 5 lines · Stefan Roesch

This adds the two functions to register and unregister the napi busy poll timeout:
- io_uring_register_busy_poll_timeout
- io_uring_unregister_busy_poll_timeout

Also, please update the CHANGELOG file if you add a new feature. Create a new entry for liburing-2.4 release.

In version 2 of the patch, the CHANGELOG file has been updated.

Quoted 1 line

Ref: https://github.com/axboe/liburing/discussions/696#discussioncomment-3962770

#9 lore raw

Re: [RFC PATCH v1 3/3] liburing: add test programs for napi busy poll

In reply to Ammar Faizi
Quoted 13 lines · Ammar Faizi

test/napi-busy-poll-client.c line 69

Quoted 9 lines · Stefan Roesch
test/napi-busy-poll-client.c new file +9 -0
+struct option longopts[] =
+{
+        {"address"  , 1, NULL, 'a'},
+        {"busy"     , 0, NULL, 'b'},
+        {"help"     , 0, NULL, 'h'},
+        {"num_pings", 1, NULL, 'n'},
+        {"port"     , 1, NULL, 'p'},
+        {"sqpoll"   , 0, NULL, 's'},
+	{"timeout"  , 1, NULL, 't'},

Inconsistent indentation.

Version 2 of the patch fixes this.

Quoted 8 lines

test/napi-busy-poll-client.c line 322

Quoted 5 lines
test/napi-busy-poll-client.c new file +5 -0
+	if (strlen(opt.addr) == 0) {
+		fprintf(stderr, "address option is mandatory\n");
+		printUsage(argv[0]);
+		exit(-1);
+	}

Don't use integer literal like 0 or -1 as the exit code in tests, use the exit code protocol:

Quoted 5 lines

T_EXIT_PASS
T_EXIT_FAIL
T_EXIT_SKIP

They are defined in test/helpers.h.

Version 2 of the patch uses the above constants.

#11 lore raw

Re: [RFC PATCH v1 3/3] liburing: add test programs for napi busy poll

In reply to Ammar Faizi
Quoted 7 lines · Ammar Faizi

test/napi-busy-poll-client.c line 120

Quoted 4 lines · Stefan Roesch
test/napi-busy-poll-client.c new file +4 -0
+void *encodeUserData(char type, int fd)
+{
+	return (void *)((uint32_t)fd | ((__u64)type << 56));
+}

This breaks 32-bit build.

Quoted 7 lines

i686-linux-gnu-gcc -Werror -D_GNU_SOURCE -D__SANE_USERSPACE_TYPES__ -I../src/include/ -include ../config-host.h -g -O3 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-sign-compare -Wstringop-overflow=0 -Warray-bounds=0 -DLIBURING_BUILD_TEST -o napi-busy-poll-client.t napi-busy-poll-client.c helpers.o -L../src/ -luring -lpthread napi-busy-poll-client.c: In function ‘encodeUserData’:
napi-busy-poll-client.c:119:16: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]

    119 |         return (void *)((uint32_t)fd | ((__u64)type << 56));
        |                ^

cc1: all warnings being treated as errors

Version 2 of the patch fixes the above problem.