xref: /illumos-gate/usr/src/uts/common/sys/schedctl.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
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 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * The enclosed is a private interface between system libraries and
29  * the kernel.  It should not be used in any other way.  It may be
30  * changed without notice in a minor release of Solaris.
31  */
32 
33 #ifndef	_SYS_SCHEDCTL_H
34 #define	_SYS_SCHEDCTL_H
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #if !defined(_ASM)
41 
42 #include <sys/types.h>
43 #include <sys/processor.h>
44 
45 /*
46  * This "public" portion of the sc_shared data is used by libsched/libc.
47  */
48 typedef struct sc_public {
49 	volatile short	sc_nopreempt;
50 	volatile short	sc_yield;
51 } sc_public_t;
52 
53 /*
54  * The private portion of the sc_shared data is for
55  * use by user-level threading support code in libc.
56  * Java has a contract to look at sc_state and sc_cpu (PSARC/2005/351).
57  */
58 typedef struct sc_shared {
59 	volatile ushort_t sc_state;	/* current LWP state */
60 	volatile char	sc_sigblock;	/* all signals blocked */
61 	volatile uchar_t sc_flgs;	/* set only by curthread; see below */
62 	volatile processorid_t sc_cpu;	/* last CPU on which LWP ran */
63 	volatile char	sc_cid;		/* scheduling class id */
64 	volatile char	sc_cpri;	/* class priority, -128..127 */
65 	volatile uchar_t sc_priority;	/* dispatch priority, 0..255 */
66 	char		sc_pad;
67 	sc_public_t	sc_preemptctl;	/* preemption control data */
68 } sc_shared_t;
69 
70 /* sc_flgs */
71 #define	SC_PARK_FLG	0x01	/* calling lwp_park() */
72 #define	SC_CANCEL_FLG	0x02	/* cancel pending and not disabled */
73 #define	SC_EINTR_FLG	0x04	/* EINTR returned due to SC_CANCEL_FLG */
74 
75 /*
76  * Possible state settings.  These are same as the kernel thread states
77  * except there is no zombie state.
78  */
79 #define	SC_FREE		0x00
80 #define	SC_SLEEP	0x01
81 #define	SC_RUN		0x02
82 #define	SC_ONPROC	0x04
83 #define	SC_STOPPED	0x10
84 #define	SC_WAIT		0x20
85 
86 /* preemption control settings */
87 #define	SC_MAX_TICKS	2		/* max time preemption can be blocked */
88 
89 #ifdef	_KERNEL
90 caddr_t	schedctl(void);
91 void	schedctl_init(void);
92 void	schedctl_lwp_cleanup(kthread_t *);
93 void	schedctl_proc_cleanup(void);
94 int	schedctl_get_nopreempt(kthread_t *);
95 void	schedctl_set_nopreempt(kthread_t *, short);
96 void	schedctl_set_yield(kthread_t *, short);
97 void	schedctl_set_cidpri(kthread_t *);
98 int	schedctl_sigblock(kthread_t *);
99 void	schedctl_finish_sigblock(kthread_t *);
100 int	schedctl_cancel_pending(void);
101 void	schedctl_cancel_eintr(void);
102 int	schedctl_is_park(void);
103 void	schedctl_set_park(void);
104 void	schedctl_unpark(void);
105 #endif	/* _KERNEL */
106 
107 #endif	/* !defined(_ASM) */
108 
109 #ifdef	__cplusplus
110 }
111 #endif
112 
113 #endif	/* _SYS_SCHEDCTL_H */
114