tools/testing/selftests/powerpc/benchmarks/context_switch.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/benchmarks/context_switch.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/benchmarks/context_switch.c- Extension
.c- Size
- 9044 bytes
- Lines
- 509
- 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.
- 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
errno.hsched.hstring.hstdio.hunistd.hstdlib.hgetopt.hsignal.hassert.hpthread.hlimits.hsys/time.hsys/syscall.hsys/sysinfo.hsys/types.hsys/shm.hlinux/futex.haltivec.hutils.h
Detected Declarations
struct actionsfunction __attribute__function touchfunction start_thread_onfunction start_process_onfunction sigalrm_handlerfunction sigusr1_handlerfunction pipe_setupfunction yield_setupfunction sys_futexfunction cmpxchgfunction xchgfunction mutex_lockfunction mutex_unlockfunction futex_setupfunction usagefunction main
Annotated Snippet
struct actions {
void (*setup)(int, int);
void *(*thread1)(void *);
void *(*thread2)(void *);
};
#define READ 0
#define WRITE 1
static int pipe_fd1[2];
static int pipe_fd2[2];
static void pipe_setup(int cpu1, int cpu2)
{
if (pipe(pipe_fd1) || pipe(pipe_fd2))
exit(1);
}
static void *pipe_thread1(void *arg)
{
signal(SIGALRM, sigalrm_handler);
alarm(1);
while (1) {
assert(read(pipe_fd1[READ], &c, 1) == 1);
touch();
assert(write(pipe_fd2[WRITE], &c, 1) == 1);
touch();
iterations += 2;
}
return NULL;
}
static void *pipe_thread2(void *arg)
{
while (1) {
assert(write(pipe_fd1[WRITE], &c, 1) == 1);
touch();
assert(read(pipe_fd2[READ], &c, 1) == 1);
touch();
}
return NULL;
}
static struct actions pipe_actions = {
.setup = pipe_setup,
.thread1 = pipe_thread1,
.thread2 = pipe_thread2,
};
static void yield_setup(int cpu1, int cpu2)
{
if (cpu1 != cpu2) {
fprintf(stderr, "Both threads must be on the same CPU for yield test\n");
exit(1);
}
}
static void *yield_thread1(void *arg)
{
signal(SIGALRM, sigalrm_handler);
alarm(1);
while (1) {
sched_yield();
touch();
iterations += 2;
}
return NULL;
}
static void *yield_thread2(void *arg)
{
while (1) {
sched_yield();
touch();
}
return NULL;
}
static struct actions yield_actions = {
.setup = yield_setup,
Annotation
- Immediate include surface: `errno.h`, `sched.h`, `string.h`, `stdio.h`, `unistd.h`, `stdlib.h`, `getopt.h`, `signal.h`.
- Detected declarations: `struct actions`, `function __attribute__`, `function touch`, `function start_thread_on`, `function start_process_on`, `function sigalrm_handler`, `function sigusr1_handler`, `function pipe_setup`, `function yield_setup`, `function sys_futex`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.