sched.h revision 122768
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 122768 2003-11-15 23:54:49Z jeff $
27104964Sjeff */
28104964Sjeff
29104964Sjeff#ifndef _SYS_SCHED_H_
30104964Sjeff#define	_SYS_SCHED_H_
31104964Sjeff
32104964Sjeff/*
33104964Sjeff * General scheduling info.
34104964Sjeff */
35104964Sjeffint	sched_rr_interval(void);
36104964Sjeffint	sched_runnable(void);
37104964Sjeff
38113355Sjeff/*
39113355Sjeff * Proc related scheduling hooks.
40113355Sjeff */
41113355Sjeffvoid	sched_exit(struct proc *p, struct proc *child);
42113355Sjeffvoid	sched_fork(struct proc *p, struct proc *child);
43113355Sjeff
44104964Sjeff/*
45104964Sjeff * KSE Groups contain scheduling priority information.  They record the
46104964Sjeff * behavior of groups of KSEs and threads.
47104964Sjeff */
48113355Sjeffvoid	sched_class(struct ksegrp *kg, int class);
49113355Sjeffvoid	sched_exit_ksegrp(struct ksegrp *kg, struct ksegrp *child);
50113355Sjeffvoid	sched_fork_ksegrp(struct ksegrp *kg, struct ksegrp *child);
51104964Sjeffvoid	sched_nice(struct ksegrp *kg, int nice);
52104964Sjeff
53104964Sjeff/*
54122036Sjeff * Threads are switched in and out, block on resources, have temporary
55122036Sjeff * priorities inherited from their ksegs, and use up cpu time.
56104964Sjeff */
57113355Sjeffvoid	sched_exit_thread(struct thread *td, struct thread *child);
58113355Sjeffvoid	sched_fork_thread(struct thread *td, struct thread *child);
59122036Sjefffixpt_t	sched_pctcpu(struct thread *td);
60113355Sjeffvoid	sched_prio(struct thread *td, u_char prio);
61104964Sjeffvoid	sched_sleep(struct thread *td, u_char prio);
62121128Sjeffvoid	sched_switch(struct thread *td);
63113355Sjeffvoid	sched_userret(struct thread *td);
64104964Sjeffvoid	sched_wakeup(struct thread *td);
65104964Sjeff
66104964Sjeff/*
67122036Sjeff * Threads are moved on and off of run queues
68104964Sjeff */
69121127Sjeffvoid	sched_add(struct thread *td);
70122036Sjeffstruct kse *sched_choose(void);		/* XXX Should be thread * */
71121127Sjeffvoid	sched_clock(struct thread *td);
72121127Sjeffvoid	sched_rem(struct thread *td);
73104964Sjeff
74107126Sjeff/*
75122036Sjeff * Binding makes cpu affinity permanent while pinning is used to temporarily
76122036Sjeff * hold a thread on a particular CPU.
77107137Sjeff */
78122036Sjeffvoid	sched_bind(struct thread *td, int cpu);
79122768Sjeffstatic __inline void sched_pin(void);
80122036Sjeffvoid	sched_unbind(struct thread *td);
81122768Sjeffstatic __inline void sched_unpin(void);
82107137Sjeff
83107137Sjeff/*
84122036Sjeff * These interfaces will eventually be removed.
85122036Sjeff */
86122036Sjeffvoid	sched_exit_kse(struct kse *ke, struct kse *child);
87122036Sjeffvoid	sched_fork_kse(struct kse *ke, struct kse *child);
88122036Sjeff
89122036Sjeff/*
90107126Sjeff * These procedures tell the process data structure allocation code how
91107126Sjeff * many bytes to actually allocate.
92107126Sjeff */
93107126Sjeffint	sched_sizeof_kse(void);
94107126Sjeffint	sched_sizeof_ksegrp(void);
95107126Sjeffint	sched_sizeof_proc(void);
96107126Sjeffint	sched_sizeof_thread(void);
97107126Sjeff
98107126Sjeffextern struct ke_sched *kse0_sched;
99107126Sjeffextern struct kg_sched *ksegrp0_sched;
100107126Sjeffextern struct p_sched *proc0_sched;
101107126Sjeffextern struct td_sched *thread0_sched;
102107126Sjeff
103122157Sjeffstatic __inline void
104122768Sjeffsched_pin(void)
105122157Sjeff{
106122768Sjeff	curthread->td_pinned++;
107122157Sjeff}
108122157Sjeff
109122157Sjeffstatic __inline void
110122768Sjeffsched_unpin(void)
111122157Sjeff{
112122768Sjeff	curthread->td_pinned--;
113122157Sjeff}
114122157Sjeff
115104964Sjeff#endif /* !_SYS_SCHED_H_ */
116