2017-10-04 16:33:43 +00:00
|
|
|
/*
|
2010-05-17 22:18:00 +00:00
|
|
|
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
|
|
|
|
* Copyright (C) 2007 The Regents of the University of California.
|
|
|
|
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
|
|
|
|
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
|
2008-05-26 04:38:26 +00:00
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
2010-05-17 22:18:00 +00:00
|
|
|
* This file is part of the SPL, Solaris Porting Layer.
|
2013-03-05 01:26:55 +00:00
|
|
|
* For details, see <http://zfsonlinux.org/>.
|
2008-05-26 04:38:26 +00:00
|
|
|
*
|
2010-05-17 22:18:00 +00:00
|
|
|
* The SPL is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* The SPL is distributed in the hope that it will be useful, but WITHOUT
|
2008-05-26 04:38:26 +00:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2010-05-17 22:18:00 +00:00
|
|
|
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
|
2017-10-04 16:33:43 +00:00
|
|
|
*/
|
2008-05-26 04:38:26 +00:00
|
|
|
|
2008-02-28 00:52:31 +00:00
|
|
|
#ifndef _SPL_TIME_H
|
2014-09-30 22:48:25 +00:00
|
|
|
#define _SPL_TIME_H
|
2008-02-26 20:36:04 +00:00
|
|
|
|
2008-02-27 19:09:51 +00:00
|
|
|
#include <linux/module.h>
|
2008-02-26 20:36:04 +00:00
|
|
|
#include <linux/time.h>
|
2008-03-01 00:45:59 +00:00
|
|
|
#include <sys/types.h>
|
2008-12-23 23:40:20 +00:00
|
|
|
#include <sys/timer.h>
|
2008-02-26 20:36:04 +00:00
|
|
|
|
2011-12-06 04:29:58 +00:00
|
|
|
#if defined(CONFIG_64BIT)
|
2014-09-30 22:48:25 +00:00
|
|
|
#define TIME_MAX INT64_MAX
|
|
|
|
#define TIME_MIN INT64_MIN
|
2011-12-06 04:29:58 +00:00
|
|
|
#else
|
2014-09-30 22:48:25 +00:00
|
|
|
#define TIME_MAX INT32_MAX
|
|
|
|
#define TIME_MIN INT32_MIN
|
2011-12-06 04:29:58 +00:00
|
|
|
#endif
|
2008-03-10 21:38:39 +00:00
|
|
|
|
2014-09-30 22:48:25 +00:00
|
|
|
#define SEC 1
|
|
|
|
#define MILLISEC 1000
|
|
|
|
#define MICROSEC 1000000
|
|
|
|
#define NANOSEC 1000000000
|
2008-02-26 20:36:04 +00:00
|
|
|
|
2013-11-01 20:37:58 +00:00
|
|
|
#define MSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MILLISEC))
|
|
|
|
#define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC))
|
|
|
|
|
2017-07-10 19:44:23 +00:00
|
|
|
#define USEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MICROSEC))
|
|
|
|
#define NSEC2USEC(n) ((n) / (NANOSEC / MICROSEC))
|
|
|
|
|
|
|
|
#define NSEC2SEC(n) ((n) / (NANOSEC / SEC))
|
|
|
|
#define SEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / SEC))
|
2016-05-05 23:10:46 +00:00
|
|
|
|
2015-12-10 10:20:33 +00:00
|
|
|
static const int hz = HZ;
|
2008-03-14 19:04:41 +00:00
|
|
|
|
2018-06-20 04:51:18 +00:00
|
|
|
typedef longlong_t hrtime_t;
|
|
|
|
typedef struct timespec timespec_t;
|
|
|
|
|
2014-09-30 22:48:25 +00:00
|
|
|
#define TIMESPEC_OVERFLOW(ts) \
|
|
|
|
((ts)->tv_sec < TIME_MIN || (ts)->tv_sec > TIME_MAX)
|
2008-03-14 19:04:41 +00:00
|
|
|
|
2018-06-20 04:51:18 +00:00
|
|
|
#if defined(HAVE_INODE_TIMESPEC64_TIMES)
|
|
|
|
typedef struct timespec64 inode_timespec_t;
|
|
|
|
#else
|
|
|
|
typedef struct timespec inode_timespec_t;
|
|
|
|
#endif
|
|
|
|
|
2014-09-30 22:48:25 +00:00
|
|
|
static inline void
|
2018-06-20 04:51:18 +00:00
|
|
|
gethrestime(inode_timespec_t *ts)
|
2014-09-30 22:48:25 +00:00
|
|
|
{
|
2018-06-20 04:51:18 +00:00
|
|
|
#if defined(HAVE_INODE_TIMESPEC64_TIMES)
|
|
|
|
*ts = current_kernel_time64();
|
|
|
|
#else
|
|
|
|
*ts = current_kernel_time();
|
|
|
|
#endif
|
2014-09-30 22:48:25 +00:00
|
|
|
}
|
2008-03-14 19:04:41 +00:00
|
|
|
|
2014-09-30 22:48:25 +00:00
|
|
|
static inline time_t
|
2008-03-10 21:38:39 +00:00
|
|
|
gethrestime_sec(void)
|
|
|
|
{
|
2014-09-30 22:48:25 +00:00
|
|
|
struct timespec ts;
|
2015-01-11 16:37:43 +00:00
|
|
|
ts = current_kernel_time();
|
2014-09-30 22:48:25 +00:00
|
|
|
return (ts.tv_sec);
|
2008-03-10 21:38:39 +00:00
|
|
|
}
|
2008-02-26 20:36:04 +00:00
|
|
|
|
2014-09-30 22:48:25 +00:00
|
|
|
static inline hrtime_t
|
|
|
|
gethrtime(void)
|
|
|
|
{
|
2018-06-20 04:51:18 +00:00
|
|
|
struct timespec ts;
|
|
|
|
getrawmonotonic(&ts);
|
|
|
|
return (((hrtime_t)ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec);
|
2014-09-30 22:48:25 +00:00
|
|
|
}
|
2011-03-01 23:21:38 +00:00
|
|
|
|
2008-02-28 00:52:31 +00:00
|
|
|
#endif /* _SPL_TIME_H */
|