2000-09-07 01:33:02 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000, All rights reserved. See /usr/src/COPYRIGHT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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>
|
|
|
|
|
|
|
|
static void idle_setup(void *dummy);
|
|
|
|
SYSINIT(idle_setup, SI_SUB_SCHED_IDLE, SI_ORDER_FIRST, idle_setup, NULL)
|
|
|
|
|
|
|
|
static void idle_proc(void *dummy);
|
|
|
|
|
|
|
|
/*
|
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) {
|
2001-04-27 19:28:25 +00:00
|
|
|
error = kthread_create(idle_proc, 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);
|
2001-12-18 00:27:18 +00:00
|
|
|
if (pc->pc_curthread == NULL) {
|
2001-12-11 23:33:44 +00:00
|
|
|
pc->pc_curthread = pc->pc_idlethread;
|
2001-12-18 00:27:18 +00:00
|
|
|
pc->pc_idlethread->td_critnest = 0;
|
|
|
|
}
|
2000-09-07 01:33:02 +00:00
|
|
|
#else
|
2001-04-27 19:28:25 +00:00
|
|
|
error = kthread_create(idle_proc, 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);
|
2002-09-11 08:13:56 +00:00
|
|
|
td->td_state = TDS_CAN_RUN;
|
2003-05-02 00:33:12 +00:00
|
|
|
td->td_flags |= TDF_IDLETD;
|
2004-06-28 16:19:50 +00:00
|
|
|
td->td_priority = 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
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-10-19 02:43:57 +00:00
|
|
|
* The actual idle process.
|
2000-09-07 01:33:02 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
idle_proc(void *dummy)
|
|
|
|
{
|
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 proc *p;
|
2003-10-19 02:43:57 +00:00
|
|
|
struct thread *td;
|
2000-09-07 01:33:02 +00:00
|
|
|
|
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 = curthread;
|
|
|
|
p = td->td_proc;
|
2000-09-07 01:33:02 +00:00
|
|
|
for (;;) {
|
|
|
|
mtx_assert(&Giant, MA_NOTOWNED);
|
|
|
|
|
2003-10-19 02:43:57 +00:00
|
|
|
while (sched_runnable() == 0)
|
2000-10-19 07:47:16 +00:00
|
|
|
cpu_idle();
|
2000-09-07 01:33:02 +00:00
|
|
|
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock_spin(&sched_lock);
|
2002-09-11 08:13:56 +00:00
|
|
|
td->td_state = TDS_CAN_RUN;
|
2004-01-25 03:54:52 +00:00
|
|
|
mi_switch(SW_VOL);
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock_spin(&sched_lock);
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
|
|
|
}
|