2000-09-07 01:33:02 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000, All rights reserved. See /usr/src/COPYRIGHT
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opt_ktrace.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/ktr.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>
|
2001-05-10 17:45:49 +00:00
|
|
|
#include <sys/pcpu.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/proc.h>
|
2000-09-07 01:33:02 +00:00
|
|
|
#include <sys/resourcevar.h>
|
2001-05-10 17:45:49 +00:00
|
|
|
#include <sys/smp.h>
|
2000-09-07 01:33:02 +00:00
|
|
|
#include <sys/unistd.h>
|
|
|
|
#ifdef KTRACE
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/ktrace.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
/*
|
2001-02-09 14:59:43 +00:00
|
|
|
* Setup per-cpu idle process contexts. The AP's shouldn't be running or
|
|
|
|
* 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,
|
2001-12-11 23:33:44 +00:00
|
|
|
RFSTOPPED | RFHIGHPID, "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,
|
|
|
|
RFSTOPPED | RFHIGHPID, "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);
|
|
|
|
|
2001-04-27 19:28:25 +00:00
|
|
|
p->p_flag |= P_NOLOAD;
|
2002-07-17 19:18:45 +00:00
|
|
|
p->p_state = PRS_NORMAL;
|
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-07-14 03:43:33 +00:00
|
|
|
td->td_state = TDS_UNQUEUED;
|
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->td_kse->ke_flags |= KEF_IDLEKSE;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* idle process context
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
idle_proc(void *dummy)
|
|
|
|
{
|
2000-10-17 23:12:37 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
2000-09-07 01:33:02 +00:00
|
|
|
int count;
|
2000-10-17 23:12:37 +00:00
|
|
|
#endif
|
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;
|
|
|
|
struct proc *p;
|
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);
|
|
|
|
|
2000-10-17 23:12:37 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
2000-09-07 01:33:02 +00:00
|
|
|
count = 0;
|
|
|
|
|
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
|
|
|
while (count >= 0 && kserunnable() == 0) {
|
2000-10-17 23:12:37 +00:00
|
|
|
#else
|
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
|
|
|
while (kserunnable() == 0) {
|
2000-10-17 23:12:37 +00:00
|
|
|
#endif
|
2000-09-07 01:33:02 +00:00
|
|
|
/*
|
|
|
|
* This is a good place to put things to be done in
|
|
|
|
* the background, including sanity checks.
|
|
|
|
*/
|
2000-09-22 03:19:24 +00:00
|
|
|
|
2000-10-17 23:12:37 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
2000-09-07 01:33:02 +00:00
|
|
|
if (count++ < 0)
|
|
|
|
CTR0(KTR_PROC, "idle_proc: timed out waiting"
|
|
|
|
" for a process");
|
2000-10-17 23:12:37 +00:00
|
|
|
#endif
|
|
|
|
|
2000-10-19 07:47:16 +00:00
|
|
|
#ifdef __i386__
|
|
|
|
cpu_idle();
|
|
|
|
#endif
|
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);
|
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
|
|
|
p->p_stats->p_ru.ru_nvcsw++;
|
2000-09-07 01:33:02 +00:00
|
|
|
mi_switch();
|
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
|
|
|
}
|
|
|
|
}
|