summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornoah <goldstein.n@wustl.edu>2020-12-16 15:48:18 -0500
committernoah <goldstein.n@wustl.edu>2020-12-17 11:09:13 -0500
commit6b951560f4f144d83d740b1333f4822ec82e7650 (patch)
tree126102fa1c90522740018b7d9e9bbc7a668f22c8
parentbd0befa63da9724adb61c6e3fbfb56d91c8537c0 (diff)
downloadliburing-6b951560f4f144d83d740b1333f4822ec82e7650.tar.gz
liburing-6b951560f4f144d83d740b1333f4822ec82e7650.tar.bz2
Added __builtin_expect macros and wrapped IORING_ENTER_SQ_WAKEUP branch
If heavy IO load then kernel thread will only very rarely need to be woken up. Only case where this condition is common is if timeout expected between IO calls in which case should be using GETEVENTS. This will avoid the compiler from optimizing the wakeup branch Signed-off-by: Noah <goldstein.w.n@gmail.com>
-rw-r--r--src/include/liburing.h8
-rw-r--r--src/queue.c9
2 files changed, 13 insertions, 4 deletions
diff --git a/src/include/liburing.h b/src/include/liburing.h
index ebfc424..520cd55 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -15,6 +15,14 @@
#include "liburing/io_uring.h"
#include "liburing/barrier.h"
+#ifndef uring_unlikely
+# define uring_unlikely(cond) __builtin_expect(!!(cond), 0)
+#endif
+
+#ifndef uring_likely
+# define uring_likely(cond) __builtin_expect(!!(cond), 1)
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/src/queue.c b/src/queue.c
index df388f6..8c4f373 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -25,10 +25,11 @@ static inline bool sq_ring_needs_enter(struct io_uring *ring, unsigned *flags)
{
if (!(ring->flags & IORING_SETUP_SQPOLL))
return true;
- if (IO_URING_READ_ONCE(*ring->sq.kflags) & IORING_SQ_NEED_WAKEUP) {
- *flags |= IORING_ENTER_SQ_WAKEUP;
- return true;
- }
+ if (uring_unlikely(IO_URING_READ_ONCE(*ring->sq.kflags) &
+ IORING_SQ_NEED_WAKEUP)) {
+ *flags |= IORING_ENTER_SQ_WAKEUP;
+ return true;
+ }
return false;
}