tools/testing/selftests/powerpc/benchmarks/fork.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/benchmarks/fork.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/benchmarks/fork.c- Extension
.c- Size
- 5163 bytes
- Lines
- 326
- 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
assert.herrno.hgetopt.hlimits.hlinux/futex.hpthread.hsched.hsignal.hstdio.hstdlib.hstring.hsys/shm.hsys/syscall.hsys/time.hsys/types.hsys/wait.hunistd.h
Detected Declarations
function set_cpufunction start_process_onfunction run_execfunction bench_forkfunction bench_vforkfunction bench_threadfunction sigalrm_handlerfunction sigusr1_handlerfunction usagefunction main
Annotated Snippet
if (pid == -1) {
perror("fork");
exit(1);
}
if (pid == 0) {
if (do_exec)
run_exec();
_exit(0);
}
pid = waitpid(pid, NULL, 0);
if (pid == -1) {
perror("waitpid");
exit(1);
}
iterations++;
}
}
static void bench_vfork(void)
{
while (1) {
pid_t pid = vfork();
if (pid == -1) {
perror("fork");
exit(1);
}
if (pid == 0) {
if (do_exec)
run_exec();
_exit(0);
}
pid = waitpid(pid, NULL, 0);
if (pid == -1) {
perror("waitpid");
exit(1);
}
iterations++;
}
}
static void *null_fn(void *arg)
{
pthread_exit(NULL);
}
static void bench_thread(void)
{
pthread_t tid;
cpu_set_t cpuset;
pthread_attr_t attr;
int rc;
rc = pthread_attr_init(&attr);
if (rc) {
errno = rc;
perror("pthread_attr_init");
exit(1);
}
if (cpu != -1) {
CPU_ZERO(&cpuset);
CPU_SET(cpu, &cpuset);
rc = pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset);
if (rc) {
errno = rc;
perror("pthread_attr_setaffinity_np");
exit(1);
}
}
while (1) {
rc = pthread_create(&tid, &attr, null_fn, NULL);
if (rc) {
errno = rc;
perror("pthread_create");
exit(1);
}
rc = pthread_join(tid, NULL);
if (rc) {
errno = rc;
perror("pthread_join");
exit(1);
}
iterations++;
}
}
static void sigalrm_handler(int junk)
{
Annotation
- Immediate include surface: `assert.h`, `errno.h`, `getopt.h`, `limits.h`, `linux/futex.h`, `pthread.h`, `sched.h`, `signal.h`.
- Detected declarations: `function set_cpu`, `function start_process_on`, `function run_exec`, `function bench_fork`, `function bench_vfork`, `function bench_thread`, `function sigalrm_handler`, `function sigusr1_handler`, `function usage`, `function main`.
- 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.