Poll & tests cleanups

Motivation:

we should remove pollIn link, as we don't use pollIn linking anymore

Modification:

-some cleanups in the tests and in IOUring
-pollIn linking was removed

Result:

clean code
This commit is contained in:
Josef Grieb 2020-08-29 10:40:17 +02:00
parent 356ce5fdc0
commit 9a5449a790
8 changed files with 33 additions and 15 deletions

View File

@ -368,7 +368,7 @@ abstract class AbstractIOUringChannel extends AbstractChannel implements UnixCha
pollInScheduled = true;
IOUringEventLoop ioUringEventLoop = (IOUringEventLoop) eventLoop();
IOUringSubmissionQueue submissionQueue = ioUringEventLoop.getRingBuffer().getIoUringSubmissionQueue();
submissionQueue.addPollInLink(socket.intValue());
submissionQueue.addPollIn(socket.intValue());
submissionQueue.submit();
}

View File

@ -29,7 +29,7 @@ final class IOUring {
static final int OP_POLL_REMOVE = 7;
static final int OP_CONNECT = 16;
static final int POLLMASK_IN_LINK = 1;
static final int POLLMASK_IN = 1;
static final int POLLMASK_OUT_LINK = 4;
static final int POLLMASK_RDHUP = 8192;
static final int POLLMASK_OUT = 4;

View File

@ -18,7 +18,6 @@ package io.netty.channel.uring;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.SingleThreadEventLoop;
import io.netty.channel.unix.FileDescriptor;
import io.netty.channel.uring.AbstractIOUringChannel.AbstractUringUnsafe;
import io.netty.util.collection.IntObjectHashMap;
import io.netty.util.collection.IntObjectMap;
import io.netty.util.internal.PlatformDependent;
@ -30,8 +29,6 @@ import java.util.Queue;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicLong;
import static io.netty.channel.unix.Errors.*;
final class IOUringEventLoop extends SingleThreadEventLoop implements
IOUringCompletionQueue.IOUringCompletionQueueCallback {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(IOUringEventLoop.class);
@ -118,7 +115,7 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements
final IOUringSubmissionQueue submissionQueue = ringBuffer.getIoUringSubmissionQueue();
// Lets add the eventfd related events before starting to do any real work.
submissionQueue.addPollInLink(eventfd.intValue());
submissionQueue.addPollIn(eventfd.intValue());
submissionQueue.submit();
for (; ; ) {
@ -232,7 +229,7 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements
// an extra eventfd_write(....)
Native.eventFdRead(eventfd.intValue());
submissionQueue.addPollInLink(eventfd.intValue());
submissionQueue.addPollIn(eventfd.intValue());
// Submit so its picked up
submissionQueue.submit();
} else {
@ -241,7 +238,7 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements
break;
}
switch (pollMask) {
case IOUring.POLLMASK_IN_LINK:
case IOUring.POLLMASK_IN:
((AbstractIOUringChannel.AbstractUringUnsafe) channel.unsafe()).pollIn(res);
break;
case IOUring.POLLMASK_OUT:

View File

@ -119,7 +119,7 @@ final class IOUringSubmissionQueue {
//user_data should be same as POLL_LINK fd
if (op == IOUring.OP_POLL_REMOVE) {
PlatformDependent.putInt(sqe + SQE_FD_FIELD, -1);
long pollLinkuData = convertToUserData((byte) IOUring.IO_POLL, fd, IOUring.POLLMASK_IN_LINK);
long pollLinkuData = convertToUserData((byte) IOUring.IO_POLL, fd, IOUring.POLLMASK_IN);
PlatformDependent.putLong(sqe + SQE_ADDRESS_FIELD, pollLinkuData);
}
@ -127,7 +127,7 @@ final class IOUringSubmissionQueue {
PlatformDependent.putLong(sqe + SQE_USER_DATA_FIELD, uData);
//poll<link>read or accept operation
if (op == 6 && (pollMask == IOUring.POLLMASK_OUT_LINK || pollMask == IOUring.POLLMASK_IN_LINK)) {
if (op == 6 && (pollMask == IOUring.POLLMASK_OUT_LINK)) {
PlatformDependent.putByte(sqe + SQE_FLAGS_FIELD, (byte) IOSQE_IO_LINK);
} else {
PlatformDependent.putByte(sqe + SQE_FLAGS_FIELD, (byte) 0);
@ -170,8 +170,8 @@ final class IOUringSubmissionQueue {
return true;
}
public boolean addPollInLink(int fd) {
return addPoll(fd, IOUring.POLLMASK_IN_LINK);
public boolean addPollIn(int fd) {
return addPoll(fd, IOUring.POLLMASK_IN);
}
public boolean addPollOutLink(int fd) {

View File

@ -19,9 +19,12 @@ import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.testsuite.transport.TestsuitePermutation.BootstrapComboFactory;
import io.netty.testsuite.transport.socket.SocketEchoTest;
import org.junit.BeforeClass;
import java.util.List;
import static org.junit.Assume.assumeTrue;
public class IOUringSocketEchoTest extends SocketEchoTest {
@Override

View File

@ -19,9 +19,12 @@ import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketFixedLengthEchoTest;
import org.junit.BeforeClass;
import java.util.List;
import static org.junit.Assume.assumeTrue;
public class IOUringSocketFixedLengthEchoTest extends SocketFixedLengthEchoTest {
@Override

View File

@ -16,6 +16,7 @@
package io.netty.channel.uring;
import io.netty.channel.unix.FileDescriptor;
import org.junit.BeforeClass;
import org.junit.Test;
import java.nio.charset.Charset;
@ -24,11 +25,17 @@ import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.UnpooledByteBufAllocator;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;
import io.netty.buffer.ByteBuf;
public class NativeTest {
@BeforeClass
public static void loadJNI() {
assumeTrue(IOUring.isAvailable());
}
@Test
public void canWriteFile() throws Exception {
ByteBufAllocator allocator = new UnpooledByteBufAllocator(true);
@ -137,7 +144,7 @@ public class NativeTest {
assertNotNull(completionQueue);
final FileDescriptor eventFd = Native.newEventFd();
assertTrue(submissionQueue.addPollInLink(eventFd.intValue()));
assertTrue(submissionQueue.addPollIn(eventFd.intValue()));
submissionQueue.submit();
new Thread() {
@ -195,7 +202,7 @@ public class NativeTest {
};
waitingCqe.start();
final FileDescriptor eventFd = Native.newEventFd();
assertTrue(submissionQueue.addPollInLink(eventFd.intValue()));
assertTrue(submissionQueue.addPollIn(eventFd.intValue()));
submissionQueue.submit();
new Thread() {
@ -223,7 +230,7 @@ public class NativeTest {
final IOUringCompletionQueue completionQueue = ringBuffer.getIoUringCompletionQueue();
FileDescriptor eventFd = Native.newEventFd();
submissionQueue.addPollInLink(eventFd.intValue());
submissionQueue.addPollIn(eventFd.intValue());
submissionQueue.submit();
Thread.sleep(10);

View File

@ -11,10 +11,18 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assume.assumeTrue;
public class PollRemoveTest {
@BeforeClass
public static void loadJNI() {
assumeTrue(IOUring.isAvailable());
}
@Sharable
class EchoUringServerHandler extends ChannelInboundHandlerAdapter {