Skip to content

Commit

Permalink
sync with v5.15-rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
tchaloupka committed Oct 23, 2021
1 parent 5819379 commit 29d47b6
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 8 deletions.
50 changes: 48 additions & 2 deletions source/during/io_uring.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* See: https://github.com/torvalds/linux/blob/master/include/uapi/linux/io_uring.h
*
* Last changes from: 9ba6a1c06279ce499fcf755d8134d679a1f3b4ed (20210630)
* Last changes from: dd47c104533dedb90434a3f142e94a671ac623a6 (20210913)
*/
module during.io_uring;

Expand Down Expand Up @@ -55,6 +55,7 @@ struct SubmissionEntry
uint splice_flags; /// from Linux 5.7
uint rename_flags; /// from Linux 5.11
uint unlink_flags; /// from Linux 5.11
uint hardlink_flags; /// from Linux 5.15
}

ulong user_data; /// data to be passed back at completion time
Expand All @@ -67,7 +68,11 @@ struct SubmissionEntry
}

ushort personality; /// personality to use, if used
int splice_fd_in;
union
{
int splice_fd_in;
uint file_index;
}
ulong[2] __pad2;

/// Resets entry fields
Expand Down Expand Up @@ -328,6 +333,31 @@ enum TimeoutFlags : uint
* Support timeout updates through `IORING_OP_TIMEOUT_REMOVE` with passed in `IORING_TIMEOUT_UPDATE`.
*/
UPDATE = 1U << 1,

/**
* `IORING_TIMEOUT_BOOTTIME` (from Linux 5.15)
*/
BOOTTIME = 1U << 2,

/**
* `IORING_TIMEOUT_REALTIME` (from Linux 5.15)
*/
REALTIME = 1U << 3,

/**
* `IORING_LINK_TIMEOUT_UPDATE` (from Linux 5.15)
*/
LINK_TIMEOUT_UPDATE = 1U << 4,

/**
* `IORING_TIMEOUT_CLOCK_MASK` (from Linux 5.15)
*/
CLOCK_MASK = BOOTTIME | REALTIME,

/**
* `IORING_TIMEOUT_UPDATE_MASK` (from Linux 5.15)
*/
UPDATE_MASK = UPDATE | LINK_TIMEOUT_UPDATE,
}

/**
Expand Down Expand Up @@ -464,6 +494,11 @@ enum Operation : ubyte
SHUTDOWN = 34, /// IORING_OP_SHUTDOWN
RENAMEAT = 35, /// IORING_OP_RENAMEAT - see renameat2()
UNLINKAT = 36, /// IORING_OP_UNLINKAT - see unlinkat(2)

// available from Linux 5.15
MKDIRAT = 37, /// IORING_OP_MKDIRAT - see mkdirat(2)
SYMLINKAT = 38, /// IORING_OP_SYMLINKAT - see symlinkat(2)
LINKAT = 39, /// IORING_OP_LINKAT - see linkat(2)
}

/// sqe->flags
Expand Down Expand Up @@ -1165,6 +1200,17 @@ enum RegisterOpCode : uint

/// `IORING_UNREGISTER_IOWQ_AFF` (from Linux 5.14)
UNREGISTER_IOWQ_AFF = 18,

/// `IORING_REGISTER_IOWQ_MAX_WORKERS` (from Linux 5.15)
/// set/get max number of io-wq workers
REGISTER_IOWQ_MAX_WORKERS = 19,
}

/* io-wq worker categories */
enum IOWQCategory
{
BOUND, /// `IO_WQ_BOUND`
UNBOUND, /// `IO_WQ_UNBOUND`
}

/// io_uring_enter(2) flags
Expand Down
141 changes: 135 additions & 6 deletions source/during/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ debug import core.stdc.stdio;
import core.stdc.stdlib;
import core.sys.linux.epoll;
import core.sys.linux.errno;
import core.sys.linux.sched;
import core.sys.linux.sys.mman;
import core.sys.linux.unistd;
import core.sys.posix.signal;
import core.sys.posix.sys.socket;
import core.sys.posix.sys.types;
import core.sys.posix.sys.uio;
import std.algorithm.comparison : among;

Expand Down Expand Up @@ -643,6 +645,56 @@ struct Uring
if (_expect(r < 0, false)) return -errno;
return 0;
}

