2017-10-04 19:33:43 +03:00
|
|
|
/*
|
2010-05-18 02:18:00 +04: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 08:38:26 +04:00
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
2010-05-18 02:18:00 +04:00
|
|
|
* This file is part of the SPL, Solaris Porting Layer.
|
2013-03-05 05:26:55 +04:00
|
|
|
* For details, see <http://zfsonlinux.org/>.
|
2008-05-26 08:38:26 +04:00
|
|
|
*
|
2010-05-18 02:18:00 +04: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 08:38:26 +04: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-18 02:18:00 +04:00
|
|
|
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
|
2017-10-04 19:33:43 +03:00
|
|
|
*/
|
2008-05-26 08:38:26 +04:00
|
|
|
|
2008-02-28 03:52:31 +03:00
|
|
|
#ifndef _SPL_TIME_H
|
2014-10-01 02:48:25 +04:00
|
|
|
#define _SPL_TIME_H
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-02-27 22:09:51 +03:00
|
|
|
#include <linux/module.h>
|
2008-02-26 23:36:04 +03:00
|
|
|
#include <linux/time.h>
|
2008-03-01 03:45:59 +03:00
|
|
|
#include <sys/types.h>
|
2008-12-24 02:40:20 +03:00
|
|
|
#include <sys/timer.h>
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2011-12-06 08:29:58 +04:00
|
|
|
#if defined(CONFIG_64BIT)
|
2014-10-01 02:48:25 +04:00
|
|
|
#define TIME_MAX INT64_MAX
|
|
|
|
#define TIME_MIN INT64_MIN
|
2011-12-06 08:29:58 +04:00
|
|
|
#else
|
2014-10-01 02:48:25 +04:00
|
|
|
#define TIME_MAX INT32_MAX
|
|
|
|
#define TIME_MIN INT32_MIN
|
2011-12-06 08:29:58 +04:00
|
|
|
#endif
|
2008-03-11 00:38:39 +03:00
|
|
|
|
2014-10-01 02:48:25 +04:00
|
|
|
#define SEC 1
|
|
|
|
#define MILLISEC 1000
|
|
|
|
#define MICROSEC 1000000
|
|
|
|
#define NANOSEC 1000000000
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2013-11-02 00:37:58 +04:00
|
|
|
#define MSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MILLISEC))
|
|
|
|
#define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC))
|
|
|
|
|
2017-07-10 22:44:23 +03: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-06 02:10:46 +03:00
|
|
|
|
2015-12-10 13:20:33 +03:00
|
|
|
static const int hz = HZ;
|
2008-03-14 22:04:41 +03:00
|
|
|
|
2014-10-01 02:48:25 +04:00
|
|
|
#define TIMESPEC_OVERFLOW(ts) \
|
|
|
|
((ts)->tv_sec < TIME_MIN || (ts)->tv_sec > TIME_MAX)
|
2008-03-14 22:04:41 +03:00
|
|
|
|
2014-10-01 02:48:25 +04:00
|
|
|
static inline void
|
|
|
|
gethrestime(timestruc_t *now)
|
|
|
|
{
|
2015-01-11 19:37:43 +03:00
|
|
|
*now = current_kernel_time();
|
2014-10-01 02:48:25 +04:00
|
|
|
}
|
2008-03-14 22:04:41 +03:00
|
|
|
|
2014-10-01 02:48:25 +04:00
|
|
|
static inline time_t
|
2008-03-11 00:38:39 +03:00
|
|
|
gethrestime_sec(void)
|
|
|
|
{
|
2014-10-01 02:48:25 +04:00
|
|
|
struct timespec ts;
|
2015-01-11 19:37:43 +03:00
|
|
|
ts = current_kernel_time();
|
2014-10-01 02:48:25 +04:00
|
|
|
return (ts.tv_sec);
|
2008-03-11 00:38:39 +03:00
|
|
|
}
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2014-10-01 02:48:25 +04:00
|
|
|
static inline hrtime_t
|
|
|
|
gethrtime(void)
|
|
|
|
{
|
|
|
|
struct timespec now;
|
|
|
|
getrawmonotonic(&now);
|
|
|
|
return (((hrtime_t)now.tv_sec * NSEC_PER_SEC) + now.tv_nsec);
|
|
|
|
}
|
2011-03-02 02:21:38 +03:00
|
|
|
|
2008-02-28 03:52:31 +03:00
|
|
|
#endif /* _SPL_TIME_H */
|