1 // SPDX-License-Identifier: GPL-2.0
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
24 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25 * Use is subject to license terms.
28 * This file is part of Lustre, http://www.lustre.org/
29 * Lustre is a trademark of Sun Microsystems, Inc.
31 * libcfs/include/libcfs/linux/linux-time.h
33 * Implementation of portable time API for Linux (kernel and user-level).
35 * Author: Nikita Danilov <nikita@clusterfs.com>
38 #ifndef __LIBCFS_LINUX_LINUX_TIME_H__
39 #define __LIBCFS_LINUX_LINUX_TIME_H__
41 #ifndef __LIBCFS_LIBCFS_H__
42 #error Do not #include this file directly. #include <linux/libcfs/libcfs.h> instead
45 #define ONE_BILLION ((u_int64_t)1000000000)
46 #define ONE_MILLION 1000000
48 #include <linux/module.h>
49 #include <linux/kernel.h>
50 #include <linux/time.h>
51 #include <asm/div64.h>
57 #include <linux/jiffies.h>
60 * Generic kernel stuff
63 static inline unsigned long cfs_time_current(void)
68 static inline long cfs_time_seconds(int seconds)
70 return ((long)seconds) * msecs_to_jiffies(MSEC_PER_SEC);
73 static inline long cfs_duration_sec(long d)
75 return d / msecs_to_jiffies(MSEC_PER_SEC);
78 #define cfs_time_current_64 get_jiffies_64
80 static inline u64 cfs_time_add_64(u64 t, u64 d)
85 static inline u64 cfs_time_shift_64(int seconds)
87 return cfs_time_add_64(cfs_time_current_64(),
88 cfs_time_seconds(seconds));
91 static inline int cfs_time_before_64(u64 t1, u64 t2)
93 return (__s64)t2 - (__s64)t1 > 0;
96 static inline int cfs_time_beforeq_64(u64 t1, u64 t2)
98 return (__s64)t2 - (__s64)t1 >= 0;
106 #define CFS_DURATION_T "%ld"
108 #endif /* __LIBCFS_LINUX_LINUX_TIME_H__ */