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