xref: /titanic_44/usr/src/uts/common/disp/thread_intr.c (revision 100b72f4fc209355ff607a0d787aad892d8a44ed)
1*100b72f4Sandrei /*
2*100b72f4Sandrei  * CDDL HEADER START
3*100b72f4Sandrei  *
4*100b72f4Sandrei  * The contents of this file are subject to the terms of the
5*100b72f4Sandrei  * Common Development and Distribution License (the "License").
6*100b72f4Sandrei  * You may not use this file except in compliance with the License.
7*100b72f4Sandrei  *
8*100b72f4Sandrei  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*100b72f4Sandrei  * or http://www.opensolaris.org/os/licensing.
10*100b72f4Sandrei  * See the License for the specific language governing permissions
11*100b72f4Sandrei  * and limitations under the License.
12*100b72f4Sandrei  *
13*100b72f4Sandrei  * When distributing Covered Code, include this CDDL HEADER in each
14*100b72f4Sandrei  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*100b72f4Sandrei  * If applicable, add the following below this CDDL HEADER, with the
16*100b72f4Sandrei  * fields enclosed by brackets "[]" replaced with your own identifying
17*100b72f4Sandrei  * information: Portions Copyright [yyyy] [name of copyright owner]
18*100b72f4Sandrei  *
19*100b72f4Sandrei  * CDDL HEADER END
20*100b72f4Sandrei  */
21*100b72f4Sandrei 
22*100b72f4Sandrei /*
23*100b72f4Sandrei  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*100b72f4Sandrei  * Use is subject to license terms.
25*100b72f4Sandrei  */
26*100b72f4Sandrei 
27*100b72f4Sandrei /*
28*100b72f4Sandrei  * FILE NOTICE BEGIN
29*100b72f4Sandrei  *
30*100b72f4Sandrei  * This file should not be modified.  If you wish to modify it or have it
31*100b72f4Sandrei  * modified, please contact Sun Microsystems at <LFI149367@-sun-.-com->
32*100b72f4Sandrei  * (without anti-spam dashes)
33*100b72f4Sandrei  *
34*100b72f4Sandrei  * FILE NOTICE END
35*100b72f4Sandrei  */
36*100b72f4Sandrei 
37*100b72f4Sandrei #pragma ident	"%Z%%M%	%I%	%E% SMI"
38*100b72f4Sandrei 
39*100b72f4Sandrei #include <sys/cpuvar.h>
40*100b72f4Sandrei #include <sys/stack.h>
41*100b72f4Sandrei #include <vm/seg_kp.h>
42*100b72f4Sandrei #include <sys/proc.h>
43*100b72f4Sandrei #include <sys/pset.h>
44*100b72f4Sandrei #include <sys/sysmacros.h>
45*100b72f4Sandrei 
46*100b72f4Sandrei /*
47*100b72f4Sandrei  * Create and initialize an interrupt thread.
48*100b72f4Sandrei  */
49*100b72f4Sandrei static void
thread_create_intr(cpu_t * cp)50*100b72f4Sandrei thread_create_intr(cpu_t *cp)
51*100b72f4Sandrei {
52*100b72f4Sandrei 	kthread_t *tp;
53*100b72f4Sandrei 
54*100b72f4Sandrei 	tp = thread_create(NULL, 0,
55*100b72f4Sandrei 	    (void (*)())thread_create_intr, NULL, 0, &p0, TS_ONPROC, 0);
56*100b72f4Sandrei 
57*100b72f4Sandrei 	/*
58*100b72f4Sandrei 	 * Set the thread in the TS_FREE state.  The state will change
59*100b72f4Sandrei 	 * to TS_ONPROC only while the interrupt is active.  Think of these
60*100b72f4Sandrei 	 * as being on a private free list for the CPU.  Being TS_FREE keeps
61*100b72f4Sandrei 	 * inactive interrupt threads out of debugger thread lists.
62*100b72f4Sandrei 	 *
63*100b72f4Sandrei 	 * We cannot call thread_create with TS_FREE because of the current
64*100b72f4Sandrei 	 * checks there for ONPROC.  Fix this when thread_create takes flags.
65*100b72f4Sandrei 	 */
66*100b72f4Sandrei 	THREAD_FREEINTR(tp, cp);
67*100b72f4Sandrei 
68*100b72f4Sandrei 	/*
69*100b72f4Sandrei 	 * Nobody should ever reference the credentials of an interrupt
70*100b72f4Sandrei 	 * thread so make it NULL to catch any such references.
71*100b72f4Sandrei 	 */
72*100b72f4Sandrei 	tp->t_cred = NULL;
73*100b72f4Sandrei 	tp->t_flag |= T_INTR_THREAD;
74*100b72f4Sandrei 	tp->t_cpu = cp;
75*100b72f4Sandrei 	tp->t_bound_cpu = cp;
76*100b72f4Sandrei 	tp->t_disp_queue = cp->cpu_disp;
77*100b72f4Sandrei 	tp->t_affinitycnt = 1;
78*100b72f4Sandrei 	tp->t_preempt = 1;
79*100b72f4Sandrei 
80*100b72f4Sandrei 	/*
81*100b72f4Sandrei 	 * Don't make a user-requested binding on this thread so that
82*100b72f4Sandrei 	 * the processor can be offlined.
83*100b72f4Sandrei 	 */
84*100b72f4Sandrei 	tp->t_bind_cpu = PBIND_NONE;	/* no USER-requested binding */
85*100b72f4Sandrei 	tp->t_bind_pset = PS_NONE;
86*100b72f4Sandrei 
87*100b72f4Sandrei #if defined(__i386) || defined(__amd64)
88*100b72f4Sandrei 	tp->t_stk -= STACK_ALIGN;
89*100b72f4Sandrei 	*(tp->t_stk) = 0;		/* terminate intr thread stack */
90*100b72f4Sandrei #endif
91*100b72f4Sandrei 
92*100b72f4Sandrei 	/*
93*100b72f4Sandrei 	 * Link onto CPU's interrupt pool.
94*100b72f4Sandrei 	 */
95*100b72f4Sandrei 	tp->t_link = cp->cpu_intr_thread;
96*100b72f4Sandrei 	cp->cpu_intr_thread = tp;
97*100b72f4Sandrei }
98*100b72f4Sandrei 
99*100b72f4Sandrei /*
100*100b72f4Sandrei  * Allocate a given number of interrupt threads for a given CPU.
101*100b72f4Sandrei  * These threads will get freed by cpu_destroy_bound_threads()
102*100b72f4Sandrei  * when CPU gets unconfigured.
103*100b72f4Sandrei  */
104*100b72f4Sandrei void
cpu_intr_alloc(cpu_t * cp,int n)105*100b72f4Sandrei cpu_intr_alloc(cpu_t *cp, int n)
106*100b72f4Sandrei {
107*100b72f4Sandrei 	int i;
108*100b72f4Sandrei 
109*100b72f4Sandrei 	for (i = 0; i < n; i++)
110*100b72f4Sandrei 		thread_create_intr(cp);
111*100b72f4Sandrei 
112*100b72f4Sandrei 	cp->cpu_intr_stack = (caddr_t)segkp_get(segkp, INTR_STACK_SIZE,
113*100b72f4Sandrei 		KPD_HASREDZONE | KPD_NO_ANON | KPD_LOCKED) +
114*100b72f4Sandrei 		INTR_STACK_SIZE - SA(MINFRAME);
115*100b72f4Sandrei }
116