GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — IoUring: Pass IORING_ENTER_NO_IOWAIT to report accurate CPU usage (#1… · netty/netty@a98360a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • transport-classes-io_uring/src/main/java/io/netty/channel/uring
    • IoUring.java
    • Native.java
    • SubmissionQueue.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUring.java‎

Copy file name to clipboardExpand all lines: transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUring.java
+28-4Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ public final class IoUring {
4848
private static final boolean IORING_SETUP_NO_SQARRAY_SUPPORTED;
4949
private static final boolean IORING_REGISTER_BUFFER_RING_SUPPORTED;
5050
private static final boolean IORING_REGISTER_BUFFER_RING_INC_SUPPORTED;
51+
private static final boolean IORING_ENTER_NO_IOWAIT_SUPPORTED;
5152
private static final boolean IORING_ACCEPT_MULTISHOT_ENABLED;
5253
private static final boolean IORING_RECV_MULTISHOT_ENABLED;
5354
private static final boolean IORING_RECVSEND_BUNDLE_ENABLED;
5455
private static final boolean IORING_POLL_ADD_MULTISHOT_ENABLED;
56+
private static final boolean IORING_ENTER_NO_IOWAIT_ENABLED;
5557
static final int NUM_ELEMENTS_IOVEC;
5658
static final int DEFAULT_RING_SIZE;
5759
static final int DEFAULT_CQ_SIZE;
@@ -81,6 +83,7 @@ public final class IoUring {
8183
boolean noSqarraySupported = false;
8284
boolean registerBufferRingSupported = false;
8385
boolean registerBufferRingIncSupported = false;
86+
boolean enterNoIoWaitSupported = false;
8487
int numElementsIoVec = 10;
8588
int pendingOpsInitialCapacity;
8689

@@ -108,8 +111,9 @@ public final class IoUring {
108111
socketNonEmptySupported = Native.isCqeFSockNonEmptySupported(ioUringProbe);
109112
spliceSupported = Native.isSpliceSupported(ioUringProbe);
110113
recvsendBundleSupported = (ringBuffer.features() & Native.IORING_FEAT_RECVSEND_BUNDLE) != 0;
114+
enterNoIoWaitSupported = (ringBuffer.features() & Native.IORING_FEAT_NO_IOWAIT) != 0;
111115
sendZcSupported = Native.isSendZcSupported(ioUringProbe);
112-
sendmsgZcSupported = Native.isSendmsgZcSupported(ioUringProbe);
116+
sendmsgZcSupported = Native.isSendmsgZcSupported(ioUringProbe);
113117
// IORING_FEAT_RECVSEND_BUNDLE was added in the same release.
114118
acceptSupportNoWait = recvsendBundleSupported;
115119

@@ -162,6 +166,7 @@ public final class IoUring {
162166
IORING_SETUP_NO_SQARRAY_SUPPORTED = noSqarraySupported;
163167
IORING_REGISTER_BUFFER_RING_SUPPORTED = registerBufferRingSupported;
164168
IORING_REGISTER_BUFFER_RING_INC_SUPPORTED = registerBufferRingIncSupported;
169+
IORING_ENTER_NO_IOWAIT_SUPPORTED = enterNoIoWaitSupported;
165170

166171
IORING_ACCEPT_MULTISHOT_ENABLED = IORING_ACCEPT_MULTISHOT_SUPPORTED && SystemPropertyUtil.getBoolean(
167172
"io.netty.iouring.acceptMultiShotEnabled", true);
@@ -173,10 +178,12 @@ public final class IoUring {
173178
IORING_RECVSEND_BUNDLE_ENABLED = IORING_RECVSEND_BUNDLE_SUPPORTED && SystemPropertyUtil.getBoolean(
174179
"io.netty.iouring.recvsendBundleEnabled", false);
175180
IORING_POLL_ADD_MULTISHOT_ENABLED = IORING_POLL_ADD_MULTISHOT_SUPPORTED && SystemPropertyUtil.getBoolean(
176-
"io.netty.iouring.pollAddMultishotEnabled", true);
181+
"io.netty.iouring.pollAddMultishotEnabled", true);
182+
IORING_ENTER_NO_IOWAIT_ENABLED = IORING_ENTER_NO_IOWAIT_SUPPORTED && SystemPropertyUtil.getBoolean(
183+
"io.netty.iouring.enterNoIoWaitEnabled", false);
177184
NUM_ELEMENTS_IOVEC = numElementsIoVec;
178185

179-
DEFAULT_RING_SIZE = Math.max(16, SystemPropertyUtil.getInt("io.netty.iouring.ringSize", 128));
186+
DEFAULT_RING_SIZE = Math.max(16, SystemPropertyUtil.getInt("io.netty.iouring.ringSize", 128));
180187
pendingOpsInitialCapacity = SystemPropertyUtil.getInt(
181188
"io.netty.iouring.pendingOpsInitialCapacity", DEFAULT_RING_SIZE);
182189
if (pendingOpsInitialCapacity <= 0) {
@@ -313,6 +320,7 @@ static boolean isSetupDeferTaskrunSupported() {
313320
static boolean isIoringSetupNoSqarraySupported() {
314321
return IORING_SETUP_NO_SQARRAY_SUPPORTED;
315322
}
323+
316324
/**
317325
* Returns if it is supported to use a buffer ring.
318326
*
@@ -331,6 +339,21 @@ public static boolean isRegisterBufferRingIncSupported() {
331339
return IORING_REGISTER_BUFFER_RING_INC_SUPPORTED;
332340
}
333341

342+
static boolean isIoringEnterNoIoWaitSupported() {
343+
return IORING_ENTER_NO_IOWAIT_SUPPORTED;
344+
}
345+
346+
/**
347+
* Returns if {@code IORING_ENTER_NO_IOWAIT} is used or not. When enabled (and supported by the kernel),
348+
* idle io_uring_enter(2) waits are not accounted as iowait, which makes server-side CPU metrics more
349+
* accurate but also suppresses the cpufreq governor's iowait boost.
350+
*
351+
* @return {@code true} if enabled, {@code false} otherwise.
352+
*/
353+
public static boolean isIoringEnterNoIoWaitEnabled() {
354+
return IORING_ENTER_NO_IOWAIT_ENABLED;
355+
}
356+
334357
/**
335358
* Returns if multi-shot ACCEPT is used or not.
336359
*
@@ -410,7 +433,8 @@ private static String supportedFeatures() {
410433
+ ", REGISTER_BUFFER_RING_SUPPORTED=" + IORING_REGISTER_BUFFER_RING_SUPPORTED
411434
+ ", REGISTER_BUFFER_RING_INC_SUPPORTED=" + IORING_REGISTER_BUFFER_RING_INC_SUPPORTED
412435
+ ", SEND_ZC_SUPPORTED=" + IORING_SEND_ZC_SUPPORTED
413-
+ ", SENDMSG_ZC_SUPPORTED=" + IORING_SENDMSG_ZC_SUPPORTED;
436+
+ ", SENDMSG_ZC_SUPPORTED=" + IORING_SENDMSG_ZC_SUPPORTED
437+
+ ", ENTER_NO_IOWAIT_SUPPORTED=" + IORING_ENTER_NO_IOWAIT_SUPPORTED;
414438
}
415439

416440
/**
Collapse file

‎transport-classes-io_uring/src/main/java/io/netty/channel/uring/Native.java‎

Copy file name to clipboardExpand all lines: transport-classes-io_uring/src/main/java/io/netty/channel/uring/Native.java
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ final class Native {
253253
static final int IORING_FEAT_NODROP = 1 << 1;
254254
static final int IORING_FEAT_SUBMIT_STABLE = 1 << 2;
255255
static final int IORING_FEAT_RECVSEND_BUNDLE = 1 << 14;
256+
static final int IORING_FEAT_NO_IOWAIT = 1 << 17;
256257

257258
static final int IORING_SQ_NEED_WAKEUP = 1 << 0;
258259
static final int IORING_SQ_CQ_OVERFLOW = 1 << 1;
@@ -316,6 +317,7 @@ static String opToStr(byte op) {
316317

317318
static final int IORING_ENTER_GETEVENTS = NativeStaticallyReferencedJniMethods.ioringEnterGetevents();
318319
static final int IORING_ENTER_REGISTERED_RING = 1 << 4;
320+
static final int IORING_ENTER_NO_IOWAIT = 1 << 7;
319321
static final int IOSQE_ASYNC = NativeStaticallyReferencedJniMethods.iosqeAsync();
320322
static final int IOSQE_LINK = NativeStaticallyReferencedJniMethods.iosqeLink();
321323
static final int IOSQE_IO_DRAIN = NativeStaticallyReferencedJniMethods.iosqeDrain();
Collapse file

‎transport-classes-io_uring/src/main/java/io/netty/channel/uring/SubmissionQueue.java‎

Copy file name to clipboardExpand all lines: transport-classes-io_uring/src/main/java/io/netty/channel/uring/SubmissionQueue.java
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,19 @@ void tryRegisterRingFd() {
115115
// Try to use IORING_REGISTER_RING_FDS.
116116
// See https://manpages.debian.org/unstable/liburing-dev/io_uring_register.2.en.html#IORING_REGISTER_RING_FDS
117117
int enterRingFd = Native.ioUringRegisterRingFds(ringFd);
118-
final int enterFlags;
118+
int enterFlags;
119119
if (enterRingFd < 0) {
120120
// Use of IORING_REGISTER_RING_FDS failed, just use the ring fd directly.
121121
enterRingFd = ringFd;
122122
enterFlags = 0;
123123
} else {
124124
enterFlags = Native.IORING_ENTER_REGISTERED_RING;
125125
}
126+
// Opt out of iowait accounting while waiting on CQEs for pure networking workloads.
127+
// See https://github.com/netty/netty/issues/16655
128+
if (IoUring.isIoringEnterNoIoWaitEnabled()) {
129+
enterFlags |= Native.IORING_ENTER_NO_IOWAIT;
130+
}
126131
this.enterRingFd = enterRingFd;
127132
this.enterFlags = enterFlags;
128133
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.