sched.h revision 132372
1104964Sjeff/*-
2104964Sjeff * Copyright (c) 2002, Jeffrey Roberson <jeff@freebsd.org>
3104964Sjeff * All rights reserved.
4104964Sjeff *
5104964Sjeff * Redistribution and use in source and binary forms, with or without
6104964Sjeff * modification, are permitted provided that the following conditions
7104964Sjeff * are met:
8104964Sjeff * 1. Redistributions of source code must retain the above copyright
9104964Sjeff *    notice unmodified, this list of conditions, and the following
10104964Sjeff *    disclaimer.
11104964Sjeff * 2. Redistributions in binary form must reproduce the above copyright
12104964Sjeff *    notice, this list of conditions and the following disclaimer in the
13104964Sjeff *    documentation and/or other materials provided with the distribution.
14104964Sjeff *
15104964Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16104964Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17104964Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18104964Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19104964Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20104964Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21104964Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22104964Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23104964Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24104964Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25104964Sjeff *
26104964Sjeff * $FreeBSD: head/sys/sys/sched.h 132372 2004-07-18 23:36:13Z julian $
27104964Sjeff */
28104964Sjeff
29104964Sjeff#ifndef _SYS_SCHED_H_
30104964Sjeff#define	_SYS_SCHED_H_
31104964Sjeff
32104964Sjeff/*
33104964Sjeff * General scheduling info.
34125287Sjeff *
35125287Sjeff * sched_load:
36125287Sjeff *	Total runnable non-ithread threads in the system.
37125287Sjeff *
38125287Sjeff * sched_runnable:
39125287Sjeff *	Runnable threads for this processor.
40104964Sjeff */
41125287Sjeffint	sched_load(void);
42104964Sjeffint	sched_rr_interval(void);
43104964Sjeffint	sched_runnable(void);
44104964Sjeff
45113355Sjeff/*
46113355Sjeff * Proc related scheduling hooks.
47113355Sjeff */
48132372Sjulianvoid	sched_exit(struct proc *p, struct thread *childtd);
49132372Sjulianvoid	sched_fork(struct thread *td, struct proc *child);
50113355Sjeff
51104964Sjeff/*
52104964Sjeff * KSE Groups contain scheduling priority information.  They record the
53104964Sjeff * behavior of groups of KSEs and threads.
54104964Sjeff */
55113355Sjeffvoid	sched_class(struct ksegrp *kg, int class);
56132372Sjulianvoid	sched_exit_ksegrp(struct ksegrp *kg, struct thread *childtd);
57132372Sjulianvoid	sched_fork_ksegrp(struct thread *td, struct ksegrp *child);
58130551Sjulianvoid	sched_nice(struct proc *p, int nice);
59104964Sjeff
60104964Sjeff/*
61122036Sjeff * Threads are switched in and out, block on resources, have temporary
62122036Sjeff * priorities inherited from their ksegs, and use up cpu time.
63104964Sjeff */
64113355Sjeffvoid	sched_exit_thread(struct thread *td, struct thread *child);
65113355Sjeffvoid	sched_fork_thread(struct thread *td, struct thread *child);
66122036Sjefffixpt_t	sched_pctcpu(struct thread *td);
67113355Sjeffvoid	sched_prio(struct thread *td, u_char prio);
68126326Sjhbvoid	sched_sleep(struct thread *td);
69131473Sjhbvoid	sched_switch(struct thread *td, struct thread *newtd);
70113355Sjeffvoid	sched_userret(struct thread *td);
71104964Sjeffvoid	sched_wakeup(struct thread *td);
72104964Sjeff
73104964Sjeff/*
74122036Sjeff * Threads are moved on and off of run queues
75104964Sjeff */
76121127Sjeffvoid	sched_add(struct thread *td);
77122036Sjeffstruct kse *sched_choose(void);		/* XXX Should be thread * */
78121127Sjeffvoid	sched_clock(struct thread *td);
79121127Sjeffvoid	sched_rem(struct thread *td);
80104964Sjeff
81107126Sjeff/*
82122036Sjeff * Binding makes cpu affinity permanent while pinning is used to temporarily
83122036Sjeff * hold a thread on a particular CPU.
84107137Sjeff */
85122036Sjeffvoid	sched_bind(struct thread *td, int cpu);
86122768Sjeffstatic __inline void sched_pin(void);
87122036Sjeffvoid	sched_unbind(struct thread *td);
88122768Sjeffstatic __inline void sched_unpin(void);
89107137Sjeff
90107137Sjeff/*
91122036Sjeff * These interfaces will eventually be removed.
92122036Sjeff */
93132372Sjulianvoid	sched_exit_kse(struct kse *ke, struct thread *childtd);
94132372Sjulianvoid	sched_fork_kse(struct thread *td, struct kse *child);
95122036Sjeff
96122036Sjeff/*
97107126Sjeff * These procedures tell the process data structure allocation code how
98107126Sjeff * many bytes to actually allocate.
99107126Sjeff */
100107126Sjeffint	sched_sizeof_kse(void);
101107126Sjeffint	sched_sizeof_ksegrp(void);
102107126Sjeffint	sched_sizeof_proc(void);
103107126Sjeffint	sched_sizeof_thread(void);
104107126Sjeff
105107126Sjeffextern struct ke_sched *kse0_sched;
106107126Sjeffextern struct kg_sched *ksegrp0_sched;
107107126Sjeffextern struct p_sched *proc0_sched;
108107126Sjeffextern struct td_sched *thread0_sched;
109107126Sjeff
110122157Sjeffstatic __inline void
111122768Sjeffsched_pin(void)
112122157Sjeff{
113122768Sjeff	curthread->td_pinned++;
114122157Sjeff}
115122157Sjeff
116122157Sjeffstatic __inline void
117122768Sjeffsched_unpin(void)
118122157Sjeff{
119122768Sjeff	curthread->td_pinned--;
120122157Sjeff}
121122157Sjeff
122104964Sjeff#endif /* !_SYS_SCHED_H_ */
123