2001-01-16 01:00:43 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 Jake Burkholder <jake@freebsd.org>.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 THE 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 THE 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.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2001-01-16 01:00:43 +00:00
|
|
|
#include "opt_ktrace.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
2001-01-16 01:00:43 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/ktr.h>
|
|
|
|
#include <sys/condvar.h>
|
2003-01-26 04:00:39 +00:00
|
|
|
#include <sys/sched.h>
|
2001-01-16 01:00:43 +00:00
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
#ifdef KTRACE
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/ktrace.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common sanity checks for cv_wait* functions.
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
#define CV_ASSERT(cvp, mp, td) do { \
|
2001-12-10 05:51:45 +00:00
|
|
|
KASSERT((td) != NULL, ("%s: curthread NULL", __func__)); \
|
2002-09-11 08:13:56 +00:00
|
|
|
KASSERT(TD_IS_RUNNING(td), ("%s: not TDS_RUNNING", __func__)); \
|
2001-12-10 05:51:45 +00:00
|
|
|
KASSERT((cvp) != NULL, ("%s: cvp NULL", __func__)); \
|
|
|
|
KASSERT((mp) != NULL, ("%s: mp NULL", __func__)); \
|
2001-01-16 01:00:43 +00:00
|
|
|
mtx_assert((mp), MA_OWNED | MA_NOTRECURSED); \
|
|
|
|
} while (0)
|
|
|
|
|
2002-03-30 03:52:52 +00:00
|
|
|
#ifdef INVARIANTS
|
2001-01-16 01:00:43 +00:00
|
|
|
#define CV_WAIT_VALIDATE(cvp, mp) do { \
|
|
|
|
if (TAILQ_EMPTY(&(cvp)->cv_waitq)) { \
|
|
|
|
/* Only waiter. */ \
|
|
|
|
(cvp)->cv_mtx = (mp); \
|
|
|
|
} else { \
|
|
|
|
/* \
|
|
|
|
* Other waiter; assert that we're using the \
|
|
|
|
* same mutex. \
|
|
|
|
*/ \
|
|
|
|
KASSERT((cvp)->cv_mtx == (mp), \
|
2001-12-10 05:51:45 +00:00
|
|
|
("%s: Multiple mutexes", __func__)); \
|
2001-01-16 01:00:43 +00:00
|
|
|
} \
|
|
|
|
} while (0)
|
2002-09-11 08:13:56 +00:00
|
|
|
|
2001-01-16 01:00:43 +00:00
|
|
|
#define CV_SIGNAL_VALIDATE(cvp) do { \
|
|
|
|
if (!TAILQ_EMPTY(&(cvp)->cv_waitq)) { \
|
|
|
|
KASSERT(mtx_owned((cvp)->cv_mtx), \
|
2002-09-11 08:13:56 +00:00
|
|
|
("%s: Mutex not owned", __func__)); \
|
2001-01-16 01:00:43 +00:00
|
|
|
} \
|
|
|
|
} while (0)
|
2002-09-11 08:13:56 +00:00
|
|
|
|
2001-01-16 01:00:43 +00:00
|
|
|
#else
|
|
|
|
#define CV_WAIT_VALIDATE(cvp, mp)
|
|
|
|
#define CV_SIGNAL_VALIDATE(cvp)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void cv_timedwait_end(void *arg);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize a condition variable. Must be called before use.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cv_init(struct cv *cvp, const char *desc)
|
|
|
|
{
|
|
|
|
|
|
|
|
TAILQ_INIT(&cvp->cv_waitq);
|
|
|
|
cvp->cv_mtx = NULL;
|
|
|
|
cvp->cv_description = desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Destroy a condition variable. The condition variable must be re-initialized
|
|
|
|
* in order to be re-used.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cv_destroy(struct cv *cvp)
|
|
|
|
{
|
|
|
|
|
2001-12-10 05:51:45 +00:00
|
|
|
KASSERT(cv_waitq_empty(cvp), ("%s: cv_waitq non-empty", __func__));
|
2001-01-16 01:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common code for cv_wait* functions. All require 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
|
|
|
/*
|
2002-10-25 07:11:12 +00:00
|
|
|
* Switch context.
|
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
|
|
|
*/
|
2002-10-25 07:11:12 +00:00
|
|
|
static __inline void
|
|
|
|
cv_switch(struct thread *td)
|
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
|
|
|
{
|
2002-09-11 08:13:56 +00:00
|
|
|
TD_SET_SLEEPING(td);
|
|
|
|
td->td_proc->p_stats->p_ru.ru_nvcsw++;
|
2001-01-16 01:00:43 +00:00
|
|
|
mi_switch();
|
2001-09-18 23:27:06 +00:00
|
|
|
CTR3(KTR_PROC, "cv_switch: resume thread %p (pid %d, %s)", td,
|
|
|
|
td->td_proc->p_pid, td->td_proc->p_comm);
|
2001-01-16 01:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Switch context, catching signals.
|
|
|
|
*/
|
|
|
|
static __inline int
|
2001-09-12 08:38:13 +00:00
|
|
|
cv_switch_catch(struct thread *td)
|
2001-01-16 01:00:43 +00:00
|
|
|
{
|
2001-09-18 23:27:06 +00:00
|
|
|
struct proc *p;
|
2001-01-16 01:00:43 +00:00
|
|
|
int sig;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We put ourselves on the sleep queue and start our timeout before
|
2002-05-29 23:44:32 +00:00
|
|
|
* calling cursig, as we could stop there, and a wakeup or a SIGCONT (or
|
2001-01-16 01:00:43 +00:00
|
|
|
* both) could occur while we were stopped. A SIGCONT would cause us to
|
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
|
|
|
* be marked as TDS_SLP without resuming us, thus we must be ready for
|
2002-05-29 23:44:32 +00:00
|
|
|
* sleep when cursig is called. If the wakeup happens while we're
|
2002-09-11 08:13:56 +00:00
|
|
|
* stopped, td->td_wchan will be 0 upon return from cursig,
|
|
|
|
* and TD_ON_SLEEPQ() will return false.
|
2001-01-16 01:00:43 +00:00
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_flags |= TDF_SINTR;
|
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);
|
2001-09-18 23:27:06 +00:00
|
|
|
p = td->td_proc;
|
|
|
|
PROC_LOCK(p);
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 20:36:02 +00:00
|
|
|
mtx_lock(&p->p_sigacts->ps_mtx);
|
2002-09-11 08:13:56 +00:00
|
|
|
sig = cursig(td);
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 20:36:02 +00:00
|
|
|
mtx_unlock(&p->p_sigacts->ps_mtx);
|
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
|
|
|
if (thread_suspend_check(1))
|
|
|
|
sig = SIGSTOP;
|
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);
|
Change the preemption code for software interrupt thread schedules and
mutex releases to not require flags for the cases when preemption is
not allowed:
The purpose of the MTX_NOSWITCH and SWI_NOSWITCH flags is to prevent
switching to a higher priority thread on mutex releease and swi schedule,
respectively when that switch is not safe. Now that the critical section
API maintains a per-thread nesting count, the kernel can easily check
whether or not it should switch without relying on flags from the
programmer. This fixes a few bugs in that all current callers of
swi_sched() used SWI_NOSWITCH, when in fact, only the ones called from
fast interrupt handlers and the swi_sched of softclock needed this flag.
Note that to ensure that swi_sched()'s in clock and fast interrupt
handlers do not switch, these handlers have to be explicitly wrapped
in critical_enter/exit pairs. Presently, just wrapping the handlers is
sufficient, but in the future with the fully preemptive kernel, the
interrupt must be EOI'd before critical_exit() is called. (critical_exit()
can switch due to a deferred preemption in a fully preemptive kernel.)
I've tested the changes to the interrupt code on i386 and alpha. I have
not tested ia64, but the interrupt code is almost identical to the alpha
code, so I expect it will work fine. PowerPC and ARM do not yet have
interrupt code in the tree so they shouldn't be broken. Sparc64 is
broken, but that's been ok'd by jake and tmm who will be fixing the
interrupt code for sparc64 shortly.
Reviewed by: peter
Tested on: i386, alpha
2002-01-05 08:47:13 +00:00
|
|
|
PROC_UNLOCK(p);
|
2001-01-16 01:00:43 +00:00
|
|
|
if (sig != 0) {
|
2002-09-11 08:13:56 +00:00
|
|
|
if (TD_ON_SLEEPQ(td))
|
2001-09-12 08:38:13 +00:00
|
|
|
cv_waitq_remove(td);
|
2002-09-11 08:13:56 +00:00
|
|
|
TD_SET_RUNNING(td);
|
|
|
|
} else if (TD_ON_SLEEPQ(td)) {
|
2001-09-12 08:38:13 +00:00
|
|
|
cv_switch(td);
|
2001-01-16 01:00:43 +00:00
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_flags &= ~TDF_SINTR;
|
2001-01-16 01:00:43 +00:00
|
|
|
|
|
|
|
return sig;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-09-12 08:38:13 +00:00
|
|
|
* Add a thread to the wait queue of a condition variable.
|
2001-01-16 01:00:43 +00:00
|
|
|
*/
|
|
|
|
static __inline void
|
2001-09-12 08:38:13 +00:00
|
|
|
cv_waitq_add(struct cv *cvp, struct thread *td)
|
2001-01-16 01:00:43 +00:00
|
|
|
{
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_flags |= TDF_CVWAITQ;
|
2002-09-11 08:13:56 +00:00
|
|
|
TD_SET_ON_SLEEPQ(td);
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_wchan = cvp;
|
|
|
|
td->td_wmesg = cvp->cv_description;
|
|
|
|
CTR3(KTR_PROC, "cv_waitq_add: thread %p (pid %d, %s)", td,
|
2001-09-18 23:27:06 +00:00
|
|
|
td->td_proc->p_pid, td->td_proc->p_comm);
|
2001-09-12 08:38:13 +00:00
|
|
|
TAILQ_INSERT_TAIL(&cvp->cv_waitq, td, td_slpq);
|
2003-01-26 04:00:39 +00:00
|
|
|
sched_sleep(td, td->td_priority);
|
2001-01-16 01:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-09-12 08:38:13 +00:00
|
|
|
* Wait on a condition variable. The current thread is placed on the condition
|
2001-01-16 01:00:43 +00:00
|
|
|
* variable's wait queue and suspended. A cv_signal or cv_broadcast on the same
|
2001-09-12 08:38:13 +00:00
|
|
|
* condition variable will resume the thread. The mutex is released before
|
2001-01-16 01:00:43 +00:00
|
|
|
* sleeping and will be held on return. It is recommended that the mutex be
|
|
|
|
* held when cv_signal or cv_broadcast are called.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cv_wait(struct cv *cvp, struct mtx *mp)
|
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
2001-01-16 01:00:43 +00:00
|
|
|
WITNESS_SAVE_DECL(mp);
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
td = curthread;
|
2001-01-16 01:00:43 +00:00
|
|
|
#ifdef KTRACE
|
2002-06-07 05:39:16 +00:00
|
|
|
if (KTRPOINT(td, KTR_CSW))
|
|
|
|
ktrcsw(1, 0);
|
2001-01-16 01:00:43 +00:00
|
|
|
#endif
|
2001-09-12 08:38:13 +00:00
|
|
|
CV_ASSERT(cvp, mp, td);
|
2003-03-04 21:03:05 +00:00
|
|
|
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, &mp->mtx_object,
|
|
|
|
"Waiting on \"%s\"", cvp->cv_description);
|
Rework the witness code to work with sx locks as well as mutexes.
- Introduce lock classes and lock objects. Each lock class specifies a
name and set of flags (or properties) shared by all locks of a given
type. Currently there are three lock classes: spin mutexes, sleep
mutexes, and sx locks. A lock object specifies properties of an
additional lock along with a lock name and all of the extra stuff needed
to make witness work with a given lock. This abstract lock stuff is
defined in sys/lock.h. The lockmgr constants, types, and prototypes have
been moved to sys/lockmgr.h. For temporary backwards compatability,
sys/lock.h includes sys/lockmgr.h.
- Replace proc->p_spinlocks with a per-CPU list, PCPU(spinlocks), of spin
locks held. By making this per-cpu, we do not have to jump through
magic hoops to deal with sched_lock changing ownership during context
switches.
- Replace proc->p_heldmtx, formerly a list of held sleep mutexes, with
proc->p_sleeplocks, which is a list of held sleep locks including sleep
mutexes and sx locks.
- Add helper macros for logging lock events via the KTR_LOCK KTR logging
level so that the log messages are consistent.
- Add some new flags that can be passed to mtx_init():
- MTX_NOWITNESS - specifies that this lock should be ignored by witness.
This is used for the mutex that blocks a sx lock for example.
- MTX_QUIET - this is not new, but you can pass this to mtx_init() now
and no events will be logged for this lock, so that one doesn't have
to change all the individual mtx_lock/unlock() operations.
- All lock objects maintain an initialized flag. Use this flag to export
a mtx_initialized() macro that can be safely called from drivers. Also,
we on longer walk the all_mtx list if MUTEX_DEBUG is defined as witness
performs the corresponding checks using the initialized flag.
- The lock order reversal messages have been improved to output slightly
more accurate file and line numbers.
2001-03-28 09:03:24 +00:00
|
|
|
WITNESS_SAVE(&mp->mtx_object, mp);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
2002-07-17 02:23:44 +00:00
|
|
|
if (cold ) {
|
2001-01-16 01:00:43 +00:00
|
|
|
/*
|
2002-07-17 02:23:44 +00:00
|
|
|
* During autoconfiguration, just give interrupts
|
|
|
|
* a chance, then just return. Don't run any other
|
|
|
|
* thread or panic below, in case this is the idle
|
|
|
|
* process and already asleep.
|
2001-01-16 01:00:43 +00:00
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
2002-04-23 19:50:22 +00:00
|
|
|
|
|
|
|
mtx_lock_spin(&sched_lock);
|
|
|
|
|
2001-01-16 01:00:43 +00:00
|
|
|
CV_WAIT_VALIDATE(cvp, mp);
|
|
|
|
|
Change the preemption code for software interrupt thread schedules and
mutex releases to not require flags for the cases when preemption is
not allowed:
The purpose of the MTX_NOSWITCH and SWI_NOSWITCH flags is to prevent
switching to a higher priority thread on mutex releease and swi schedule,
respectively when that switch is not safe. Now that the critical section
API maintains a per-thread nesting count, the kernel can easily check
whether or not it should switch without relying on flags from the
programmer. This fixes a few bugs in that all current callers of
swi_sched() used SWI_NOSWITCH, when in fact, only the ones called from
fast interrupt handlers and the swi_sched of softclock needed this flag.
Note that to ensure that swi_sched()'s in clock and fast interrupt
handlers do not switch, these handlers have to be explicitly wrapped
in critical_enter/exit pairs. Presently, just wrapping the handlers is
sufficient, but in the future with the fully preemptive kernel, the
interrupt must be EOI'd before critical_exit() is called. (critical_exit()
can switch due to a deferred preemption in a fully preemptive kernel.)
I've tested the changes to the interrupt code on i386 and alpha. I have
not tested ia64, but the interrupt code is almost identical to the alpha
code, so I expect it will work fine. PowerPC and ARM do not yet have
interrupt code in the tree so they shouldn't be broken. Sparc64 is
broken, but that's been ok'd by jake and tmm who will be fixing the
interrupt code for sparc64 shortly.
Reviewed by: peter
Tested on: i386, alpha
2002-01-05 08:47:13 +00:00
|
|
|
DROP_GIANT();
|
|
|
|
mtx_unlock(mp);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
cv_waitq_add(cvp, td);
|
|
|
|
cv_switch(td);
|
2001-01-16 01:00:43 +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_unlock_spin(&sched_lock);
|
2001-01-16 01:00:43 +00:00
|
|
|
#ifdef KTRACE
|
2002-06-07 05:39:16 +00:00
|
|
|
if (KTRPOINT(td, KTR_CSW))
|
|
|
|
ktrcsw(0, 0);
|
2001-01-16 01:00:43 +00:00
|
|
|
#endif
|
|
|
|
PICKUP_GIANT();
|
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(mp);
|
Rework the witness code to work with sx locks as well as mutexes.
- Introduce lock classes and lock objects. Each lock class specifies a
name and set of flags (or properties) shared by all locks of a given
type. Currently there are three lock classes: spin mutexes, sleep
mutexes, and sx locks. A lock object specifies properties of an
additional lock along with a lock name and all of the extra stuff needed
to make witness work with a given lock. This abstract lock stuff is
defined in sys/lock.h. The lockmgr constants, types, and prototypes have
been moved to sys/lockmgr.h. For temporary backwards compatability,
sys/lock.h includes sys/lockmgr.h.
- Replace proc->p_spinlocks with a per-CPU list, PCPU(spinlocks), of spin
locks held. By making this per-cpu, we do not have to jump through
magic hoops to deal with sched_lock changing ownership during context
switches.
- Replace proc->p_heldmtx, formerly a list of held sleep mutexes, with
proc->p_sleeplocks, which is a list of held sleep locks including sleep
mutexes and sx locks.
- Add helper macros for logging lock events via the KTR_LOCK KTR logging
level so that the log messages are consistent.
- Add some new flags that can be passed to mtx_init():
- MTX_NOWITNESS - specifies that this lock should be ignored by witness.
This is used for the mutex that blocks a sx lock for example.
- MTX_QUIET - this is not new, but you can pass this to mtx_init() now
and no events will be logged for this lock, so that one doesn't have
to change all the individual mtx_lock/unlock() operations.
- All lock objects maintain an initialized flag. Use this flag to export
a mtx_initialized() macro that can be safely called from drivers. Also,
we on longer walk the all_mtx list if MUTEX_DEBUG is defined as witness
performs the corresponding checks using the initialized flag.
- The lock order reversal messages have been improved to output slightly
more accurate file and line numbers.
2001-03-28 09:03:24 +00:00
|
|
|
WITNESS_RESTORE(&mp->mtx_object, mp);
|
2001-01-16 01:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait on a condition variable, allowing interruption by signals. Return 0 if
|
2001-09-12 08:38:13 +00:00
|
|
|
* the thread was resumed with cv_signal or cv_broadcast, EINTR or ERESTART if
|
2001-01-16 01:00:43 +00:00
|
|
|
* a signal was caught. If ERESTART is returned the system call should be
|
|
|
|
* restarted if possible.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
cv_wait_sig(struct cv *cvp, struct mtx *mp)
|
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
2001-09-19 02:53:59 +00:00
|
|
|
struct proc *p;
|
2001-01-16 01:00:43 +00:00
|
|
|
int rval;
|
|
|
|
int sig;
|
|
|
|
WITNESS_SAVE_DECL(mp);
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
td = curthread;
|
2001-09-18 23:27:06 +00:00
|
|
|
p = td->td_proc;
|
2001-01-16 01:00:43 +00:00
|
|
|
rval = 0;
|
|
|
|
#ifdef KTRACE
|
2002-06-07 05:39:16 +00:00
|
|
|
if (KTRPOINT(td, KTR_CSW))
|
|
|
|
ktrcsw(1, 0);
|
2001-01-16 01:00:43 +00:00
|
|
|
#endif
|
2001-09-12 08:38:13 +00:00
|
|
|
CV_ASSERT(cvp, mp, td);
|
2003-03-04 21:03:05 +00:00
|
|
|
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, &mp->mtx_object,
|
|
|
|
"Waiting on \"%s\"", cvp->cv_description);
|
Rework the witness code to work with sx locks as well as mutexes.
- Introduce lock classes and lock objects. Each lock class specifies a
name and set of flags (or properties) shared by all locks of a given
type. Currently there are three lock classes: spin mutexes, sleep
mutexes, and sx locks. A lock object specifies properties of an
additional lock along with a lock name and all of the extra stuff needed
to make witness work with a given lock. This abstract lock stuff is
defined in sys/lock.h. The lockmgr constants, types, and prototypes have
been moved to sys/lockmgr.h. For temporary backwards compatability,
sys/lock.h includes sys/lockmgr.h.
- Replace proc->p_spinlocks with a per-CPU list, PCPU(spinlocks), of spin
locks held. By making this per-cpu, we do not have to jump through
magic hoops to deal with sched_lock changing ownership during context
switches.
- Replace proc->p_heldmtx, formerly a list of held sleep mutexes, with
proc->p_sleeplocks, which is a list of held sleep locks including sleep
mutexes and sx locks.
- Add helper macros for logging lock events via the KTR_LOCK KTR logging
level so that the log messages are consistent.
- Add some new flags that can be passed to mtx_init():
- MTX_NOWITNESS - specifies that this lock should be ignored by witness.
This is used for the mutex that blocks a sx lock for example.
- MTX_QUIET - this is not new, but you can pass this to mtx_init() now
and no events will be logged for this lock, so that one doesn't have
to change all the individual mtx_lock/unlock() operations.
- All lock objects maintain an initialized flag. Use this flag to export
a mtx_initialized() macro that can be safely called from drivers. Also,
we on longer walk the all_mtx list if MUTEX_DEBUG is defined as witness
performs the corresponding checks using the initialized flag.
- The lock order reversal messages have been improved to output slightly
more accurate file and line numbers.
2001-03-28 09:03:24 +00:00
|
|
|
WITNESS_SAVE(&mp->mtx_object, mp);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
|
|
|
if (cold || panicstr) {
|
|
|
|
/*
|
|
|
|
* After a panic, or during autoconfiguration, just give
|
|
|
|
* interrupts a chance, then just return; don't run any other
|
|
|
|
* procs or panic below, in case this is the idle process and
|
|
|
|
* already asleep.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
2002-04-23 19:50:22 +00:00
|
|
|
|
|
|
|
mtx_lock_spin(&sched_lock);
|
|
|
|
|
2001-01-16 01:00:43 +00:00
|
|
|
CV_WAIT_VALIDATE(cvp, mp);
|
|
|
|
|
Change the preemption code for software interrupt thread schedules and
mutex releases to not require flags for the cases when preemption is
not allowed:
The purpose of the MTX_NOSWITCH and SWI_NOSWITCH flags is to prevent
switching to a higher priority thread on mutex releease and swi schedule,
respectively when that switch is not safe. Now that the critical section
API maintains a per-thread nesting count, the kernel can easily check
whether or not it should switch without relying on flags from the
programmer. This fixes a few bugs in that all current callers of
swi_sched() used SWI_NOSWITCH, when in fact, only the ones called from
fast interrupt handlers and the swi_sched of softclock needed this flag.
Note that to ensure that swi_sched()'s in clock and fast interrupt
handlers do not switch, these handlers have to be explicitly wrapped
in critical_enter/exit pairs. Presently, just wrapping the handlers is
sufficient, but in the future with the fully preemptive kernel, the
interrupt must be EOI'd before critical_exit() is called. (critical_exit()
can switch due to a deferred preemption in a fully preemptive kernel.)
I've tested the changes to the interrupt code on i386 and alpha. I have
not tested ia64, but the interrupt code is almost identical to the alpha
code, so I expect it will work fine. PowerPC and ARM do not yet have
interrupt code in the tree so they shouldn't be broken. Sparc64 is
broken, but that's been ok'd by jake and tmm who will be fixing the
interrupt code for sparc64 shortly.
Reviewed by: peter
Tested on: i386, alpha
2002-01-05 08:47:13 +00:00
|
|
|
DROP_GIANT();
|
|
|
|
mtx_unlock(mp);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
cv_waitq_add(cvp, td);
|
|
|
|
sig = cv_switch_catch(td);
|
2001-01-16 01:00:43 +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_unlock_spin(&sched_lock);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
2001-09-18 23:27:06 +00:00
|
|
|
PROC_LOCK(p);
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 20:36:02 +00:00
|
|
|
mtx_lock(&p->p_sigacts->ps_mtx);
|
2001-01-16 01:00:43 +00:00
|
|
|
if (sig == 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
|
|
|
sig = cursig(td); /* XXXKSE */
|
2001-01-16 01:00:43 +00:00
|
|
|
if (sig != 0) {
|
2001-09-18 23:27:06 +00:00
|
|
|
if (SIGISMEMBER(p->p_sigacts->ps_sigintr, sig))
|
2001-01-16 01:00:43 +00:00
|
|
|
rval = EINTR;
|
|
|
|
else
|
|
|
|
rval = ERESTART;
|
|
|
|
}
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 20:36:02 +00:00
|
|
|
mtx_unlock(&p->p_sigacts->ps_mtx);
|
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
|
|
|
if (p->p_flag & P_WEXIT)
|
|
|
|
rval = EINTR;
|
2003-04-17 22:21:05 +00:00
|
|
|
PROC_UNLOCK(p);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
|
|
|
#ifdef KTRACE
|
2002-06-07 05:39:16 +00:00
|
|
|
if (KTRPOINT(td, KTR_CSW))
|
|
|
|
ktrcsw(0, 0);
|
2001-01-16 01:00:43 +00:00
|
|
|
#endif
|
2002-06-07 05:39:16 +00:00
|
|
|
PICKUP_GIANT();
|
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(mp);
|
Rework the witness code to work with sx locks as well as mutexes.
- Introduce lock classes and lock objects. Each lock class specifies a
name and set of flags (or properties) shared by all locks of a given
type. Currently there are three lock classes: spin mutexes, sleep
mutexes, and sx locks. A lock object specifies properties of an
additional lock along with a lock name and all of the extra stuff needed
to make witness work with a given lock. This abstract lock stuff is
defined in sys/lock.h. The lockmgr constants, types, and prototypes have
been moved to sys/lockmgr.h. For temporary backwards compatability,
sys/lock.h includes sys/lockmgr.h.
- Replace proc->p_spinlocks with a per-CPU list, PCPU(spinlocks), of spin
locks held. By making this per-cpu, we do not have to jump through
magic hoops to deal with sched_lock changing ownership during context
switches.
- Replace proc->p_heldmtx, formerly a list of held sleep mutexes, with
proc->p_sleeplocks, which is a list of held sleep locks including sleep
mutexes and sx locks.
- Add helper macros for logging lock events via the KTR_LOCK KTR logging
level so that the log messages are consistent.
- Add some new flags that can be passed to mtx_init():
- MTX_NOWITNESS - specifies that this lock should be ignored by witness.
This is used for the mutex that blocks a sx lock for example.
- MTX_QUIET - this is not new, but you can pass this to mtx_init() now
and no events will be logged for this lock, so that one doesn't have
to change all the individual mtx_lock/unlock() operations.
- All lock objects maintain an initialized flag. Use this flag to export
a mtx_initialized() macro that can be safely called from drivers. Also,
we on longer walk the all_mtx list if MUTEX_DEBUG is defined as witness
performs the corresponding checks using the initialized flag.
- The lock order reversal messages have been improved to output slightly
more accurate file and line numbers.
2001-03-28 09:03:24 +00:00
|
|
|
WITNESS_RESTORE(&mp->mtx_object, mp);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
|
|
|
return (rval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait on a condition variable for at most timo/hz seconds. Returns 0 if the
|
|
|
|
* process was resumed by cv_signal or cv_broadcast, EWOULDBLOCK if the timeout
|
|
|
|
* expires.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
cv_timedwait(struct cv *cvp, struct mtx *mp, int timo)
|
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
2001-01-16 01:00:43 +00:00
|
|
|
int rval;
|
|
|
|
WITNESS_SAVE_DECL(mp);
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
td = curthread;
|
2001-01-16 01:00:43 +00:00
|
|
|
rval = 0;
|
|
|
|
#ifdef KTRACE
|
2002-06-07 05:39:16 +00:00
|
|
|
if (KTRPOINT(td, KTR_CSW))
|
|
|
|
ktrcsw(1, 0);
|
2001-01-16 01:00:43 +00:00
|
|
|
#endif
|
2001-09-12 08:38:13 +00:00
|
|
|
CV_ASSERT(cvp, mp, td);
|
2003-03-04 21:03:05 +00:00
|
|
|
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, &mp->mtx_object,
|
|
|
|
"Waiting on \"%s\"", cvp->cv_description);
|
Rework the witness code to work with sx locks as well as mutexes.
- Introduce lock classes and lock objects. Each lock class specifies a
name and set of flags (or properties) shared by all locks of a given
type. Currently there are three lock classes: spin mutexes, sleep
mutexes, and sx locks. A lock object specifies properties of an
additional lock along with a lock name and all of the extra stuff needed
to make witness work with a given lock. This abstract lock stuff is
defined in sys/lock.h. The lockmgr constants, types, and prototypes have
been moved to sys/lockmgr.h. For temporary backwards compatability,
sys/lock.h includes sys/lockmgr.h.
- Replace proc->p_spinlocks with a per-CPU list, PCPU(spinlocks), of spin
locks held. By making this per-cpu, we do not have to jump through
magic hoops to deal with sched_lock changing ownership during context
switches.
- Replace proc->p_heldmtx, formerly a list of held sleep mutexes, with
proc->p_sleeplocks, which is a list of held sleep locks including sleep
mutexes and sx locks.
- Add helper macros for logging lock events via the KTR_LOCK KTR logging
level so that the log messages are consistent.
- Add some new flags that can be passed to mtx_init():
- MTX_NOWITNESS - specifies that this lock should be ignored by witness.
This is used for the mutex that blocks a sx lock for example.
- MTX_QUIET - this is not new, but you can pass this to mtx_init() now
and no events will be logged for this lock, so that one doesn't have
to change all the individual mtx_lock/unlock() operations.
- All lock objects maintain an initialized flag. Use this flag to export
a mtx_initialized() macro that can be safely called from drivers. Also,
we on longer walk the all_mtx list if MUTEX_DEBUG is defined as witness
performs the corresponding checks using the initialized flag.
- The lock order reversal messages have been improved to output slightly
more accurate file and line numbers.
2001-03-28 09:03:24 +00:00
|
|
|
WITNESS_SAVE(&mp->mtx_object, mp);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
|
|
|
if (cold || panicstr) {
|
|
|
|
/*
|
|
|
|
* After a panic, or during autoconfiguration, just give
|
|
|
|
* interrupts a chance, then just return; don't run any other
|
2001-09-12 08:38:13 +00:00
|
|
|
* thread or panic below, in case this is the idle process and
|
2001-01-16 01:00:43 +00:00
|
|
|
* already asleep.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
2002-04-23 19:50:22 +00:00
|
|
|
|
|
|
|
mtx_lock_spin(&sched_lock);
|
|
|
|
|
2001-01-16 01:00:43 +00:00
|
|
|
CV_WAIT_VALIDATE(cvp, mp);
|
|
|
|
|
Change the preemption code for software interrupt thread schedules and
mutex releases to not require flags for the cases when preemption is
not allowed:
The purpose of the MTX_NOSWITCH and SWI_NOSWITCH flags is to prevent
switching to a higher priority thread on mutex releease and swi schedule,
respectively when that switch is not safe. Now that the critical section
API maintains a per-thread nesting count, the kernel can easily check
whether or not it should switch without relying on flags from the
programmer. This fixes a few bugs in that all current callers of
swi_sched() used SWI_NOSWITCH, when in fact, only the ones called from
fast interrupt handlers and the swi_sched of softclock needed this flag.
Note that to ensure that swi_sched()'s in clock and fast interrupt
handlers do not switch, these handlers have to be explicitly wrapped
in critical_enter/exit pairs. Presently, just wrapping the handlers is
sufficient, but in the future with the fully preemptive kernel, the
interrupt must be EOI'd before critical_exit() is called. (critical_exit()
can switch due to a deferred preemption in a fully preemptive kernel.)
I've tested the changes to the interrupt code on i386 and alpha. I have
not tested ia64, but the interrupt code is almost identical to the alpha
code, so I expect it will work fine. PowerPC and ARM do not yet have
interrupt code in the tree so they shouldn't be broken. Sparc64 is
broken, but that's been ok'd by jake and tmm who will be fixing the
interrupt code for sparc64 shortly.
Reviewed by: peter
Tested on: i386, alpha
2002-01-05 08:47:13 +00:00
|
|
|
DROP_GIANT();
|
|
|
|
mtx_unlock(mp);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
cv_waitq_add(cvp, td);
|
|
|
|
callout_reset(&td->td_slpcallout, timo, cv_timedwait_end, td);
|
|
|
|
cv_switch(td);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
if (td->td_flags & TDF_TIMEOUT) {
|
|
|
|
td->td_flags &= ~TDF_TIMEOUT;
|
2001-01-16 01:00:43 +00:00
|
|
|
rval = EWOULDBLOCK;
|
2001-09-12 08:38:13 +00:00
|
|
|
} else if (td->td_flags & TDF_TIMOFAIL)
|
|
|
|
td->td_flags &= ~TDF_TIMOFAIL;
|
|
|
|
else if (callout_stop(&td->td_slpcallout) == 0) {
|
2001-08-21 18:42:45 +00:00
|
|
|
/*
|
|
|
|
* Work around race with cv_timedwait_end similar to that
|
|
|
|
* between msleep and endtsleep.
|
2002-07-02 05:33:46 +00:00
|
|
|
* Go back to sleep.
|
2001-08-21 18:42:45 +00:00
|
|
|
*/
|
2002-09-11 08:13:56 +00:00
|
|
|
TD_SET_SLEEPING(td);
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_proc->p_stats->p_ru.ru_nivcsw++;
|
2001-08-21 18:42:45 +00:00
|
|
|
mi_switch();
|
2002-09-11 08:13:56 +00:00
|
|
|
td->td_flags &= ~TDF_TIMOFAIL;
|
2001-08-21 18:42:45 +00:00
|
|
|
}
|
2001-01-16 01:00:43 +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_unlock_spin(&sched_lock);
|
2001-01-16 01:00:43 +00:00
|
|
|
#ifdef KTRACE
|
2002-06-07 05:39:16 +00:00
|
|
|
if (KTRPOINT(td, KTR_CSW))
|
|
|
|
ktrcsw(0, 0);
|
2001-01-16 01:00:43 +00:00
|
|
|
#endif
|
|
|
|
PICKUP_GIANT();
|
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(mp);
|
Rework the witness code to work with sx locks as well as mutexes.
- Introduce lock classes and lock objects. Each lock class specifies a
name and set of flags (or properties) shared by all locks of a given
type. Currently there are three lock classes: spin mutexes, sleep
mutexes, and sx locks. A lock object specifies properties of an
additional lock along with a lock name and all of the extra stuff needed
to make witness work with a given lock. This abstract lock stuff is
defined in sys/lock.h. The lockmgr constants, types, and prototypes have
been moved to sys/lockmgr.h. For temporary backwards compatability,
sys/lock.h includes sys/lockmgr.h.
- Replace proc->p_spinlocks with a per-CPU list, PCPU(spinlocks), of spin
locks held. By making this per-cpu, we do not have to jump through
magic hoops to deal with sched_lock changing ownership during context
switches.
- Replace proc->p_heldmtx, formerly a list of held sleep mutexes, with
proc->p_sleeplocks, which is a list of held sleep locks including sleep
mutexes and sx locks.
- Add helper macros for logging lock events via the KTR_LOCK KTR logging
level so that the log messages are consistent.
- Add some new flags that can be passed to mtx_init():
- MTX_NOWITNESS - specifies that this lock should be ignored by witness.
This is used for the mutex that blocks a sx lock for example.
- MTX_QUIET - this is not new, but you can pass this to mtx_init() now
and no events will be logged for this lock, so that one doesn't have
to change all the individual mtx_lock/unlock() operations.
- All lock objects maintain an initialized flag. Use this flag to export
a mtx_initialized() macro that can be safely called from drivers. Also,
we on longer walk the all_mtx list if MUTEX_DEBUG is defined as witness
performs the corresponding checks using the initialized flag.
- The lock order reversal messages have been improved to output slightly
more accurate file and line numbers.
2001-03-28 09:03:24 +00:00
|
|
|
WITNESS_RESTORE(&mp->mtx_object, mp);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
|
|
|
return (rval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait on a condition variable for at most timo/hz seconds, allowing
|
2001-09-12 08:38:13 +00:00
|
|
|
* interruption by signals. Returns 0 if the thread was resumed by cv_signal
|
2001-01-16 01:00:43 +00:00
|
|
|
* or cv_broadcast, EWOULDBLOCK if the timeout expires, and EINTR or ERESTART if
|
|
|
|
* a signal was caught.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
cv_timedwait_sig(struct cv *cvp, struct mtx *mp, int timo)
|
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
2001-09-18 23:27:06 +00:00
|
|
|
struct proc *p;
|
2001-01-16 01:00:43 +00:00
|
|
|
int rval;
|
|
|
|
int sig;
|
|
|
|
WITNESS_SAVE_DECL(mp);
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
td = curthread;
|
2001-09-18 23:27:06 +00:00
|
|
|
p = td->td_proc;
|
2001-01-16 01:00:43 +00:00
|
|
|
rval = 0;
|
|
|
|
#ifdef KTRACE
|
2002-06-07 05:39:16 +00:00
|
|
|
if (KTRPOINT(td, KTR_CSW))
|
|
|
|
ktrcsw(1, 0);
|
2001-01-16 01:00:43 +00:00
|
|
|
#endif
|
2001-09-12 08:38:13 +00:00
|
|
|
CV_ASSERT(cvp, mp, td);
|
2003-03-04 21:03:05 +00:00
|
|
|
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, &mp->mtx_object,
|
|
|
|
"Waiting on \"%s\"", cvp->cv_description);
|
Rework the witness code to work with sx locks as well as mutexes.
- Introduce lock classes and lock objects. Each lock class specifies a
name and set of flags (or properties) shared by all locks of a given
type. Currently there are three lock classes: spin mutexes, sleep
mutexes, and sx locks. A lock object specifies properties of an
additional lock along with a lock name and all of the extra stuff needed
to make witness work with a given lock. This abstract lock stuff is
defined in sys/lock.h. The lockmgr constants, types, and prototypes have
been moved to sys/lockmgr.h. For temporary backwards compatability,
sys/lock.h includes sys/lockmgr.h.
- Replace proc->p_spinlocks with a per-CPU list, PCPU(spinlocks), of spin
locks held. By making this per-cpu, we do not have to jump through
magic hoops to deal with sched_lock changing ownership during context
switches.
- Replace proc->p_heldmtx, formerly a list of held sleep mutexes, with
proc->p_sleeplocks, which is a list of held sleep locks including sleep
mutexes and sx locks.
- Add helper macros for logging lock events via the KTR_LOCK KTR logging
level so that the log messages are consistent.
- Add some new flags that can be passed to mtx_init():
- MTX_NOWITNESS - specifies that this lock should be ignored by witness.
This is used for the mutex that blocks a sx lock for example.
- MTX_QUIET - this is not new, but you can pass this to mtx_init() now
and no events will be logged for this lock, so that one doesn't have
to change all the individual mtx_lock/unlock() operations.
- All lock objects maintain an initialized flag. Use this flag to export
a mtx_initialized() macro that can be safely called from drivers. Also,
we on longer walk the all_mtx list if MUTEX_DEBUG is defined as witness
performs the corresponding checks using the initialized flag.
- The lock order reversal messages have been improved to output slightly
more accurate file and line numbers.
2001-03-28 09:03:24 +00:00
|
|
|
WITNESS_SAVE(&mp->mtx_object, mp);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
|
|
|
if (cold || panicstr) {
|
|
|
|
/*
|
|
|
|
* After a panic, or during autoconfiguration, just give
|
|
|
|
* interrupts a chance, then just return; don't run any other
|
2001-09-12 08:38:13 +00:00
|
|
|
* thread or panic below, in case this is the idle process and
|
2001-01-16 01:00:43 +00:00
|
|
|
* already asleep.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
2002-04-23 19:50:22 +00:00
|
|
|
|
|
|
|
mtx_lock_spin(&sched_lock);
|
|
|
|
|
2001-01-16 01:00:43 +00:00
|
|
|
CV_WAIT_VALIDATE(cvp, mp);
|
|
|
|
|
Change the preemption code for software interrupt thread schedules and
mutex releases to not require flags for the cases when preemption is
not allowed:
The purpose of the MTX_NOSWITCH and SWI_NOSWITCH flags is to prevent
switching to a higher priority thread on mutex releease and swi schedule,
respectively when that switch is not safe. Now that the critical section
API maintains a per-thread nesting count, the kernel can easily check
whether or not it should switch without relying on flags from the
programmer. This fixes a few bugs in that all current callers of
swi_sched() used SWI_NOSWITCH, when in fact, only the ones called from
fast interrupt handlers and the swi_sched of softclock needed this flag.
Note that to ensure that swi_sched()'s in clock and fast interrupt
handlers do not switch, these handlers have to be explicitly wrapped
in critical_enter/exit pairs. Presently, just wrapping the handlers is
sufficient, but in the future with the fully preemptive kernel, the
interrupt must be EOI'd before critical_exit() is called. (critical_exit()
can switch due to a deferred preemption in a fully preemptive kernel.)
I've tested the changes to the interrupt code on i386 and alpha. I have
not tested ia64, but the interrupt code is almost identical to the alpha
code, so I expect it will work fine. PowerPC and ARM do not yet have
interrupt code in the tree so they shouldn't be broken. Sparc64 is
broken, but that's been ok'd by jake and tmm who will be fixing the
interrupt code for sparc64 shortly.
Reviewed by: peter
Tested on: i386, alpha
2002-01-05 08:47:13 +00:00
|
|
|
DROP_GIANT();
|
|
|
|
mtx_unlock(mp);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
cv_waitq_add(cvp, td);
|
|
|
|
callout_reset(&td->td_slpcallout, timo, cv_timedwait_end, td);
|
|
|
|
sig = cv_switch_catch(td);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
if (td->td_flags & TDF_TIMEOUT) {
|
|
|
|
td->td_flags &= ~TDF_TIMEOUT;
|
2001-01-16 01:00:43 +00:00
|
|
|
rval = EWOULDBLOCK;
|
2001-09-12 08:38:13 +00:00
|
|
|
} else if (td->td_flags & TDF_TIMOFAIL)
|
|
|
|
td->td_flags &= ~TDF_TIMOFAIL;
|
|
|
|
else if (callout_stop(&td->td_slpcallout) == 0) {
|
2001-08-21 18:42:45 +00:00
|
|
|
/*
|
|
|
|
* Work around race with cv_timedwait_end similar to that
|
|
|
|
* between msleep and endtsleep.
|
2002-07-02 05:33:46 +00:00
|
|
|
* Go back to sleep.
|
2001-08-21 18:42:45 +00:00
|
|
|
*/
|
2002-09-11 08:13:56 +00:00
|
|
|
TD_SET_SLEEPING(td);
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_proc->p_stats->p_ru.ru_nivcsw++;
|
2001-08-21 18:42:45 +00:00
|
|
|
mi_switch();
|
2002-09-11 08:13:56 +00:00
|
|
|
td->td_flags &= ~TDF_TIMOFAIL;
|
2001-08-21 18:42:45 +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_unlock_spin(&sched_lock);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
2001-09-18 23:27:06 +00:00
|
|
|
PROC_LOCK(p);
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 20:36:02 +00:00
|
|
|
mtx_lock(&p->p_sigacts->ps_mtx);
|
2001-01-16 01:00:43 +00:00
|
|
|
if (sig == 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
|
|
|
sig = cursig(td);
|
2001-01-16 01:00:43 +00:00
|
|
|
if (sig != 0) {
|
2001-09-18 23:27:06 +00:00
|
|
|
if (SIGISMEMBER(p->p_sigacts->ps_sigintr, sig))
|
2001-01-16 01:00:43 +00:00
|
|
|
rval = EINTR;
|
|
|
|
else
|
|
|
|
rval = ERESTART;
|
|
|
|
}
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 20:36:02 +00:00
|
|
|
mtx_unlock(&p->p_sigacts->ps_mtx);
|
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
|
|
|
if (p->p_flag & P_WEXIT)
|
|
|
|
rval = EINTR;
|
2003-04-17 22:21:05 +00:00
|
|
|
PROC_UNLOCK(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
|
|
|
|
2001-01-16 01:00:43 +00:00
|
|
|
#ifdef KTRACE
|
2002-06-07 05:39:16 +00:00
|
|
|
if (KTRPOINT(td, KTR_CSW))
|
|
|
|
ktrcsw(0, 0);
|
2001-01-16 01:00:43 +00:00
|
|
|
#endif
|
2002-06-07 05:39:16 +00:00
|
|
|
PICKUP_GIANT();
|
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(mp);
|
Rework the witness code to work with sx locks as well as mutexes.
- Introduce lock classes and lock objects. Each lock class specifies a
name and set of flags (or properties) shared by all locks of a given
type. Currently there are three lock classes: spin mutexes, sleep
mutexes, and sx locks. A lock object specifies properties of an
additional lock along with a lock name and all of the extra stuff needed
to make witness work with a given lock. This abstract lock stuff is
defined in sys/lock.h. The lockmgr constants, types, and prototypes have
been moved to sys/lockmgr.h. For temporary backwards compatability,
sys/lock.h includes sys/lockmgr.h.
- Replace proc->p_spinlocks with a per-CPU list, PCPU(spinlocks), of spin
locks held. By making this per-cpu, we do not have to jump through
magic hoops to deal with sched_lock changing ownership during context
switches.
- Replace proc->p_heldmtx, formerly a list of held sleep mutexes, with
proc->p_sleeplocks, which is a list of held sleep locks including sleep
mutexes and sx locks.
- Add helper macros for logging lock events via the KTR_LOCK KTR logging
level so that the log messages are consistent.
- Add some new flags that can be passed to mtx_init():
- MTX_NOWITNESS - specifies that this lock should be ignored by witness.
This is used for the mutex that blocks a sx lock for example.
- MTX_QUIET - this is not new, but you can pass this to mtx_init() now
and no events will be logged for this lock, so that one doesn't have
to change all the individual mtx_lock/unlock() operations.
- All lock objects maintain an initialized flag. Use this flag to export
a mtx_initialized() macro that can be safely called from drivers. Also,
we on longer walk the all_mtx list if MUTEX_DEBUG is defined as witness
performs the corresponding checks using the initialized flag.
- The lock order reversal messages have been improved to output slightly
more accurate file and line numbers.
2001-03-28 09:03:24 +00:00
|
|
|
WITNESS_RESTORE(&mp->mtx_object, mp);
|
2001-01-16 01:00:43 +00:00
|
|
|
|
|
|
|
return (rval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common code for signal and broadcast. Assumes waitq is not empty. Must be
|
|
|
|
* called with sched_lock held.
|
|
|
|
*/
|
|
|
|
static __inline void
|
|
|
|
cv_wakeup(struct cv *cvp)
|
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
2001-01-16 01:00:43 +00:00
|
|
|
|
2001-01-24 10:44:01 +00:00
|
|
|
mtx_assert(&sched_lock, MA_OWNED);
|
2001-09-12 08:38:13 +00:00
|
|
|
td = TAILQ_FIRST(&cvp->cv_waitq);
|
2001-12-10 05:51:45 +00:00
|
|
|
KASSERT(td->td_wchan == cvp, ("%s: bogus wchan", __func__));
|
|
|
|
KASSERT(td->td_flags & TDF_CVWAITQ, ("%s: not on waitq", __func__));
|
2002-09-11 08:13:56 +00:00
|
|
|
cv_waitq_remove(td);
|
|
|
|
TD_CLR_SLEEPING(td);
|
|
|
|
setrunnable(td);
|
2001-01-16 01:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-09-12 08:38:13 +00:00
|
|
|
* Signal a condition variable, wakes up one waiting thread. Will also wakeup
|
2001-01-16 01:00:43 +00:00
|
|
|
* the swapper if the process is not in memory, so that it can bring the
|
2001-09-12 08:38:13 +00:00
|
|
|
* sleeping process in. Note that this may also result in additional threads
|
2001-01-16 01:00:43 +00:00
|
|
|
* being made runnable. Should be called with the same mutex as was passed to
|
|
|
|
* cv_wait held.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cv_signal(struct cv *cvp)
|
|
|
|
{
|
|
|
|
|
2001-12-10 05:51:45 +00:00
|
|
|
KASSERT(cvp != NULL, ("%s: cvp NULL", __func__));
|
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);
|
2001-01-16 01:00:43 +00:00
|
|
|
if (!TAILQ_EMPTY(&cvp->cv_waitq)) {
|
|
|
|
CV_SIGNAL_VALIDATE(cvp);
|
|
|
|
cv_wakeup(cvp);
|
|
|
|
}
|
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);
|
2001-01-16 01:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-09-12 08:38:13 +00:00
|
|
|
* Broadcast a signal to a condition variable. Wakes up all waiting threads.
|
2001-01-16 01:00:43 +00:00
|
|
|
* Should be called with the same mutex as was passed to cv_wait held.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cv_broadcast(struct cv *cvp)
|
|
|
|
{
|
|
|
|
|
2001-12-10 05:51:45 +00:00
|
|
|
KASSERT(cvp != NULL, ("%s: cvp NULL", __func__));
|
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);
|
2001-01-16 01:00:43 +00:00
|
|
|
CV_SIGNAL_VALIDATE(cvp);
|
|
|
|
while (!TAILQ_EMPTY(&cvp->cv_waitq))
|
|
|
|
cv_wakeup(cvp);
|
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);
|
2001-01-16 01:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-09-12 08:38:13 +00:00
|
|
|
* Remove a thread from the wait queue of its condition variable. This may be
|
2001-01-16 01:00:43 +00:00
|
|
|
* called externally.
|
|
|
|
*/
|
|
|
|
void
|
2001-09-12 08:38:13 +00:00
|
|
|
cv_waitq_remove(struct thread *td)
|
2001-01-16 01:00:43 +00:00
|
|
|
{
|
|
|
|
struct cv *cvp;
|
|
|
|
|
2002-09-11 08:13:56 +00:00
|
|
|
mtx_assert(&sched_lock, MA_OWNED);
|
2001-09-12 08:38:13 +00:00
|
|
|
if ((cvp = td->td_wchan) != NULL && td->td_flags & TDF_CVWAITQ) {
|
|
|
|
TAILQ_REMOVE(&cvp->cv_waitq, td, td_slpq);
|
|
|
|
td->td_flags &= ~TDF_CVWAITQ;
|
2003-02-27 08:43:27 +00:00
|
|
|
td->td_wmesg = NULL;
|
2002-09-11 08:13:56 +00:00
|
|
|
TD_CLR_ON_SLEEPQ(td);
|
2001-01-16 01:00:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-09-12 08:38:13 +00:00
|
|
|
* Timeout function for cv_timedwait. Put the thread on the runqueue and set
|
2001-01-16 01:00:43 +00:00
|
|
|
* its timeout flag.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cv_timedwait_end(void *arg)
|
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
2001-01-16 01:00:43 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
td = arg;
|
2002-09-11 08:13:56 +00:00
|
|
|
CTR3(KTR_PROC, "cv_timedwait_end: thread %p (pid %d, %s)",
|
|
|
|
td, td->td_proc->p_pid, td->td_proc->p_comm);
|
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
|
|
|
if (TD_ON_SLEEPQ(td)) {
|
|
|
|
cv_waitq_remove(td);
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_flags |= TDF_TIMEOUT;
|
2002-09-11 08:13:56 +00:00
|
|
|
} else {
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_flags |= TDF_TIMOFAIL;
|
2002-09-11 08:13:56 +00:00
|
|
|
}
|
|
|
|
TD_CLR_SLEEPING(td);
|
|
|
|
setrunnable(td);
|
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);
|
2001-01-16 01:00:43 +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
|
|
|
|
|
|
|
/*
|
|
|
|
* For now only abort interruptable waits.
|
|
|
|
* The others will have to either complete on their own or have a timeout.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cv_abort(struct thread *td)
|
|
|
|
{
|
|
|
|
|
|
|
|
CTR3(KTR_PROC, "cv_abort: thread %p (pid %d, %s)", td,
|
2002-09-11 08:13:56 +00:00
|
|
|
td->td_proc->p_pid, td->td_proc->p_comm);
|
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
|
|
|
mtx_lock_spin(&sched_lock);
|
|
|
|
if ((td->td_flags & (TDF_SINTR|TDF_TIMEOUT)) == TDF_SINTR) {
|
2002-09-11 08:13:56 +00:00
|
|
|
if (TD_ON_SLEEPQ(td)) {
|
|
|
|
cv_waitq_remove(td);
|
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
|
|
|
}
|
2002-09-11 08:13:56 +00:00
|
|
|
TD_CLR_SLEEPING(td);
|
|
|
|
setrunnable(td);
|
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
|
|
|
}
|
|
|
|
mtx_unlock_spin(&sched_lock);
|
|
|
|
}
|
|
|
|
|