2000-09-07 01:33:02 +00:00
|
|
|
/*-
|
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);
|
|
|
|
SYSINIT(idle_setup, SI_SUB_SCHED_IDLE, SI_ORDER_FIRST, idle_setup, NULL)
|
|
|
|
|
|
|
|
/*
|
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;
|
|
|
|
|
|
|
|
#ifdef SMP
|
2001-12-11 23:33:44 +00:00
|
|
|
SLIST_FOREACH(pc, &cpuhead, pc_allcpu) {
|
2007-01-23 08:46:51 +00:00
|
|
|
error = kthread_create(sched_idletd, NULL, &p,
|
2002-10-02 07:44:29 +00:00
|
|
|
RFSTOPPED | RFHIGHPID, 0, "idle: cpu%d", pc->pc_cpuid);
|
2002-02-07 20:58:47 +00:00
|
|
|
pc->pc_idlethread = FIRST_THREAD_IN_PROC(p);
|
2000-09-07 01:33:02 +00:00
|
|
|
#else
|
2007-01-23 08:46:51 +00:00
|
|
|
error = kthread_create(sched_idletd, NULL, &p,
|
2002-10-02 07:44:29 +00:00
|
|
|
RFSTOPPED | RFHIGHPID, 0, "idle");
|
2002-02-07 20:58:47 +00:00
|
|
|
PCPU_SET(idlethread, FIRST_THREAD_IN_PROC(p));
|
2000-09-07 01:33:02 +00:00
|
|
|
#endif
|
|
|
|
if (error)
|
|
|
|
panic("idle_setup: kthread_create error %d\n", error);
|
|
|
|
|
2003-04-17 22:25:35 +00:00
|
|
|
PROC_LOCK(p);
|
2001-04-27 19:28:25 +00:00
|
|
|
p->p_flag |= P_NOLOAD;
|
2003-04-17 22:25:35 +00:00
|
|
|
mtx_lock_spin(&sched_lock);
|
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
|
|
|
td = FIRST_THREAD_IN_PROC(p);
|
2004-07-02 19:09:50 +00:00
|
|
|
TD_SET_CAN_RUN(td);
|
2003-05-02 00:33:12 +00:00
|
|
|
td->td_flags |= TDF_IDLETD;
|
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);
|
2003-04-17 22:25:35 +00:00
|
|
|
mtx_unlock_spin(&sched_lock);
|
|
|
|
PROC_UNLOCK(p);
|
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
|
|
|
}
|