1993-06-12 14:58:17 +00:00
|
|
|
/*-
|
1994-06-06 14:54:41 +00:00
|
|
|
* Copyright (C) 1994, David Greenman
|
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-06-12 14:58:17 +00:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* the University of Utah, and William Jolitz.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
|
|
|
*
|
genassym.c:
Remove NKMEMCLUSTERS, it is no longer define or used.
locores.s:
Fix comment on PTDpde and APTDpde to be pde instead of pte
Add new equation for calculating location of Sysmap
Remove Bill's old #ifdef garbage for counting up memory,
that stuff will never be made to work and was just cluttering
up the file.
Add code that places the PTD, page table pages, and kernel
stack below the 640k ISA hole if there is room for it, otherwise
put this stuff all at 1MB. This fixes the 28K bogusity in
the boot blocks, that can now go away!
Fix the caclulation of where first is to be dependent on
NKPDE so that we can skip over the above mentioned areas.
The 28K thing is now 44K in size due to the increase in
kernel virtual memory space, but since we no longer have
to worry about that this is no big deal.
Use if NNPX > 0 instead of ifdef NPX for floating point code.
machdep.c
Change the calculation of for the buffer cache to be
20% of all memory above 2MB and add back the upper limit
of 2/5's of the VM_KMEM_SIZE so that we do not eat ALL
of the kernel memory space on large memory machines, note
that this will not even come into effect unless you have
more than 32MB. The current buffer cache limit is 6.7MB
due to this caclulation.
It seems that we where erroniously allocating bufpages pages
for buffer_map. buffer_map is UNUSED in this implementation
of the buffer cache, but since the map is referenced in
several if statements a quick fix was to simply allocate
1 vm page (but no real memory) to it.
pmap.h
Remove rcsid, don't want them in the kernel files!
Removed some cruft inside an #ifdef DEBUGx that caused
compiler errors if you where compiling this for debug.
Use the #defines for PD_SHIFT and PG_SHIFT in place of
constants.
trap.c:
Remove patch kit header and rcsid, fix $Id$.
Now include "npx.h" and use NNPX for controlling the
floating point code.
Remove a now completly invalid check for a maximum virtual
address, the virtual address now ends at 0xFFFFFFFF so
there is no more MAX!! (Thanks David, I completly missed
that one!)
vm_machdep.c
Remove patch kit header and rcsid, fix $Id$.
Now include "npx.h" and use NNPX for controlling the
floating point code.
Replace several 0xFE00000 constants with KERNBASE
1993-10-15 10:34:29 +00:00
|
|
|
* from: @(#)trap.c 7.4 (Berkeley) 5/13/91
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
|
|
|
|
2001-06-29 19:51:37 +00:00
|
|
|
#ifdef __i386__
|
2001-01-19 13:19:02 +00:00
|
|
|
#include "opt_npx.h"
|
2001-06-29 19:51:37 +00:00
|
|
|
#endif
|
1996-01-03 21:42:35 +00:00
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
#include <sys/param.h>
|
2000-09-07 01:33:02 +00:00
|
|
|
#include <sys/bus.h>
|
1994-05-25 09:21:21 +00:00
|
|
|
#include <sys/kernel.h>
|
2001-06-29 19:51:37 +00:00
|
|
|
#include <sys/lock.h>
|
2000-10-20 07:58:15 +00:00
|
|
|
#include <sys/mutex.h>
|
2001-06-29 19:51:37 +00:00
|
|
|
#include <sys/proc.h>
|
1997-11-24 13:25:37 +00:00
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
#include <sys/signalvar.h>
|
2001-06-29 19:51:37 +00:00
|
|
|
#include <sys/systm.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <sys/vmmeter.h>
|
1994-05-25 09:21:21 +00:00
|
|
|
#include <machine/cpu.h>
|
1997-11-24 13:25:37 +00:00
|
|
|
#include <machine/pcb.h>
|
2000-12-12 01:14:32 +00:00
|
|
|
|
2001-06-29 19:51:37 +00:00
|
|
|
/*
|
|
|
|
* Define the code needed before returning to user mode, for
|
|
|
|
* trap and syscall.
|
2001-08-30 18:50:57 +00:00
|
|
|
*
|
|
|
|
* MPSAFE
|
2001-06-29 19:51:37 +00:00
|
|
|
*/
|
2001-01-24 09:53:49 +00:00
|
|
|
void
|
2001-09-12 08:38:13 +00:00
|
|
|
userret(td, frame, oticks)
|
|
|
|
struct thread *td;
|
1994-06-06 14:54:41 +00:00
|
|
|
struct trapframe *frame;
|
2001-08-10 22:53:32 +00:00
|
|
|
u_int oticks;
|
1994-06-06 14:54:41 +00:00
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
struct proc *p = td->td_proc;
|
|
|
|
struct kse *ke = td->td_kse;
|
|
|
|
struct ksegrp *kg = td->td_ksegrp;
|
2001-01-24 09:53:49 +00:00
|
|
|
int sig;
|
1994-06-06 14:54:41 +00:00
|
|
|
|
2001-07-03 05:27:53 +00:00
|
|
|
mtx_lock(&Giant);
|
2001-06-22 23:05:11 +00:00
|
|
|
PROC_LOCK(p);
|
2001-03-07 03:53:39 +00:00
|
|
|
while ((sig = CURSIG(p)) != 0)
|
1994-06-06 14:54:41 +00:00
|
|
|
postsig(sig);
|
2001-08-10 22:53:32 +00:00
|
|
|
PROC_UNLOCK(p);
|
2001-08-30 18:50:57 +00:00
|
|
|
mtx_unlock(&Giant);
|
2000-03-28 07:16:37 +00:00
|
|
|
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock_spin(&sched_lock);
|
2001-09-12 08:38:13 +00:00
|
|
|
kg->kg_pri.pri_level = kg->kg_pri.pri_user;
|
|
|
|
if (ke->ke_flags & KEF_NEEDRESCHED) {
|
1994-06-06 14:54:41 +00:00
|
|
|
/*
|
2001-06-29 19:51:37 +00:00
|
|
|
* Since we are curproc, a clock interrupt could
|
|
|
|
* change our priority without changing run queues
|
|
|
|
* (the running process is not kept on a run queue).
|
|
|
|
* If this happened after we setrunqueue ourselves but
|
|
|
|
* before we switch()'ed, we might not be on the queue
|
|
|
|
* indicated by our priority.
|
1994-06-06 14:54:41 +00:00
|
|
|
*/
|
2000-11-17 18:09:18 +00:00
|
|
|
DROP_GIANT_NOSWITCH();
|
2001-09-12 08:38:13 +00:00
|
|
|
setrunqueue(td);
|
1994-06-06 14:54:41 +00:00
|
|
|
p->p_stats->p_ru.ru_nivcsw++;
|
|
|
|
mi_switch();
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock_spin(&sched_lock);
|
2000-11-16 02:16:44 +00:00
|
|
|
PICKUP_GIANT();
|
2001-07-04 15:36:30 +00:00
|
|
|
mtx_lock(&Giant);
|
2001-06-22 23:05:11 +00:00
|
|
|
PROC_LOCK(p);
|
2001-03-07 03:53:39 +00:00
|
|
|
while ((sig = CURSIG(p)) != 0)
|
1994-06-06 14:54:41 +00:00
|
|
|
postsig(sig);
|
2001-07-04 15:36:30 +00:00
|
|
|
mtx_unlock(&Giant);
|
2001-08-10 22:53:32 +00:00
|
|
|
PROC_UNLOCK(p);
|
|
|
|
} else
|
|
|
|
mtx_unlock_spin(&sched_lock);
|
2001-01-24 09:53:49 +00:00
|
|
|
|
1995-02-10 06:25:14 +00:00
|
|
|
/*
|
|
|
|
* Charge system time if profiling.
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
if (p->p_sflag & PS_PROFIL) {
|
|
|
|
addupc_task(ke, TRAPF_PC(frame),
|
|
|
|
(u_int)(ke->ke_sticks - oticks) * psratio);
|
|
|
|
}
|
1994-06-06 14:54:41 +00:00
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
/*
|
2001-06-29 19:51:37 +00:00
|
|
|
* Process an asynchronous software trap.
|
|
|
|
* This is relatively easy.
|
2001-08-10 22:53:32 +00:00
|
|
|
* This function will return with preemption disabled.
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
2000-09-07 01:33:02 +00:00
|
|
|
void
|
2001-02-22 18:05:15 +00:00
|
|
|
ast(framep)
|
|
|
|
struct trapframe *framep;
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td = curthread;
|
|
|
|
struct proc *p = td->td_proc;
|
|
|
|
struct kse *ke = td->td_kse;
|
2001-08-10 22:53:32 +00:00
|
|
|
u_int prticks, sticks;
|
|
|
|
critical_t s;
|
|
|
|
int sflag;
|
2001-09-12 08:38:13 +00:00
|
|
|
int flags;
|
2001-05-22 21:20:49 +00:00
|
|
|
#if defined(DEV_NPX) && !defined(SMP)
|
|
|
|
int ucode;
|
|
|
|
#endif
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2001-02-22 18:05:15 +00:00
|
|
|
KASSERT(TRAPF_USERMODE(framep), ("ast in kernel mode"));
|
2001-08-10 22:53:32 +00:00
|
|
|
#ifdef WITNESS
|
2001-09-12 08:38:13 +00:00
|
|
|
if (witness_list(td))
|
2001-08-10 22:53:32 +00:00
|
|
|
panic("Returning to user mode with mutex(s) held");
|
|
|
|
#endif
|
|
|
|
mtx_assert(&Giant, MA_NOTOWNED);
|
|
|
|
s = critical_enter();
|
2001-09-12 08:38:13 +00:00
|
|
|
while ((ke->ke_flags & (KEF_ASTPENDING | KEF_NEEDRESCHED)) != 0) {
|
2001-08-10 22:53:32 +00:00
|
|
|
critical_exit(s);
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_frame = framep;
|
2001-08-10 22:53:32 +00:00
|
|
|
/*
|
|
|
|
* This updates the p_sflag's for the checks below in one
|
|
|
|
* "atomic" operation with turning off the astpending flag.
|
|
|
|
* If another AST is triggered while we are handling the
|
|
|
|
* AST's saved in sflag, the astpending flag will be set and
|
|
|
|
* we will loop again.
|
|
|
|
*/
|
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-09-12 08:38:13 +00:00
|
|
|
sticks = ke->ke_sticks;
|
2001-08-10 22:53:32 +00:00
|
|
|
sflag = p->p_sflag;
|
2001-09-12 08:38:13 +00:00
|
|
|
flags = ke->ke_flags;
|
|
|
|
p->p_sflag &= ~(PS_PROFPEND | PS_ALRMPEND);
|
|
|
|
ke->ke_flags &= ~(KEF_OWEUPC | KEF_ASTPENDING);
|
2001-08-10 22:53:32 +00:00
|
|
|
cnt.v_soft++;
|
2001-09-12 08:38:13 +00:00
|
|
|
if (flags & KEF_OWEUPC) {
|
2001-08-10 22:53:32 +00:00
|
|
|
prticks = p->p_stats->p_prof.pr_ticks;
|
|
|
|
p->p_stats->p_prof.pr_ticks = 0;
|
|
|
|
mtx_unlock_spin(&sched_lock);
|
2001-09-12 08:38:13 +00:00
|
|
|
addupc_task(ke, p->p_stats->p_prof.pr_addr, prticks);
|
2001-08-10 22:53:32 +00:00
|
|
|
} else
|
|
|
|
mtx_unlock_spin(&sched_lock);
|
|
|
|
if (sflag & PS_ALRMPEND) {
|
|
|
|
PROC_LOCK(p);
|
|
|
|
psignal(p, SIGVTALRM);
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
}
|
2001-05-22 21:20:49 +00:00
|
|
|
#if defined(DEV_NPX) && !defined(SMP)
|
2001-08-10 22:53:32 +00:00
|
|
|
if (PCPU_GET(curpcb)->pcb_flags & PCB_NPXTRAP) {
|
|
|
|
atomic_clear_char(&PCPU_GET(curpcb)->pcb_flags,
|
|
|
|
PCB_NPXTRAP);
|
|
|
|
ucode = npxtrap();
|
|
|
|
if (ucode != -1) {
|
|
|
|
trapsignal(p, SIGFPE, ucode);
|
|
|
|
}
|
2001-05-22 21:20:49 +00:00
|
|
|
}
|
|
|
|
#endif
|
2001-08-10 22:53:32 +00:00
|
|
|
if (sflag & PS_PROFPEND) {
|
|
|
|
PROC_LOCK(p);
|
|
|
|
psignal(p, SIGPROF);
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
}
|
1997-04-07 07:16:06 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
userret(td, framep, sticks);
|
2001-08-10 22:53:32 +00:00
|
|
|
s = critical_enter();
|
|
|
|
}
|
|
|
|
mtx_assert(&Giant, MA_NOTOWNED);
|
|
|
|
/*
|
|
|
|
* We need to keep interrupts disabled so that if any further AST's
|
|
|
|
* come in, the interrupt they come in on will be delayed until we
|
|
|
|
* finish returning to userland. We assume that the return to userland
|
|
|
|
* will perform the equivalent of critical_exit().
|
|
|
|
*/
|
1997-04-07 07:16:06 +00:00
|
|
|
}
|