Motr  M0
time.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #pragma once
24 
25 #ifndef __MOTR_LIB_TIME_H__
26 #define __MOTR_LIB_TIME_H__
27 
28 #include "lib/types.h"
29 
37 typedef uint64_t m0_time_t;
38 
39 enum {
40  M0_TIME_ONE_SECOND = 1000000000ULL,
42 };
43 
44 #define TIME_F "[%" PRIu64 ":%09" PRIu64 "]"
45 #define TIME_P(t) m0_time_seconds(t), m0_time_nanoseconds(t)
46 
51 extern const m0_time_t M0_TIME_IMMEDIATELY;
53 extern const m0_time_t M0_TIME_NEVER;
54 
55 #ifdef __KERNEL__
56 # include "lib/linux_kernel/time.h"
57 #else
58 # include "lib/user_space/time.h"
59 #endif
60 
61 
63 extern const enum CLOCK_SOURCES M0_CLOCK_SOURCE;
64 
70 
80 M0_INTERNAL m0_time_t m0_time_to_realtime(m0_time_t abs_time);
81 
83 m0_time_t m0_time(uint64_t secs, long ns);
84 
86 #define M0_MKTIME(secs, ns) \
87  ((m0_time_t)((uint64_t)(secs) * M0_TIME_ONE_SECOND + (uint64_t)(ns)))
88 
91 
100 m0_time_t m0_time_from_now(uint64_t secs, long ns);
101 
109 
117 
125 int m0_nanosleep(const m0_time_t req, m0_time_t *rem);
126 
128 uint64_t m0_time_seconds(const m0_time_t time);
129 
131 uint64_t m0_time_nanoseconds(const m0_time_t time);
132 
133 bool m0_time_is_in_past(m0_time_t time);
134 
136 #endif /* __MOTR_LIB_TIME_H__ */
137 
138 /*
139  * Local variables:
140  * c-indentation-style: "K&R"
141  * c-basic-offset: 8
142  * tab-width: 8
143  * fill-column: 80
144  * scroll-step: 1
145  * End:
146  */
m0_time_t m0_time_monotonic_offset
Definition: time.c:113
CLOCK_SOURCES
Definition: time.h:36
const m0_time_t M0_TIME_NEVER
Definition: time.c:108
static struct io_request req
Definition: file.c:100
uint64_t m0_time_t
Definition: time.h:37
uint64_t m0_time_nanoseconds(const m0_time_t time)
Definition: time.c:89
enum CLOCK_SOURCES M0_CLOCK_SOURCE
Definition: time.c:112
m0_time_t m0_time(uint64_t secs, long ns)
Definition: time.c:41
static void t2(int n)
Definition: thread.c:48
bool m0_time_is_in_past(m0_time_t t)
Definition: time.c:102
m0_time_t m0_time_now(void)
Definition: time.c:134
m0_time_t m0_time_add(const m0_time_t t1, const m0_time_t t2)
Definition: time.c:47
uint64_t m0_time_seconds(const m0_time_t time)
Definition: time.c:83
m0_time_t m0_time_from_now(uint64_t secs, long ns)
Definition: time.c:96
m0_time_t m0_time_sub(const m0_time_t t1, const m0_time_t t2)
Definition: time.c:65
static void t1(int n)
Definition: mutex.c:48
M0_INTERNAL m0_time_t m0_time_to_realtime(m0_time_t abs_time)
Definition: time.c:160
const m0_time_t M0_TIME_IMMEDIATELY
Definition: time.c:107
int m0_nanosleep(const m0_time_t req, m0_time_t *rem)
Definition: ktime.c:73