From: David Butler <[email protected]>
To: [email protected]
Subject: Beginner question, user_data not getting filled in as expected
Date: Wed, 22 Dec 2021 18:48:56 -0800 [thread overview]
Message-ID: <CANm61jem0rMt75PuaK_+-suX_WRi+jXPy3BqHZjAR95vzP73Jg@mail.gmail.com> (raw)
Hello,
I'm trying to learn the basics of io_uring. I have this code `hello_uring.cpp':
// clang-13 -O0 -glldb -fsanitize=address -fno-exceptions -Wall
-Werror -luring hello_uring.cpp -o build/hello_uring.exec
#include <fcntl.h>
#include <stdio.h>
#include <assert.h>
#include <liburing.h>
#define error_check(v) if ((u_int64_t)v == -1) {perror(#v);
assert((u_int64_t)v != -1);}
static int const queue_depth = 4;
static int const buf_size = 1<<10;
char buffers[queue_depth][buf_size];
int main () { int r;
{
// setup test
auto f = fopen("build/testfile2", "w");
for (unsigned long i = 0; i< 1024; i++) {
fwrite(&i, sizeof i, 1, f);
}
fclose(f);
}
auto file_fd = open("build/testfile2", O_RDONLY);
io_uring ring;
r = io_uring_queue_init(queue_depth, &ring, 0);
error_check(r);
{
struct iovec vecs[queue_depth];
for (int veci = 0; veci < queue_depth; veci++) {
auto sqe = io_uring_get_sqe(&ring);
assert(sqe);
sqe->user_data = veci;
printf("submit: %d\n", veci);
vecs[veci] = { .iov_base = buffers[veci], .iov_len = buf_size};
io_uring_prep_readv(sqe, file_fd, &vecs[veci], 1, veci * buf_size);
}
r = io_uring_submit(&ring);
error_check(r);
assert(r == queue_depth);
}
for (int done_count = 0; done_count < queue_depth; done_count++) {
struct io_uring_cqe *cqe;
r = io_uring_wait_cqe(&ring, &cqe);
error_check(r);
printf("got_completion: %lld, %d, %d\n", cqe->user_data,
cqe->res, cqe->flags);
io_uring_cqe_seen(&ring, cqe);
}
{
unsigned long next_value = 0;
for (int buf_i = 0; buf_i < queue_depth; buf_i++) {
for (auto buf_values = (unsigned long *)buffers[buf_i];
(char*)buf_values < buffers[buf_i] + buf_size; buf_values++) {
assert(*buf_values == next_value++);
}
}
assert(next_value == (1024/8) * 4);
}
}
On execution, I get all zeros for user_data on the `got_completion'
lines... I was expecting those to be 0, 1, 2, 3.... What am I missing
here?
Thanks :)
--Dave
next reply other threads:[~2021-12-23 2:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-23 2:48 David Butler [this message]
2021-12-23 2:50 ` Beginner question, user_data not getting filled in as expected Jens Axboe
2021-12-23 2:54 ` David Butler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CANm61jem0rMt75PuaK_+-suX_WRi+jXPy3BqHZjAR95vzP73Jg@mail.gmail.com \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox