arch/um/os-Linux/time.c
Source file repositories/reference/linux-study-clean/arch/um/os-Linux/time.c
File Facts
- System
- Linux kernel
- Corpus path
arch/um/os-Linux/time.c- Extension
.c- Size
- 3631 bytes
- Lines
- 158
- Domain
- Architecture Layer
- Bucket
- arch/um
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stddef.hunistd.herrno.hsignal.htime.hsys/signalfd.hsys/time.hkern_util.hos.hsmp.hstring.hinternal.h
Detected Declarations
function timespec_to_nsfunction os_persistent_clock_emulationfunction os_timer_createfunction os_timer_set_intervalfunction os_timer_one_shotfunction os_timer_disablefunction os_nsecsfunction os_idle_preparefunction os_idle_sleep
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2015 Anton Ivanov (aivanov@{brocade.com,kot-begemot.co.uk})
* Copyright (C) 2015 Thomas Meyer (thomas@m3y3r.de)
* Copyright (C) 2012-2014 Cisco Systems
* Copyright (C) 2000 - 2007 Jeff Dike (jdike{addtoit,linux.intel}.com)
*/
#include <stddef.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <time.h>
#include <sys/signalfd.h>
#include <sys/time.h>
#include <kern_util.h>
#include <os.h>
#include <smp.h>
#include <string.h>
#include "internal.h"
static timer_t event_high_res_timer[CONFIG_NR_CPUS] = { 0 };
static inline long long timespec_to_ns(const struct timespec *ts)
{
return ((long long) ts->tv_sec * UM_NSEC_PER_SEC) + ts->tv_nsec;
}
long long os_persistent_clock_emulation(void)
{
struct timespec realtime_tp;
clock_gettime(CLOCK_REALTIME, &realtime_tp);
return timespec_to_ns(&realtime_tp);
}
#ifndef sigev_notify_thread_id
#define sigev_notify_thread_id _sigev_un._tid
#endif
/**
* os_timer_create() - create an new posix (interval) timer
*/
int os_timer_create(void)
{
int cpu = uml_curr_cpu();
timer_t *t = &event_high_res_timer[cpu];
struct sigevent sev = {
.sigev_notify = SIGEV_THREAD_ID,
.sigev_signo = SIGALRM,
.sigev_value.sival_ptr = t,
.sigev_notify_thread_id = gettid(),
};
if (timer_create(CLOCK_MONOTONIC, &sev, t) == -1)
return -1;
return 0;
}
int os_timer_set_interval(int cpu, unsigned long long nsecs)
{
struct itimerspec its;
its.it_value.tv_sec = nsecs / UM_NSEC_PER_SEC;
its.it_value.tv_nsec = nsecs % UM_NSEC_PER_SEC;
its.it_interval.tv_sec = nsecs / UM_NSEC_PER_SEC;
its.it_interval.tv_nsec = nsecs % UM_NSEC_PER_SEC;
if (timer_settime(event_high_res_timer[cpu], 0, &its, NULL) == -1)
return -errno;
return 0;
}
int os_timer_one_shot(int cpu, unsigned long long nsecs)
{
struct itimerspec its = {
.it_value.tv_sec = nsecs / UM_NSEC_PER_SEC,
.it_value.tv_nsec = nsecs % UM_NSEC_PER_SEC,
.it_interval.tv_sec = 0,
.it_interval.tv_nsec = 0, // we cheat here
};
timer_settime(event_high_res_timer[cpu], 0, &its, NULL);
return 0;
}
Annotation
- Immediate include surface: `stddef.h`, `unistd.h`, `errno.h`, `signal.h`, `time.h`, `sys/signalfd.h`, `sys/time.h`, `kern_util.h`.
- Detected declarations: `function timespec_to_ns`, `function os_persistent_clock_emulation`, `function os_timer_create`, `function os_timer_set_interval`, `function os_timer_one_shot`, `function os_timer_disable`, `function os_nsecs`, `function os_idle_prepare`, `function os_idle_sleep`.
- Atlas domain: Architecture Layer / arch/um.
- 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.