io_uring/loop.c
Source file repositories/reference/linux-study-clean/io_uring/loop.c
File Facts
- System
- Linux kernel
- Corpus path
io_uring/loop.c- Extension
.c- Size
- 2016 bytes
- Lines
- 92
- Domain
- Kernel Services
- Bucket
- io_uring
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
io_uring.hwait.hloop.h
Detected Declarations
function io_loop_nr_cqesfunction io_loop_wait_startfunction io_loop_wait_finishfunction io_loop_waitfunction __io_run_loopfunction io_run_loop
Annotated Snippet
READ_ONCE(ctx->check_cq)) {
io_loop_wait_finish(ctx);
return;
}
mutex_unlock(&ctx->uring_lock);
schedule();
io_loop_wait_finish(ctx);
mutex_lock(&ctx->uring_lock);
}
static int __io_run_loop(struct io_ring_ctx *ctx)
{
struct iou_loop_params lp = {};
while (true) {
int nr_wait, step_res;
if (unlikely(!ctx->loop_step))
return -EFAULT;
step_res = ctx->loop_step(io_loop_mangle_ctx(ctx), &lp);
if (step_res == IOU_LOOP_STOP)
break;
if (step_res != IOU_LOOP_CONTINUE)
return -EINVAL;
nr_wait = io_loop_nr_cqes(ctx, &lp);
if (nr_wait > 0)
io_loop_wait(ctx, &lp, nr_wait);
else
nr_wait = 0;
if (task_work_pending(current)) {
mutex_unlock(&ctx->uring_lock);
io_run_task_work();
mutex_lock(&ctx->uring_lock);
}
if (unlikely(task_sigpending(current)))
return -EINTR;
io_run_local_work_locked(ctx, nr_wait);
if (READ_ONCE(ctx->check_cq) & BIT(IO_CHECK_CQ_OVERFLOW_BIT))
io_cqring_overflow_flush_locked(ctx);
}
return 0;
}
int io_run_loop(struct io_ring_ctx *ctx)
{
int ret;
if (!io_allowed_run_tw(ctx))
return -EEXIST;
mutex_lock(&ctx->uring_lock);
ret = __io_run_loop(ctx);
mutex_unlock(&ctx->uring_lock);
return ret;
}
Annotation
- Immediate include surface: `io_uring.h`, `wait.h`, `loop.h`.
- Detected declarations: `function io_loop_nr_cqes`, `function io_loop_wait_start`, `function io_loop_wait_finish`, `function io_loop_wait`, `function __io_run_loop`, `function io_run_loop`.
- Atlas domain: Kernel Services / io_uring.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.