tools/testing/selftests/sched_ext/cyclic_kick_wait.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/sched_ext/cyclic_kick_wait.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/sched_ext/cyclic_kick_wait.c- Extension
.c- Size
- 4481 bytes
- Lines
- 195
- 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.herrno.hpthread.hsched.hscx/common.hstdint.hstring.htime.hunistd.hscx_test.hcyclic_kick_wait.bpf.skel.h
Detected Declarations
struct worker_ctxfunction join_workerfunction setupfunction runfunction cleanup
Annotated Snippet
struct worker_ctx {
pthread_t tid;
int cpu;
volatile bool stop;
volatile __u64 iters;
bool started;
};
static void *worker_fn(void *arg)
{
struct worker_ctx *worker = arg;
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(worker->cpu, &mask);
if (sched_setaffinity(0, sizeof(mask), &mask))
return (void *)(uintptr_t)errno;
while (!worker->stop) {
sched_yield();
worker->iters++;
}
return NULL;
}
static int join_worker(struct worker_ctx *worker)
{
void *ret;
struct timespec ts;
int err;
if (!worker->started)
return 0;
if (clock_gettime(CLOCK_REALTIME, &ts))
return -errno;
ts.tv_sec += 2;
err = pthread_timedjoin_np(worker->tid, &ret, &ts);
if (err == ETIMEDOUT)
pthread_detach(worker->tid);
if (err)
return -err;
if ((uintptr_t)ret)
return -(int)(uintptr_t)ret;
return 0;
}
static enum scx_test_status setup(void **ctx)
{
struct cyclic_kick_wait *skel;
skel = cyclic_kick_wait__open();
SCX_FAIL_IF(!skel, "Failed to open skel");
SCX_ENUM_INIT(skel);
*ctx = skel;
return SCX_TEST_PASS;
}
static enum scx_test_status run(void *ctx)
{
struct cyclic_kick_wait *skel = ctx;
struct worker_ctx workers[NR_WORKERS] = {};
struct bpf_link *link = NULL;
enum scx_test_status status = SCX_TEST_PASS;
int test_cpus[NR_TEST_CPUS];
int nr_cpus = 0;
cpu_set_t mask;
int ret, i;
if (sched_getaffinity(0, sizeof(mask), &mask)) {
SCX_ERR("Failed to get affinity (%d)", errno);
return SCX_TEST_FAIL;
}
for (i = 0; i < CPU_SETSIZE; i++) {
if (CPU_ISSET(i, &mask))
test_cpus[nr_cpus++] = i;
if (nr_cpus == NR_TEST_CPUS)
break;
}
if (nr_cpus < NR_TEST_CPUS)
return SCX_TEST_SKIP;
Annotation
- Immediate include surface: `bpf/bpf.h`, `errno.h`, `pthread.h`, `sched.h`, `scx/common.h`, `stdint.h`, `string.h`, `time.h`.
- Detected declarations: `struct worker_ctx`, `function join_worker`, `function setup`, `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.