]> git.proxmox.com Git - mirror_spl.git/blame - modules/spl/spl-time.c
Pull in timespec, list, and type compat changes to support
[mirror_spl.git] / modules / spl / spl-time.c
CommitLineData
715f6251 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
ee476682 27#include <sys/sysmacros.h>
28#include <sys/time.h>
ee476682 29
937879f1 30#ifdef DEBUG_SUBSYSTEM
31#undef DEBUG_SUBSYSTEM
32#endif
33
34#define DEBUG_SUBSYSTEM S_TIME
35
ee476682 36void
37__gethrestime(timestruc_t *ts)
38{
39 getnstimeofday((struct timespec *)ts);
40}
ee476682 41EXPORT_SYMBOL(__gethrestime);
79b31f36 42
43int
44__clock_gettime(clock_type_t type, timespec_t *tp)
45{
46 /* Only support CLOCK_REALTIME+__CLOCK_REALTIME0 for now */
937879f1 47 ASSERT((type == CLOCK_REALTIME) || (type == __CLOCK_REALTIME0));
79b31f36 48
49 getnstimeofday(tp);
50 return 0;
51}
52EXPORT_SYMBOL(__clock_gettime);
53
54/* This function may not be as fast as using monotonic_clock() but it
55 * should be much more portable, if performance becomes as issue we can
56 * look at using monotonic_clock() for x86_64 and x86 arches.
57 */
58hrtime_t
59__gethrtime(void) {
60 timespec_t tv;
61 hrtime_t rc;
62
63 do_posix_clock_monotonic_gettime(&tv);
64 rc = (NSEC_PER_SEC * (hrtime_t)tv.tv_sec) + (hrtime_t)tv.tv_nsec;
65
66 return rc;
67}
68EXPORT_SYMBOL(__gethrtime);
ff449ac4 69
6a6cafbe 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 prototypedefined but not exported
73 * 2.6.26 - 2.6.x: Function defined and exported
ff449ac4 74 */
6a6cafbe 75#if !defined(HAVE_SET_NORMALIZED_TIMESPEC_INLINE) && \
76 !defined(HAVE_SET_NORMALIZED_TIMESPEC_EXPORT)
ff449ac4 77void
78set_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}
91EXPORT_SYMBOL(set_normalized_timespec);
6a6cafbe 92#endif