xref: /onnv-gate/usr/src/uts/intel/asm/clock.h (revision 5322:010e79fdab36)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*5084Sjohnlev  * Common Development and Distribution License (the "License").
6*5084Sjohnlev  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*5084Sjohnlev  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef _ASM_CLOCK_H
270Sstevel@tonic-gate #define	_ASM_CLOCK_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/types.h>
320Sstevel@tonic-gate #include <sys/time.h>
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #ifdef	__cplusplus
350Sstevel@tonic-gate extern "C" {
360Sstevel@tonic-gate #endif
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #if !defined(__lint) && defined(__GNUC__)
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #include <sys/machlock.h>
410Sstevel@tonic-gate 
unlock_hres_lock(void)420Sstevel@tonic-gate extern __inline__ void unlock_hres_lock(void)
430Sstevel@tonic-gate {
440Sstevel@tonic-gate 	__asm__ __volatile__(
450Sstevel@tonic-gate 	    "lock; incl %0"
460Sstevel@tonic-gate 	    : /* no output */
470Sstevel@tonic-gate 	    : "m" (hres_lock)
480Sstevel@tonic-gate 	    : "cc");
490Sstevel@tonic-gate }
500Sstevel@tonic-gate 
51*5084Sjohnlev #if defined(__xpv)
52*5084Sjohnlev 
__rdtsc_insn(void)53*5084Sjohnlev extern __inline__ hrtime_t __rdtsc_insn(void)
540Sstevel@tonic-gate {
550Sstevel@tonic-gate #if defined(__amd64)
560Sstevel@tonic-gate 	uint32_t lobits, hibits;
570Sstevel@tonic-gate 
580Sstevel@tonic-gate 	__asm__ __volatile__(
590Sstevel@tonic-gate 	    "rdtsc"
600Sstevel@tonic-gate 	    : "=a" (lobits), "=d" (hibits));
610Sstevel@tonic-gate 	return (lobits | ((hrtime_t)hibits << 32));
620Sstevel@tonic-gate #elif defined(__i386)
630Sstevel@tonic-gate 	hrtime_t __value;
640Sstevel@tonic-gate 
650Sstevel@tonic-gate 	__asm__ __volatile__(
660Sstevel@tonic-gate 	    "rdtsc"
670Sstevel@tonic-gate 	    : "=A" (__value));
680Sstevel@tonic-gate 	return (__value);
690Sstevel@tonic-gate #else
700Sstevel@tonic-gate #error	"port me"
710Sstevel@tonic-gate #endif
720Sstevel@tonic-gate }
730Sstevel@tonic-gate 
74*5084Sjohnlev #endif /* __xpv */
75*5084Sjohnlev 
760Sstevel@tonic-gate #endif	/* !__lint && __GNUC__ */
770Sstevel@tonic-gate 
780Sstevel@tonic-gate #ifdef	__cplusplus
790Sstevel@tonic-gate }
800Sstevel@tonic-gate #endif
810Sstevel@tonic-gate 
820Sstevel@tonic-gate #endif	/* _ASM_CLOCK_H */
83