]> git.proxmox.com Git - mirror_zfs.git/blob - module/spl/spl-time.c
SLES10 Fixes (part 2):
[mirror_zfs.git] / module / spl / spl-time.c
1 /*
2 * This file is part of the SPL: Solaris Porting Layer.
3 *
4 * Copyright (c) 2008 Lawrence Livermore National Security, LLC.
5 * Produced at Lawrence Livermore National Laboratory
6 * Written by:
7 * Brian Behlendorf <behlendorf1@llnl.gov>,
8 * Herb Wartens <wartens2@llnl.gov>,
9 * Jim Garlick <garlick@llnl.gov>
10 * UCRL-CODE-235197
11 *
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.
16 *
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
20 * for more details.
21 *
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.
25 */
26
27 #include <sys/sysmacros.h>
28 #include <sys/time.h>
29
30 #ifdef HAVE_MONOTONIC_CLOCK
31 extern unsigned long long monotonic_clock(void);
32 #endif
33
34 #ifdef DEBUG_SUBSYSTEM
35 #undef DEBUG_SUBSYSTEM
36 #endif
37
38 #define DEBUG_SUBSYSTEM S_TIME
39
40 void
41 __gethrestime(timestruc_t *ts)
42 {
43 struct timeval tv;
44
45 do_gettimeofday(&tv);
46 ts->tv_sec = tv.tv_sec;
47 ts->tv_nsec = tv.tv_usec * NSEC_PER_USEC;
48 }
49 EXPORT_SYMBOL(__gethrestime);
50
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().
54 */
55 hrtime_t
56 __gethrtime(void) {
57 #ifdef HAVE_MONOTONIC_CLOCK
58 unsigned long long res = monotonic_clock();
59
60 /* Deal with signed/unsigned mismatch */
61 return (hrtime_t)(res & ~(1ULL << 63));
62 #else
63 uint64_t j = get_jiffies_64();
64
65 return (hrtime_t)(j * NSEC_PER_SEC / HZ);
66 #endif
67 }
68 EXPORT_SYMBOL(__gethrtime);
69
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
74 */
75 #if !defined(HAVE_SET_NORMALIZED_TIMESPEC_INLINE) && \
76 !defined(HAVE_SET_NORMALIZED_TIMESPEC_EXPORT)
77 void
78 set_normalized_timespec(struct timespec *ts, time_t sec, long nsec)
79 {
80 while (nsec >= NSEC_PER_SEC) {
81 nsec -= NSEC_PER_SEC;
82 ++sec;
83 }
84 while (nsec < 0) {
85 nsec += NSEC_PER_SEC;
86 --sec;
87 }
88 ts->tv_sec = sec;
89 ts->tv_nsec = nsec;
90 }
91 EXPORT_SYMBOL(set_normalized_timespec);
92 #endif