Linux-libre 4.15.7-gnu
[librecmc/linux-libre.git] / drivers / staging / lustre / include / linux / libcfs / linux / linux-time.h
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * GPL HEADER START
4  *
5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 only,
9  * as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License version 2 for more details (a copy is included
15  * in the LICENSE file that accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License
18  * version 2 along with this program; If not, see
19  * http://www.gnu.org/licenses/gpl-2.0.html
20  *
21  * GPL HEADER END
22  */
23 /*
24  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25  * Use is subject to license terms.
26  */
27 /*
28  * This file is part of Lustre, http://www.lustre.org/
29  * Lustre is a trademark of Sun Microsystems, Inc.
30  *
31  * libcfs/include/libcfs/linux/linux-time.h
32  *
33  * Implementation of portable time API for Linux (kernel and user-level).
34  *
35  * Author: Nikita Danilov <nikita@clusterfs.com>
36  */
37
38 #ifndef __LIBCFS_LINUX_LINUX_TIME_H__
39 #define __LIBCFS_LINUX_LINUX_TIME_H__
40
41 #ifndef __LIBCFS_LIBCFS_H__
42 #error Do not #include this file directly. #include <linux/libcfs/libcfs.h> instead
43 #endif
44
45 #define ONE_BILLION ((u_int64_t)1000000000)
46 #define ONE_MILLION 1000000
47
48 #include <linux/module.h>
49 #include <linux/kernel.h>
50 #include <linux/time.h>
51 #include <asm/div64.h>
52
53 /*
54  * post 2.5 kernels.
55  */
56
57 #include <linux/jiffies.h>
58
59 /*
60  * Generic kernel stuff
61  */
62
63 static inline unsigned long cfs_time_current(void)
64 {
65         return jiffies;
66 }
67
68 static inline long cfs_time_seconds(int seconds)
69 {
70         return ((long)seconds) * msecs_to_jiffies(MSEC_PER_SEC);
71 }
72
73 static inline long cfs_duration_sec(long d)
74 {
75         return d / msecs_to_jiffies(MSEC_PER_SEC);
76 }
77
78 #define cfs_time_current_64 get_jiffies_64
79
80 static inline u64 cfs_time_add_64(u64 t, u64 d)
81 {
82         return t + d;
83 }
84
85 static inline u64 cfs_time_shift_64(int seconds)
86 {
87         return cfs_time_add_64(cfs_time_current_64(),
88                                cfs_time_seconds(seconds));
89 }
90
91 static inline int cfs_time_before_64(u64 t1, u64 t2)
92 {
93         return (__s64)t2 - (__s64)t1 > 0;
94 }
95
96 static inline int cfs_time_beforeq_64(u64 t1, u64 t2)
97 {
98         return (__s64)t2 - (__s64)t1 >= 0;
99 }
100
101 /*
102  * One jiffy
103  */
104 #define CFS_TICK                (1)
105
106 #define CFS_DURATION_T    "%ld"
107
108 #endif /* __LIBCFS_LINUX_LINUX_TIME_H__ */