]>
Commit | Line | Data |
---|---|---|
716154c5 BB |
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>. | |
715f6251 | 6 | * UCRL-CODE-235197 |
7 | * | |
716154c5 | 8 | * This file is part of the SPL, Solaris Porting Layer. |
3d6af2dd | 9 | * For details, see <http://zfsonlinux.org/>. |
715f6251 | 10 | * |
716154c5 BB |
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 | |
715f6251 | 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 | |
716154c5 BB |
22 | * with the SPL. If not, see <http://www.gnu.org/licenses/>. |
23 | \*****************************************************************************/ | |
715f6251 | 24 | |
09b414e8 | 25 | #ifndef _SPL_TIME_H |
26 | #define _SPL_TIME_H | |
f1ca4da6 | 27 | |
28 | /* | |
29 | * Structure returned by gettimeofday(2) system call, | |
30 | * and used in other calls. | |
31 | */ | |
f1b59d26 | 32 | #include <linux/module.h> |
f1ca4da6 | 33 | #include <linux/time.h> |
f4b37741 | 34 | #include <sys/types.h> |
2b88beb7 | 35 | #include <sys/timer.h> |
f1ca4da6 | 36 | |
791dc876 CD |
37 | #if defined(CONFIG_64BIT) |
38 | #define TIME_MAX INT64_MAX | |
39 | #define TIME_MIN INT64_MIN | |
40 | #else | |
41 | #define TIME_MAX INT32_MAX | |
42 | #define TIME_MIN INT32_MIN | |
43 | #endif | |
ee476682 | 44 | |
45 | #define SEC 1 | |
46 | #define MILLISEC 1000 | |
47 | #define MICROSEC 1000000 | |
48 | #define NANOSEC 1000000000 | |
f1ca4da6 | 49 | |
33a20369 LG |
50 | #define MSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MILLISEC)) |
51 | #define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC)) | |
52 | ||
79b31f36 | 53 | /* Already defined in include/linux/time.h */ |
54 | #undef CLOCK_THREAD_CPUTIME_ID | |
55 | #undef CLOCK_REALTIME | |
56 | #undef CLOCK_MONOTONIC | |
57 | #undef CLOCK_PROCESS_CPUTIME_ID | |
58 | ||
59 | typedef enum clock_type { | |
60 | __CLOCK_REALTIME0 = 0, /* obsolete; same as CLOCK_REALTIME */ | |
61 | CLOCK_VIRTUAL = 1, /* thread's user-level CPU clock */ | |
62 | CLOCK_THREAD_CPUTIME_ID = 2, /* thread's user+system CPU clock */ | |
63 | CLOCK_REALTIME = 3, /* wall clock */ | |
64 | CLOCK_MONOTONIC = 4, /* high resolution monotonic clock */ | |
65 | CLOCK_PROCESS_CPUTIME_ID = 5, /* process's user+system CPU clock */ | |
66 | CLOCK_HIGHRES = CLOCK_MONOTONIC, /* alternate name */ | |
67 | CLOCK_PROF = CLOCK_THREAD_CPUTIME_ID,/* alternate name */ | |
68 | } clock_type_t; | |
69 | ||
f1ca4da6 | 70 | #define hz \ |
71 | ({ \ | |
937879f1 | 72 | ASSERT(HZ >= 100 && HZ <= MICROSEC); \ |
f1ca4da6 | 73 | HZ; \ |
74 | }) | |
75 | ||
79b31f36 | 76 | extern void __gethrestime(timestruc_t *); |
77 | extern int __clock_gettime(clock_type_t, timespec_t *); | |
78 | extern hrtime_t __gethrtime(void); | |
79 | ||
80 | #define gethrestime(ts) __gethrestime(ts) | |
81 | #define clock_gettime(fl, tp) __clock_gettime(fl, tp) | |
82 | #define gethrtime() __gethrtime() | |
83 | ||
ee476682 | 84 | static __inline__ time_t |
85 | gethrestime_sec(void) | |
86 | { | |
87 | timestruc_t now; | |
88 | ||
89 | __gethrestime(&now); | |
90 | return now.tv_sec; | |
91 | } | |
f1ca4da6 | 92 | |
a4a1e1ec | 93 | #define TIMESPEC_OVERFLOW(ts) \ |
791dc876 | 94 | ((ts)->tv_sec < TIME_MIN || (ts)->tv_sec > TIME_MAX) |
a4a1e1ec | 95 | |
09b414e8 | 96 | #endif /* _SPL_TIME_H */ |