tools/virtio/ringtest/main.c
Source file repositories/reference/linux-study-clean/tools/virtio/ringtest/main.c
File Facts
- System
- Linux kernel
- Corpus path
tools/virtio/ringtest/main.c- Extension
.c- Size
- 6532 bytes
- Lines
- 392
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
getopt.hpthread.hassert.hsched.hmain.hsys/eventfd.hstdlib.hstdio.hunistd.hlimits.h
Detected Declarations
function notifyfunction wait_for_notifyfunction kickfunction wait_for_kickfunction callfunction wait_for_callfunction set_affinityfunction poll_usedfunction __attribute__function poll_availfunction __attribute__function helpfunction main
Annotated Snippet
if (__builtin_expect(r == 0, true)) {
++started;
if (!--tokick) {
tokick = batch;
if (do_sleep)
kick_available();
}
}
} else
r = -1;
/* Flush out completed bufs if any */
if (get_buf(&len, &buf)) {
++completed;
if (__builtin_expect(completed == bufs, false))
return;
r = 0;
}
} while (r == 0);
if (completed == completed_before)
++spurious;
assert(completed <= bufs);
assert(started <= bufs);
if (do_sleep) {
if (used_empty() && enable_call())
wait_for_call();
} else {
poll_used();
}
}
}
void poll_avail(void)
{
while (avail_empty())
busy_wait();
}
static void __attribute__((__flatten__)) run_host(void)
{
int completed_before;
int completed = 0;
int spurious = 0;
int bufs = runcycles;
unsigned len;
void *buf;
for (;;) {
if (do_sleep) {
if (avail_empty() && enable_kick())
wait_for_kick();
} else {
poll_avail();
}
if (do_sleep)
disable_kick();
completed_before = completed;
while (__builtin_expect(use_buf(&len, &buf), true)) {
if (do_sleep)
call_used();
++completed;
if (__builtin_expect(completed == bufs, false))
return;
}
if (completed == completed_before)
++spurious;
assert(completed <= bufs);
if (completed == bufs)
break;
}
}
void *start_guest(void *arg)
{
set_affinity(arg);
run_guest();
pthread_exit(NULL);
}
void *start_host(void *arg)
{
set_affinity(arg);
run_host();
pthread_exit(NULL);
}
static const char optstring[] = "";
static const struct option longopts[] = {
{
Annotation
- Immediate include surface: `getopt.h`, `pthread.h`, `assert.h`, `sched.h`, `main.h`, `sys/eventfd.h`, `stdlib.h`, `stdio.h`.
- Detected declarations: `function notify`, `function wait_for_notify`, `function kick`, `function wait_for_kick`, `function call`, `function wait_for_call`, `function set_affinity`, `function poll_used`, `function __attribute__`, `function poll_avail`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.