diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-11-27 20:10:19 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-12-02 16:39:16 -0500 |
commit | 35c7c72601cee9692846de13117411d80b3d13f6 (patch) | |
tree | c111329c85ef972e536d32d1ff0c00f5f0990142 /src/ioq.c | |
parent | bac8214e90488fd562d29f6fea18ae75ecd9029e (diff) | |
download | bfs-35c7c72601cee9692846de13117411d80b3d13f6.tar.xz |
ioq: Add an ioq_nop() operation for benchmarking
Diffstat (limited to 'src/ioq.c')
-rw-r--r-- | src/ioq.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -136,6 +136,7 @@ #include <stdint.h> #include <stdlib.h> #include <sys/stat.h> +#include <unistd.h> #if BFS_WITH_LIBURING # include <liburing.h> @@ -532,6 +533,14 @@ static bool ioq_check_cancel(struct ioq *ioq, struct ioq_ent *ent) { /** Dispatch a single request synchronously. */ static void ioq_dispatch_sync(struct ioq *ioq, struct ioq_ent *ent) { switch (ent->op) { + case IOQ_NOP: + if (ent->nop.type == IOQ_NOP_HEAVY) { + // A fast, no-op syscall + getpid(); + } + ent->result = 0; + return; + case IOQ_CLOSE: ent->result = try(xclose(ent->close.fd)); return; @@ -587,6 +596,13 @@ static struct io_uring_sqe *ioq_dispatch_async(struct ioq_ring_state *state, str struct io_uring_sqe *sqe = NULL; switch (ent->op) { + case IOQ_NOP: + if (ent->nop.type == IOQ_NOP_HEAVY) { + sqe = io_uring_get_sqe(ring); + io_uring_prep_nop(sqe); + } + return sqe; + case IOQ_CLOSE: if (ops & IOQ_RING_CLOSE) { sqe = io_uring_get_sqe(ring); @@ -1010,6 +1026,18 @@ static struct ioq_ent *ioq_request(struct ioq *ioq, enum ioq_op op, void *ptr) { return ent; } +int ioq_nop(struct ioq *ioq, enum ioq_nop_type type, void *ptr) { + struct ioq_ent *ent = ioq_request(ioq, IOQ_NOP, ptr); + if (!ent) { + return -1; + } + + ent->nop.type = type; + + ioqq_push(ioq->pending, ent); + return 0; +} + int ioq_close(struct ioq *ioq, int fd, void *ptr) { struct ioq_ent *ent = ioq_request(ioq, IOQ_CLOSE, ptr); if (!ent) { |