~sircmpwn/hare-linux

0b33642d855b5534476d611256ecd0a67c59bae7 — Drew DeVault 2 years ago 0f4464a
iobus: buffer pool management

Signed-off-by: Drew DeVault <sir@cmpwn.com>
3 files changed, 12 insertions(+), 7 deletions(-)

M io_uring/cqe.ha
M io_uring/sqe.ha
M io_uring/uring.ha
M io_uring/cqe.ha => io_uring/cqe.ha +1 -0
@@ 41,6 41,7 @@ export fn get_user(cqe: *cqe) nullable *void =
// [[set_buffer_select]]. Aborts the program if this CQE was not configured to
// use a buffer pool.
export fn get_buffer_id(cqe: *cqe) u16 = {
	// TODO: Handle ENOBUFS
	assert(cqe.flags & cqe_flags::F_BUFFER > 0,
		"get_buffer_id called for CQE without buffer");
	return (cqe.flags: u32 >> CQE_BUFFER_SHIFT): u16;

M io_uring/sqe.ha => io_uring/sqe.ha +6 -5
@@ 1,6 1,7 @@
use endian;
use rt;
use types;
use fmt;

fn prep(sq: *sqe, op: op, flags: flags...) void = {
	rt::memset(sq, 0, size(sqe));


@@ 38,7 39,7 @@ export fn set_user(sqe: *sqe, user_data: *void) void = {
// retrieve the buffer used from the corresponding [[cqe]].
export fn set_buffer_select(sqe: *sqe, group: u16) void = {
	sqe.flags |= flags::BUFFER_SELECT;
	sqe.buf_group = group;
	sqe.extras.buffers.buf_group = group;
};

// Prepares a no-op "operation" for an [[sqe]].


@@ 109,7 110,7 @@ export fn read_fixed(
) void = {
	assert(count <= types::U32_MAX);
	preprw(sqe, op::READ_FIXED, fd, buf, count: u32, 0, flags...);
	sqe.buf_index = index;
	sqe.extras.buffers.buf_index = index;
};

// Prepares a write for a fixed buffer previously registered with


@@ 125,7 126,7 @@ export fn write_fixed(
) void = {
	assert(count <= types::U32_MAX);
	preprw(sqe, op::WRITE_FIXED, fd, buf, count: u32, 0, flags...);
	sqe.buf_index = index;
	sqe.extras.buffers.buf_index = index;
};

// Prepares an fsync operation for an [[sqe]]. Note that operations are executed


@@ 327,7 328,7 @@ export fn provide_buffers(
	assert(len(pool) == nbuf * bufsz);
	preprw(sqe, op::PROVIDE_BUFFERS, nbuf: int, pool: *[*]u8,
		bufsz: uint, bufid: uint, flags...);
	sqe.buf_group = group;
	sqe.extras.buffers.buf_group = group;
};

// Removes buffers previously registered with [[provide_buffers]].


@@ 338,5 339,5 @@ export fn remove_buffers(
	flags: flags...
) void = {
	preprw(sqe, op::REMOVE_BUFFERS, nbuf: int, null, 0, 0, flags...);
	sqe.buf_group = group;
	sqe.extras.buffers.buf_group = group;
};

M io_uring/uring.ha => io_uring/uring.ha +5 -2
@@ 108,6 108,7 @@ export type splice_flags = enum u32 {
export type cqe_flags = enum u32 {
	NONE = 0,
	F_BUFFER = 1 << 0,
	F_MORE = 1 << 1,
};

// A submission queue entry.


@@ 141,9 142,11 @@ export type sqe = struct {
		splice_flags: splice_flags,
	},
	user_data: u64,
	// TODO: Remove the names on these embedded types
	// See https://todo.sr.ht/~sircmpwn/hare/493
	union {
		struct {
			union {
		extras: struct {
			buffers: union {
				buf_index: u16,
				buf_group: u16,
			},