/**
* By default, async workers created by io_uring will inherit the CPU mask of its parent. This
* is usually all the CPUs in the system, unless the parent is being run with a limited set. If
* this isn't the desired outcome, the application may explicitly tell io_uring what CPUs the
* async workers may run on.
*
* Note: Available since 5.14.
*/
int registerIOWQAffinity(cpu_set_t[] cpus) @trusted
in (cpus.length)
{
immutable r = io_uring_register(payload.fd, RegisterOpCode.REGISTER_IOWQ_AFF, cpus.ptr, cast(uint)cpus.length);
if (_expect(r < 0, false)) return -errno;
return 0;
}

/**
* Undoes a CPU mask previously set with `registerIOWQAffinity`.
*
* Note: Available since 5.14
*/
int unregisterIOWQAffinity() @trusted
{
immutable r = io_uring_register(payload.fd, RegisterOpCode.UNREGISTER_IOWQ_AFF, null, 0);
if (_expect(r < 0, false)) return -errno;
return 0;
}

/**
* By default, io_uring limits the unbounded workers created to the maximum processor count set
* by `RLIMIT_NPROC` and the bounded workers is a function of the SQ ring size and the number of
* CPUs in the system. Sometimes this can be excessive (or too little, for bounded), and this
* command provides a way to change the count per ring (per NUMA node) instead.
*
* `val` must be set to an `uint` pointer to an array of two values, with the values in the
* array being set to the maximum count of workers per NUMA node. Index 0 holds the bounded
* worker count, and index 1 holds the unbounded worker count. On successful return, the passed
* in array will contain the previous maximum values for each type. If the count being passed in
* is 0, then this command returns the current maximum values and doesn't modify the current
* setting.
*
* Note: Available since 5.15
*/
int registerIOWQMaxWorkers(ref uint[2] workers) @trusted
{
immutable r = io_uring_register(payload.fd, RegisterOpCode.REGISTER_IOWQ_MAX_WORKERS, &workers, 2);
if (_expect(r < 0, false)) return -errno;
return 0;
}
}

/**
Expand Down Expand Up @@ -729,7 +781,7 @@ ref SubmissionEntry prepRW(return ref SubmissionEntry entry, Operation op,
entry.user_data = 0;
entry.buf_index = 0;
entry.personality = 0;
entry.splice_fd_in = 0;
entry.file_index = 0;
entry.__pad2[0] = entry.__pad2[1] = 0;
return entry;
}
Expand Down Expand Up @@ -1061,6 +1113,19 @@ ref SubmissionEntry prepAccept(ADDR)(return ref SubmissionEntry entry, int fd, r
return entry;
}

/**
* Same as `prepAccept`, but fd is put directly into fixed file table on `fileIndex`.
* Note: available from Linux 5.15
*/
ref SubmissionEntry prepAcceptDirect(ADDR)(return ref SubmissionEntry entry, int fd, ref ADDR addr, ref socklen_t addrlen,
uint fileIndex, AcceptFlags flags = AcceptFlags.NONE) @trusted
{
entry.prepRW(Operation.ACCEPT, fd, cast(void*)&addr, 0, cast(ulong)(cast(void*)&addrlen));
entry.accept_flags = flags;
entry.file_index = fileIndex+1;
return entry;
}

/**
* Prepares operation that cancels existing async work.
*
Expand Down Expand Up @@ -1143,13 +1208,25 @@ ref SubmissionEntry prepFallocate(return ref SubmissionEntry entry, int fd, int
/**
* Note: Available from Linux 5.6
*/
ref SubmissionEntry prepOpenat(return ref SubmissionEntry entry, int fd, const char* path, int flags, uint mode) @trusted
ref SubmissionEntry prepOpenat(return ref SubmissionEntry entry, int fd, const(char)* path, int flags, uint mode) @trusted
{
entry.prepRW(Operation.OPENAT, fd, cast(void*)path, mode, 0);
entry.open_flags = flags;
return entry;
}

/**
* Same as `prepOpenat`, but fd is put directly into fixed file table on `fileIndex`.
* Note: available from Linux 5.15
*/
ref SubmissionEntry prepOpenatDirect(return ref SubmissionEntry entry, int fd, const(char)* path, int flags, uint mode, uint fileIndex) @trusted
{
entry.prepRW(Operation.OPENAT, fd, cast(void*)path, mode, 0);
entry.open_flags = flags;
entry.file_index = fileIndex+1;
return entry;
}

/**
* Note: Available from Linux 5.6
*/
Expand All @@ -1158,6 +1235,17 @@ ref SubmissionEntry prepClose(return ref SubmissionEntry entry, int fd) @safe
return entry.prepRW(Operation.CLOSE, fd);
}

