io_uring/wait.c
Source file repositories/reference/linux-study-clean/io_uring/wait.c
File Facts
- System
- Linux kernel
- Corpus path
io_uring/wait.c- Extension
.c- Size
- 9109 bytes
- Lines
- 325
- 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
linux/kernel.hlinux/sched/signal.hlinux/io_uring.hlinux/time_namespace.htrace/events/io_uring.huapi/linux/io_uring.hio_uring.hnapi.hwait.h
Detected Declarations
function io_wake_functionfunction io_run_task_work_sigfunction current_pending_iofunction io_cqring_timer_wakeupfunction io_cqring_min_timer_wakeupfunction io_cqring_schedule_timeoutfunction __io_cqring_wait_schedulefunction io_cqring_wait_schedulefunction io_cqring_wait
Annotated Snippet
if (ctx->flags & IORING_SETUP_DEFER_TASKRUN) {
atomic_set(&ctx->cq_wait_nr, nr_wait);
set_current_state(TASK_INTERRUPTIBLE);
} else {
prepare_to_wait_exclusive(&ctx->cq_wait, &iowq.wq,
TASK_INTERRUPTIBLE);
}
ret = io_cqring_wait_schedule(ctx, &iowq, ext_arg, start_time);
__set_current_state(TASK_RUNNING);
atomic_set(&ctx->cq_wait_nr, IO_CQ_WAKE_INIT);
/*
* Run task_work after scheduling and before io_should_wake().
* If we got woken because of task_work being processed, run it
* now rather than let the caller do another wait loop.
*/
if (io_local_work_pending(ctx))
io_run_local_work(ctx, nr_wait, nr_wait);
io_run_task_work();
/*
* Non-local task_work will be run on exit to userspace, but
* if we're using DEFER_TASKRUN, then we could have waited
* with a timeout for a number of requests. If the timeout
* hits, we could have some requests ready to process. Ensure
* this break is _after_ we have run task_work, to avoid
* deferring running potentially pending requests until the
* next time we wait for events.
*/
if (ret < 0)
break;
check_cq = READ_ONCE(ctx->check_cq);
if (unlikely(check_cq)) {
/* let the caller flush overflows, retry */
if (check_cq & BIT(IO_CHECK_CQ_OVERFLOW_BIT))
io_cqring_do_overflow_flush(ctx);
if (check_cq & BIT(IO_CHECK_CQ_DROPPED_BIT)) {
ret = -EBADR;
break;
}
}
if (io_should_wake(&iowq)) {
ret = 0;
break;
}
cond_resched();
/* if min timeout has been hit, don't reset wait count */
if (!iowq.hit_timeout)
scoped_guard(rcu)
nr_wait = (int) iowq.cq_tail -
READ_ONCE(io_get_rings(ctx)->cq.tail);
else
nr_wait = 1;
} while (1);
if (!(ctx->flags & IORING_SETUP_DEFER_TASKRUN))
finish_wait(&ctx->cq_wait, &iowq.wq);
restore_saved_sigmask_unless(ret == -EINTR);
guard(rcu)();
return READ_ONCE(io_get_rings(ctx)->cq.head) == READ_ONCE(io_get_rings(ctx)->cq.tail) ? ret : 0;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/sched/signal.h`, `linux/io_uring.h`, `linux/time_namespace.h`, `trace/events/io_uring.h`, `uapi/linux/io_uring.h`, `io_uring.h`, `napi.h`.
- Detected declarations: `function io_wake_function`, `function io_run_task_work_sig`, `function current_pending_io`, `function io_cqring_timer_wakeup`, `function io_cqring_min_timer_wakeup`, `function io_cqring_schedule_timeout`, `function __io_cqring_wait_schedule`, `function io_cqring_wait_schedule`, `function io_cqring_wait`.
- 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.