diff --git a/transport-native-io_uring/src/main/c/barrier.h b/transport-native-io_uring/src/main/c/barrier.h deleted file mode 100644 index 6bf035c75c..0000000000 --- a/transport-native-io_uring/src/main/c/barrier.h +++ /dev/null @@ -1,34 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -#ifndef LIBURING_BARRIER_H -#define LIBURING_BARRIER_H - -#include - -/* -From the kernel documentation file refcount-vs-atomic.rst: -A RELEASE memory ordering guarantees that all prior loads and -stores (all po-earlier instructions) on the same CPU are completed -before the operation. It also guarantees that all po-earlier -stores on the same CPU and all propagated stores from other CPUs -must propagate to all other CPUs before the release operation -(A-cumulative property). This is implemented using -:c:func:`smp_store_release`. -An ACQUIRE memory ordering guarantees that all post loads and -stores (all po-later instructions) on the same CPU are -completed after the acquire operation. It also guarantees that all -po-later stores on the same CPU must propagate to all other CPUs -after the acquire operation executes. This is implemented using -:c:func:`smp_acquire__after_ctrl_dep`. -*/ - -#define IO_URING_WRITE_ONCE(var, val) \ - atomic_store_explicit(&(var), (val), memory_order_relaxed) -#define IO_URING_READ_ONCE(var) \ - atomic_load_explicit(&(var), memory_order_relaxed) - -#define io_uring_smp_store_release(p, v) \ - atomic_store_explicit((p), (v), memory_order_release) -#define io_uring_smp_load_acquire(p) \ - atomic_load_explicit((p), memory_order_acquire) - -#endif /* defined(LIBURING_BARRIER_H) */ \ No newline at end of file diff --git a/transport-native-io_uring/src/main/c/io_uring.h b/transport-native-io_uring/src/main/c/io_uring.h index 9e9e9e1a44..fba84d5ff2 100644 --- a/transport-native-io_uring/src/main/c/io_uring.h +++ b/transport-native-io_uring/src/main/c/io_uring.h @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: MIT */ -#include "barrier.h" #include #include #include @@ -44,39 +43,4 @@ struct io_uring { int ring_fd; }; -#define io_uring_for_each_cqe(ring, head, cqe) \ - /* \ - * io_uring_smp_load_acquire() enforces the order of tail \ - * and CQE reads. \ - */ \ - for (head = *(ring)->cq.khead; \ - (cqe = (head != io_uring_smp_load_acquire((ring)->cq.ktail) \ - ? &(ring)->cq.cqes[head & (*(ring)->cq.kring_mask)] \ - : NULL)); \ - head++) - -/* - * Must be called after io_uring_for_each_cqe() - */ -static inline void io_uring_cq_advance(struct io_uring *ring, unsigned nr) { - if (nr) { - struct io_uring_cq *cq = &ring->cq; - - /* - * Ensure that the kernel only sees the new value of the head - * index after the CQEs have been read. - */ - io_uring_smp_store_release(cq->khead, *cq->khead + nr); - } -} - -/* - * Must be called after io_uring_{peek,wait}_cqe() after the cqe has - * been processed by the application. - */ -static void io_uring_cqe_seen(struct io_uring *ring, struct io_uring_cqe *cqe) { - if (cqe) - io_uring_cq_advance(ring, 1); -} - #endif \ No newline at end of file diff --git a/transport-native-io_uring/src/main/c/netty_io_uring_native.c b/transport-native-io_uring/src/main/c/netty_io_uring_native.c index 9636271d3a..b1af413587 100644 --- a/transport-native-io_uring/src/main/c/netty_io_uring_native.c +++ b/transport-native-io_uring/src/main/c/netty_io_uring_native.c @@ -46,6 +46,14 @@ #include #include +#include "netty_unix_buffer.h" +#include "netty_unix_errors.h" +#include "netty_unix_filedescriptor.h" +#include "netty_unix_jni.h" +#include "netty_unix_limits.h" +#include "netty_unix_socket.h" +#include "netty_unix_util.h" + static jmethodID ringBufferMethodId = NULL; static jmethodID ioUringSubmissionQueueMethodId = NULL; static jmethodID ioUringCommpletionQueueMethodId = NULL; @@ -223,12 +231,34 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { dlinfo.dli_fname); return JNI_ERR; } + if (netty_unix_util_register_natives(env, packagePrefix, "io/netty/channel/uring/Native", method_table, method_table_size) != 0) { printf("netty register natives error\n"); } + // Load all c modules that we depend upon + if (netty_unix_limits_JNI_OnLoad(env, packagePrefix) == JNI_ERR) { + goto done; + } + + if (netty_unix_errors_JNI_OnLoad(env, packagePrefix) == JNI_ERR) { + goto done; + } + + if (netty_unix_filedescriptor_JNI_OnLoad(env, packagePrefix) == JNI_ERR) { + goto done; + } + + if (netty_unix_socket_JNI_OnLoad(env, packagePrefix) == JNI_ERR) { + goto done; + } + + if (netty_unix_buffer_JNI_OnLoad(env, packagePrefix) == JNI_ERR) { + goto done; + } + NETTY_PREPEND(packagePrefix, "io/netty/channel/uring/RingBuffer", nettyClassName, done); NETTY_LOAD_CLASS(env, ringBufferClass, nettyClassName, done); diff --git a/transport-native-io_uring/src/main/c/syscall.c b/transport-native-io_uring/src/main/c/syscall.c index 682d185a0c..0d0871b19c 100644 --- a/transport-native-io_uring/src/main/c/syscall.c +++ b/transport-native-io_uring/src/main/c/syscall.c @@ -8,32 +8,6 @@ #include #include -#ifdef __alpha__ -/* - * alpha is the only exception, all other architectures - * have common numbers for new system calls. - */ -#ifndef __NR_io_uring_setup -#define __NR_io_uring_setup 535 -#endif -#ifndef __NR_io_uring_enter -#define __NR_io_uring_enter 536 -#endif -#ifndef __NR_io_uring_register -#define __NR_io_uring_register 537 -#endif -#else /* !__alpha__ */ -#ifndef __NR_io_uring_setup -#define __NR_io_uring_setup 425 -#endif -#ifndef __NR_io_uring_enter -#define __NR_io_uring_enter 426 -#endif -#ifndef __NR_io_uring_register -#define __NR_io_uring_register 427 -#endif -#endif - int sys_io_uring_register(int fd, unsigned opcode, const void *arg, unsigned nr_args) { return syscall(__NR_io_uring_register, fd, opcode, arg, nr_args); diff --git a/transport-native-io_uring/src/main/c/syscall.h b/transport-native-io_uring/src/main/c/syscall.h index 344996f8d9..ffef0b95e2 100644 --- a/transport-native-io_uring/src/main/c/syscall.h +++ b/transport-native-io_uring/src/main/c/syscall.h @@ -7,7 +7,6 @@ /* * System calls */ -// extern int sys_io_uring_setup(unsigned entries, struct io_uring_params *p); extern int sys_io_uring_setup(unsigned entries, struct io_uring_params *p); extern int sys_io_uring_enter(int fd, unsigned to_submit, unsigned min_complete, unsigned flags, sigset_t *sig);