tools/testing/selftests/proc/proc-uptime-002.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/proc/proc-uptime-002.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/proc/proc-uptime-002.c- Extension
.c- Size
- 2483 bytes
- Lines
- 93
- 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
assert.herrno.hunistd.hsys/syscall.hstdlib.hstring.hstdint.hsys/types.hsys/stat.hfcntl.hproc-uptime.h
Detected Declarations
function sys_sched_getaffinityfunction sys_sched_setaffinityfunction main
Annotated Snippet
// Test that boottime value in /proc/uptime and CLOCK_BOOTTIME increment
// monotonically while shifting across CPUs. We don't test idle time
// monotonicity due to broken iowait task counting, cf: comment above
// get_cpu_idle_time_us()
#undef NDEBUG
#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "proc-uptime.h"
static inline int sys_sched_getaffinity(pid_t pid, unsigned int len, unsigned long *m)
{
return syscall(SYS_sched_getaffinity, pid, len, m);
}
static inline int sys_sched_setaffinity(pid_t pid, unsigned int len, unsigned long *m)
{
return syscall(SYS_sched_setaffinity, pid, len, m);
}
int main(void)
{
uint64_t u0, u1, c0, c1;
unsigned int len;
unsigned long *m;
unsigned int cpu;
int fd;
/* find out "nr_cpu_ids" */
m = NULL;
len = 0;
do {
len += sizeof(unsigned long);
free(m);
m = malloc(len);
} while (sys_sched_getaffinity(0, len, m) == -1 && errno == EINVAL);
fd = open("/proc/uptime", O_RDONLY);
assert(fd >= 0);
u0 = proc_uptime(fd);
c0 = clock_boottime();
for (cpu = 0; cpu < len * 8; cpu++) {
memset(m, 0, len);
m[cpu / (8 * sizeof(unsigned long))] |= 1UL << (cpu % (8 * sizeof(unsigned long)));
/* CPU might not exist, ignore error */
sys_sched_setaffinity(0, len, m);
u1 = proc_uptime(fd);
c1 = clock_boottime();
/* Is /proc/uptime monotonic ? */
assert(u1 >= u0);
/* Is CLOCK_BOOTTIME monotonic ? */
assert(c1 >= c0);
/* Is CLOCK_BOOTTIME VS /proc/uptime monotonic ? */
assert(c0 >= u0);
u0 = u1;
c0 = c1;
}
return 0;
}
Annotation
- Immediate include surface: `assert.h`, `errno.h`, `unistd.h`, `sys/syscall.h`, `stdlib.h`, `string.h`, `stdint.h`, `sys/types.h`.
- Detected declarations: `function sys_sched_getaffinity`, `function sys_sched_setaffinity`, `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.