2000-09-07 01:33:02 +00:00
|
|
|
/*-
|
2017-11-27 15:20:12 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2004-07-25 19:49:01 +00:00
|
|
|
* Copyright (C) 2000-2004 The FreeBSD Project. All rights reserved.
|
2000-09-07 01:33:02 +00:00
|
|
|
*
|
2004-07-25 19:49:01 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2000-09-07 01:33:02 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-09-07 01:33:02 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
2001-05-10 17:45:49 +00:00
|
|
|
#include <sys/kthread.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/proc.h>
|
2000-09-07 01:33:02 +00:00
|
|
|
#include <sys/resourcevar.h>
|
2002-10-12 05:32:24 +00:00
|
|
|
#include <sys/sched.h>
|
2000-09-07 01:33:02 +00:00
|
|
|
#include <sys/unistd.h>
|
2004-09-01 06:42:02 +00:00
|
|
|
#ifdef SMP
|
|
|
|
#include <sys/smp.h>
|
|
|
|
#endif
|
2000-09-07 01:33:02 +00:00
|
|
|
|
|
|
|
static void idle_setup(void *dummy);
|
2008-03-16 10:58:09 +00:00
|
|
|
SYSINIT(idle_setup, SI_SUB_SCHED_IDLE, SI_ORDER_FIRST, idle_setup, NULL);
|
2000-09-07 01:33:02 +00:00
|
|
|
|
|
|
|
/*
|
2003-10-19 02:43:57 +00:00
|
|
|
* Set up per-cpu idle process contexts. The AP's shouldn't be running or
|
2001-02-09 14:59:43 +00:00
|
|
|
* accessing their idle processes at this point, so don't bother with
|
|
|
|
* locking.
|
2000-09-07 01:33:02 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
idle_setup(void *dummy)
|
|
|
|
{
|
2001-04-27 19:28:25 +00:00
|
|
|
#ifdef SMP
|
2001-12-11 23:33:44 +00:00
|
|
|
struct pcpu *pc;
|
2001-04-27 19:28:25 +00:00
|
|
|
#endif
|
|
|
|
struct proc *p;
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
struct thread *td;
|
2000-09-07 01:33:02 +00:00
|
|
|
int error;
|
|
|
|
|
2007-10-27 00:42:40 +00:00
|
|
|
p = NULL; /* start with no idle process */
|
2000-09-07 01:33:02 +00:00
|
|
|
#ifdef SMP
|
2011-05-31 15:11:43 +00:00
|
|
|
STAILQ_FOREACH(pc, &cpuhead, pc_allcpu) {
|
2007-10-26 08:00:41 +00:00
|
|
|
#endif
|
2007-10-26 20:32:33 +00:00
|
|
|
#ifdef SMP
|
2007-10-26 08:00:41 +00:00
|
|
|
error = kproc_kthread_add(sched_idletd, NULL, &p, &td,
|
2007-10-27 00:52:26 +00:00
|
|
|
RFSTOPPED | RFHIGHPID, 0, "idle", "idle: cpu%d", pc->pc_cpuid);
|
2007-10-26 08:00:41 +00:00
|
|
|
pc->pc_idlethread = td;
|
2000-09-07 01:33:02 +00:00
|
|
|
#else
|
2007-10-26 20:32:33 +00:00
|
|
|
error = kproc_kthread_add(sched_idletd, NULL, &p, &td,
|
2007-10-27 00:52:26 +00:00
|
|
|
RFSTOPPED | RFHIGHPID, 0, "idle", "idle");
|
2007-10-26 08:00:41 +00:00
|
|
|
PCPU_SET(idlethread, td);
|
2000-09-07 01:33:02 +00:00
|
|
|
#endif
|
|
|
|
if (error)
|
2007-10-20 23:23:23 +00:00
|
|
|
panic("idle_setup: kproc_create error %d\n", error);
|
2000-09-07 01:33:02 +00:00
|
|
|
|
Commit 14/14 of sched_lock decomposition.
- Use thread_lock() rather than sched_lock for per-thread scheduling
sychronization.
- Use the per-process spinlock rather than the sched_lock for per-process
scheduling synchronization.
Tested by: kris, current@
Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc.
Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
2007-06-05 00:00:57 +00:00
|
|
|
thread_lock(td);
|
2004-07-02 19:09:50 +00:00
|
|
|
TD_SET_CAN_RUN(td);
|
2009-11-03 16:46:52 +00:00
|
|
|
td->td_flags |= TDF_IDLETD | TDF_NOLOAD;
|
2006-10-26 21:42:22 +00:00
|
|
|
sched_class(td, PRI_IDLE);
|
2005-02-04 06:16:05 +00:00
|
|
|
sched_prio(td, PRI_MAX_IDLE);
|
Commit 14/14 of sched_lock decomposition.
- Use thread_lock() rather than sched_lock for per-thread scheduling
sychronization.
- Use the per-process spinlock rather than the sched_lock for per-process
scheduling synchronization.
Tested by: kris, current@
Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc.
Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
2007-06-05 00:00:57 +00:00
|
|
|
thread_unlock(td);
|
2001-04-27 19:28:25 +00:00
|
|
|
#ifdef SMP
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
2001-04-27 19:28:25 +00:00
|
|
|
#endif
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|