include/linux/ktime.h
Source file repositories/reference/linux-study-clean/include/linux/ktime.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/ktime.h- Extension
.h- Size
- 5542 bytes
- Lines
- 238
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/bug.hlinux/jiffies.hlinux/time.hlinux/types.hvdso/ktime.hlinux/timekeeping.h
Detected Declarations
function Copyrightfunction timespec64_to_ktimefunction ktime_to_nsfunction ktime_comparefunction ktime_afterfunction ktime_beforefunction ktime_divnsfunction ktime_divnsfunction ktime_to_usfunction ktime_to_msfunction ktime_us_deltafunction ktime_ms_deltafunction ktime_add_usfunction ktime_add_msfunction ktime_sub_usfunction ktime_sub_msfunction ktime_to_timespec64_condfunction ns_to_ktimefunction us_to_ktimefunction ms_to_ktime
Annotated Snippet
#ifndef _LINUX_KTIME_H
#define _LINUX_KTIME_H
#include <asm/bug.h>
#include <linux/jiffies.h>
#include <linux/time.h>
#include <linux/types.h>
/**
* ktime_set - Set a ktime_t variable from a seconds/nanoseconds value
* @secs: seconds to set
* @nsecs: nanoseconds to set
*
* Return: The ktime_t representation of the value.
*/
static inline ktime_t ktime_set(const s64 secs, const unsigned long nsecs)
{
if (unlikely(secs >= KTIME_SEC_MAX))
return KTIME_MAX;
return secs * NSEC_PER_SEC + (s64)nsecs;
}
/* Subtract two ktime_t variables. rem = lhs -rhs: */
#define ktime_sub(lhs, rhs) ((lhs) - (rhs))
/* Add two ktime_t variables. res = lhs + rhs: */
#define ktime_add(lhs, rhs) ((lhs) + (rhs))
/*
* Same as ktime_add(), but avoids undefined behaviour on overflow; however,
* this means that you must check the result for overflow yourself.
*/
#define ktime_add_unsafe(lhs, rhs) ((u64) (lhs) + (rhs))
/*
* Add a ktime_t variable and a scalar nanosecond value.
* res = kt + nsval:
*/
#define ktime_add_ns(kt, nsval) ((kt) + (nsval))
/*
* Subtract a scalar nanosecod from a ktime_t variable
* res = kt - nsval:
*/
#define ktime_sub_ns(kt, nsval) ((kt) - (nsval))
/* convert a timespec64 to ktime_t format: */
static inline ktime_t timespec64_to_ktime(struct timespec64 ts)
{
return ktime_set(ts.tv_sec, ts.tv_nsec);
}
/* Map the ktime_t to timespec conversion to ns_to_timespec function */
#define ktime_to_timespec64(kt) ns_to_timespec64((kt))
/* Convert ktime_t to nanoseconds */
static inline s64 ktime_to_ns(const ktime_t kt)
{
return kt;
}
/**
* ktime_compare - Compares two ktime_t variables for less, greater or equal
* @cmp1: comparable1
* @cmp2: comparable2
*
* Return: ...
* cmp1 < cmp2: return <0
* cmp1 == cmp2: return 0
* cmp1 > cmp2: return >0
*/
static inline int ktime_compare(const ktime_t cmp1, const ktime_t cmp2)
{
if (cmp1 < cmp2)
return -1;
if (cmp1 > cmp2)
return 1;
return 0;
}
/**
* ktime_after - Compare if a ktime_t value is bigger than another one.
* @cmp1: comparable1
* @cmp2: comparable2
*
* Return: true if cmp1 happened after cmp2.
*/
static inline bool ktime_after(const ktime_t cmp1, const ktime_t cmp2)
{
Annotation
- Immediate include surface: `asm/bug.h`, `linux/jiffies.h`, `linux/time.h`, `linux/types.h`, `vdso/ktime.h`, `linux/timekeeping.h`.
- Detected declarations: `function Copyright`, `function timespec64_to_ktime`, `function ktime_to_ns`, `function ktime_compare`, `function ktime_after`, `function ktime_before`, `function ktime_divns`, `function ktime_divns`, `function ktime_to_us`, `function ktime_to_ms`.
- Atlas domain: Core OS / Core Kernel Interface.
- 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.