From 0421c9c751c66941a5bb402ce705aaa0198b71e9 Mon Sep 17 00:00:00 2001 From: Josef Grieb Date: Wed, 23 Sep 2020 09:55:51 +0200 Subject: [PATCH] Some cleanup to make it more readable (#10586) Motivation: some cleanup to make it more readable Modifications: - fix typos - remove cqe kRingMask - remove unused pendingWakeup Result: cleaner code --- .../channel/uring/AbstractIOUringChannel.java | 6 +++++- .../channel/uring/IOUringCompletionQueue.java | 12 ++++++------ .../io/netty/channel/uring/IOUringEventLoop.java | 8 ++------ .../channel/uring/IOUringSubmissionQueue.java | 14 +++++++------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/transport-native-io_uring/src/main/java/io/netty/channel/uring/AbstractIOUringChannel.java b/transport-native-io_uring/src/main/java/io/netty/channel/uring/AbstractIOUringChannel.java index d9ac209f96..fbd4adce43 100644 --- a/transport-native-io_uring/src/main/java/io/netty/channel/uring/AbstractIOUringChannel.java +++ b/transport-native-io_uring/src/main/java/io/netty/channel/uring/AbstractIOUringChannel.java @@ -714,10 +714,14 @@ abstract class AbstractIOUringChannel extends AbstractChannel implements UnixCha } @Override - protected void doDeregister() throws Exception { + protected void doDeregister() { IOUringSubmissionQueue submissionQueue = submissionQueue(); if (submissionQueue != null) { + if ((ioState & (POLL_IN_SCHEDULED | POLL_OUT_SCHEDULED | POLL_RDHUP_SCHEDULED)) == 0) { + ((IOUringEventLoop) eventLoop()).remove(this); + return; + } if ((ioState & POLL_IN_SCHEDULED) != 0) { submissionQueue.addPollRemove(socket.intValue(), Native.POLLIN); } diff --git a/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringCompletionQueue.java b/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringCompletionQueue.java index ecacb6a433..d483fcdc43 100644 --- a/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringCompletionQueue.java +++ b/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringCompletionQueue.java @@ -33,8 +33,8 @@ final class IOUringCompletionQueue { //these unsigned integer pointers(shared with the kernel) will be changed by the kernel private final long kHeadAddress; private final long kTailAddress; - private final long kringMaskAddress; - private final long kringEntries; + private final long kRingMaskAddress; + private final long kRingEntriesAddress; private final long kOverflowAddress; private final long completionQueueArrayAddress; @@ -46,20 +46,20 @@ final class IOUringCompletionQueue { private final int ringMask; private int ringHead; - IOUringCompletionQueue(long kHeadAddress, long kTailAddress, long kringMaskAddress, long kringEntries, + IOUringCompletionQueue(long kHeadAddress, long kTailAddress, long kRingMaskAddress, long kRingEntriesAddress, long kOverflowAddress, long completionQueueArrayAddress, int ringSize, long ringAddress, int ringFd) { this.kHeadAddress = kHeadAddress; this.kTailAddress = kTailAddress; - this.kringMaskAddress = kringMaskAddress; - this.kringEntries = kringEntries; + this.kRingMaskAddress = kRingMaskAddress; + this.kRingEntriesAddress = kRingEntriesAddress; this.kOverflowAddress = kOverflowAddress; this.completionQueueArrayAddress = completionQueueArrayAddress; this.ringSize = ringSize; this.ringAddress = ringAddress; this.ringFd = ringFd; - this.ringMask = PlatformDependent.getIntVolatile(kringMaskAddress); + this.ringMask = PlatformDependent.getIntVolatile(kRingMaskAddress); this.ringHead = PlatformDependent.getIntVolatile(kHeadAddress); } diff --git a/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringEventLoop.java b/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringEventLoop.java index a172c8a07b..3b3bef10af 100644 --- a/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringEventLoop.java +++ b/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringEventLoop.java @@ -57,7 +57,6 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements private final byte[] inet6AddressArray = new byte[16]; private long prevDeadlineNanos = NONE; - private boolean pendingWakeup; IOUringEventLoop(IOUringEventLoopGroup parent, Executor executor, int ringSize, boolean ioseqAsync, RejectedExecutionHandler rejectedExecutionHandler, EventLoopTaskQueueFactory queueFactory) { @@ -168,9 +167,7 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements } } } finally { - if (nextWakeupNanos.get() == AWAKE || nextWakeupNanos.getAndSet(AWAKE) == AWAKE) { - pendingWakeup = true; - } + nextWakeupNanos.set(AWAKE); } } catch (Throwable t) { handleLoopException(t); @@ -224,7 +221,6 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements public void handle(int fd, int res, int flags, int op, int data) { if (op == Native.IORING_OP_READ && eventfd.intValue() == fd) { if (res != Native.ERRNO_ECANCELED_NEGATIVE) { - pendingWakeup = false; addEventFdRead(ringBuffer.ioUringSubmissionQueue()); } } else if (op == Native.IORING_OP_TIMEOUT) { @@ -251,7 +247,7 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements } if (!channel.ioScheduled()) { // We cancelled the POLL ops which means we are done and should remove the mapping. - channels.remove(fd); + remove(channel); return; } } else if (op == Native.IORING_OP_CONNECT) { diff --git a/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringSubmissionQueue.java b/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringSubmissionQueue.java index 14908a651e..ef8973d79c 100644 --- a/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringSubmissionQueue.java +++ b/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringSubmissionQueue.java @@ -48,9 +48,9 @@ final class IOUringSubmissionQueue { //these unsigned integer pointers(shared with the kernel) will be changed by the kernel private final long kHeadAddress; private final long kTailAddress; - private final long fFlagsAdress; + private final long kFlagsAddress; private final long kDroppedAddress; - private final long arrayAddress; + private final long kArrayAddress; final long submissionQueueArrayAddress; final int ringEntries; @@ -66,14 +66,14 @@ final class IOUringSubmissionQueue { private int tail; IOUringSubmissionQueue(long kHeadAddress, long kTailAddress, long kRingMaskAddress, long kRingEntriesAddress, - long fFlagsAdress, long kDroppedAddress, long arrayAddress, long submissionQueueArrayAddress, - int ringSize, long ringAddress, int ringFd, + long kFlagsAddress, long kDroppedAddress, long kArrayAddress, + long submissionQueueArrayAddress, int ringSize, long ringAddress, int ringFd, boolean iosqeAsync, Runnable submissionCallback) { this.kHeadAddress = kHeadAddress; this.kTailAddress = kTailAddress; - this.fFlagsAdress = fFlagsAdress; + this.kFlagsAddress = kFlagsAddress; this.kDroppedAddress = kDroppedAddress; - this.arrayAddress = arrayAddress; + this.kArrayAddress = kArrayAddress; this.submissionQueueArrayAddress = submissionQueueArrayAddress; this.ringSize = ringSize; this.ringAddress = ringAddress; @@ -90,7 +90,7 @@ final class IOUringSubmissionQueue { PlatformDependent.setMemory(submissionQueueArrayAddress, ringEntries * SQE_SIZE, (byte) 0); // Fill SQ array indices (1-1 with SQE array) and set nonzero constant SQE fields - long address = arrayAddress; + long address = kArrayAddress; long sqeFlagsAddress = submissionQueueArrayAddress + SQE_FLAGS_FIELD; byte flag = iosqeAsync ? (byte) Native.IOSQE_ASYNC : 0; for (int i = 0; i < ringEntries; i++, address += INT_SIZE, sqeFlagsAddress += SQE_SIZE) {