tools/testing/selftests/timers/set-timer-lat.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/timers/set-timer-lat.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/timers/set-timer-lat.c- Extension
.c- Size
- 6331 bytes
- Lines
- 273
- 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
errno.hstdio.hunistd.htime.hstring.hsignal.hstdlib.hpthread.hinclude/vdso/time64.hkselftest.h
Detected Declarations
function timespec_subfunction sigalarmfunction describe_timerfunction setup_timerfunction check_timer_latencyfunction check_alarmcountfunction do_timerfunction do_timer_oneshotfunction main
Annotated Snippet
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include <signal.h>
#include <stdlib.h>
#include <pthread.h>
#include <include/vdso/time64.h>
#include "kselftest.h"
/* CLOCK_HWSPECIFIC == CLOCK_SGI_CYCLE (Deprecated) */
#define CLOCK_HWSPECIFIC 10
#define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */
#define TIMER_SECS 1
int alarmcount;
int clock_id;
struct timespec start_time;
long long max_latency_ns;
int timer_fired_early;
char *clockstring(int clockid)
{
switch (clockid) {
case CLOCK_REALTIME:
return "CLOCK_REALTIME";
case CLOCK_MONOTONIC:
return "CLOCK_MONOTONIC";
case CLOCK_PROCESS_CPUTIME_ID:
return "CLOCK_PROCESS_CPUTIME_ID";
case CLOCK_THREAD_CPUTIME_ID:
return "CLOCK_THREAD_CPUTIME_ID";
case CLOCK_MONOTONIC_RAW:
return "CLOCK_MONOTONIC_RAW";
case CLOCK_REALTIME_COARSE:
return "CLOCK_REALTIME_COARSE";
case CLOCK_MONOTONIC_COARSE:
return "CLOCK_MONOTONIC_COARSE";
case CLOCK_BOOTTIME:
return "CLOCK_BOOTTIME";
case CLOCK_REALTIME_ALARM:
return "CLOCK_REALTIME_ALARM";
case CLOCK_BOOTTIME_ALARM:
return "CLOCK_BOOTTIME_ALARM";
case CLOCK_TAI:
return "CLOCK_TAI";
}
return "UNKNOWN_CLOCKID";
}
long long timespec_sub(struct timespec a, struct timespec b)
{
long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;
ret -= NSEC_PER_SEC * a.tv_sec + a.tv_nsec;
return ret;
}
void sigalarm(int signo)
{
long long delta_ns;
struct timespec ts;
clock_gettime(clock_id, &ts);
alarmcount++;
delta_ns = timespec_sub(start_time, ts);
delta_ns -= NSEC_PER_SEC * TIMER_SECS * alarmcount;
if (delta_ns < 0)
timer_fired_early = 1;
if (delta_ns > max_latency_ns)
max_latency_ns = delta_ns;
}
void describe_timer(int flags, int interval)
{
printf("%-22s %s %s ",
clockstring(clock_id),
flags ? "ABSTIME":"RELTIME",
interval ? "PERIODIC":"ONE-SHOT");
}
int setup_timer(int clock_id, int flags, int interval, timer_t *tm1)
{
Annotation
- Immediate include surface: `errno.h`, `stdio.h`, `unistd.h`, `time.h`, `string.h`, `signal.h`, `stdlib.h`, `pthread.h`.
- Detected declarations: `function timespec_sub`, `function sigalarm`, `function describe_timer`, `function setup_timer`, `function check_timer_latency`, `function check_alarmcount`, `function do_timer`, `function do_timer_oneshot`, `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.