tools/perf/bench/syscall.c
Source file repositories/reference/linux-study-clean/tools/perf/bench/syscall.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/bench/syscall.c- Extension
.c- Size
- 3649 bytes
- Lines
- 189
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: syscall or user/kernel boundary
- Status
- core 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 participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
../perf.h../util/util.hsubcmd/parse-options.h../builtin.hbench.hstdio.hsys/time.hsys/syscall.hsys/types.hsys/wait.hunistd.hstdlib.h
Detected Declarations
function test_forkfunction test_execvefunction bench_syscall_commonfunction bench_syscall_basicfunction bench_syscall_getpgidfunction bench_syscall_forkfunction bench_syscall_execve
Annotated Snippet
if (waitpid(pid, NULL, 0) < 0) {
fprintf(stderr, "waitpid failed\n");
exit(1);
}
}
}
static void test_execve(void)
{
const char *pathname = "/bin/true";
char *const argv[] = { (char *)pathname, NULL };
pid_t pid = fork();
if (pid < 0) {
fprintf(stderr, "fork failed\n");
exit(1);
} else if (pid == 0) {
execve(pathname, argv, NULL);
fprintf(stderr, "execve /bin/true failed\n");
exit(1);
} else {
if (waitpid(pid, NULL, 0) < 0) {
fprintf(stderr, "waitpid failed\n");
exit(1);
}
}
}
static int bench_syscall_common(int argc, const char **argv, int syscall)
{
struct timeval start, stop, diff;
unsigned long long result_usec = 0;
const char *name = NULL;
int i;
switch (syscall) {
case __NR_fork:
case __NR_execve:
/* Limit default loop to 10000 times to save time */
loops = 10000;
break;
default:
loops = 10000000;
break;
}
/* Options -l and --loops override default above */
argc = parse_options(argc, argv, options, bench_syscall_usage, 0);
gettimeofday(&start, NULL);
for (i = 0; i < loops; i++) {
switch (syscall) {
case __NR_getppid:
getppid();
break;
case __NR_getpgid:
getpgid(0);
break;
case __NR_fork:
test_fork();
break;
case __NR_execve:
test_execve();
default:
break;
}
}
gettimeofday(&stop, NULL);
timersub(&stop, &start, &diff);
switch (syscall) {
case __NR_getppid:
name = "getppid()";
break;
case __NR_getpgid:
name = "getpgid()";
break;
case __NR_fork:
name = "fork()";
break;
case __NR_execve:
name = "execve()";
break;
default:
break;
}
switch (bench_format) {
Annotation
- Immediate include surface: `../perf.h`, `../util/util.h`, `subcmd/parse-options.h`, `../builtin.h`, `bench.h`, `stdio.h`, `sys/time.h`, `sys/syscall.h`.
- Detected declarations: `function test_fork`, `function test_execve`, `function bench_syscall_common`, `function bench_syscall_basic`, `function bench_syscall_getpgid`, `function bench_syscall_fork`, `function bench_syscall_execve`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: core 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.