/**
* Same as `prepClose` but operation works directly with fd registered in fixed file table on index `fileIndex`.
* Note: Available from Linux 5.15
*/
ref SubmissionEntry prepCloseDirect(return ref SubmissionEntry entry, int fd, uint fileIndex) @safe
{
entry.prepRW(Operation.CLOSE, fd);
entry.file_index = fileIndex+1;
return entry;
}

/**
* Note: Available from Linux 5.6
*/
Expand All @@ -1177,7 +1265,7 @@ ref SubmissionEntry prepWrite(return ref SubmissionEntry entry, int fd, const(ub
/**
* Note: Available from Linux 5.6
*/
ref SubmissionEntry prepStatx(Statx)(return ref SubmissionEntry entry, int fd, const char* path, int flags, uint mask, ref Statx statxbuf) @trusted
ref SubmissionEntry prepStatx(Statx)(return ref SubmissionEntry entry, int fd, const(char)* path, int flags, uint mask, ref Statx statxbuf) @trusted
{
entry.prepRW(Operation.STATX, fd, cast(void*)path, mask, cast(ulong)(cast(void*)&statxbuf));
entry.statx_flags = flags;
Expand Down Expand Up @@ -1249,6 +1337,17 @@ ref SubmissionEntry prepOpenat2(return ref SubmissionEntry entry, int fd, const
return entry.prepRW(Operation.OPENAT2, fd, cast(void*)path, cast(uint)OpenHow.sizeof, cast(ulong)(cast(void*)&how));
}

/**
* Same as `prepOpenat2`, but fd is put directly into fixed file table on `fileIndex`.
* Note: available from Linux 5.15
*/
ref SubmissionEntry prepOpenat2Direct(return ref SubmissionEntry entry, int fd, const char *path, ref OpenHow how, uint fileIndex) @trusted
{
entry.prepRW(Operation.OPENAT2, fd, cast(void*)path, cast(uint)OpenHow.sizeof, cast(ulong)(cast(void*)&how));
entry.file_index = fileIndex+1;
return entry;
}

/**
* Note: Available from Linux 5.6
*/
Expand Down Expand Up @@ -1377,8 +1476,8 @@ ref SubmissionEntry prepShutdown(return ref SubmissionEntry entry, int fd, int h
/**
* Note: Available from Linux 5.11
*/
ref SubmissionEntry prepRenameAt(return ref SubmissionEntry entry,
int olddfd, const char* oldpath, int newfd, const char* newpath, int flags) @trusted
ref SubmissionEntry prepRenameat(return ref SubmissionEntry entry,
int olddfd, const(char)* oldpath, int newfd, const(char)* newpath, int flags) @trusted
{
entry.prepRW(Operation.RENAMEAT, olddfd, cast(void*)oldpath, newfd, cast(ulong)cast(void*)newpath);
entry.rename_flags = flags;
Expand All @@ -1388,13 +1487,43 @@ ref SubmissionEntry prepRenameAt(return ref SubmissionEntry entry,
/**
* Note: Available from Linux 5.11
*/
ref SubmissionEntry prepUnlinkAt(return ref SubmissionEntry entry, int dirfd, const char* path, int flags) @trusted
ref SubmissionEntry prepUnlinkat(return ref SubmissionEntry entry, int dirfd, const(char)* path, int flags) @trusted
{
entry.prepRW(Operation.UNLINKAT, dirfd, cast(void*)path, 0, 0);
entry.unlink_flags = flags;
return entry;
}

/**
* Note: Available from Linux 5.15
*/
ref SubmissionEntry prepMkdirat(return ref SubmissionEntry entry, int dirfd, const(char)* path, mode_t mode) @trusted
{
entry.prepRW(Operation.MKDIRAT, dirfd, cast(void*)path, mode, 0);
return entry;
}

/**
* Note: Available from Linux 5.15
*/
ref SubmissionEntry prepSymlinkat(return ref SubmissionEntry entry, const(char)* target, int newdirfd, const(char)* linkpath) @trusted
{
entry.prepRW(Operation.SYMLINKAT, newdirfd, cast(void*)target, 0, cast(ulong)cast(void*)linkpath);
return entry;
}

/**
* Note: Available from Linux 5.15
*/
ref SubmissionEntry prepLinkat(return ref SubmissionEntry entry,
int olddirfd, const(char)* oldpath,
int newdirfd, const(char)* newpath, int flags) @trusted
{
entry.prepRW(Operation.LINKAT, olddirfd, cast(void*)oldpath, newdirfd, cast(ulong)cast(void*)newpath);
entry.hardlink_flags = flags;
return entry;
}

private:

// uring cleanup
Expand Down

0 comments on commit 29d47b6

Please sign in to comment.