Skip to contentSkip to conversation

liburing.h helpers cleanup

PATCH Applied Pavel Begunkov 2 participants 4 messages Aug 25, 2021 io_uring

lore
Share & tools
lore
#0 lore raw

cover liburing.h helpers cleanup

Add a helper for preparing multishot poll requests + a poll mask conversion cleanup.

Pavel Begunkov (2):
liburing.h: add a multipoll helper
liburing.h: dedup poll mask conversion

 src/include/liburing.h   | 25 +++++++++++++++++--------
 test/poll-mshot-update.c |  3 +--
 2 files changed, 18 insertions(+), 10 deletions(-)
Signature · 1 line
2.32.0
#1 lore raw

PATCH 1/2 liburing.h: add a multipoll helper

Add a helper for preparing a multipoll request and use it in a test.

---
 src/include/liburing.h   | 7 +++++++
 test/poll-mshot-update.c | 3 +--
 2 files changed, 8 insertions(+), 2 deletions(-)
src/include/liburing.h +7 -0
index f073e25..d20dd25 100644
@@ -323,6 +323,13 @@ static inline void io_uring_prep_poll_add(struct io_uring_sqe *sqe, int fd,
 	sqe->poll32_events = poll_mask;
 }
 
+static inline void io_uring_prep_poll_multishot(struct io_uring_sqe *sqe,
+						int fd, unsigned poll_mask)
+{
+	io_uring_prep_poll_add(sqe, fd, poll_mask);
+	sqe->len = IORING_POLL_ADD_MULTI;
+}
+
 static inline void io_uring_prep_poll_remove(struct io_uring_sqe *sqe,
 					     void *user_data)
 {
test/poll-mshot-update.c +1 -2
index 6bf4679..75ee52f 100644
@@ -70,8 +70,7 @@ static int arm_poll(struct io_uring *ring, int off)
 		return 1;
 	}
 
-	io_uring_prep_poll_add(sqe, p[off].fd[0], POLLIN);
-	sqe->len = IORING_POLL_ADD_MULTI;
+	io_uring_prep_poll_multishot(sqe, p[off].fd[0], POLLIN);
 	sqe->user_data = off;
 	return 0;
 }
Signature · 1 line
2.32.0
#2 lore raw

PATCH 2/2 liburing.h: dedup poll mask conversion

In reply to Pavel Begunkov

Poll mask LE/BE translation is ugly enough to want to hide it in a helper and not hand code many times.

---
 src/include/liburing.h | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
src/include/liburing.h +10 -8
index d20dd25..0ec07ee 100644
@@ -313,14 +313,19 @@ static inline void io_uring_prep_sendmsg(struct io_uring_sqe *sqe, int fd,
 	sqe->msg_flags = flags;
 }
 
-static inline void io_uring_prep_poll_add(struct io_uring_sqe *sqe, int fd,
-					  unsigned poll_mask)
+static inline unsigned __io_uring_prep_poll_mask(unsigned poll_mask)
 {
-	io_uring_prep_rw(IORING_OP_POLL_ADD, sqe, fd, NULL, 0, 0);
 #if __BYTE_ORDER == __BIG_ENDIAN
 	poll_mask = __swahw32(poll_mask);
 #endif
-	sqe->poll32_events = poll_mask;
+	return poll_mask;
+}
+
+static inline void io_uring_prep_poll_add(struct io_uring_sqe *sqe, int fd,
+					  unsigned poll_mask)
+{
+	io_uring_prep_rw(IORING_OP_POLL_ADD, sqe, fd, NULL, 0, 0);
+	sqe->poll32_events = __io_uring_prep_poll_mask(poll_mask);
 }
 
 static inline void io_uring_prep_poll_multishot(struct io_uring_sqe *sqe,
@@ -343,10 +348,7 @@ static inline void io_uring_prep_poll_update(struct io_uring_sqe *sqe,
 {
 	io_uring_prep_rw(IORING_OP_POLL_REMOVE, sqe, -1, old_user_data, flags,
 			 (__u64)(uintptr_t)new_user_data);
-#if __BYTE_ORDER == __BIG_ENDIAN
-	poll_mask = __swahw32(poll_mask);
-#endif
-	sqe->poll32_events = poll_mask;
+	sqe->poll32_events = __io_uring_prep_poll_mask(poll_mask);
 }
 
 static inline void io_uring_prep_fsync(struct io_uring_sqe *sqe, int fd,
Signature · 1 line
2.32.0
maintainer Applied
#3 lore raw
In reply to Pavel Begunkov
Quoted 10 lines · Pavel Begunkov

Add a helper for preparing multishot poll requests + a poll mask conversion cleanup.

Pavel Begunkov (2):
liburing.h: add a multipoll helper
liburing.h: dedup poll mask conversion

 src/include/liburing.h   | 25 +++++++++++++++++--------
 test/poll-mshot-update.c |  3 +--
 2 files changed, 18 insertions(+), 10 deletions(-)

Applied, thanks.

Signature · 1 line
Jens Axboe