Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement liburing methods #1

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
dec713c
Merge pull request #1 from armanbilge/main
josgarmar28 Jun 6, 2024
ccaa1ee
feat: prep methods
josgarmar28 Jun 13, 2024
d0223c6
feat: io_uring_queue_init first iteration and structure code
josgarmar28 Jun 19, 2024
5628ab3
chore: avoid memory allocations and implement io_uring_queue_exit
josgarmar28 Jun 25, 2024
525062c
feat: structure lib and rewrite liburing methods
josgarmar28 Jul 6, 2024
e202b53
refactor: add methods to get MemorySegments
josgarmar28 Jul 6, 2024
74c9da9
chore: create playgrounds
josgarmar28 Jul 8, 2024
1a49e49
chore: ofAddress playground
josgarmar28 Jul 8, 2024
6e95d2b
chore: apply reinterpret memory logic
josgarmar28 Jul 9, 2024
54b22b3
chore: compare segments logic
josgarmar28 Jul 11, 2024
ccc098f
fix: minor improvements
josgarmar28 Jul 12, 2024
20ce4c2
refactor: lib API and pre allocation logic
josgarmar28 Jul 20, 2024
3f59c5a
chore: constants depending on system arch
josgarmar28 Jul 20, 2024
da8afea
chore: sort code and logic fixes
josgarmar28 Jul 21, 2024
5ea3548
chore: sample test
josgarmar28 Jul 22, 2024
b150cf4
fix: align io_uring layouts
josgarmar28 Jul 24, 2024
5dacb6f
fix: ValueLayout.ADDRESS manipulation
josgarmar28 Jul 24, 2024
44bf770
fix: address segments needed to be reinterpreted
josgarmar28 Jul 24, 2024
3a21185
chore: test 7ad0e4b2f83c
josgarmar28 Jul 28, 2024
7e85238
fix: errors related to 7ad0e4b2f83c test
josgarmar28 Jul 29, 2024
5faa30c
chore: add more tests
josgarmar28 Aug 1, 2024
ca26009
fix: test link minor error
josgarmar28 Aug 4, 2024
5445d2f
chore: minor changes
josgarmar28 Aug 5, 2024
8350f98
Merge pull request #2 from josgarmar28/feat/implement-liburing-methods
josgarmar28 Aug 5, 2024
2581340
feat: add constructors not using Arena
josgarmar28 Aug 7, 2024
4da8575
Merge pull request #3 from josgarmar28/feat/implement-liburing-methods
josgarmar28 Aug 7, 2024
3c90eb9
Merge branch 'armanbilge:main' into main
josgarmar28 Aug 7, 2024
9d21f59
refactor: prep methods API
josgarmar28 Sep 15, 2024
625fd0c
Add junit library to dependencies
antoniojimeneznieto Sep 16, 2024
3abce15
Add testClass
antoniojimeneznieto Sep 16, 2024
f1b367a
chore: rewrite tests
josgarmar28 Sep 16, 2024
621f952
Merge branch 'main' into feat/implement-liburing-methods
josgarmar28 Sep 16, 2024
5b434e8
refactor: update VarHandle API
josgarmar28 Sep 17, 2024
3eaa23c
Merge pull request #4 from josgarmar28/feat/implement-liburing-methods
josgarmar28 Sep 17, 2024
ad5fe1b
chore: update to jdk-23
josgarmar28 Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ native_amd64_task:
- echo "deb [signed-by=/usr/share/keyrings/azul.gpg] https://repos.azul.com/zulu/deb stable main" | tee /etc/apt/sources.list.d/zulu.list
- apt-get update && apt-get install -y build-essential clang zulu22-jdk
- git clone https://github.com/axboe/liburing.git && cd liburing && ./configure && make && sudo make install && cd ..
- wget -q https://github.com/sbt/sbt/releases/download/v1.10.0/sbt-1.10.0.tgz && tar xvfz sbt-1.10.0.tgz
- wget -q https://github.com/sbt/sbt/releases/download/v1.10.2/sbt-1.10.2.tgz && tar xvfz sbt-1.10.2.tgz
- sbt/bin/sbt test
10 changes: 7 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ ThisBuild / developers += tlGitHubDev("armanbilge", "Arman Bilge")
ThisBuild / startYear := Some(2024)
ThisBuild / tlSonatypeUseLegacyHost := false

ThisBuild / tlJdkRelease := Some(22)
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("22"))
ThisBuild / tlJdkRelease := Some(23)
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("23"))

ThisBuild / githubWorkflowBuild ~= { steps =>
steps.flatMap {
Expand All @@ -26,9 +26,13 @@ ThisBuild / githubWorkflowPublishPreamble +=
)

name := "cheshire"
libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.3" % Test

libraryDependencies += "com.github.sbt" % "junit-interface" % "0.13.2" % Test
testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "-v")

// Java library
crossPaths := false
autoScalaLibrary := false
Compile / compileOrder := CompileOrder.JavaThenScala
Compile / doc / javacOptions -= "-Xlint:all"
Test / doc / javacOptions -= "-Xlint:all"
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.10.1
sbt.version=1.10.2
55 changes: 55 additions & 0 deletions src/main/java/cheshire/__kernel_timespec.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cheshire;

import java.lang.foreign.Arena;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemoryLayout.PathElement;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.VarHandle;

public class __kernel_timespec {

public MemorySegment segment;

public __kernel_timespec(Arena session) {
this.segment = session.allocate(layout);
};

public __kernel_timespec(MemorySegment s) {
this.segment = s;
};

public __kernel_timespec() {
try (Arena session = Arena.ofShared()) {
this.segment = session.allocate(layout);
} catch (Throwable cause) {
throw new RuntimeException(cause);
}
};

public static final GroupLayout layout = MemoryLayout.structLayout(
ValueLayout.JAVA_LONG.withName("tv_sec"),
ValueLayout.JAVA_LONG.withName("tv_nsec"))
.withName("__kernel_timespec");

private static VarHandle tvSecVarHandle = layout.varHandle(PathElement.groupElement("tv_sec"));
private static VarHandle tvNsecVarHandle = layout.varHandle(PathElement.groupElement("tv_nsec"));

public static long getTvSec(MemorySegment data) {
return (long) tvSecVarHandle.get(data, 0);
};

public static void setTvSec(MemorySegment data, long value) {
tvSecVarHandle.set(data, 0, value);
};

public static long getTvNsec(MemorySegment data) {
return (long) tvNsecVarHandle.get(data, 0);
};

public static void setTvNsec(MemorySegment data, long value) {
tvNsecVarHandle.set(data, 0, value);
};

};
98 changes: 98 additions & 0 deletions src/main/java/cheshire/constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package cheshire;

public final class constants {

public static final int INT_FLAG_REG_RING = 1;
public static final int INT_FLAG_REG_REG_RING = 2;
public static final int INT_FLAG_APP_MEM = 4;

public static final int IORING_ENTER_GETEVENTS = 1 << 0;
public static final int IORING_ENTER_SQ_WAKEUP = 1 << 1;
public static final int IORING_ENTER_EXT_ARG = 1 << 3;
public static final int IORING_ENTER_REGISTERED_RING = 1 << 4;

public static final int IORING_FEAT_SINGLE_MMAP = 1 << 0;
public static final int IORING_FEAT_EXT_ARG = 1 << 8;

public static final long IORING_OFF_CQ_RING = 0x8000000L;
public static final long IORING_OFF_SQ_RING = 0L;
public static final long IORING_OFF_SQES = 0x10000000L;

public static final int IORING_OP_NOP = 0;
public static final int IORING_OP_TIMEOUT = 11;
public static final int IORING_OP_ACCEPT = 13;
public static final int IORING_OP_ASYNC_CANCEL = 14;
public static final int IORING_OP_CONNECT = 16;
public static final int IORING_OP_CLOSE = 19;
public static final int IORING_OP_RECV = 27;
public static final int IORING_OP_SEND = 26;
public static final int IORING_OP_SHUTDOWN = 34;
public static final int IORING_OP_SOCKET = 45;

public static final int IORING_REGISTER_USE_REGISTERED_RING = 1 << 31;
public static final int IORING_UNREGISTER_RING_FDS = 21;

public static final int IORING_SETUP_IOPOLL = 1 << 0;
public static final int IORING_SETUP_SQPOLL = 1 << 1;
public static final int IORING_SETUP_CQSIZE = 1 << 3;
public static final int IORING_SETUP_CLAMP = 1 << 4;
public static final int IORING_SETUP_SUBMIT_ALL = 1 << 7;
public static final int IORING_SETUP_COOP_TASKRUN = 1 << 8;
public static final int IORING_SETUP_TASKRUN_FLAG = 1 << 9;
public static final int IORING_SETUP_SQE128 = 1 << 10;
public static final int IORING_SETUP_CQE32 = 1 << 11;
public static final int IORING_SETUP_SINGLE_ISSUER = 1 << 12;
public static final int IORING_SETUP_DEFER_TASKRUN = 1 << 13;
public static final int IORING_SETUP_NO_MMAP = 1 << 14;
public static final int IORING_SETUP_REGISTERED_FD_ONLY = 1 << 15;
public static final int IORING_SETUP_NO_SQARRAY = 1 << 16;

public static final int IORING_SQ_NEED_WAKEUP = 1 << 0;
public static final int IORING_SQ_CQ_OVERFLOW = 1 << 1;
public static final int IORING_SQ_TASKRUN = 1 << 2;

public static final int KERN_MAX_ENTRIES = 32768;
public static final int KERN_MAX_CQ_ENTRIES = (2 * KERN_MAX_ENTRIES);

public static final long LIBURING_UDATA_TIMEOUT = 0xFFFFFFFFFFFFFFFFL;

public static final int MAP_ANONYMOUS = 0x20;
public static final int MAP_HUGETLB = 0x0040000;
public static final int MAP_POPULATE = 0x8000;
public static final int MAP_SHARED = 0x01;

public static final int PROT_READ = 0x1;
public static final int PROT_WRITE = 0x2;

public static final int ENOMEM = 5;
public static final int EAGAIN = 11;
public static final int EINVAL = 22;
public static final int ETIME = 62;
public static final long MAP_FAILED = -1L;
public static final long EADDRESS = -4095L;

// Review
public static final int _NSIG = 64;

public static final int __NR_io_uring_setup;
public static final int __NR_io_uring_enter;
public static final int __NR_io_uring_register;
public static final int __NR_Linux = 4000;

static {
String arch = System.getProperty("os.arch");
if ("alpha".equals(arch)) {
__NR_io_uring_setup = 535;
__NR_io_uring_enter = 536;
__NR_io_uring_register = 537;
} else if ("mips".equals(arch)) {
__NR_io_uring_setup = __NR_Linux + 425;
__NR_io_uring_enter = __NR_Linux + 426;
__NR_io_uring_register = __NR_Linux + 427;
} else {
__NR_io_uring_setup = 425;
__NR_io_uring_enter = 426;
__NR_io_uring_register = 427;
}
}
}
77 changes: 77 additions & 0 deletions src/main/java/cheshire/get_data.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package cheshire;

import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemoryLayout.PathElement;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.VarHandle;

public class get_data {

public static final GroupLayout layout = MemoryLayout.structLayout(
ValueLayout.JAVA_INT.withName("submit"),
ValueLayout.JAVA_INT.withName("wait_nr"),
ValueLayout.JAVA_INT.withName("get_flags"),
ValueLayout.JAVA_INT.withName("sz"),
ValueLayout.JAVA_INT.withName("has_ts"),
MemoryLayout.paddingLayout(4),
ValueLayout.ADDRESS.withName("arg"))
.withName("get_data");

private static VarHandle submitVarHandle = layout.varHandle(PathElement.groupElement("submit"));
private static VarHandle waitNrVarHandle = layout.varHandle(PathElement.groupElement("wait_nr"));
private static VarHandle getFlagsVarHandle = layout.varHandle(PathElement.groupElement("get_flags"));
private static VarHandle szVarHandle = layout.varHandle(PathElement.groupElement("sz"));
private static VarHandle hasTsVarHandle = layout.varHandle(PathElement.groupElement("has_ts"));
private static VarHandle argVarHandle = layout.varHandle(PathElement.groupElement("arg"));

public static int getSubmit(MemorySegment data) {
return (int) submitVarHandle.get(data, 0);
};

public static void setSubmit(MemorySegment data, int value) {
submitVarHandle.set(data, 0, value);
};

public static int getWaitNr(MemorySegment data) {
return (int) waitNrVarHandle.get(data, 0);
};

public static void setWaitNr(MemorySegment data, int value) {
waitNrVarHandle.set(data, 0, value);
};

public static int getGetFlags(MemorySegment data) {
return (int) getFlagsVarHandle.get(data, 0);
};

public static void setGetFlags(MemorySegment data, int value) {
getFlagsVarHandle.set(data, 0, value);
};

public static int getSz(MemorySegment data) {
return (int) szVarHandle.get(data, 0);
};

public static void setSz(MemorySegment data, int value) {
szVarHandle.set(data, 0, value);
};

public static int getHasTs(MemorySegment data) {
return (int) hasTsVarHandle.get(data, 0);
};

public static void setHasTs(MemorySegment data, int value) {
hasTsVarHandle.set(data, 0, value);
};

public static MemorySegment getArg(MemorySegment data) {
return (MemorySegment) argVarHandle.get(data, 0);
};

public static void setArg(MemorySegment data, MemorySegment value) {
argVarHandle.set(data, 0, value);
};

};
97 changes: 97 additions & 0 deletions src/main/java/cheshire/io_cqring_offsets.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package cheshire;

