35 #include <sys/cdefs.h>
38 #include "opt_hwpmc_hooks.h"
39 #include "opt_sched.h"
40 #include "opt_kdtrace.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/cpuset.h>
45 #include <sys/kernel.h>
48 #include <sys/kthread.h>
49 #include <sys/mutex.h>
51 #include <sys/resourcevar.h>
52 #include <sys/sched.h>
55 #include <sys/sysctl.h>
57 #include <sys/turnstile.h>
59 #include <machine/pcb.h>
60 #include <machine/smp.h>
63 #include <sys/pmckern.h>
67 #include <sys/dtrace_bsd.h>
68 int dtrace_vtime_active;
69 dtrace_vtime_switch_func_t dtrace_vtime_switch_func;
76 #define ESTCPULIM(e) \
77 min((e), INVERSE_ESTCPU_WEIGHT * (NICE_WEIGHT * (PRIO_MAX - PRIO_MIN) - \
78 RQ_PPQ) + INVERSE_ESTCPU_WEIGHT - 1)
80 #define INVERSE_ESTCPU_WEIGHT (8 * smp_cpus)
82 #define INVERSE_ESTCPU_WEIGHT 8
86 #define TS_NAME_LEN (MAXCOMLEN + sizeof(" td ") + sizeof(__XSTRING(UINT_MAX)))
106 #define TDF_DIDRUN TDF_SCHED0
107 #define TDF_BOUND TDF_SCHED1
108 #define TDF_SLICEEND TDF_SCHED2
111 #define TSF_AFFINITY 0x0001
113 #define SKE_RUNQ_PCPU(ts) \
114 ((ts)->ts_runq != 0 && (ts)->ts_runq != &runq)
116 #define THREAD_CAN_SCHED(td, cpu) \
117 CPU_ISSET((cpu), &(td)->td_cpuset->cs_mask)
132 static void updatepri(
struct thread *td);
136 static int sched_pickcpu(
struct thread *td);
137 static int forward_wakeup(
int cpunum);
138 static void kick_other_cpu(
int pri,
int cpuid);
163 static struct runq runq_pcpu[MAXCPU];
164 long runq_length[MAXCPU];
166 static cpuset_t idle_cpus_mask;
181 for (i = 0; i < MAXCPU; ++i)
191 int error, new_val, period;
196 if (error != 0 || req->newptr == NULL)
200 sched_slice = imax(1, (new_val + period / 2) / period);
206 SYSCTL_NODE(_kern, OID_AUTO, sched, CTLFLAG_RD, 0,
"Scheduler");
210 SYSCTL_PROC(_kern_sched, OID_AUTO, quantum, CTLTYPE_INT | CTLFLAG_RW,
212 "Quantum for timeshare threads in microseconds");
214 "Quantum for timeshare threads in stathz ticks");
217 static SYSCTL_NODE(_kern_sched, OID_AUTO, ipiwakeup, CTLFLAG_RD, NULL,
220 static int runq_fuzz = 1;
221 SYSCTL_INT(_kern_sched, OID_AUTO, runq_fuzz, CTLFLAG_RW, &runq_fuzz, 0,
"");
223 static int forward_wakeup_enabled = 1;
224 SYSCTL_INT(_kern_sched_ipiwakeup, OID_AUTO, enabled, CTLFLAG_RW,
225 &forward_wakeup_enabled, 0,
226 "Forwarding of wakeup to idle CPUs");
228 static int forward_wakeups_requested = 0;
229 SYSCTL_INT(_kern_sched_ipiwakeup, OID_AUTO, requested, CTLFLAG_RD,
230 &forward_wakeups_requested, 0,
231 "Requests for Forwarding of wakeup to idle CPUs");
233 static int forward_wakeups_delivered = 0;
234 SYSCTL_INT(_kern_sched_ipiwakeup, OID_AUTO, delivered, CTLFLAG_RD,
235 &forward_wakeups_delivered, 0,
236 "Completed Forwarding of wakeup to idle CPUs");
238 static int forward_wakeup_use_mask = 1;
239 SYSCTL_INT(_kern_sched_ipiwakeup, OID_AUTO, usemask, CTLFLAG_RW,
240 &forward_wakeup_use_mask, 0,
241 "Use the mask of idle cpus");
243 static int forward_wakeup_use_loop = 0;
244 SYSCTL_INT(_kern_sched_ipiwakeup, OID_AUTO, useloop, CTLFLAG_RW,
245 &forward_wakeup_use_loop, 0,
246 "Use a loop to find idle cpus");
250 static int sched_followon = 0;
251 SYSCTL_INT(_kern_sched, OID_AUTO, followon, CTLFLAG_RW,
253 "allow threads to share a quantum");
259 "struct proc *",
"uint8_t");
261 "struct proc *",
"void *");
263 "struct proc *",
"void *",
"int");
265 "struct proc *",
"uint8_t",
"struct thread *");
279 KTR_COUNTER0(KTR_SCHED,
"load",
"global load",
sched_tdcnt);
280 SDT_PROBE2(sched, , , load__change, NOCPU,
sched_tdcnt);
288 KTR_COUNTER0(KTR_SCHED,
"load",
"global load",
sched_tdcnt);
289 SDT_PROBE2(sched, , , load__change, NOCPU,
sched_tdcnt);
299 THREAD_LOCK_ASSERT(td, MA_OWNED);
300 if (td->td_priority < curthread->td_priority)
301 curthread->td_flags |= TDF_NEEDRESCHED;
342 THREAD_LOCK_ASSERT(td, MA_OWNED);
343 KASSERT((td->td_inhibitors == 0),
344 (
"maybe_preempt: trying to run inhibited thread"));
345 pri = td->td_priority;
346 cpri = ctd->td_priority;
347 if (
panicstr != NULL || pri >= cpri || cold ||
348 TD_IS_INHIBITED(ctd))
350 #ifndef FULL_PREEMPTION
351 if (pri > PRI_MAX_ITHD && cpri < PRI_MIN_IDLE)
355 if (ctd->td_critnest > 1) {
356 CTR1(KTR_PROC,
"maybe_preempt: in critical section %d",
358 ctd->td_owepreempt = 1;
364 MPASS(ctd->td_lock == td->td_lock);
365 MPASS(TD_ON_RUNQ(td));
367 CTR3(KTR_PROC,
"preempting to thread %p (pid %d, %s)\n", td,
368 td->td_proc->p_pid, td->td_name);
369 mi_switch(SW_INVOL | SW_PREEMPT | SWT_PREEMPT, td);
449 #define loadfactor(loadav) (2 * (loadav))
450 #define decay_cpu(loadfac, cpu) (((loadfac) * (cpu)) / ((loadfac) + FSCALE))
453 static fixpt_t
ccpu = 0.95122942450071400909 * FSCALE;
468 #define CCPU_SHIFT 11
485 FOREACH_PROC_IN_SYSTEM(p) {
487 if (p->p_state == PRS_NEW) {
491 FOREACH_THREAD_IN_PROC(p, td) {
504 if (TD_ON_RUNQ(td)) {
507 }
else if (TD_IS_RUNNING(td)) {
525 #if (FSHIFT >= CCPU_SHIFT)
563 td->td_estcpu =
decay_cpu(loadfac, td->td_estcpu);
603 newcpu = td->td_estcpu;
607 td->td_estcpu = newcpu;
619 register unsigned int newpriority;
621 if (td->td_pri_class == PRI_TIMESHARE) {
624 newpriority = min(max(newpriority, PRI_MIN_TIMESHARE),
639 if (td->td_priority < PRI_MIN_TIMESHARE ||
640 td->td_priority > PRI_MAX_TIMESHARE)
687 proc0.p_sched = NULL;
732 THREAD_LOCK_ASSERT(td, MA_OWNED);
736 td->td_estcpu =
ESTCPULIM(td->td_estcpu + 1);
746 if (!TD_IS_IDLETHREAD(td) && --ts->
ts_slice <= 0) {
751 stat = DPCPU_PTR(idlestat);
763 KTR_STATE1(KTR_SCHED,
"thread",
sched_tdname(td),
"proc exit",
764 "prio:%d", td->td_priority);
766 PROC_LOCK_ASSERT(p, MA_OWNED);
774 KTR_STATE1(KTR_SCHED,
"thread",
sched_tdname(child),
"exit",
775 "prio:%d", child->td_priority);
777 td->td_estcpu =
ESTCPULIM(td->td_estcpu + child->td_estcpu);
780 if ((child->td_flags & TDF_NOLOAD) == 0)
782 thread_unlock(child);
796 childtd->td_oncpu = NOCPU;
797 childtd->td_lastcpu = NOCPU;
798 childtd->td_estcpu = td->td_estcpu;
800 childtd->td_cpuset =
cpuset_ref(td->td_cpuset);
801 childtd->td_priority = childtd->td_base_pri;
802 ts = childtd->td_sched;
803 bzero(ts,
sizeof(*ts));
813 PROC_LOCK_ASSERT(p, MA_OWNED);
815 FOREACH_THREAD_IN_PROC(p, td) {
826 THREAD_LOCK_ASSERT(td, MA_OWNED);
827 td->td_pri_class =
class;
838 KTR_POINT3(KTR_SCHED,
"thread",
sched_tdname(td),
"priority change",
839 "prio:%d", td->td_priority,
"new prio:%d", prio, KTR_ATTR_LINKED,
841 SDT_PROBE3(sched, , , change__pri, td, td->td_proc, prio);
842 if (td != curthread && prio > td->td_priority) {
843 KTR_POINT3(KTR_SCHED,
"thread",
sched_tdname(curthread),
844 "lend prio",
"prio:%d", td->td_priority,
"new prio:%d",
846 SDT_PROBE4(sched, , , lend__pri, td, td->td_proc, prio,
849 THREAD_LOCK_ASSERT(td, MA_OWNED);
850 if (td->td_priority == prio)
852 td->td_priority = prio;
853 if (TD_ON_RUNQ(td) && td->td_rqindex != (prio / RQ_PPQ)) {
867 td->td_flags |= TDF_BORROWING;
884 if (td->td_base_pri >= PRI_MIN_TIMESHARE &&
885 td->td_base_pri <= PRI_MAX_TIMESHARE)
886 base_pri = td->td_user_pri;
888 base_pri = td->td_base_pri;
889 if (prio >= base_pri) {
890 td->td_flags &= ~TDF_BORROWING;
902 td->td_base_pri = prio;
908 if (td->td_flags & TDF_BORROWING && td->td_priority < prio)
912 oldprio = td->td_priority;
919 if (TD_ON_LOCK(td) && oldprio != prio)
927 THREAD_LOCK_ASSERT(td, MA_OWNED);
928 td->td_base_user_pri = prio;
929 if (td->td_lend_user_pri <= prio)
931 td->td_user_pri = prio;
938 THREAD_LOCK_ASSERT(td, MA_OWNED);
939 td->td_lend_user_pri = prio;
940 td->td_user_pri = min(prio, td->td_base_user_pri);
941 if (td->td_priority > td->td_user_pri)
943 else if (td->td_priority != td->td_user_pri)
944 td->td_flags |= TDF_NEEDRESCHED;
951 THREAD_LOCK_ASSERT(td, MA_OWNED);
952 td->td_slptick =
ticks;
953 td->td_sched->ts_slptime = 0;
954 if (pri != 0 && PRI_BASE(td->td_pri_class) == PRI_TIMESHARE)
956 if (TD_IS_SUSPENDED(td) || pri >= PSOCK)
957 td->td_flags |= TDF_CANSWAP;
972 THREAD_LOCK_ASSERT(td, MA_OWNED);
984 if ((td->td_flags & TDF_NOLOAD) == 0)
987 td->td_lastcpu = td->td_oncpu;
989 (flags & SWT_RELINQUISH));
991 td->td_owepreempt = 0;
992 td->td_oncpu = NOCPU;
1000 if (td->td_flags & TDF_IDLETD) {
1003 CPU_CLR(PCPU_GET(cpuid), &idle_cpus_mask);
1006 if (TD_IS_RUNNING(td)) {
1009 SRQ_OURSELF|SRQ_YIELDING|SRQ_PREEMPTED :
1010 SRQ_OURSELF|SRQ_YIELDING);
1022 KASSERT((newtd->td_inhibitors == 0),
1023 (
"trying to run inhibited thread"));
1025 TD_SET_RUNNING(newtd);
1026 if ((newtd->td_flags & TDF_NOLOAD) == 0)
1035 if (PMC_PROC_IS_USING_PMCS(td->td_proc))
1036 PMC_SWITCH_CONTEXT(td, PMC_FN_CSW_OUT);
1039 SDT_PROBE2(sched, , , off__cpu, newtd, newtd->td_proc);
1042 lock_profile_release_lock(&
sched_lock.lock_object);
1043 #ifdef KDTRACE_HOOKS
1049 if (dtrace_vtime_active)
1050 (*dtrace_vtime_switch_func)(newtd);
1053 cpu_switch(td, newtd, tmtx != NULL ? tmtx : td->td_lock);
1054 lock_profile_obtain_lock_success(&
sched_lock.lock_object,
1055 0, 0, __FILE__, __LINE__);
1073 SDT_PROBE0(sched, , , on__cpu);
1075 if (PMC_PROC_IS_USING_PMCS(td->td_proc))
1076 PMC_SWITCH_CONTEXT(td, PMC_FN_CSW_IN);
1079 SDT_PROBE0(sched, , , remain__cpu);
1082 if (td->td_flags & TDF_IDLETD)
1083 CPU_SET(PCPU_GET(cpuid), &idle_cpus_mask);
1086 td->td_oncpu = PCPU_GET(cpuid);
1095 THREAD_LOCK_ASSERT(td, MA_OWNED);
1097 td->td_flags &= ~TDF_CANSWAP;
1110 forward_wakeup(
int cpunum)
1113 cpuset_t dontuse, map, map2;
1119 CTR0(KTR_RUNQ,
"forward_wakeup()");
1121 if ((!forward_wakeup_enabled) ||
1122 (forward_wakeup_use_mask == 0 && forward_wakeup_use_loop == 0))
1127 forward_wakeups_requested++;
1133 me = PCPU_GET(cpuid);
1136 if (CPU_ISSET(me, &idle_cpus_mask) &&
1137 (cpunum == NOCPU || me == cpunum))
1140 CPU_SETOF(me, &dontuse);
1141 CPU_OR(&dontuse, &stopped_cpus);
1142 CPU_OR(&dontuse, &hlt_cpus_mask);
1144 if (forward_wakeup_use_loop) {
1145 STAILQ_FOREACH(pc, &cpuhead, pc_allcpu) {
1147 if (!CPU_ISSET(
id, &dontuse) &&
1148 pc->pc_curthread == pc->pc_idlethread) {
1154 if (forward_wakeup_use_mask) {
1155 map = idle_cpus_mask;
1156 CPU_NAND(&map, &dontuse);
1159 if (forward_wakeup_use_loop) {
1160 if (CPU_CMP(&map, &map2)) {
1161 printf(
"map != map2, loop method preferred\n");
1170 if (cpunum != NOCPU) {
1171 KASSERT((cpunum <=
mp_maxcpus),(
"forward_wakeup: bad cpunum."));
1172 iscpuset = CPU_ISSET(cpunum, &map);
1176 CPU_SETOF(cpunum, &map);
1178 if (!CPU_EMPTY(&map)) {
1179 forward_wakeups_delivered++;
1180 STAILQ_FOREACH(pc, &cpuhead, pc_allcpu) {
1182 if (!CPU_ISSET(
id, &map))
1184 if (cpu_idle_wakeup(pc->pc_cpuid))
1187 if (!CPU_EMPTY(&map))
1188 ipi_selected(map, IPI_AST);
1191 if (cpunum == NOCPU)
1192 printf(
"forward_wakeup: Idle processor not found\n");
1197 kick_other_cpu(
int pri,
int cpuid)
1203 if (CPU_ISSET(cpuid, &idle_cpus_mask)) {
1204 forward_wakeups_delivered++;
1205 if (!cpu_idle_wakeup(cpuid))
1206 ipi_cpu(cpuid, IPI_AST);
1210 cpri = pcpu->pc_curthread->td_priority;
1214 #if defined(IPI_PREEMPTION) && defined(PREEMPTION)
1215 #if !defined(FULL_PREEMPTION)
1216 if (pri <= PRI_MAX_ITHD)
1219 ipi_cpu(cpuid, IPI_PREEMPT);
1224 pcpu->pc_curthread->td_flags |= TDF_NEEDRESCHED;
1225 ipi_cpu(cpuid, IPI_AST);
1232 sched_pickcpu(
struct thread *td)
1239 best = td->td_lastcpu;
1248 else if (runq_length[cpu] < runq_length[best])
1251 KASSERT(best != NOCPU, (
"no valid CPUs"));
1268 THREAD_LOCK_ASSERT(td, MA_OWNED);
1269 KASSERT((td->td_inhibitors == 0),
1270 (
"sched_add: trying to run inhibited thread"));
1271 KASSERT((TD_CAN_RUN(td) || TD_IS_RUNNING(td)),
1272 (
"sched_add: bad thread state"));
1273 KASSERT(td->td_flags & TDF_INMEM,
1274 (
"sched_add: thread swapped out"));
1276 KTR_STATE2(KTR_SCHED,
"thread",
sched_tdname(td),
"runq add",
1277 "prio:%d", td->td_priority, KTR_ATTR_LINKED,
1279 KTR_POINT1(KTR_SCHED,
"thread",
sched_tdname(curthread),
"wokeup",
1281 SDT_PROBE4(sched, , , enqueue, td, td->td_proc, NULL,
1282 flags & SRQ_PREEMPTED);
1306 if (td->td_pinned != 0)
1307 cpu = td->td_lastcpu;
1311 (
"sched_add: bound td_sched not on cpu runq"));
1312 cpu = ts->
ts_runq - &runq_pcpu[0];
1315 cpu = sched_pickcpu(td);
1316 ts->
ts_runq = &runq_pcpu[cpu];
1319 "sched_add: Put td_sched:%p(td:%p) on cpu%d runq", ts, td,
1323 "sched_add: adding td_sched:%p (td:%p) to gbl runq", ts,
1329 cpuid = PCPU_GET(cpuid);
1330 if (single_cpu && cpu != cpuid) {
1331 kick_other_cpu(td->td_priority, cpu);
1334 tidlemsk = idle_cpus_mask;
1335 CPU_NAND(&tidlemsk, &hlt_cpus_mask);
1336 CPU_CLR(cpuid, &tidlemsk);
1338 if (!CPU_ISSET(cpuid, &idle_cpus_mask) &&
1339 ((flags & SRQ_INTR) == 0) &&
1340 !CPU_EMPTY(&tidlemsk))
1341 forwarded = forward_wakeup(cpu);
1352 if ((td->td_flags & TDF_NOLOAD) == 0)
1363 THREAD_LOCK_ASSERT(td, MA_OWNED);
1364 KASSERT((td->td_inhibitors == 0),
1365 (
"sched_add: trying to run inhibited thread"));
1366 KASSERT((TD_CAN_RUN(td) || TD_IS_RUNNING(td)),
1367 (
"sched_add: bad thread state"));
1368 KASSERT(td->td_flags & TDF_INMEM,
1369 (
"sched_add: thread swapped out"));
1370 KTR_STATE2(KTR_SCHED,
"thread",
sched_tdname(td),
"runq add",
1371 "prio:%d", td->td_priority, KTR_ATTR_LINKED,
1373 KTR_POINT1(KTR_SCHED,
"thread",
sched_tdname(curthread),
"wokeup",
1375 SDT_PROBE4(sched, , , enqueue, td, td->td_proc, NULL,
1376 flags & SRQ_PREEMPTED);
1387 CTR2(KTR_RUNQ,
"sched_add: adding td_sched:%p (td:%p) to runq", ts, td);
1399 if ((flags & SRQ_YIELDING) == 0) {
1403 if ((td->td_flags & TDF_NOLOAD) == 0)
1416 KASSERT(td->td_flags & TDF_INMEM,
1417 (
"sched_rem: thread swapped out"));
1418 KASSERT(TD_ON_RUNQ(td),
1419 (
"sched_rem: thread not on run queue"));
1421 KTR_STATE2(KTR_SCHED,
"thread",
sched_tdname(td),
"runq rem",
1422 "prio:%d", td->td_priority, KTR_ATTR_LINKED,
1424 SDT_PROBE3(sched, , , dequeue, td, td->td_proc, NULL);
1426 if ((td->td_flags & TDF_NOLOAD) == 0)
1430 runq_length[ts->
ts_runq - runq_pcpu]--;
1448 struct thread *tdcpu;
1456 tdcpu->td_priority < td->td_priority)) {
1457 CTR2(KTR_RUNQ,
"choosing td %p from pcpu runq %d", tdcpu,
1460 rq = &runq_pcpu[PCPU_GET(cpuid)];
1462 CTR1(KTR_RUNQ,
"choosing td_sched %p from main runq", td);
1473 runq_length[PCPU_GET(cpuid)]--;
1478 KASSERT(td->td_flags & TDF_INMEM,
1479 (
"sched_choose: thread swapped out"));
1482 return (PCPU_GET(idlethread));
1489 SDT_PROBE2(sched, , , surrender, td, td->td_proc);
1491 if (td->td_critnest > 1)
1492 td->td_owepreempt = 1;
1494 mi_switch(SW_INVOL | SW_PREEMPT | SWT_PREEMPT, NULL);
1510 KASSERT((td->td_flags & TDF_BORROWING) == 0,
1511 (
"thread with borrowed priority returning to userland"));
1512 if (td->td_priority != td->td_user_pri) {
1514 td->td_priority = td->td_user_pri;
1515 td->td_base_pri = td->td_user_pri;
1525 THREAD_LOCK_ASSERT(td, MA_OWNED|MA_NOTRECURSED);
1526 KASSERT(td == curthread, (
"sched_bind: can only bind curthread"));
1532 ts->
ts_runq = &runq_pcpu[cpu];
1533 if (PCPU_GET(cpuid) == cpu)
1543 THREAD_LOCK_ASSERT(td, MA_OWNED);
1544 KASSERT(td == curthread, (
"sched_unbind: can only bind curthread"));
1551 THREAD_LOCK_ASSERT(td, MA_OWNED);
1559 mi_switch(SW_VOL | SWT_RELINQUISH, NULL);
1572 return (
sizeof(
struct proc));
1578 return (
sizeof(
struct thread) +
sizeof(
struct td_sched));
1586 THREAD_LOCK_ASSERT(td, MA_OWNED);
1597 sched_pctcpu_delta(
struct thread *td)
1603 THREAD_LOCK_ASSERT(td, MA_OWNED);
1608 #if (FSHIFT >= CCPU_SHIFT)
1609 delta = (realstathz == 100)
1615 delta = ((FSCALE -
ccpu) *
1617 FSCALE / realstathz)) >> FSHIFT;
1638 stat = DPCPU_PTR(idlestat);
1640 mtx_assert(&
Giant, MA_NOTOWNED);
1672 PCPU_SET(switchticks,
ticks);
1674 lock_profile_release_lock(&
sched_lock.lock_object);
1676 td->td_lastcpu = td->td_oncpu;
1677 td->td_oncpu = NOCPU;
1680 KASSERT(curthread->td_md.md_spinlock_count == 1, (
"invalid count"));
1692 td->td_oncpu = PCPU_GET(cpuid);
1694 lock_profile_obtain_lock_success(&
sched_lock.lock_object,
1695 0, 0, __FILE__, __LINE__);
1696 THREAD_LOCK_ASSERT(td, MA_OWNED | MA_NOTRECURSED);
1706 if (ts->ts_name[0] ==
'\0')
1707 snprintf(ts->ts_name,
sizeof(ts->ts_name),
1708 "%s tid %d", td->td_name, td->td_tid);
1709 return (ts->ts_name);
1711 return (td->td_name);
1717 sched_clear_tdname(
struct thread *td)
1722 ts->ts_name[0] =
'\0';
1733 THREAD_LOCK_ASSERT(td, MA_OWNED);
1755 if (td->td_pinned != 0 || td->td_flags &
TDF_BOUND)
1758 switch (td->td_state) {
1780 td->td_flags |= TDF_NEEDRESCHED;
1781 if (td != curthread)
1782 ipi_cpu(cpu, IPI_AST);
void sched_rem(struct thread *td)
static __inline void sched_load_rem(void)
void sched_clock(struct thread *td)
static void updatepri(struct thread *td)
static void schedcpu_thread(void)
void runq_add(struct runq *rq, struct thread *td, int flags)
void sched_prio(struct thread *td, u_char prio)
void sched_relinquish(struct thread *td)
void turnstile_adjust(struct thread *td, u_char oldpri)
void sched_switch(struct thread *td, struct thread *newtd, int flags)
static __inline void sched_load_add(void)
int snprintf(char *str, size_t size, const char *format,...)
char * sched_tdname(struct thread *td)
void sched_preempt(struct thread *td)
#define THREAD_CAN_SCHED(td, cpu)
void sched_fork_exit(struct thread *td)
void sched_exit(struct proc *p, struct thread *td)
int sched_sizeof_thread(void)
SYSCTL_INT(_kern_sched, OID_AUTO, slice, CTLFLAG_RW,&sched_slice, 0,"Quantum for timeshare threads in stathz ticks")
void sched_nice(struct proc *p, int nice)
struct thread * choosethread(void)
struct thread * sched_choose(void)
static void sched_setup(void *dummy)
struct pcpu * pcpu_find(u_int cpuid)
int runq_check(struct runq *rq)
static void sched_initticks(void *dummy)
void mi_switch(int flags, struct thread *newtd)
SDT_PROBE_DEFINE(sched,,, on__cpu)
void sched_fork_thread(struct thread *td, struct thread *childtd)
static void resetpriority_thread(struct thread *td)
SDT_PROVIDER_DEFINE(sched)
static struct kproc_desc sched_kp
void sched_add(struct thread *td, int flags)
void runq_init(struct runq *rq)
struct loadavg averunnable
struct thread * runq_choose(struct runq *rq)
void thread_lock_set(struct thread *td, struct mtx *new)
struct cpuset * cpuset_ref(struct cpuset *set)
void sched_exit_thread(struct thread *td, struct thread *child)
void sched_lend_prio(struct thread *td, u_char prio)
void sched_class(struct thread *td, int class)
void sched_fork(struct thread *td, struct thread *childtd)
void sched_affinity(struct thread *td)
void sched_userret(struct thread *td)
#define SKE_RUNQ_PCPU(ts)
SYSINIT(schedcpu, SI_SUB_LAST, SI_ORDER_FIRST, kproc_start,&sched_kp)
void sched_wakeup(struct thread *td)
int sysctl_handle_int(SYSCTL_HANDLER_ARGS)
int sched_rr_interval(void)
static void resetpriority(struct thread *td)
int sched_is_bound(struct thread *td)
void runq_remove(struct runq *rq, struct thread *td)
#define loadfactor(loadav)
SDT_PROBE_DEFINE4(sched,,, enqueue,"struct thread *","struct proc *","void *","int")
struct thread * runq_choose_fuzz(struct runq *rq, int fuzz)
int pause(const char *wmesg, int timo)
int printf(const char *fmt,...)
void sched_user_prio(struct thread *td, u_char prio)
void sched_throw(struct thread *td)
void sched_idletd(void *dummy)
void sched_lend_user_prio(struct thread *td, u_char prio)
SYSCTL_NODE(_kern, OID_AUTO, sched, CTLFLAG_RD, 0,"Scheduler")
static int sysctl_kern_quantum(SYSCTL_HANDLER_ARGS)
void mtx_init(struct mtx *m, const char *name, const char *type, int opts)
static DPCPU_DEFINE(struct pcpuidlestat, idlestat)
void sched_bind(struct thread *td, int cpu)
void kproc_start(void *udata) const
SYSCTL_STRING(_kern_sched, OID_AUTO, name, CTLFLAG_RD,"4BSD", 0,"Scheduler name")
int sched_sizeof_proc(void)
static struct td_sched td_sched0
SDT_PROBE_DEFINE2(sched,,, load__change,"int","int")
SYSCTL_UINT(_kern, OID_AUTO, ccpu, CTLFLAG_RD,&ccpu, 0,"")
static void sched_priority(struct thread *td, u_char prio)
static void maybe_resched(struct thread *td)
struct mtx * thread_lock_block(struct thread *td)
#define INVERSE_ESTCPU_WEIGHT
int maybe_preempt(struct thread *td)
void sched_unbind(struct thread *td)
SYSCTL_PROC(_kern_sched, OID_AUTO, quantum, CTLTYPE_INT|CTLFLAG_RW, NULL, 0, sysctl_kern_quantum,"I","Quantum for timeshare threads in microseconds")
static void setup_runqs(void)
void sched_unlend_prio(struct thread *td, u_char prio)
static void schedcpu(void)
#define decay_cpu(loadfac, cpu)
void sched_sleep(struct thread *td, int pri)
fixpt_t sched_pctcpu(struct thread *td)
SDT_PROBE_DEFINE3(sched,,, change__pri,"struct thread *","struct proc *","uint8_t")