xref: /linux/drivers/md/dm-vdo/time-utils.h (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright 2023 Red Hat
4  */
5 
6 #ifndef UDS_TIME_UTILS_H
7 #define UDS_TIME_UTILS_H
8 
9 #include <linux/ktime.h>
10 #include <linux/time.h>
11 #include <linux/types.h>
12 
ktime_to_seconds(ktime_t reltime)13 static inline s64 ktime_to_seconds(ktime_t reltime)
14 {
15 	return reltime / NSEC_PER_SEC;
16 }
17 
current_time_ns(clockid_t clock)18 static inline ktime_t current_time_ns(clockid_t clock)
19 {
20 	return clock == CLOCK_MONOTONIC ? ktime_get_ns() : ktime_get_real_ns();
21 }
22 
current_time_us(void)23 static inline ktime_t current_time_us(void)
24 {
25 	return current_time_ns(CLOCK_REALTIME) / NSEC_PER_USEC;
26 }
27 
28 #endif /* UDS_TIME_UTILS_H */
29