xref: /dflybsd-src/sys/dev/drm/include/linux/timekeeping.h (revision a85cb24f18e3804e75ab8bcda7692564d0563317)
181d31d56SFrançois Tigeot /*
2*a85cb24fSFrançois Tigeot  * Copyright (c) 2015-2020 François Tigeot <ftigeot@wolfpond.org>
381d31d56SFrançois Tigeot  * All rights reserved.
481d31d56SFrançois Tigeot  *
581d31d56SFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
681d31d56SFrançois Tigeot  * modification, are permitted provided that the following conditions
781d31d56SFrançois Tigeot  * are met:
881d31d56SFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
981d31d56SFrançois Tigeot  *    notice unmodified, this list of conditions, and the following
1081d31d56SFrançois Tigeot  *    disclaimer.
1181d31d56SFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
1281d31d56SFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
1381d31d56SFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
1481d31d56SFrançois Tigeot  *
1581d31d56SFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1681d31d56SFrançois Tigeot  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1781d31d56SFrançois Tigeot  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1881d31d56SFrançois Tigeot  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1981d31d56SFrançois Tigeot  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2081d31d56SFrançois Tigeot  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2181d31d56SFrançois Tigeot  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2281d31d56SFrançois Tigeot  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2381d31d56SFrançois Tigeot  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2481d31d56SFrançois Tigeot  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2581d31d56SFrançois Tigeot  */
2681d31d56SFrançois Tigeot 
2781d31d56SFrançois Tigeot #ifndef _LINUX_TIMEKEEPING_H_
2881d31d56SFrançois Tigeot #define _LINUX_TIMEKEEPING_H_
2981d31d56SFrançois Tigeot 
ktime_get_raw_ns(void)3081d31d56SFrançois Tigeot static inline u64 ktime_get_raw_ns(void)
3181d31d56SFrançois Tigeot {
3281d31d56SFrançois Tigeot 	struct timespec ts;
3381d31d56SFrançois Tigeot 
3481d31d56SFrançois Tigeot 	nanouptime(&ts);
3581d31d56SFrançois Tigeot 
3681d31d56SFrançois Tigeot 	return (ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec;
3781d31d56SFrançois Tigeot }
3881d31d56SFrançois Tigeot 
ktime_mono_to_real(ktime_t mono)399342d33fSFrançois Tigeot static inline ktime_t ktime_mono_to_real(ktime_t mono)
409342d33fSFrançois Tigeot {
419342d33fSFrançois Tigeot 	return mono;
429342d33fSFrançois Tigeot }
439342d33fSFrançois Tigeot 
ktime_get_real(void)449342d33fSFrançois Tigeot static inline ktime_t ktime_get_real(void)
459342d33fSFrançois Tigeot {
460856d15dSFrançois Tigeot 	return ktime_get_raw_ns();
479342d33fSFrançois Tigeot }
489342d33fSFrançois Tigeot 
49347f670aSFrançois Tigeot /* Include time spent in suspend state */
50347f670aSFrançois Tigeot static inline ktime_t
ktime_get_boottime(void)51347f670aSFrançois Tigeot ktime_get_boottime(void)
52347f670aSFrançois Tigeot {
53347f670aSFrançois Tigeot 	return ktime_get_real();
54347f670aSFrançois Tigeot }
55347f670aSFrançois Tigeot 
56347f670aSFrançois Tigeot static inline s64
ktime_ms_delta(const ktime_t later,const ktime_t earlier)57347f670aSFrançois Tigeot ktime_ms_delta(const ktime_t later, const ktime_t earlier)
58347f670aSFrançois Tigeot {
590856d15dSFrançois Tigeot 	return (later - earlier) / NSEC_PER_MSEC;
60347f670aSFrançois Tigeot }
61347f670aSFrançois Tigeot 
62f4fb8e4fSFrançois Tigeot static inline void
do_gettimeofday(struct timeval * tv)63f4fb8e4fSFrançois Tigeot do_gettimeofday(struct timeval *tv)
64f4fb8e4fSFrançois Tigeot {
65f4fb8e4fSFrançois Tigeot 	microtime(tv);
66f4fb8e4fSFrançois Tigeot }
67f4fb8e4fSFrançois Tigeot 
68*a85cb24fSFrançois Tigeot static inline ktime_t
ktime_get_raw(void)69*a85cb24fSFrançois Tigeot ktime_get_raw(void)
70*a85cb24fSFrançois Tigeot {
71*a85cb24fSFrançois Tigeot 	return ktime_get_raw_ns();
72*a85cb24fSFrançois Tigeot }
73*a85cb24fSFrançois Tigeot 
7481d31d56SFrançois Tigeot #endif	/* _LINUX_TIMEKEEPING_H_ */
75