tools/testing/selftests/timers/clocksource-switch.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/timers/clocksource-switch.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/timers/clocksource-switch.c- Extension
.c- Size
- 4145 bytes
- Lines
- 192
- 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.
Dependency Surface
fcntl.hstdio.hstdlib.hstring.hsys/stat.hsys/time.hsys/timex.hsys/types.hsys/wait.htime.hunistd.hkselftest.h
Detected Declarations
function get_clocksourcesfunction get_cur_clocksourcefunction change_clocksourcefunction run_testsfunction main
Annotated Snippet
switch (opt) {
case 's':
do_sanity_check = 0;
break;
case 't':
runtime = atoi(optarg);
break;
default:
printf("Usage: %s [-s] [-t <secs>]\n", argv[0]);
printf(" -s: skip sanity checks\n");
printf(" -t: Number of seconds to run\n");
exit(-1);
}
}
get_cur_clocksource(orig_clk, 512);
count = get_clocksources(clocksource_list);
if (change_clocksource(clocksource_list[0])) {
printf("Error: You probably need to run this as root\n");
return -1;
}
/* Check everything is sane before we start switching asynchronously */
if (do_sanity_check) {
for (i = 0; i < count; i++) {
ksft_print_msg("Validating clocksource %s\n",
clocksource_list[i]);
if (change_clocksource(clocksource_list[i])) {
status = -1;
goto out;
}
if (run_tests(5)) {
status = -1;
goto out;
}
}
}
ksft_print_msg("Running Asynchronous Switching Tests...\n");
pid = fork();
if (!pid)
return run_tests(runtime);
while (pid != waitpid(pid, &status, WNOHANG))
for (i = 0; i < count; i++)
if (change_clocksource(clocksource_list[i])) {
status = -1;
goto out;
}
out:
change_clocksource(orig_clk);
/* Print at the end to not mix output with child process */
ksft_print_header();
ksft_set_plan(1);
ksft_test_result(!status, "clocksource-switch\n");
ksft_exit(!status);
}
Annotation
- Immediate include surface: `fcntl.h`, `stdio.h`, `stdlib.h`, `string.h`, `sys/stat.h`, `sys/time.h`, `sys/timex.h`, `sys/types.h`.
- Detected declarations: `function get_clocksources`, `function get_cur_clocksource`, `function change_clocksource`, `function run_tests`, `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.