import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.MemoryLayout.PathElement;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.VarHandle;

public final class io_cqring_offsets {

public static final GroupLayout layout = MemoryLayout.structLayout(
ValueLayout.JAVA_INT.withName("head"),
ValueLayout.JAVA_INT.withName("tail"),
ValueLayout.JAVA_INT.withName("ring_mask"),
ValueLayout.JAVA_INT.withName("ring_entries"),
ValueLayout.JAVA_INT.withName("overflow"),
ValueLayout.JAVA_INT.withName("cqes"),
ValueLayout.JAVA_INT.withName("flags"),
ValueLayout.JAVA_INT.withName("resv1"),
ValueLayout.JAVA_LONG.withName("user_addr"))
.withName("io_cqring_offsets");

private static VarHandle headVarHandle = layout.varHandle(PathElement.groupElement("head"));
private static VarHandle tailVarHandle = layout.varHandle(PathElement.groupElement("tail"));
private static VarHandle ringMaskVarHandle = layout.varHandle(PathElement.groupElement("ring_mask"));
private static VarHandle ringEntriesVarHandle = layout.varHandle(PathElement.groupElement("ring_entries"));
private static VarHandle overflowVarHandle = layout.varHandle(PathElement.groupElement("overflow"));
private static VarHandle cqesVarHandle = layout.varHandle(PathElement.groupElement("cqes"));
private static VarHandle flagsVarHandle = layout.varHandle(PathElement.groupElement("flags"));
private static VarHandle userAddrVarHandle = layout.varHandle(PathElement.groupElement("user_addr"));

public static int getHead(MemorySegment data) {
return (int) headVarHandle.get(data, 0);
};

public static void setHead(MemorySegment data, int value) {
headVarHandle.set(data, 0, value);
};

public static int getTail(MemorySegment data) {
return (int) tailVarHandle.get(data, 0);
};

public static void setTail(MemorySegment data, int value) {
tailVarHandle.set(data, 0, value);
};

public static int getRingMask(MemorySegment data) {
return (int) ringMaskVarHandle.get(data, 0);
};

public static void setRingMask(MemorySegment data, int value) {
ringMaskVarHandle.set(data, 0, value);
};

public static int getRingEntries(MemorySegment data) {
return (int) ringEntriesVarHandle.get(data, 0);
};

public static void setRingEntries(MemorySegment data, int value) {
ringEntriesVarHandle.set(data, 0, value);
};

public static int getOverflow(MemorySegment data) {
return (int) overflowVarHandle.get(data, 0);
};

public static void setOverflow(MemorySegment data, int value) {
overflowVarHandle.set(data, 0, value);
};

public static int getCqes(MemorySegment data) {
return (int) cqesVarHandle.get(data, 0);
};

public static void setCqes(MemorySegment data, int value) {
cqesVarHandle.set(data, 0, value);
};

public static int getFlags(MemorySegment data) {
return (int) flagsVarHandle.get(data, 0);
};

public static void setFlags(MemorySegment data, int value) {
flagsVarHandle.set(data, 0, value);
};

public static long getUserAddr(MemorySegment data) {
return (long) userAddrVarHandle.get(data, 0);
};

public static void setUserAddr(MemorySegment data, long value) {
userAddrVarHandle.set(data, 0, value);
};

};
Loading
Loading