Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
i4
manycore
syscall-eval
Commits
d11862a3
Commit
d11862a3
authored
Aug 02, 2021
by
Florian Fischer
Browse files
move duplicated io_uring code into io_uring.h
parent
0978dafc
Changes
4
Hide whitespace changes
Inline
Side-by-side
common.h
View file @
d11862a3
#pragma once
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
extern
size_t
warmup
,
iterations
;
io-uring-no-syscall.c
View file @
d11862a3
...
...
@@ -4,26 +4,18 @@
#include
<stdlib.h>
#include
"common.h"
#include
"io_uring.h"
#include
"stopwatch.h"
struct
io_uring
ring
;
void
init
(
__attribute__
((
unused
))
int
fd
)
{
int
res
=
io_uring_queue_init
(
16
,
&
ring
,
IORING_SETUP_SQPOLL
);
if
(
res
<
0
)
{
errno
=
res
;
err
(
EXIT_FAILURE
,
"io_uring_setup failed"
);
}
}
void
init
(
__attribute__
((
unused
))
int
fd
)
{
io_uring_init_sqpoll
(
&
ring
);
}
void
do_write
(
int
fd
,
const
void
*
buf
,
size_t
count
)
{
start_watch
();
struct
io_uring_sqe
*
sqe
=
io_uring_get_sqe
(
&
ring
);
while
(
unlikely
(
!
sqe
))
{
sqe
=
io_uring_get_sqe
(
&
ring
);
}
struct
io_uring_sqe
*
sqe
=
sqpoll_ring_get_sqe
(
&
ring
);
io_uring_prep_write
(
sqe
,
fd
,
buf
,
count
,
0
);
start_watch
();
int
res
=
io_uring_submit
(
&
ring
);
struct
io_uring_cqe
*
cqe
;
...
...
@@ -32,11 +24,7 @@ void do_write(int fd, const void *buf, size_t count) {
stop_watch
();
if
(
res
<
0
)
{
err
(
EXIT_FAILURE
,
"io_submit failed"
);
}
if
(
res
<
0
)
err
(
EXIT_FAILURE
,
"io_submit failed"
);
if
(
cqe
->
res
<
0
)
{
err
(
EXIT_FAILURE
,
"write request failed"
);
}
if
(
cqe
->
res
<
0
)
err
(
EXIT_FAILURE
,
"write request failed"
);
}
io-uring-sqpoll.c
View file @
d11862a3
...
...
@@ -4,29 +4,19 @@
#include
<stdlib.h>
#include
"common.h"
#include
"io_uring.h"
#include
"stopwatch.h"
struct
io_uring
ring
;
void
init
(
__attribute__
((
unused
))
int
fd
)
{
int
res
=
io_uring_queue_init
(
16
,
&
ring
,
IORING_SETUP_SQPOLL
);
if
(
res
<
0
)
{
errno
=
res
;
err
(
EXIT_FAILURE
,
"io_uring_setup failed"
);
}
}
void
init
(
__attribute__
((
unused
))
int
fd
)
{
io_uring_init_sqpoll
(
&
ring
);
}
void
do_write
(
int
fd
,
const
void
*
buf
,
size_t
count
)
{
start_watch
();
struct
io_uring_sqe
*
sqe
=
io_uring_get_sqe
(
&
ring
);
while
(
unlikely
(
!
sqe
))
{
sqe
=
io_uring_get_sqe
(
&
ring
);
}
struct
io_uring_sqe
*
sqe
=
sqpoll_ring_get_sqe
(
&
ring
);
io_uring_prep_write
(
sqe
,
fd
,
buf
,
count
,
0
);
start_watch
();
int
res
=
io_uring_submit_and_wait
(
&
ring
,
1
);
stop_watch
();
if
(
res
<
0
)
{
...
...
@@ -35,11 +25,8 @@ void do_write(int fd, const void *buf, size_t count) {
struct
io_uring_cqe
*
cqe
;
res
=
io_uring_peek_cqe
(
&
ring
,
&
cqe
);
if
(
res
<
0
)
{
err
(
EXIT_FAILURE
,
"io_uring_peek_cqe failed"
);
}
if
(
cqe
->
res
<
0
)
{
err
(
EXIT_FAILURE
,
"write request failed"
);
}
if
(
res
<
0
)
err
(
EXIT_FAILURE
,
"io_uring_peek_cqe failed"
);
if
(
cqe
->
res
<
0
)
err
(
EXIT_FAILURE
,
"write request failed"
);
}
io_uring.h
0 → 100644
View file @
d11862a3
#pragma once
#include
<err.h>
#include
<liburing.h>
#include
"common.h"
#define GET_SQE_ATTEMPTS 1000000
struct
io_uring_sqe
*
sqpoll_ring_get_sqe
(
struct
io_uring
*
ring
)
{
struct
io_uring_sqe
*
sqe
;
size_t
attempts
=
0
;
for
(;;)
{
sqe
=
io_uring_get_sqe
(
ring
);
if
(
likely
(
sqe
))
return
sqe
;
++
attempts
;
if
(
attempts
<
GET_SQE_ATTEMPTS
)
continue
;
errx
(
EXIT_FAILURE
,
"failed to get sqe after %d"
,
GET_SQE_ATTEMPTS
);
}
}
#define SQPOLL_RING_ENTRIES 16
void
io_uring_init_sqpoll
(
struct
io_uring
*
ring
)
{
int
res
=
io_uring_queue_init
(
SQPOLL_RING_ENTRIES
,
ring
,
IORING_SETUP_SQPOLL
);
if
(
res
<
0
)
{
errno
=
res
;
err
(
EXIT_FAILURE
,
"io_uring_setup failed"
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment