]>
git.proxmox.com Git - mirror_zfs.git/blob - modules/spl/spl-time.c
88722afe1bfa4466406279c7e1a3c721d84b03e4
2 * This file is part of the SPL: Solaris Porting Layer.
4 * Copyright (c) 2008 Lawrence Livermore National Security, LLC.
5 * Produced at Lawrence Livermore National Laboratory
7 * Brian Behlendorf <behlendorf1@llnl.gov>,
8 * Herb Wartens <wartens2@llnl.gov>,
9 * Jim Garlick <garlick@llnl.gov>
12 * This is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <sys/sysmacros.h>
30 #ifdef HAVE_MONOTONIC_CLOCK
31 extern unsigned long long monotonic_clock(void);
34 #ifdef DEBUG_SUBSYSTEM
35 #undef DEBUG_SUBSYSTEM
38 #define DEBUG_SUBSYSTEM S_TIME
41 __gethrestime(timestruc_t
*ts
)
46 ts
->tv_sec
= tv
.tv_sec
;
47 ts
->tv_nsec
= tv
.tv_usec
* NSEC_PER_USEC
;
49 EXPORT_SYMBOL(__gethrestime
);
51 /* Use monotonic_clock() by default. It's faster and is available on older
52 * kernels, but few architectures have them, so we must fallback to
53 * do_posix_clock_monotonic_gettime().
57 #ifdef HAVE_MONOTONIC_CLOCK
58 unsigned long long res
= monotonic_clock();
60 /* Deal with signed/unsigned mismatch */
61 return (hrtime_t
)(res
& ~(1ULL << 63));
63 int64_t j
= get_jiffies_64();
65 return j
* NSEC_PER_SEC
/ HZ
;
68 EXPORT_SYMBOL(__gethrtime
);
70 /* set_normalized_timespec() API changes
71 * 2.6.0 - 2.6.15: Inline function provided by linux/time.h
72 * 2.6.16 - 2.6.25: Function prototype defined but not exported
73 * 2.6.26 - 2.6.x: Function defined and exported
75 #if !defined(HAVE_SET_NORMALIZED_TIMESPEC_INLINE) && \
76 !defined(HAVE_SET_NORMALIZED_TIMESPEC_EXPORT)
78 set_normalized_timespec(struct timespec
*ts
, time_t sec
, long nsec
)
80 while (nsec
>= NSEC_PER_SEC
) {
91 EXPORT_SYMBOL(set_normalized_timespec
);