machclock.h revision bd28a477274db2b836577dfd6f223c696ad00720
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#ifndef _SYS_MACHCLOCK_H
#define _SYS_MACHCLOCK_H
#ifdef __cplusplus
extern "C" {
#endif
/*
*
* The following assembly language macros are defined for reading
* the %tick and %stick registers as well as reading and writing
* the stick compare register. With the exception of trapstat, reads
* and writes of these registers all take into account an offset
* value which is added to the hardware counter. By default, this
* offset is zero. The offsets can only be modified when CPUs are
* paused and are only intended to be modified during an OS suspend
* operation.
*
* Since the read of the %tick or %stick is not an atomic operation,
* it is possible for a suspend operation to occur between the read
* of the hardware register and its offset variable. The default
* macros here take this into account by comparing the value of the
* offset variable before and after reading the hardware register.
* Callers that need to read the %tick register and can guarantee
* they will not be preempted can use the RD_TICK_NO_SUSPEND_CHECK
* which does not check for native_tick_offset changing.
*/
/* CSTYLED */ \
/*
* These macros on sun4v read the %stick register, because :
*
* For sun4v platforms %tick can change dynamically *without* kernel
* knowledge, due to SP side power & thermal management cases,
* which is triggered externally by SP and handled by Hypervisor.
*
* The frequency of %tick cannot be relied upon by kernel code,
* since it changes dynamically without the kernel being aware.
* So, always use the constant-frequency %stick on sun4v.
*/
/* CSTYLED */ \
/* CSTYLED */ \
#ifndef _ASM
#ifdef _KERNEL
extern u_longlong_t gettick(void);
#endif /* _KERNEL */
#endif /* _ASM */
/* CSTYLED */ \
/*
* Read the %stick register without taking the native_stick_offset
* into account.
*/
#define RD_STICK_PHYSICAL(out) \
/*
* Read the %tick register without taking the native_tick_offset
* into account. Required to be a single instruction, usable in a
* delay slot.
*/
#define RD_TICK_PHYSICAL(out) \
/*
* For traptrace, which requires either the %tick or %stick
* counter depending on the value of a global variable.
* If the kernel variable passed in as 'use_stick' is non-zero,
* read the %stick counter into the 'out' register, otherwise,
* read the %tick counter. Note the label-less branches.
* We do not check for the tick or stick offset variables changing
* during the course of the macro's execution and as a result
* if a suspend operation occurs between the time the offset
* variable is read and the hardware register is read, we will
* use an inaccurate traptrace timestamp.
*/
/* CSTYLED */ \
ba .+16; \
.rd_stickcmpr.label: \
/* CSTYLED */ \
/* CSTYLED */ \
/*
* Sun4v processors come up with NPT cleared and there is no need to
* clear it again. Also, clearing of the NPT cannot be done atomically
* on a CMT processor.
*/
#define CLEARTICKNPT
#if defined(CPU_MODULE)
/*
* Constants used to convert hi-res timestamps into nanoseconds
*/
/*
* At least 62.5 MHz, for faster %tick-based systems.
*/
#define NSEC_SHIFT 4
/*
* NOTE: the macros below assume that the various time-related variables
* (hrestime, hrestime_adj, hres_last_tick, timedelta, nsec_scale, etc)
* are all stored together on a 64-byte boundary. The primary motivation
* is cache performance, but we also take advantage of a convenient side
* effect: these variables all have the same high 22 address bits, so only
* one sethi is needed to access them all.
*/
/*
* GET_HRESTIME() returns the value of hrestime, hrestime_adj and the
* number of nanoseconds since the last clock tick ('nslt'). It also
* sets 'nano' to the value NANOSEC (one billion).
*
* This macro assumes that all registers are globals or outs so they can
* safely contain 64-bit data, and that it's safe to use the label "5:".
* Further, this macro calls the NATIVE_TIME_TO_NSEC_SCALE which in turn
* uses the labels "6:" and "7:"; labels "5:", "6:" and "7:" must not
* be used across invocations of this macro.
*/
/* CSTYLED */ \
/* membar #LoadLoad; (see comment (2) above) */ \
/* CSTYLED */ \
/*
* Similar to above, but returns current gethrtime() value in 'base'.
*/
/* CSTYLED */ \
/* membar #LoadLoad; (see comment (2) above) */ \
/* CSTYLED */ \
#endif /* CPU_MODULE */
#ifdef __cplusplus
}
#endif
#endif /* !_SYS_MACHCLOCK_H */