summaryrefslogtreecommitdiffstats
path: root/sys/amd64/isa
diff options
context:
space:
mode:
authorbmilekic <bmilekic@FreeBSD.org>2001-02-09 06:11:45 +0000
committerbmilekic <bmilekic@FreeBSD.org>2001-02-09 06:11:45 +0000
commitf364d4ac3621ae2689a3cc1b82c73eb491475a24 (patch)
tree84444d0341ce519800ed7913d826f5f38c622d6d /sys/amd64/isa
parent363bdddf694863339f6629340cfb324771b8ffe7 (diff)
downloadFreeBSD-src-f364d4ac3621ae2689a3cc1b82c73eb491475a24.zip
FreeBSD-src-f364d4ac3621ae2689a3cc1b82c73eb491475a24.tar.gz
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)
Diffstat (limited to 'sys/amd64/isa')
-rw-r--r--sys/amd64/isa/clock.c32
-rw-r--r--sys/amd64/isa/intr_machdep.c4
-rw-r--r--sys/amd64/isa/ithread.c14
-rw-r--r--sys/amd64/isa/nmi.c4
-rw-r--r--sys/amd64/isa/npx.c4
5 files changed, 29 insertions, 29 deletions
diff --git a/sys/amd64/isa/clock.c b/sys/amd64/isa/clock.c
index d7a1ff0..bbd066b 100644
--- a/sys/amd64/isa/clock.c
+++ b/sys/amd64/isa/clock.c
@@ -207,7 +207,7 @@ clkintr(struct clockframe frame)
{
if (timecounter->tc_get_timecount == i8254_get_timecount) {
- mtx_enter(&clock_lock, MTX_SPIN);
+ mtx_lock_spin(&clock_lock);
if (i8254_ticked)
i8254_ticked = 0;
else {
@@ -215,7 +215,7 @@ clkintr(struct clockframe frame)
i8254_lastcount = 0;
}
clkintr_pending = 0;
- mtx_exit(&clock_lock, MTX_SPIN);
+ mtx_unlock_spin(&clock_lock);
}
timer_func(&frame);
switch (timer0_state) {
@@ -232,14 +232,14 @@ clkintr(struct clockframe frame)
break;
case ACQUIRE_PENDING:
- mtx_enter(&clock_lock, MTX_SPIN);
+ mtx_lock_spin(&clock_lock);
i8254_offset = i8254_get_timecount(NULL);
i8254_lastcount = 0;
timer0_max_count = TIMER_DIV(new_rate);
outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
outb(TIMER_CNTR0, timer0_max_count & 0xff);
outb(TIMER_CNTR0, timer0_max_count >> 8);
- mtx_exit(&clock_lock, MTX_SPIN);
+ mtx_unlock_spin(&clock_lock);
timer_func = new_function;
timer0_state = ACQUIRED;
break;
@@ -247,7 +247,7 @@ clkintr(struct clockframe frame)
case RELEASE_PENDING:
if ((timer0_prescaler_count += timer0_max_count)
>= hardclock_max_count) {
- mtx_enter(&clock_lock, MTX_SPIN);
+ mtx_lock_spin(&clock_lock);
i8254_offset = i8254_get_timecount(NULL);
i8254_lastcount = 0;
timer0_max_count = hardclock_max_count;
@@ -255,7 +255,7 @@ clkintr(struct clockframe frame)
TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
outb(TIMER_CNTR0, timer0_max_count & 0xff);
outb(TIMER_CNTR0, timer0_max_count >> 8);
- mtx_exit(&clock_lock, MTX_SPIN);
+ mtx_unlock_spin(&clock_lock);
timer0_prescaler_count = 0;
timer_func = hardclock;
timer0_state = RELEASED;
@@ -403,7 +403,7 @@ getit(void)
{
int high, low;
- mtx_enter(&clock_lock, MTX_SPIN);
+ mtx_lock_spin(&clock_lock);
/* Select timer0 and latch counter value. */
outb(TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
@@ -411,7 +411,7 @@ getit(void)
low = inb(TIMER_CNTR0);
high = inb(TIMER_CNTR0);
- mtx_exit(&clock_lock, MTX_SPIN);
+ mtx_unlock_spin(&clock_lock);
return ((high << 8) | low);
}
@@ -525,10 +525,10 @@ sysbeep(int pitch, int period)
splx(x);
return (-1); /* XXX Should be EBUSY, but nobody cares anyway. */
}
- mtx_enter(&clock_lock, MTX_SPIN);
+ mtx_lock_spin(&clock_lock);
outb(TIMER_CNTR2, pitch);
outb(TIMER_CNTR2, (pitch>>8));
- mtx_exit(&clock_lock, MTX_SPIN);
+ mtx_unlock_spin(&clock_lock);
if (!beeping) {
/* enable counter2 output to speaker */
outb(IO_PPI, inb(IO_PPI) | 3);
@@ -679,7 +679,7 @@ set_timer_freq(u_int freq, int intr_freq)
{
int new_timer0_max_count;
- mtx_enter(&clock_lock, MTX_SPIN);
+ mtx_lock_spin(&clock_lock);
timer_freq = freq;
new_timer0_max_count = hardclock_max_count = TIMER_DIV(intr_freq);
if (new_timer0_max_count != timer0_max_count) {
@@ -688,7 +688,7 @@ set_timer_freq(u_int freq, int intr_freq)
outb(TIMER_CNTR0, timer0_max_count & 0xff);
outb(TIMER_CNTR0, timer0_max_count >> 8);
}
- mtx_exit(&clock_lock, MTX_SPIN);
+ mtx_unlock_spin(&clock_lock);
}
/*
@@ -703,11 +703,11 @@ void
i8254_restore(void)
{
- mtx_enter(&clock_lock, MTX_SPIN);
+ mtx_lock_spin(&clock_lock);
outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
outb(TIMER_CNTR0, timer0_max_count & 0xff);
outb(TIMER_CNTR0, timer0_max_count >> 8);
- mtx_exit(&clock_lock, MTX_SPIN);
+ mtx_unlock_spin(&clock_lock);
}
/*
@@ -1194,7 +1194,7 @@ i8254_get_timecount(struct timecounter *tc)
u_int eflags;
eflags = read_eflags();
- mtx_enter(&clock_lock, MTX_SPIN);
+ mtx_lock_spin(&clock_lock);
/* Select timer0 and latch counter value. */
outb(TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
@@ -1218,7 +1218,7 @@ i8254_get_timecount(struct timecounter *tc)
}
i8254_lastcount = count;
count += i8254_offset;
- mtx_exit(&clock_lock, MTX_SPIN);
+ mtx_unlock_spin(&clock_lock);
return (count);
}
diff --git a/sys/amd64/isa/intr_machdep.c b/sys/amd64/isa/intr_machdep.c
index d44a672..70b9378 100644
--- a/sys/amd64/isa/intr_machdep.c
+++ b/sys/amd64/isa/intr_machdep.c
@@ -701,7 +701,7 @@ inthand_remove(struct intrhand *idesc)
ithds[ithd->irq] = NULL;
if ((idesc->ih_flags & INTR_FAST) == 0) {
- mtx_enter(&sched_lock, MTX_SPIN);
+ mtx_lock_spin(&sched_lock);
if (ithd->it_proc->p_stat == SWAIT) {
ithd->it_proc->p_intr_nesting_level = 0;
ithd->it_proc->p_stat = SRUN;
@@ -713,7 +713,7 @@ inthand_remove(struct intrhand *idesc)
* XXX: should we lower the threads priority?
*/
}
- mtx_exit(&sched_lock, MTX_SPIN);
+ mtx_unlock_spin(&sched_lock);
}
}
free(idesc->ih_name, M_DEVBUF);
diff --git a/sys/amd64/isa/ithread.c b/sys/amd64/isa/ithread.c
index 5f64861..99a1abf 100644
--- a/sys/amd64/isa/ithread.c
+++ b/sys/amd64/isa/ithread.c
@@ -114,7 +114,7 @@ sched_ithd(void *cookie)
* is higher priority than their current thread, it gets run now.
*/
ir->it_need = 1;
- mtx_enter(&sched_lock, MTX_SPIN);
+ mtx_lock_spin(&sched_lock);
if (ir->it_proc->p_stat == SWAIT) { /* not on run queue */
CTR1(KTR_INTR, "sched_ithd: setrunqueue %d",
ir->it_proc->p_pid);
@@ -134,7 +134,7 @@ sched_ithd(void *cookie)
ir->it_proc->p_stat );
need_resched();
}
- mtx_exit(&sched_lock, MTX_SPIN);
+ mtx_unlock_spin(&sched_lock);
}
/*
@@ -163,7 +163,7 @@ ithd_loop(void *dummy)
me->it_proc->p_pid, me->it_proc->p_comm);
curproc->p_ithd = NULL;
free(me, M_DEVBUF);
- mtx_enter(&Giant, MTX_DEF);
+ mtx_lock(&Giant);
kthread_exit(0);
}
@@ -188,10 +188,10 @@ ithd_loop(void *dummy)
ih->ih_flags);
if ((ih->ih_flags & INTR_MPSAFE) == 0)
- mtx_enter(&Giant, MTX_DEF);
+ mtx_lock(&Giant);
ih->ih_handler(ih->ih_argument);
if ((ih->ih_flags & INTR_MPSAFE) == 0)
- mtx_exit(&Giant, MTX_DEF);
+ mtx_unlock(&Giant);
}
}
@@ -201,7 +201,7 @@ ithd_loop(void *dummy)
* set again, so we have to check it again.
*/
mtx_assert(&Giant, MA_NOTOWNED);
- mtx_enter(&sched_lock, MTX_SPIN);
+ mtx_lock_spin(&sched_lock);
if (!me->it_need) {
INTREN (1 << me->irq); /* reset the mask bit */
@@ -217,6 +217,6 @@ ithd_loop(void *dummy)
CTR1(KTR_INTR, "ithd_loop pid %d: resumed",
me->it_proc->p_pid);
}
- mtx_exit(&sched_lock, MTX_SPIN);
+ mtx_unlock_spin(&sched_lock);
}
}
diff --git a/sys/amd64/isa/nmi.c b/sys/amd64/isa/nmi.c
index d44a672..70b9378 100644
--- a/sys/amd64/isa/nmi.c
+++ b/sys/amd64/isa/nmi.c
@@ -701,7 +701,7 @@ inthand_remove(struct intrhand *idesc)
ithds[ithd->irq] = NULL;
if ((idesc->ih_flags & INTR_FAST) == 0) {
- mtx_enter(&sched_lock, MTX_SPIN);
+ mtx_lock_spin(&sched_lock);
if (ithd->it_proc->p_stat == SWAIT) {
ithd->it_proc->p_intr_nesting_level = 0;
ithd->it_proc->p_stat = SRUN;
@@ -713,7 +713,7 @@ inthand_remove(struct intrhand *idesc)
* XXX: should we lower the threads priority?
*/
}
- mtx_exit(&sched_lock, MTX_SPIN);
+ mtx_unlock_spin(&sched_lock);
}
}
free(idesc->ih_name, M_DEVBUF);
diff --git a/sys/amd64/isa/npx.c b/sys/amd64/isa/npx.c
index a729e0f..0dab6ae 100644
--- a/sys/amd64/isa/npx.c
+++ b/sys/amd64/isa/npx.c
@@ -724,7 +724,7 @@ npx_intr(dummy)
u_short control;
struct intrframe *frame;
- mtx_enter(&Giant, MTX_DEF);
+ mtx_lock(&Giant);
if (PCPU_GET(npxproc) == NULL || !npx_exists) {
printf("npxintr: npxproc = %p, curproc = %p, npx_exists = %d\n",
PCPU_GET(npxproc), curproc, npx_exists);
@@ -783,7 +783,7 @@ npx_intr(dummy)
*/
psignal(curproc, SIGFPE);
}
- mtx_exit(&Giant, MTX_DEF);
+ mtx_unlock(&Giant);
}
/*
OpenPOWER on IntegriCloud