aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2024-02-02 19:39:01 -0700
committerJens Axboe <axboe@kernel.dk>2024-02-02 19:39:01 -0700
commitc0cb6c705a7bb0bc2dfa481e6d5b28fa5c781937 (patch)
treef4e77454d6590f53cf94dbf3bf943a8a3e082831
parent4e2e46abd2624e4ee874f44bb6b628f3d31a056b (diff)
downloadliburing-napi.tar.gz
examples/napi-busy-poll-{client,server}: cleanups and docnapi
Add example usage, and various little code cleanups. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--examples/napi-busy-poll-client.c18
-rw-r--r--examples/napi-busy-poll-server.c15
2 files changed, 29 insertions, 4 deletions
diff --git a/examples/napi-busy-poll-client.c b/examples/napi-busy-poll-client.c
index 6fa13bf2..bf8cabe1 100644
--- a/examples/napi-busy-poll-client.c
+++ b/examples/napi-busy-poll-client.c
@@ -1,3 +1,17 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Simple ping/pong client which can use the io_uring NAPI support.
+ *
+ * Needs to be run as root because it sets SCHED_FIFO scheduling class,
+ * but will work without that.
+ *
+ * Example:
+ *
+ * sudo examples/napi-busy-poll-client -a 192.168.2.2 -n100000 -p4444 \
+ * -b -t10 -u
+ *
+ * send and receive 100k packets, using NAPI.
+ */
#include <ctype.h>
#include <errno.h>
#include <float.h>
@@ -180,7 +194,6 @@ static void sendPing(struct ctx *ctx)
struct io_uring_sqe *sqe = io_uring_get_sqe(&ctx->ring);
clock_gettime(CLOCK_REALTIME, (struct timespec *)ctx->buffer);
-
io_uring_prep_send(sqe, ctx->sockfd, ctx->buffer, sizeof(struct timespec), 0);
sqe->user_data = encodeUserData(IOURING_SEND, ctx->sockfd);
}
@@ -479,10 +492,9 @@ out:
if (ret)
fprintf(stderr, "io_uring_unregister_napi: %d\n", ret);
}
- io_uring_queue_exit(&ctx.ring);
+ io_uring_queue_exit(&ctx.ring);
free(ctx.rtt);
close(ctx.sockfd);
-
return 0;
}
diff --git a/examples/napi-busy-poll-server.c b/examples/napi-busy-poll-server.c
index ef524479..a1bd17c5 100644
--- a/examples/napi-busy-poll-server.c
+++ b/examples/napi-busy-poll-server.c
@@ -1,3 +1,17 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Simple ping/pong backend which can use the io_uring NAPI support.
+ *
+ * Needs to be run as root because it sets SCHED_FIFO scheduling class,
+ * but will work without that.
+ *
+ * Example:
+ *
+ * sudo examples/napi-busy-poll-server -l -a 192.168.2.2 -n100000 \
+ * -p4444 -t10 -b -u
+ *
+ * will respond to 100k packages, using NAPI.
+ */
#include <ctype.h>
#include <errno.h>
#include <getopt.h>
@@ -375,7 +389,6 @@ int main(int argc, char *argv[])
else
tsPtr = NULL;
-
// Use realtime scheduler.
setProcessScheduler();