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