]>
Commit | Line | Data |
---|---|---|
1 | /*****************************************************************************\ | |
2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. | |
3 | * Copyright (C) 2007 The Regents of the University of California. | |
4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). | |
5 | * Written by Brian Behlendorf <behlendorf1@llnl.gov>. | |
6 | * UCRL-CODE-235197 | |
7 | * | |
8 | * This file is part of the SPL, Solaris Porting Layer. | |
9 | * For details, see <http://zfsonlinux.org/>. | |
10 | * | |
11 | * The SPL is free software; you can redistribute it and/or modify it | |
12 | * under the terms of the GNU General Public License as published by the | |
13 | * Free Software Foundation; either version 2 of the License, or (at your | |
14 | * option) any later version. | |
15 | * | |
16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT | |
17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
19 | * for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License along | |
22 | * with the SPL. If not, see <http://www.gnu.org/licenses/>. | |
23 | ***************************************************************************** | |
24 | * Solaris Porting Layer (SPL) Time Implementation. | |
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 timespec tspec = current_kernel_time(); | |
44 | ||
45 | ts->tv_sec = tspec.tv_sec; | |
46 | ts->tv_nsec = tspec.tv_nsec; | |
47 | } | |
48 | EXPORT_SYMBOL(__gethrestime); | |
49 | ||
50 | /* Use monotonic_clock() by default. It's faster and is available on older | |
51 | * kernels, but few architectures have them, so we must fallback to | |
52 | * do_posix_clock_monotonic_gettime(). | |
53 | */ | |
54 | hrtime_t | |
55 | __gethrtime(void) { | |
56 | #ifdef HAVE_MONOTONIC_CLOCK | |
57 | unsigned long long res = monotonic_clock(); | |
58 | ||
59 | /* Deal with signed/unsigned mismatch */ | |
60 | return (hrtime_t)(res & ~(1ULL << 63)); | |
61 | #else | |
62 | struct timespec ts; | |
63 | ||
64 | do_posix_clock_monotonic_gettime(&ts); | |
65 | return (((hrtime_t)ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec); | |
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 |