tools/testing/selftests/sched_ext/peek_dsq.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/sched_ext/peek_dsq.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/sched_ext/peek_dsq.c- Extension
.c- Size
- 6106 bytes
- Lines
- 225
- 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
bpf/bpf.hscx/common.hsys/wait.hunistd.hpthread.hstring.hsched.hpeek_dsq.bpf.skel.hscx_test.h
Detected Declarations
function setupfunction print_observed_pidsfunction runfunction cleanup
Annotated Snippet
if (err == 0) {
if (pid == 0) {
printf(" Sample %d: NULL peek\n", i);
} else if (pid > 0) {
printf(" Sample %d: pid %ld\n", i, pid);
count++;
}
} else {
printf(" Sample %d: error reading pid (err=%d)\n", i, err);
}
}
printf("Observed ~%ld pids in the %s DSQ(s)\n", count, dsq_name);
return count;
}
static enum scx_test_status run(void *ctx)
{
struct peek_dsq *skel = ctx;
bool failed = false;
int seconds = 3;
int err;
/* Enable the scheduler to test DSQ operations */
printf("Enabling scheduler to test DSQ insert operations...\n");
struct bpf_link *link =
bpf_map__attach_struct_ops(skel->maps.peek_dsq_ops);
if (!link) {
SCX_ERR("Failed to attach struct_ops");
return SCX_TEST_FAIL;
}
printf("Starting %d background workload threads...\n", NUM_WORKERS);
workload_running = true;
for (int i = 0; i < NUM_WORKERS; i++) {
err = pthread_create(&workload_threads[i], NULL, workload_thread_fn, NULL);
if (err) {
SCX_ERR("Failed to create workload thread %d: %s", i, strerror(err));
/* Stop already created threads */
workload_running = false;
for (int j = 0; j < i; j++)
pthread_join(workload_threads[j], NULL);
bpf_link__destroy(link);
return SCX_TEST_FAIL;
}
}
printf("Waiting for enqueue events.\n");
sleep(seconds);
while (skel->data->enqueue_count <= 0) {
printf(".");
fflush(stdout);
sleep(1);
seconds++;
if (seconds >= 30) {
printf("\n\u2717 Timeout waiting for enqueue events\n");
/* Stop workload threads and cleanup */
workload_running = false;
for (int i = 0; i < NUM_WORKERS; i++)
pthread_join(workload_threads[i], NULL);
bpf_link__destroy(link);
return SCX_TEST_FAIL;
}
}
workload_running = false;
for (int i = 0; i < NUM_WORKERS; i++) {
err = pthread_join(workload_threads[i], NULL);
if (err) {
SCX_ERR("Failed to join workload thread %d: %s", i, strerror(err));
bpf_link__destroy(link);
return SCX_TEST_FAIL;
}
}
printf("Background workload threads stopped.\n");
SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_NONE));
/* Detach the scheduler */
bpf_link__destroy(link);
printf("Enqueue/dispatch count over %d seconds: %d / %d\n", seconds,
skel->data->enqueue_count, skel->data->dispatch_count);
printf("Debug: ksym_exists=%d\n",
skel->bss->debug_ksym_exists);
/* Check DSQ insert result */
printf("DSQ insert test done on cpu: %d\n", skel->data->insert_test_cpu);
if (skel->data->insert_test_cpu != -1)
Annotation
- Immediate include surface: `bpf/bpf.h`, `scx/common.h`, `sys/wait.h`, `unistd.h`, `pthread.h`, `string.h`, `sched.h`, `peek_dsq.bpf.skel.h`.
- Detected declarations: `function setup`, `function print_observed_pids`, `function run`, `function cleanup`.
- 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.