xref: /onnv-gate/usr/src/uts/intel/sys/machlock.h (revision 4551:af6e7cd796cc)
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*4551Ssudheer  * Common Development and Distribution License (the "License").
6*4551Ssudheer  * 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*4551Ssudheer  * 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 _SYS_MACHLOCK_H
270Sstevel@tonic-gate #define	_SYS_MACHLOCK_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #ifndef _ASM
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <sys/time.h>
340Sstevel@tonic-gate #endif /* _ASM */
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #ifdef	__cplusplus
370Sstevel@tonic-gate extern "C" {
380Sstevel@tonic-gate #endif
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #ifndef	_ASM
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #ifdef _KERNEL
430Sstevel@tonic-gate 
440Sstevel@tonic-gate extern void	lock_set(lock_t *lp);
450Sstevel@tonic-gate extern int	lock_try(lock_t *lp);
460Sstevel@tonic-gate extern int	lock_spin_try(lock_t *lp);
470Sstevel@tonic-gate extern int	ulock_try(lock_t *lp);
480Sstevel@tonic-gate extern void	lock_clear(lock_t *lp);
490Sstevel@tonic-gate extern void	ulock_clear(lock_t *lp);
500Sstevel@tonic-gate extern void	lock_set_spl(lock_t *lp, int new_pil, ushort_t *old_pil);
510Sstevel@tonic-gate extern void	lock_clear_splx(lock_t *lp, int s);
520Sstevel@tonic-gate 
530Sstevel@tonic-gate #endif	/* _KERNEL */
540Sstevel@tonic-gate 
550Sstevel@tonic-gate #define	LOCK_HELD_VALUE		0xff
560Sstevel@tonic-gate #define	LOCK_INIT_CLEAR(lp)	(*(lp) = 0)
570Sstevel@tonic-gate #define	LOCK_INIT_HELD(lp)	(*(lp) = LOCK_HELD_VALUE)
580Sstevel@tonic-gate #define	LOCK_HELD(lp)		(*(volatile lock_t *)(lp) != 0)
590Sstevel@tonic-gate 
600Sstevel@tonic-gate typedef	lock_t	disp_lock_t;		/* dispatcher lock type */
610Sstevel@tonic-gate 
620Sstevel@tonic-gate /*
630Sstevel@tonic-gate  * SPIN_LOCK() macro indicates whether lock is implemented as a spin lock or
640Sstevel@tonic-gate  * an adaptive mutex, depending on what interrupt levels use it.
650Sstevel@tonic-gate  */
660Sstevel@tonic-gate #define	SPIN_LOCK(pl)	((pl) > ipltospl(LOCK_LEVEL))
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate  * Macro to control loops which spin on a lock and then check state
700Sstevel@tonic-gate  * periodically.  Its passed an integer, and returns a boolean value
710Sstevel@tonic-gate  * that if true indicates its a good time to get the scheduler lock and
720Sstevel@tonic-gate  * check the state of the current owner of the lock.
730Sstevel@tonic-gate  */
740Sstevel@tonic-gate #define	LOCK_SAMPLE_INTERVAL(i)	(((i) & 0xff) == 0)
750Sstevel@tonic-gate 
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate  * Externs for CLOCK_LOCK and clock resolution
780Sstevel@tonic-gate  */
790Sstevel@tonic-gate extern volatile int hres_lock;
800Sstevel@tonic-gate extern hrtime_t hrtime_base;
810Sstevel@tonic-gate extern int clock_res;
820Sstevel@tonic-gate 
830Sstevel@tonic-gate #endif	/* _ASM */
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /*
860Sstevel@tonic-gate  * The definitions of the symbolic interrupt levels:
870Sstevel@tonic-gate  *
880Sstevel@tonic-gate  *   CLOCK_LEVEL =>  The level at which one must be to block the clock.
890Sstevel@tonic-gate  *
900Sstevel@tonic-gate  *   LOCK_LEVEL  =>  The highest level at which one may block (and thus the
910Sstevel@tonic-gate  *                   highest level at which one may acquire adaptive locks)
920Sstevel@tonic-gate  *                   Also the highest level at which one may be preempted.
930Sstevel@tonic-gate  *
940Sstevel@tonic-gate  *   DISP_LEVEL  =>  The level at which one must be to perform dispatcher
950Sstevel@tonic-gate  *                   operations.
960Sstevel@tonic-gate  *
970Sstevel@tonic-gate  * The constraints on the platform:
980Sstevel@tonic-gate  *
990Sstevel@tonic-gate  *  - CLOCK_LEVEL must be less than or equal to LOCK_LEVEL
1000Sstevel@tonic-gate  *  - LOCK_LEVEL must be less than DISP_LEVEL
1010Sstevel@tonic-gate  *  - DISP_LEVEL should be as close to LOCK_LEVEL as possible
1020Sstevel@tonic-gate  *
1030Sstevel@tonic-gate  * Note that LOCK_LEVEL and CLOCK_LEVEL have historically always been equal;
1040Sstevel@tonic-gate  * changing this relationship is probably possible but not advised.
1050Sstevel@tonic-gate  *
1060Sstevel@tonic-gate  */
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate #define	PIL_MAX		15
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate #define	CLOCK_LEVEL	10
1110Sstevel@tonic-gate #define	LOCK_LEVEL	10
1120Sstevel@tonic-gate #define	DISP_LEVEL	(LOCK_LEVEL + 1)
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate #define	HIGH_LEVELS	(PIL_MAX - LOCK_LEVEL)
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate /*
1170Sstevel@tonic-gate  * The following mask is for the cpu_intr_actv bits corresponding to
1180Sstevel@tonic-gate  * high-level PILs. It should equal:
1190Sstevel@tonic-gate  * ((((1 << PIL_MAX + 1) - 1) >> LOCK_LEVEL + 1) << LOCK_LEVEL + 1)
1200Sstevel@tonic-gate  */
1210Sstevel@tonic-gate #define	CPU_INTR_ACTV_HIGH_LEVEL_MASK	0xF800
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate /*
1240Sstevel@tonic-gate  * The semaphore code depends on being able to represent a lock plus
1250Sstevel@tonic-gate  * owner in a single 32-bit word.  (Mutexes used to have a similar
1260Sstevel@tonic-gate  * dependency, but no longer.)  Thus the owner must contain at most
1270Sstevel@tonic-gate  * 24 significant bits.  At present only threads and semaphores
1280Sstevel@tonic-gate  * must be aware of this vile constraint.  Different ISAs may handle this
1290Sstevel@tonic-gate  * differently depending on their capabilities (e.g. compare-and-swap)
1300Sstevel@tonic-gate  * and limitations (e.g. constraints on alignment and/or KERNELBASE).
1310Sstevel@tonic-gate  */
1320Sstevel@tonic-gate #define	PTR24_LSB	5			/* lower bits all zero */
1330Sstevel@tonic-gate #define	PTR24_MSB	(PTR24_LSB + 24)	/* upper bits all one */
1340Sstevel@tonic-gate #define	PTR24_ALIGN	32		/* minimum alignment (1 << lsb) */
1350Sstevel@tonic-gate #define	PTR24_BASE	0xe0000000	/* minimum ptr value (-1 >> (32-msb)) */
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate #ifdef	__cplusplus
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate #endif
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate #endif	/* _SYS_MACHLOCK_H */
142