1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*0Sstevel@tonic-gate /* All Rights Reserved */ 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #ifndef _SYS_DISP_H 32*0Sstevel@tonic-gate #define _SYS_DISP_H 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.11 */ 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate #include <sys/priocntl.h> 37*0Sstevel@tonic-gate #include <sys/thread.h> 38*0Sstevel@tonic-gate #include <sys/class.h> 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate #ifdef __cplusplus 41*0Sstevel@tonic-gate extern "C" { 42*0Sstevel@tonic-gate #endif 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate /* 45*0Sstevel@tonic-gate * The following is the format of a dispatcher queue entry. 46*0Sstevel@tonic-gate */ 47*0Sstevel@tonic-gate typedef struct dispq { 48*0Sstevel@tonic-gate kthread_t *dq_first; /* first thread on queue or NULL */ 49*0Sstevel@tonic-gate kthread_t *dq_last; /* last thread on queue or NULL */ 50*0Sstevel@tonic-gate int dq_sruncnt; /* number of loaded, runnable */ 51*0Sstevel@tonic-gate /* threads on queue */ 52*0Sstevel@tonic-gate } dispq_t; 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gate /* 55*0Sstevel@tonic-gate * Dispatch queue structure. 56*0Sstevel@tonic-gate */ 57*0Sstevel@tonic-gate typedef struct _disp { 58*0Sstevel@tonic-gate disp_lock_t disp_lock; /* protects dispatching fields */ 59*0Sstevel@tonic-gate pri_t disp_npri; /* # of priority levels in queue */ 60*0Sstevel@tonic-gate dispq_t *disp_q; /* the dispatch queue */ 61*0Sstevel@tonic-gate dispq_t *disp_q_limit; /* ptr past end of dispatch queue */ 62*0Sstevel@tonic-gate ulong_t *disp_qactmap; /* bitmap of active dispatch queues */ 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate /* 65*0Sstevel@tonic-gate * Priorities: 66*0Sstevel@tonic-gate * disp_maxrunpri is the maximum run priority of runnable threads 67*0Sstevel@tonic-gate * on this queue. It is -1 if nothing is runnable. 68*0Sstevel@tonic-gate * 69*0Sstevel@tonic-gate * disp_max_unbound_pri is the maximum run priority of threads on 70*0Sstevel@tonic-gate * this dispatch queue but runnable by any CPU. This may be left 71*0Sstevel@tonic-gate * artificially high, then corrected when some CPU tries to take 72*0Sstevel@tonic-gate * an unbound thread. It is -1 if nothing is runnable. 73*0Sstevel@tonic-gate */ 74*0Sstevel@tonic-gate pri_t disp_maxrunpri; /* maximum run priority */ 75*0Sstevel@tonic-gate pri_t disp_max_unbound_pri; /* max pri of unbound threads */ 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate volatile int disp_nrunnable; /* runnable threads in cpu dispq */ 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate struct cpu *disp_cpu; /* cpu owning this queue or NULL */ 80*0Sstevel@tonic-gate } disp_t; 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate #if defined(_KERNEL) 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate #define MAXCLSYSPRI 99 85*0Sstevel@tonic-gate #define MINCLSYSPRI 60 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate /* 89*0Sstevel@tonic-gate * Global scheduling variables. 90*0Sstevel@tonic-gate * - See sys/cpuvar.h for CPU-local variables. 91*0Sstevel@tonic-gate */ 92*0Sstevel@tonic-gate extern int nswapped; /* number of swapped threads */ 93*0Sstevel@tonic-gate /* nswapped protected by swap_lock */ 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate extern pri_t minclsyspri; /* minimum level of any system class */ 96*0Sstevel@tonic-gate extern pri_t maxclsyspri; /* maximum level of any system class */ 97*0Sstevel@tonic-gate extern pri_t intr_pri; /* interrupt thread priority base level */ 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate /* 100*0Sstevel@tonic-gate * Amount of time that may elapse before a thread is considered to have 101*0Sstevel@tonic-gate * lost it's cache investment. 102*0Sstevel@tonic-gate */ 103*0Sstevel@tonic-gate #define RECHOOSE_INTERVAL 3 104*0Sstevel@tonic-gate extern int rechoose_interval; 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate /* 107*0Sstevel@tonic-gate * Kernel preemption occurs if a higher-priority thread is runnable with 108*0Sstevel@tonic-gate * a priority at or above kpreemptpri. 109*0Sstevel@tonic-gate * 110*0Sstevel@tonic-gate * So that other processors can watch for such threads, a separate 111*0Sstevel@tonic-gate * dispatch queue with unbound work above kpreemptpri is maintained. 112*0Sstevel@tonic-gate * This is part of the CPU partition structure (cpupart_t). 113*0Sstevel@tonic-gate */ 114*0Sstevel@tonic-gate extern pri_t kpreemptpri; /* level above which preemption takes place */ 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate extern void disp_kp_alloc(disp_t *, pri_t); /* allocate kp queue */ 117*0Sstevel@tonic-gate extern void disp_kp_free(disp_t *); /* free kp queue */ 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate /* 120*0Sstevel@tonic-gate * Macro for use by scheduling classes to decide whether the thread is about 121*0Sstevel@tonic-gate * to be scheduled or not. This returns the maximum run priority. 122*0Sstevel@tonic-gate */ 123*0Sstevel@tonic-gate #define DISP_MAXRUNPRI(t) ((t)->t_disp_queue->disp_maxrunpri) 124*0Sstevel@tonic-gate 125*0Sstevel@tonic-gate /* 126*0Sstevel@tonic-gate * Platform callbacks for various dispatcher operations 127*0Sstevel@tonic-gate * 128*0Sstevel@tonic-gate * idle_cpu() is invoked when a cpu goes idle, and has nothing to do. 129*0Sstevel@tonic-gate * disp_enq_thread() is invoked when a thread is placed on a run queue. 130*0Sstevel@tonic-gate */ 131*0Sstevel@tonic-gate extern void (*idle_cpu)(); 132*0Sstevel@tonic-gate extern void (*disp_enq_thread)(struct cpu *, int); 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate extern int dispdeq(kthread_t *); 136*0Sstevel@tonic-gate extern void dispinit(void); 137*0Sstevel@tonic-gate extern void disp_add(sclass_t *); 138*0Sstevel@tonic-gate extern int intr_active(struct cpu *, int); 139*0Sstevel@tonic-gate extern int servicing_interrupt(void); 140*0Sstevel@tonic-gate extern void preempt(void); 141*0Sstevel@tonic-gate extern void setbackdq(kthread_t *); 142*0Sstevel@tonic-gate extern void setfrontdq(kthread_t *); 143*0Sstevel@tonic-gate extern void swtch(void); 144*0Sstevel@tonic-gate extern void swtch_to(kthread_t *); 145*0Sstevel@tonic-gate extern void swtch_from_zombie(void) 146*0Sstevel@tonic-gate __NORETURN; 147*0Sstevel@tonic-gate extern void dq_sruninc(kthread_t *); 148*0Sstevel@tonic-gate extern void dq_srundec(kthread_t *); 149*0Sstevel@tonic-gate extern void cpu_rechoose(kthread_t *); 150*0Sstevel@tonic-gate extern void cpu_surrender(kthread_t *); 151*0Sstevel@tonic-gate extern void kpreempt(int); 152*0Sstevel@tonic-gate extern struct cpu *disp_lowpri_cpu(struct cpu *, struct lgrp_ld *, pri_t, 153*0Sstevel@tonic-gate struct cpu *); 154*0Sstevel@tonic-gate extern int disp_bound_threads(struct cpu *, int); 155*0Sstevel@tonic-gate extern int disp_bound_anythreads(struct cpu *, int); 156*0Sstevel@tonic-gate extern int disp_bound_partition(struct cpu *, int); 157*0Sstevel@tonic-gate extern void disp_cpu_init(struct cpu *); 158*0Sstevel@tonic-gate extern void disp_cpu_fini(struct cpu *); 159*0Sstevel@tonic-gate extern void disp_cpu_inactive(struct cpu *); 160*0Sstevel@tonic-gate extern void disp_adjust_unbound_pri(kthread_t *); 161*0Sstevel@tonic-gate extern void resume(kthread_t *); 162*0Sstevel@tonic-gate extern void resume_from_intr(kthread_t *); 163*0Sstevel@tonic-gate extern void resume_from_zombie(kthread_t *) 164*0Sstevel@tonic-gate __NORETURN; 165*0Sstevel@tonic-gate extern void disp_swapped_enq(kthread_t *); 166*0Sstevel@tonic-gate extern int disp_anywork(void); 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gate #define KPREEMPT_SYNC (-1) 169*0Sstevel@tonic-gate #define kpreempt_disable() \ 170*0Sstevel@tonic-gate { \ 171*0Sstevel@tonic-gate curthread->t_preempt++; \ 172*0Sstevel@tonic-gate ASSERT(curthread->t_preempt >= 1); \ 173*0Sstevel@tonic-gate } 174*0Sstevel@tonic-gate #define kpreempt_enable() \ 175*0Sstevel@tonic-gate { \ 176*0Sstevel@tonic-gate ASSERT(curthread->t_preempt >= 1); \ 177*0Sstevel@tonic-gate if (--curthread->t_preempt == 0 && \ 178*0Sstevel@tonic-gate CPU->cpu_kprunrun) \ 179*0Sstevel@tonic-gate kpreempt(KPREEMPT_SYNC); \ 180*0Sstevel@tonic-gate } 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate #endif /* _KERNEL */ 183*0Sstevel@tonic-gate 184*0Sstevel@tonic-gate #ifdef __cplusplus 185*0Sstevel@tonic-gate } 186*0Sstevel@tonic-gate #endif 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate #endif /* _SYS_DISP_H */ 189