PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1#include <errno.h>
2#include <stdio.h>
3#include <string.h>
4#include <sys/ioring.h>
5
6#define SENTRIES 64
7#define CENTRIES 128
8
9int main()
10{
11 printf("setting up ring test...\n");
12 ioring_t ring;
14 if (id == ERR)
15 {
16 printf("failed to set up ring\n");
17 return errno;
18 }
19
20 memset(&ring.ctrl->regs, -1, sizeof(ring.ctrl->regs));
21
22 printf("pushing nop sqe to ring %llu...\n", ring.id);
24 sqe_push(&ring, &sqe);
25
26 printf("pushing nop sqe to ring %llu...\n", ring.id);
28 sqe_push(&ring, &sqe);
29
30 printf("entering ring...\n");
31 if (ioring_enter(id, 2, 2) == ERR)
32 {
33 printf("failed to enter ring\n");
34 return errno;
35 }
36
37 cqe_t cqe;
38 while (cqe_pop(&ring, &cqe))
39 {
40 printf("cqe:\n");
41
42 printf("cqe data: %p\n", cqe.data);
43 printf("cqe op: %d\n", cqe.op);
44 printf("cqe error: %s\n", strerror(cqe.error));
45 printf("cqe result: %llu\n", cqe._result);
46 }
47
48 printf("registers:\n");
49 for (uint64_t i = 0; i < SQE_REGS_MAX; i++)
50 {
51 printf("reg[%llu]: %llu\n", i, ring.ctrl->regs[i]);
52 }
53
54 printf("tearing down ring...\n");
56 return 0;
57}
int main(void)
Definition main.c:5
#define CLOCKS_PER_SEC
Definition clock_t.h:15
#define IO_OP_NOP
No-op operation.
Definition ioring.h:42
#define SQE_REG0
The first register.
Definition ioring.h:49
#define SQE_LINK
Definition ioring.h:73
#define SQE_REGS_MAX
The maximum number of registers.
Definition ioring.h:57
#define SQE_HARDLINK
Definition ioring.h:77
#define SQE_CREATE(_op, _flags, _timeout, _data)
Macro to create an asynchronous submission queue entry (SQE).
Definition ioring.h:128
#define SQE_SAVE
The offset to specify the register to save the result into.
Definition ioring.h:66
#define errno
Error number variable.
Definition errno.h:27
uint64_t ioring_enter(ioring_id_t id, size_t amount, size_t wait)
System call to notify the kernel of new submission queue entries (SQEs).
Definition ioring_enter.c:5
uint64_t ioring_teardown(ioring_id_t id)
System call to deinitialize the I/O ring.
uint64_t ioring_id_t
I/O ring ID type.
Definition ioring.h:195
static bool sqe_push(ioring_t *ring, sqe_t *sqe)
Pushes a submission queue entry (SQE) to the submission queue.
Definition ioring.h:256
static bool cqe_pop(ioring_t *ring, cqe_t *cqe)
Pops a completion queue entry (CQE) from the completion queue.
Definition ioring.h:279
ioring_id_t ioring_setup(ioring_t *ring, void *address, size_t sentries, size_t centries)
System call to initialize the I/O ring.
Definition ioring_setup.c:5
#define NULL
Pointer error value.
Definition NULL.h:25
#define ERR
Integer error value.
Definition ERR.h:17
#define SENTRIES
Definition main.c:6
#define CENTRIES
Definition main.c:7
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
_PUBLIC int printf(const char *_RESTRICT format,...)
Definition printf.c:3
_PUBLIC char * strerror(int errnum)
Definition strerror.c:6
_PUBLIC void * memset(void *s, int c, size_t n)
Definition memset.c:4
Asynchronous completion queue entry (CQE).
Definition ioring.h:143
errno_t error
Error code, if not equal to EOK an error occurred.
Definition ioring.h:145
io_op_t op
The operation that was performed.
Definition ioring.h:144
uint64_t _result
Definition ioring.h:152
void * data
Private data from the submission entry.
Definition ioring.h:146
User I/O ring structure.
Definition ioring.h:204
ioring_ctrl_t * ctrl
Pointer to the shared control structure.
Definition ioring.h:205
ioring_id_t id
The ID of the ring.
Definition ioring.h:206
Asynchronous submission queue entry (SQE).
Definition ioring.h:89