summaryrefslogtreecommitdiffstats
path: root/src/ioq.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-11-27 20:10:19 -0500
committerTavian Barnes <tavianator@tavianator.com>2024-12-02 16:39:16 -0500
commit35c7c72601cee9692846de13117411d80b3d13f6 (patch)
treec111329c85ef972e536d32d1ff0c00f5f0990142 /src/ioq.c
parentbac8214e90488fd562d29f6fea18ae75ecd9029e (diff)
downloadbfs-35c7c72601cee9692846de13117411d80b3d13f6.tar.xz
ioq: Add an ioq_nop() operation for benchmarking
Diffstat (limited to 'src/ioq.c')
-rw-r--r--src/ioq.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/ioq.c b/src/ioq.c
index 1c5524e..5668a83 100644
--- a/src/ioq.c
+++ b/src/ioq.c
@@ -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) {