From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Pavel Begunkov <asml.silence@gmail.com>
Cc: io-uring <io-uring@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCH v8 5/5] selftests/io_uring: add a bpf io_uring selftest
Date: Thu, 19 Feb 2026 11:01:00 -0800 [thread overview]
Message-ID: <CAADnVQK0RaOA9ZYZdYyQxOzLde9MR8HpMM0SexcW59A9u7X2Jw@mail.gmail.com> (raw)
In-Reply-To: <7cc147a959ac068c55dae4f540e38e9e4ab121e0.1771327059.git.asml.silence@gmail.com>
On Tue, Feb 17, 2026 at 3:33 AM Pavel Begunkov <asml.silence@gmail.com> wrote:
>
> +
> +struct {
> + __uint(type, BPF_MAP_TYPE_ARRAY);
> + __uint(max_entries, 3);
> + __type(key, u32);
> + __type(value, s64);
> +} res_map SEC(".maps");
> +
> +#define t_min(a, b) ((a) < (b) ? (a) : (b))
> +
> +static inline void set_cq_wait(struct iou_loop_params *lp,
> + struct io_uring *cq_hdr, unsigned to_wait)
> +{
> + lp->cq_wait_idx = cq_hdr->head + to_wait;
> +}
> +
> +static inline void write_result(int res)
> +{
> + u32 key = SLOT_RES;
> + u64 *val;
> +
> + val = bpf_map_lookup_elem(&res_map, &key);
> + if (val)
> + *val = res;
> +}
> +
> +static inline void write_stats(int idx, unsigned int v)
> +{
> + u32 key = idx;
> + u64 *val;
> +
> + val = bpf_map_lookup_elem(&res_map, &key);
> + if (val)
> + *val += v;
> +}
Since these examples will be copied around, let's use
good coding practices. Use properly named global variables
for stats and counters, and drop this opaque array.
Also bpf_map_lookup_elem() doesn't need if (val) check
when key is a constant and lookup is from array map.
> +
> +SEC("struct_ops.s/nops_loop_step")
> +int BPF_PROG(nops_loop_step, struct io_ring_ctx *ring, struct iou_loop_params *ls)
> +{
> + struct io_uring *sq_hdr, *cq_hdr;
> + struct io_uring_sqe *sqes;
> + struct io_uring_cqe *cqes;
> + void *rings;
> + int ret;
> +
> + sqes = (void *)bpf_io_uring_get_region(ring, IOU_REGION_SQ,
> + SQ_ENTRIES * sizeof(struct io_uring_sqe));
> + rings = (void *)bpf_io_uring_get_region(ring, IOU_REGION_CQ,
> + cqes_offset + CQ_ENTRIES * sizeof(struct io_uring_cqe));
> + if (!rings || !sqes) {
> + write_result(-1);
> + return IOU_LOOP_STOP;
> + }
> +
> + sq_hdr = rings + (sq_hdr_offset & 63);
> + cq_hdr = rings + (cq_hdr_offset & 63);
> + cqes = rings + cqes_offset;
> +
> + unsigned to_wait = cq_hdr->tail - cq_hdr->head;
> + to_wait = t_min(to_wait, CQ_ENTRIES);
> + for (int i = 0; i < to_wait; i++) {
> + struct io_uring_cqe *cqe = &cqes[cq_hdr->head & (CQ_ENTRIES - 1)];
> +
> + if (cqe->user_data != REQ_TOKEN) {
> + write_result(-3);
> + return IOU_LOOP_STOP;
> + }
> + cq_hdr->head++;
> + }
CQ_ENTRIES is just 8.
Is it enough for real progs?
Does the above approach scale ?
I mean the above works as a bounded loop because loop
count is small, but for 100+ you want open coded iterators.
In general all progs seem to be toy progs.
Would be good to have something more realistic.
next prev parent reply other threads:[~2026-02-19 19:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-17 11:33 [PATCH v8 0/5] BPF controlled io_uring Pavel Begunkov
2026-02-17 11:33 ` [PATCH v8 1/5] io_uring: introduce callback driven main loop Pavel Begunkov
2026-02-17 11:33 ` [PATCH v8 2/5] io_uring/bpf-ops: implement loop_step with BPF struct_ops Pavel Begunkov
2026-02-17 11:33 ` [PATCH v8 3/5] io_uring/bpf-ops: add kfunc helpers Pavel Begunkov
2026-02-17 11:33 ` [PATCH v8 4/5] io_uring/bpf-ops: implement bpf ops registration Pavel Begunkov
2026-02-17 11:33 ` [PATCH v8 5/5] selftests/io_uring: add a bpf io_uring selftest Pavel Begunkov
2026-02-19 19:01 ` Alexei Starovoitov [this message]
2026-02-20 11:41 ` Pavel Begunkov
2026-02-20 17:45 ` Alexei Starovoitov
2026-02-20 22:35 ` Pavel Begunkov
2026-02-23 15:23 ` Ming Lei
2026-02-23 16:26 ` Pavel Begunkov
2026-02-25 8:41 ` Ming Lei
2026-02-25 11:12 ` Pavel Begunkov
2026-02-23 14:37 ` Pavel Begunkov
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=CAADnVQK0RaOA9ZYZdYyQxOzLde9MR8HpMM0SexcW59A9u7X2Jw@mail.gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=bpf@vger.kernel.org \
--cc=io-uring@vger.kernel.org \
/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