xref: /titanic_50/usr/src/lib/libfakekernel/common/clock.c (revision a90cf9f29973990687fa61de9f1f6ea22e924e40)
1b819cea2SGordon Ross /*
2b819cea2SGordon Ross  * This file and its contents are supplied under the terms of the
3b819cea2SGordon Ross  * Common Development and Distribution License ("CDDL"), version 1.0.
4b819cea2SGordon Ross  * You may only use this file in accordance with the terms of version
5b819cea2SGordon Ross  * 1.0 of the CDDL.
6b819cea2SGordon Ross  *
7b819cea2SGordon Ross  * A full copy of the text of the CDDL should have accompanied this
8b819cea2SGordon Ross  * source.  A copy of the CDDL is also available via the Internet at
9b819cea2SGordon Ross  * http://www.illumos.org/license/CDDL.
10b819cea2SGordon Ross  */
11b819cea2SGordon Ross 
12b819cea2SGordon Ross /*
13*a90cf9f2SGordon Ross  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
14b819cea2SGordon Ross  */
15b819cea2SGordon Ross 
16b819cea2SGordon Ross 
17b819cea2SGordon Ross #include <sys/types.h>
18b819cea2SGordon Ross #include <sys/time.h>
19b819cea2SGordon Ross #include <sys/thread.h>
20b819cea2SGordon Ross #include <sys/proc.h>
21b819cea2SGordon Ross 
22b819cea2SGordon Ross #include <sys/poll.h>
23b819cea2SGordon Ross 
24b819cea2SGordon Ross #include <time.h>
25b819cea2SGordon Ross 
26b819cea2SGordon Ross int hz = 1000;
27b819cea2SGordon Ross int tick_per_msec = 0;
28b819cea2SGordon Ross int msec_per_tick = 1;
29b819cea2SGordon Ross int usec_per_tick = 1000;
30b819cea2SGordon Ross int nsec_per_tick = 1000000;
31b819cea2SGordon Ross time_t boot_time = 0;
32b819cea2SGordon Ross 
33b819cea2SGordon Ross #pragma init(_boot_time_init)
34b819cea2SGordon Ross static int
_boot_time_init(void)35b819cea2SGordon Ross _boot_time_init(void)
36b819cea2SGordon Ross {
37b819cea2SGordon Ross 	boot_time = time(NULL);
38b819cea2SGordon Ross 	return (0);
39b819cea2SGordon Ross }
40b819cea2SGordon Ross 
41b819cea2SGordon Ross clock_t
ddi_get_lbolt(void)42b819cea2SGordon Ross ddi_get_lbolt(void)
43b819cea2SGordon Ross {
44b819cea2SGordon Ross 	hrtime_t hrt;
45b819cea2SGordon Ross 
46b819cea2SGordon Ross 	hrt = gethrtime();
47b819cea2SGordon Ross 	return (hrt / nsec_per_tick);
48b819cea2SGordon Ross }
49b819cea2SGordon Ross 
50b819cea2SGordon Ross int64_t
ddi_get_lbolt64(void)51b819cea2SGordon Ross ddi_get_lbolt64(void)
52b819cea2SGordon Ross {
53b819cea2SGordon Ross 	hrtime_t hrt;
54b819cea2SGordon Ross 
55b819cea2SGordon Ross 	hrt = gethrtime();
56b819cea2SGordon Ross 	return (hrt / nsec_per_tick);
57b819cea2SGordon Ross }
58b819cea2SGordon Ross 
59b819cea2SGordon Ross void
clock2ts(clock_t clk,timespec_t * ts)60b819cea2SGordon Ross clock2ts(clock_t clk, timespec_t *ts)
61b819cea2SGordon Ross {
62b819cea2SGordon Ross 	ts->tv_sec = clk / hz;
63b819cea2SGordon Ross 	ts->tv_nsec = (clk % hz) * (NANOSEC / hz);
64b819cea2SGordon Ross }
65b819cea2SGordon Ross 
66b819cea2SGordon Ross hrtime_t
gethrtime_unscaled(void)67b819cea2SGordon Ross gethrtime_unscaled(void)
68b819cea2SGordon Ross {
69b819cea2SGordon Ross 	return (gethrtime());
70b819cea2SGordon Ross }
71b819cea2SGordon Ross 
72b819cea2SGordon Ross void
gethrestime(timespec_t * ts)73b819cea2SGordon Ross gethrestime(timespec_t *ts)
74b819cea2SGordon Ross {
75*a90cf9f2SGordon Ross 	struct timeval tv;
76b819cea2SGordon Ross 
77*a90cf9f2SGordon Ross 	(void) gettimeofday(&tv, NULL);
78*a90cf9f2SGordon Ross 	ts->tv_sec = tv.tv_sec;
79*a90cf9f2SGordon Ross 	ts->tv_nsec = tv.tv_usec * 1000;
80b819cea2SGordon Ross }
81b819cea2SGordon Ross 
82b819cea2SGordon Ross time_t
gethrestime_sec(void)83b819cea2SGordon Ross gethrestime_sec(void)
84b819cea2SGordon Ross {
85b819cea2SGordon Ross 	return (time(NULL));
86b819cea2SGordon Ross }
87b819cea2SGordon Ross 
88b819cea2SGordon Ross /* ARGSUSED */
89b819cea2SGordon Ross void
scalehrtime(hrtime_t * t)90b819cea2SGordon Ross scalehrtime(hrtime_t *t)
91b819cea2SGordon Ross {
92b819cea2SGordon Ross }
93