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 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2016 Joyent, Inc.
26 */
27
28 #include <sys/types.h>
29 #include <sys/systm.h>
30 #include <sys/schedctl.h>
31 #include <sys/proc.h>
32 #include <sys/thread.h>
33 #include <sys/class.h>
34 #include <sys/cred.h>
35 #include <sys/kmem.h>
36 #include <sys/cmn_err.h>
37 #include <sys/stack.h>
38 #include <sys/debug.h>
39 #include <sys/cpuvar.h>
40 #include <sys/sobject.h>
41 #include <sys/door.h>
42 #include <sys/modctl.h>
43 #include <sys/syscall.h>
44 #include <sys/sysmacros.h>
45 #include <sys/vmsystm.h>
96 * System call interface to scheduler activations.
97 * This always operates on the current lwp.
98 */
99 caddr_t
100 schedctl(void)
101 {
102 kthread_t *t = curthread;
103 sc_shared_t *ssp;
104 uintptr_t uaddr;
105 int error;
106
107 if (t->t_schedctl == NULL) {
108 /*
109 * Allocate and initialize the shared structure.
110 */
111 if ((error = schedctl_shared_alloc(&ssp, &uaddr)) != 0)
112 return ((caddr_t)(uintptr_t)set_errno(error));
113 bzero(ssp, sizeof (*ssp));
114
115 installctx(t, ssp, schedctl_save, schedctl_restore,
116 schedctl_fork, NULL, NULL, NULL);
117
118 thread_lock(t); /* protect against ts_tick and ts_update */
119 t->t_schedctl = ssp;
120 t->t_sc_uaddr = uaddr;
121 ssp->sc_cid = t->t_cid;
122 ssp->sc_cpri = t->t_cpri;
123 ssp->sc_priority = DISP_PRIO(t);
124 thread_unlock(t);
125 }
126
127 return ((caddr_t)t->t_sc_uaddr);
128 }
129
130
131 /*
132 * Clean up scheduler activations state associated with an exiting
133 * (or execing) lwp. t is always the current thread.
134 */
135 void
136 schedctl_lwp_cleanup(kthread_t *t)
|
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 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2021 Joyent, Inc.
26 */
27
28 #include <sys/types.h>
29 #include <sys/systm.h>
30 #include <sys/schedctl.h>
31 #include <sys/proc.h>
32 #include <sys/thread.h>
33 #include <sys/class.h>
34 #include <sys/cred.h>
35 #include <sys/kmem.h>
36 #include <sys/cmn_err.h>
37 #include <sys/stack.h>
38 #include <sys/debug.h>
39 #include <sys/cpuvar.h>
40 #include <sys/sobject.h>
41 #include <sys/door.h>
42 #include <sys/modctl.h>
43 #include <sys/syscall.h>
44 #include <sys/sysmacros.h>
45 #include <sys/vmsystm.h>
96 * System call interface to scheduler activations.
97 * This always operates on the current lwp.
98 */
99 caddr_t
100 schedctl(void)
101 {
102 kthread_t *t = curthread;
103 sc_shared_t *ssp;
104 uintptr_t uaddr;
105 int error;
106
107 if (t->t_schedctl == NULL) {
108 /*
109 * Allocate and initialize the shared structure.
110 */
111 if ((error = schedctl_shared_alloc(&ssp, &uaddr)) != 0)
112 return ((caddr_t)(uintptr_t)set_errno(error));
113 bzero(ssp, sizeof (*ssp));
114
115 installctx(t, ssp, schedctl_save, schedctl_restore,
116 schedctl_fork, NULL, NULL, NULL, NULL);
117
118 thread_lock(t); /* protect against ts_tick and ts_update */
119 t->t_schedctl = ssp;
120 t->t_sc_uaddr = uaddr;
121 ssp->sc_cid = t->t_cid;
122 ssp->sc_cpri = t->t_cpri;
123 ssp->sc_priority = DISP_PRIO(t);
124 thread_unlock(t);
125 }
126
127 return ((caddr_t)t->t_sc_uaddr);
128 }
129
130
131 /*
132 * Clean up scheduler activations state associated with an exiting
133 * (or execing) lwp. t is always the current thread.
134 */
135 void
136 schedctl_lwp_cleanup(kthread_t *t)
|