tools/testing/selftests/timers/raw_skew.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/timers/raw_skew.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/timers/raw_skew.c- Extension
.c- Size
- 3596 bytes
- Lines
- 146
- 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
stdio.hunistd.hstdlib.hsys/time.hsys/timex.htime.hinclude/vdso/time64.hkselftest.h
Detected Declarations
function llabsfunction ts_to_nsecfunction nsec_to_tsfunction diff_timespecfunction get_monotonic_and_rawfunction main
Annotated Snippet
if (diff == 0 || newdiff < diff) {
diff = newdiff;
*raw = mid;
tmp = (ts_to_nsec(start) + ts_to_nsec(end))/2;
*mon = nsec_to_ts(tmp);
}
}
}
int main(int argc, char **argv)
{
struct timespec mon, raw, start, end;
long long delta1, delta2, interval, eppm, ppm;
struct timex tx1, tx2;
setbuf(stdout, NULL);
if (clock_gettime(CLOCK_MONOTONIC_RAW, &raw)) {
printf("ERR: NO CLOCK_MONOTONIC_RAW\n");
return -1;
}
tx1.modes = 0;
adjtimex(&tx1);
get_monotonic_and_raw(&mon, &raw);
start = mon;
delta1 = diff_timespec(mon, raw);
if (tx1.offset)
printf("WARNING: ADJ_OFFSET in progress, this will cause inaccurate results\n");
printf("Estimating clock drift: ");
fflush(stdout);
sleep(120);
get_monotonic_and_raw(&mon, &raw);
end = mon;
tx2.modes = 0;
adjtimex(&tx2);
delta2 = diff_timespec(mon, raw);
interval = diff_timespec(start, end);
/* calculate measured ppm between MONOTONIC and MONOTONIC_RAW */
eppm = ((delta2-delta1)*NSEC_PER_SEC)/interval;
eppm = -eppm;
printf("%lld.%i(est)", eppm/1000, abs((int)(eppm%1000)));
/* Avg the two actual freq samples adjtimex gave us */
ppm = (long long)(tx1.freq + tx2.freq) * 1000 / 2;
ppm = shift_right(ppm, 16);
printf(" %lld.%i(act)", ppm/1000, abs((int)(ppm%1000)));
if (llabs(eppm - ppm) > 1000) {
if (tx1.offset || tx2.offset ||
tx1.freq != tx2.freq || tx1.tick != tx2.tick) {
printf(" [SKIP]\n");
ksft_exit_skip("The clock was adjusted externally. Shutdown NTPd or other time sync daemons\n");
}
printf(" [FAILED]\n");
ksft_exit_fail();
}
printf(" [OK]\n");
ksft_exit_pass();
}
Annotation
- Immediate include surface: `stdio.h`, `unistd.h`, `stdlib.h`, `sys/time.h`, `sys/timex.h`, `time.h`, `include/vdso/time64.h`, `kselftest.h`.
- Detected declarations: `function llabs`, `function ts_to_nsec`, `function nsec_to_ts`, `function diff_timespec`, `function get_monotonic_and_raw`, `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.