5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #include <sys/types.h>
28 #include <sys/clock.h>
29 #include <sys/panic.h>
30 #include <sys/atomic.h>
31 #include <sys/hypervisor.h>
32
33 #include <sys/archsystm.h>
34
35 /*
36 * On the hypervisor, we have a virtualized system time based upon the
37 * information provided for each VCPU, which is updated every time it is
38 * scheduled onto a real CPU. Thus, none of the traditional code in
39 * i86pc/os/timestamp.c applies, our gethrtime() implementation is run through
40 * the PSM, and there is no scaling step to apply.
41 *
42 * However, the platform does not guarantee monotonicity; thus we have to fake
43 * this up, which is a deeply unpleasant thing to have to do.
44 *
54 * long time to expire cyclics in the heap. Thus we have two functions:
55 *
56 * xpv_getsystime()
57 *
58 * The unadulterated system time from the hypervisor. This is only to be
59 * used when programming the hypervisor (setting a timer or calculating
60 * the TOD).
61 *
62 * xpv_gethrtime()
63 *
64 * This is the monotonic hrtime counter to be used by everything else such
65 * as the cyclic subsystem. We should never pass an hrtime directly into
66 * a hypervisor interface, as hrtime_addend may well be non-zero.
67 */
68
69 int hrtime_fake_mt = 1;
70 static volatile hrtime_t hrtime_last;
71 static hrtime_t hrtime_suspend_time;
72 static hrtime_t hrtime_addend;
73
74 /*
75 * These functions are used in DTrace probe context, and must be removed from
76 * fbt consideration. Currently fbt ignores all weak symbols, so this will
77 * achieve that.
78 */
79 #pragma weak xpv_gethrtime = dtrace_xpv_gethrtime
80 #pragma weak xpv_getsystime = dtrace_xpv_getsystime
81 #pragma weak dtrace_gethrtime = dtrace_xpv_gethrtime
82 #pragma weak tsc_read = dtrace_xpv_gethrtime
83
84 hrtime_t
85 dtrace_xpv_getsystime(void)
86 {
87 vcpu_time_info_t *src;
88 vcpu_time_info_t __vti, *dst = &__vti;
89 uint64_t tsc_delta;
90 uint64_t tsc;
91 hrtime_t result;
92 uint32_t stamp;
93
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2016 Joyent, Inc.
26 */
27
28 #include <sys/types.h>
29 #include <sys/clock.h>
30 #include <sys/panic.h>
31 #include <sys/atomic.h>
32 #include <sys/hypervisor.h>
33
34 #include <sys/archsystm.h>
35
36 /*
37 * On the hypervisor, we have a virtualized system time based upon the
38 * information provided for each VCPU, which is updated every time it is
39 * scheduled onto a real CPU. Thus, none of the traditional code in
40 * i86pc/os/timestamp.c applies, our gethrtime() implementation is run through
41 * the PSM, and there is no scaling step to apply.
42 *
43 * However, the platform does not guarantee monotonicity; thus we have to fake
44 * this up, which is a deeply unpleasant thing to have to do.
45 *
55 * long time to expire cyclics in the heap. Thus we have two functions:
56 *
57 * xpv_getsystime()
58 *
59 * The unadulterated system time from the hypervisor. This is only to be
60 * used when programming the hypervisor (setting a timer or calculating
61 * the TOD).
62 *
63 * xpv_gethrtime()
64 *
65 * This is the monotonic hrtime counter to be used by everything else such
66 * as the cyclic subsystem. We should never pass an hrtime directly into
67 * a hypervisor interface, as hrtime_addend may well be non-zero.
68 */
69
70 int hrtime_fake_mt = 1;
71 static volatile hrtime_t hrtime_last;
72 static hrtime_t hrtime_suspend_time;
73 static hrtime_t hrtime_addend;
74
75 volatile uint32_t hres_lock;
76 hrtime_t hres_last_tick;
77 int64_t hrestime_adj;
78 volatile timestruc_t hrestime;
79
80 /*
81 * These functions are used in DTrace probe context, and must be removed from
82 * fbt consideration. Currently fbt ignores all weak symbols, so this will
83 * achieve that.
84 */
85 #pragma weak xpv_gethrtime = dtrace_xpv_gethrtime
86 #pragma weak xpv_getsystime = dtrace_xpv_getsystime
87 #pragma weak dtrace_gethrtime = dtrace_xpv_gethrtime
88 #pragma weak tsc_read = dtrace_xpv_gethrtime
89
90 hrtime_t
91 dtrace_xpv_getsystime(void)
92 {
93 vcpu_time_info_t *src;
94 vcpu_time_info_t __vti, *dst = &__vti;
95 uint64_t tsc_delta;
96 uint64_t tsc;
97 hrtime_t result;
98 uint32_t stamp;
99
|