Annotation of src/sys/sys/sched.h, Revision 1.53
1.53 ! ad 1: /* $NetBSD: sched.h,v 1.52 2008/04/24 13:56:30 ad Exp $ */
1.1 ross 2:
3: /*-
1.51 ad 4: * Copyright (c) 1999, 2000, 2001, 2002, 2007, 2008 The NetBSD Foundation, Inc.
1.1 ross 5: * All rights reserved.
6: *
7: * This code is derived from software contributed to The NetBSD Foundation
1.34 yamt 8: * by Ross Harvey, Jason R. Thorpe, Nathan J. Williams, Andrew Doran and
9: * Daniel Sieger.
1.1 ross 10: *
11: * Redistribution and use in source and binary forms, with or without
12: * modification, are permitted provided that the following conditions
13: * are met:
14: * 1. Redistributions of source code must retain the above copyright
15: * notice, this list of conditions and the following disclaimer.
16: * 2. Redistributions in binary form must reproduce the above copyright
17: * notice, this list of conditions and the following disclaimer in the
18: * documentation and/or other materials provided with the distribution.
19: * 3. All advertising materials mentioning features or use of this software
20: * must display the following acknowledgement:
21: * This product includes software developed by the NetBSD
22: * Foundation, Inc. and its contributors.
23: * 4. Neither the name of The NetBSD Foundation nor the names of its
24: * contributors may be used to endorse or promote products derived
25: * from this software without specific prior written permission.
26: *
27: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37: * POSSIBILITY OF SUCH DAMAGE.
38: */
39:
40: /*-
41: * Copyright (c) 1982, 1986, 1991, 1993
42: * The Regents of the University of California. All rights reserved.
43: * (c) UNIX System Laboratories, Inc.
44: * All or some portions of this file are derived from material licensed
45: * to the University of California by American Telephone and Telegraph
46: * Co. or Unix System Laboratories, Inc. and are reproduced herein with
47: * the permission of UNIX System Laboratories, Inc.
48: *
49: * Redistribution and use in source and binary forms, with or without
50: * modification, are permitted provided that the following conditions
51: * are met:
52: * 1. Redistributions of source code must retain the above copyright
53: * notice, this list of conditions and the following disclaimer.
54: * 2. Redistributions in binary form must reproduce the above copyright
55: * notice, this list of conditions and the following disclaimer in the
56: * documentation and/or other materials provided with the distribution.
1.19 agc 57: * 3. Neither the name of the University nor the names of its contributors
1.1 ross 58: * may be used to endorse or promote products derived from this software
59: * without specific prior written permission.
60: *
61: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
62: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
65: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
67: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71: * SUCH DAMAGE.
72: *
73: * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94
74: */
75:
76: #ifndef _SYS_SCHED_H_
77: #define _SYS_SCHED_H_
78:
1.17 bjh21 79: #include <sys/featuretest.h>
1.45 rmind 80: #include <sys/types.h>
1.17 bjh21 81:
1.13 mrg 82: #if defined(_KERNEL_OPT)
1.6 thorpej 83: #include "opt_multiprocessor.h"
84: #include "opt_lockdebug.h"
85: #endif
86:
1.15 thorpej 87: struct sched_param {
88: int sched_priority;
89: };
90:
1.1 ross 91: /*
1.15 thorpej 92: * Scheduling policies required by IEEE Std 1003.1-2001
1.1 ross 93: */
1.45 rmind 94: #define SCHED_NONE -1
95: #define SCHED_OTHER 0
1.15 thorpej 96: #define SCHED_FIFO 1
97: #define SCHED_RR 2
98:
1.45 rmind 99: #if defined(_NETBSD_SOURCE)
1.1 ross 100:
1.46 rmind 101: /* XXX: Size of the CPU set bitmap */
102: #define CPUSET_SHIFT 5
103: #define CPUSET_MASK 31
104: #if MAXCPUS > 32
105: #define CPUSET_SIZE (MAXCPUS >> CPUSET_SHIFT)
106: #else
107: #define CPUSET_SIZE 1
108: #endif
109:
110: /* Bitmap of the CPUs */
111: typedef struct {
112: uint32_t bits[CPUSET_SIZE];
113: } cpuset_t;
114:
115: #define CPU_ZERO(c) \
116: (memset(c, 0, sizeof(cpuset_t)))
117:
118: #define CPU_ISSET(i, c) \
119: ((1 << (i & CPUSET_MASK)) & (c)->bits[i >> CPUSET_SHIFT])
120:
121: #define CPU_SET(i, c) \
122: ((c)->bits[i >> CPUSET_SHIFT] |= 1 << (i & CPUSET_MASK))
123:
124: #define CPU_CLR(i, c) \
125: ((c)->bits[i >> CPUSET_SHIFT] &= ~(1 << (i & CPUSET_MASK)))
126:
1.45 rmind 127: int _sched_getaffinity(pid_t, lwpid_t, size_t, void *);
128: int _sched_setaffinity(pid_t, lwpid_t, size_t, void *);
1.47 yamt 129: int _sched_getparam(pid_t, lwpid_t, int *, struct sched_param *);
130: int _sched_setparam(pid_t, lwpid_t, int, const struct sched_param *);
1.4 sommerfe 131:
1.33 yamt 132: /*
133: * CPU states.
134: * XXX Not really scheduler state, but no other good place to put
135: * it right now, and it really is per-CPU.
136: */
137: #define CP_USER 0
138: #define CP_NICE 1
139: #define CP_SYS 2
140: #define CP_INTR 3
141: #define CP_IDLE 4
142: #define CPUSTATES 5
143:
144: #if defined(_KERNEL)
145:
1.34 yamt 146: #include <sys/mutex.h>
1.4 sommerfe 147: #include <sys/time.h>
148:
1.3 thorpej 149: /*
1.34 yamt 150: * Per-CPU scheduler state. Field markings and the corresponding locks:
1.3 thorpej 151: *
1.34 yamt 152: * s: splsched, may only be safely accessed by the CPU itself
153: * m: spc_mutex
154: * (: unlocked, stable
1.36 ad 155: * c: cpu_lock
1.3 thorpej 156: */
157: struct schedstate_percpu {
1.38 ad 158: /* First set of data is likely to be accessed by other CPUs. */
1.34 yamt 159: kmutex_t *spc_mutex; /* (: lock on below, runnable LWPs */
1.48 ad 160: kmutex_t *spc_lwplock; /* (: general purpose lock for LWPs */
1.38 ad 161: pri_t spc_curpriority;/* m: usrpri of curlwp */
1.51 ad 162: pri_t spc_maxpriority;/* m: highest priority queued */
1.45 rmind 163: psetid_t spc_psid; /* (: processor-set ID */
1.38 ad 164: time_t spc_lastmod; /* c: time of last cpu state change */
165:
166: /* For the most part, this set of data is CPU-private. */
167: void *spc_sched_info;/* (: scheduler-specific structure */
168: volatile int spc_flags; /* s: flags; see below */
1.34 yamt 169: u_int spc_schedticks; /* s: ticks for schedclock() */
170: uint64_t spc_cp_time[CPUSTATES];/* s: CPU state statistics */
171: int spc_ticks; /* s: ticks until sched_tick() */
172: int spc_pscnt; /* s: prof/stat counter */
173: int spc_psdiv; /* s: prof/stat divisor */
1.3 thorpej 174: };
175:
176: /* spc_flags */
177: #define SPCF_SEENRR 0x0001 /* process has seen roundrobin() */
178: #define SPCF_SHOULDYIELD 0x0002 /* process should yield the CPU */
1.36 ad 179: #define SPCF_OFFLINE 0x0004 /* CPU marked offline */
1.52 ad 180: #define SPCF_RUNNING 0x0008 /* CPU is running */
1.3 thorpej 181:
182: #define SPCF_SWITCHCLEAR (SPCF_SEENRR|SPCF_SHOULDYIELD)
183:
1.33 yamt 184: #endif /* defined(_KERNEL) */
185:
1.14 thorpej 186: /*
187: * Flags passed to the Linux-compatible __clone(2) system call.
188: */
189: #define CLONE_CSIGNAL 0x000000ff /* signal to be sent at exit */
190: #define CLONE_VM 0x00000100 /* share address space */
191: #define CLONE_FS 0x00000200 /* share "file system" info */
192: #define CLONE_FILES 0x00000400 /* share file descriptors */
193: #define CLONE_SIGHAND 0x00000800 /* share signal actions */
194: #define CLONE_PID 0x00001000 /* share process ID */
1.20 perry 195: #define CLONE_PTRACE 0x00002000 /* ptrace(2) continues on
1.14 thorpej 196: child */
197: #define CLONE_VFORK 0x00004000 /* parent blocks until child
198: exits */
199:
1.45 rmind 200: #endif /* _NETBSD_SOURCE */
1.3 thorpej 201:
1.14 thorpej 202: #ifdef _KERNEL
1.1 ross 203:
1.12 simonb 204: extern int schedhz; /* ideally: 16 */
1.34 yamt 205:
206: struct proc;
207: struct cpu_info;
1.1 ross 208:
1.3 thorpej 209: /*
1.37 rmind 210: * Common Scheduler Interface.
1.3 thorpej 211: */
212:
1.34 yamt 213: /* Scheduler initialization */
1.37 rmind 214: void sched_init(void);
215: void sched_rqinit(void);
216: void sched_cpuattach(struct cpu_info *);
217:
1.39 rmind 218: /* Time-driven events */
1.37 rmind 219: void sched_tick(struct cpu_info *);
220: void schedclock(struct lwp *);
221: void sched_schedclock(struct lwp *);
222: void sched_pstats(void *);
1.39 rmind 223: void sched_pstats_hook(struct lwp *);
1.34 yamt 224:
225: /* Runqueue-related functions */
1.37 rmind 226: bool sched_curcpu_runnable_p(void);
227: void sched_dequeue(struct lwp *);
228: void sched_enqueue(struct lwp *, bool);
229: struct lwp * sched_nextlwp(void);
1.51 ad 230: void sched_oncpu(struct lwp *);
231: void sched_newts(struct lwp *);
1.34 yamt 232:
233: /* Priority adjustment */
1.37 rmind 234: void sched_nice(struct proc *, int);
1.34 yamt 235:
1.37 rmind 236: /* Handlers of fork and exit */
237: void sched_proc_fork(struct proc *, struct proc *);
238: void sched_proc_exit(struct proc *, struct proc *);
1.41 ad 239: void sched_lwp_fork(struct lwp *, struct lwp *);
1.37 rmind 240: void sched_lwp_exit(struct lwp *);
1.41 ad 241: void sched_lwp_collect(struct lwp *);
1.37 rmind 242:
1.39 rmind 243: void sched_slept(struct lwp *);
244: void sched_wakeup(struct lwp *);
245:
1.37 rmind 246: void setrunnable(struct lwp *);
247: void sched_setrunnable(struct lwp *);
1.39 rmind 248:
249: struct cpu_info *sched_takecpu(struct lwp *);
1.37 rmind 250: void sched_print_runqueue(void (*pr)(const char *, ...));
251:
252: /* Dispatching */
1.53 ! ad 253: bool kpreempt(uintptr_t);
1.37 rmind 254: void preempt(void);
255: int mi_switch(struct lwp *);
1.41 ad 256: void resched_cpu(struct lwp *);
1.44 yamt 257: void updatertime(lwp_t *, const struct bintime *);
1.6 thorpej 258:
1.49 elad 259: int do_sched_setparam(pid_t, lwpid_t, int, const struct sched_param *);
260: int do_sched_getparam(pid_t, lwpid_t, int *, struct sched_param *);
261:
1.1 ross 262: #endif /* _KERNEL */
263: #endif /* _SYS_SCHED_H_ */
CVSweb <webmaster@jp.NetBSD.org>