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