io_uring_register_eventfd(3)

πŸ“¦
version 2.14 Β· 3 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute

πŸ’– io_uring_register_eventfd(3) β€” the liburing bestie guide πŸ’–

okay so bestie, this is a page from the liburing manual, and it's about wiring an eventfd up to your ring so you get lil notifications when stuff finishes. it's short, it's sweet, it's lowkey iconic. let's go πŸ¦‹


🌸 NAME 🌸

io_uring_register_eventfd β€” register an eventfd with a ring

like... you're handing the ring a little doorbell. that's the whole vibe. πŸ””


✨ SYNOPSIS ✨

#include <liburing.h>

int io_uring_register_eventfd(struct io_uring *ring,
                              int fd);

int io_uring_register_eventfd_async(struct io_uring *ring,
                                    int fd);

int io_uring_unregister_eventfd(struct io_uring *ring);

three functions, three moods: register, register but async-only, and unregister. pick your fighter πŸ’…


πŸŽ€ DESCRIPTION πŸŽ€

io_uring_register_eventfd(3) registers the eventfd file descriptor fd with the ring that ring points at. that's it, that's the registration. so official. so demure. 🫢

and then?? the good part: whenever completions get posted to the CQ ring, an eventfd notification is generated using that registered eventfd descriptor. so your eventfd is basically the ring's group chat β€” it pings you when things are done. πŸ”₯

but wait, there's a plot twist: if you use io_uring_register_eventfd_async(3) instead, then only the events that completed out-of-line will trigger a notification. so it's the selective-notifications version. main character energy, only shows up for the dramatic stuff. ✨

and if you're over it β€” notifications no longer desired, no cap β€” you can call io_uring_unregister_eventfd(3) to remove the eventfd registration. heads up: you do not pass an eventfd argument, because a ring can only have a single eventfd registered. one ring, one eventfd, monogamy fr fr πŸ’€


πŸ‘‘ NOTES πŸ‘‘

okay this part is important so pay attention bestie, i'm being so serious rn 😭

so io_uring generally takes care to avoid spurious events β€” key word: generally. they can still occur. πŸ™ˆ

similarly, batched completions of CQEs may only trigger a single eventfd notification, even if multiple CQEs are posted. like, five CQEs walk into the ring and the doorbell rings once. rude but legal.

so your application should make no assumptions about the number of events being available having a direct correlation to the eventfd notifications posted.

which means: an eventfd notification must only be treated as a hint to go check the CQ ring for completions. it's a vibe check, not a receipt. πŸ’…


⭐ RETURN VALUE ⭐

returns 0 on success, or -errno on error. classic. no notes. πŸ’–


🌈 SEE ALSO 🌈


and that's the whole page babes 🧚 this was the liburing-2.2 manual, dated April 16, 2022, and it was io_uring_register_eventfd(3) all along. go ring your doorbell. mwah πŸ’œ

πŸ“¦ where this page comes from