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
|
|
|
*/
|
|
|
|
|
2002-10-02 02:42:38 +00:00
|
|
|
#include "opt_mac.h"
|
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>
|
2002-10-02 02:42:38 +00:00
|
|
|
#include <sys/mac.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>
|
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
|
|
|
#include <sys/kse.h>
|
|
|
|
#include <sys/ktr.h>
|
1997-11-24 13:25:37 +00:00
|
|
|
#include <sys/resourcevar.h>
|
2002-10-12 05:32:24 +00:00
|
|
|
#include <sys/sched.h>
|
1997-11-24 13:25:37 +00:00
|
|
|
#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;
|
Move UPCALL related data structure out of kse, introduce a new
data structure called kse_upcall to manage UPCALL. All KSE binding
and loaning code are gone.
A thread owns an upcall can collect all completed syscall contexts in
its ksegrp, turn itself into UPCALL mode, and takes those contexts back
to userland. Any thread without upcall structure has to export their
contexts and exit at user boundary.
Any thread running in user mode owns an upcall structure, when it enters
kernel, if the kse mailbox's current thread pointer is not NULL, then
when the thread is blocked in kernel, a new UPCALL thread is created and
the upcall structure is transfered to the new UPCALL thread. if the kse
mailbox's current thread pointer is NULL, then when a thread is blocked
in kernel, no UPCALL thread will be created.
Each upcall always has an owner thread. Userland can remove an upcall by
calling kse_exit, when all upcalls in ksegrp are removed, the group is
atomatically shutdown. An upcall owner thread also exits when process is
in exiting state. when an owner thread exits, the upcall it owns is also
removed.
KSE is a pure scheduler entity. it represents a virtual cpu. when a thread
is running, it always has a KSE associated with it. scheduler is free to
assign a KSE to thread according thread priority, if thread priority is changed,
KSE can be moved from one thread to another.
When a ksegrp is created, there is always N KSEs created in the group. the
N is the number of physical cpu in the current system. This makes it is
possible that even an userland UTS is single CPU safe, threads in kernel still
can execute on different cpu in parallel. Userland calls kse_create to add more
upcall structures into ksegrp to increase concurrent in userland itself, kernel
is not restricted by number of upcalls userland provides.
The code hasn't been tested under SMP by author due to lack of hardware.
Reviewed by: julian
2003-01-26 11:41:35 +00:00
|
|
|
#ifdef INVARIANTS
|
|
|
|
struct kse *ke;
|
|
|
|
#endif
|
1994-06-06 14:54:41 +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
|
|
|
CTR3(KTR_SYSC, "userret: thread %p (pid %d, %s)", td, p->p_pid,
|
|
|
|
p->p_comm);
|
2002-04-04 17:49:48 +00:00
|
|
|
#ifdef INVARIANTS
|
Move UPCALL related data structure out of kse, introduce a new
data structure called kse_upcall to manage UPCALL. All KSE binding
and loaning code are gone.
A thread owns an upcall can collect all completed syscall contexts in
its ksegrp, turn itself into UPCALL mode, and takes those contexts back
to userland. Any thread without upcall structure has to export their
contexts and exit at user boundary.
Any thread running in user mode owns an upcall structure, when it enters
kernel, if the kse mailbox's current thread pointer is not NULL, then
when the thread is blocked in kernel, a new UPCALL thread is created and
the upcall structure is transfered to the new UPCALL thread. if the kse
mailbox's current thread pointer is NULL, then when a thread is blocked
in kernel, no UPCALL thread will be created.
Each upcall always has an owner thread. Userland can remove an upcall by
calling kse_exit, when all upcalls in ksegrp are removed, the group is
atomatically shutdown. An upcall owner thread also exits when process is
in exiting state. when an owner thread exits, the upcall it owns is also
removed.
KSE is a pure scheduler entity. it represents a virtual cpu. when a thread
is running, it always has a KSE associated with it. scheduler is free to
assign a KSE to thread according thread priority, if thread priority is changed,
KSE can be moved from one thread to another.
When a ksegrp is created, there is always N KSEs created in the group. the
N is the number of physical cpu in the current system. This makes it is
possible that even an userland UTS is single CPU safe, threads in kernel still
can execute on different cpu in parallel. Userland calls kse_create to add more
upcall structures into ksegrp to increase concurrent in userland itself, kernel
is not restricted by number of upcalls userland provides.
The code hasn't been tested under SMP by author due to lack of hardware.
Reviewed by: julian
2003-01-26 11:41:35 +00:00
|
|
|
/*
|
|
|
|
* Check that we called signotify() enough.
|
|
|
|
* XXXKSE this checking is bogus for threaded program,
|
|
|
|
*/
|
2001-07-03 05:27:53 +00:00
|
|
|
mtx_lock(&Giant);
|
2001-06-22 23:05:11 +00:00
|
|
|
PROC_LOCK(p);
|
2002-04-04 17:49:48 +00:00
|
|
|
mtx_lock_spin(&sched_lock);
|
Move UPCALL related data structure out of kse, introduce a new
data structure called kse_upcall to manage UPCALL. All KSE binding
and loaning code are gone.
A thread owns an upcall can collect all completed syscall contexts in
its ksegrp, turn itself into UPCALL mode, and takes those contexts back
to userland. Any thread without upcall structure has to export their
contexts and exit at user boundary.
Any thread running in user mode owns an upcall structure, when it enters
kernel, if the kse mailbox's current thread pointer is not NULL, then
when the thread is blocked in kernel, a new UPCALL thread is created and
the upcall structure is transfered to the new UPCALL thread. if the kse
mailbox's current thread pointer is NULL, then when a thread is blocked
in kernel, no UPCALL thread will be created.
Each upcall always has an owner thread. Userland can remove an upcall by
calling kse_exit, when all upcalls in ksegrp are removed, the group is
atomatically shutdown. An upcall owner thread also exits when process is
in exiting state. when an owner thread exits, the upcall it owns is also
removed.
KSE is a pure scheduler entity. it represents a virtual cpu. when a thread
is running, it always has a KSE associated with it. scheduler is free to
assign a KSE to thread according thread priority, if thread priority is changed,
KSE can be moved from one thread to another.
When a ksegrp is created, there is always N KSEs created in the group. the
N is the number of physical cpu in the current system. This makes it is
possible that even an userland UTS is single CPU safe, threads in kernel still
can execute on different cpu in parallel. Userland calls kse_create to add more
upcall structures into ksegrp to increase concurrent in userland itself, kernel
is not restricted by number of upcalls userland provides.
The code hasn't been tested under SMP by author due to lack of hardware.
Reviewed by: julian
2003-01-26 11:41:35 +00:00
|
|
|
ke = td->td_kse;
|
2002-10-01 17:15:53 +00:00
|
|
|
if (SIGPENDING(p) && ((p->p_sflag & PS_NEEDSIGCHK) == 0 ||
|
2002-10-02 18:25:09 +00:00
|
|
|
(td->td_kse->ke_flags & KEF_ASTPENDING) == 0))
|
2002-08-22 14:36:03 +00:00
|
|
|
printf("failed to set signal flags properly for ast()\n");
|
2002-04-04 17:49:48 +00:00
|
|
|
mtx_unlock_spin(&sched_lock);
|
2001-08-10 22:53:32 +00:00
|
|
|
PROC_UNLOCK(p);
|
2001-08-30 18:50:57 +00:00
|
|
|
mtx_unlock(&Giant);
|
2002-04-04 17:49:48 +00:00
|
|
|
#endif
|
2000-03-28 07:16:37 +00:00
|
|
|
|
2002-04-04 17:49:48 +00:00
|
|
|
/*
|
2002-10-12 05:32:24 +00:00
|
|
|
* Let the scheduler adjust our priority etc.
|
2002-04-04 17:49:48 +00:00
|
|
|
*/
|
2002-10-12 05:32:24 +00:00
|
|
|
sched_userret(td);
|
2001-01-24 09:53:49 +00:00
|
|
|
|
Move UPCALL related data structure out of kse, introduce a new
data structure called kse_upcall to manage UPCALL. All KSE binding
and loaning code are gone.
A thread owns an upcall can collect all completed syscall contexts in
its ksegrp, turn itself into UPCALL mode, and takes those contexts back
to userland. Any thread without upcall structure has to export their
contexts and exit at user boundary.
Any thread running in user mode owns an upcall structure, when it enters
kernel, if the kse mailbox's current thread pointer is not NULL, then
when the thread is blocked in kernel, a new UPCALL thread is created and
the upcall structure is transfered to the new UPCALL thread. if the kse
mailbox's current thread pointer is NULL, then when a thread is blocked
in kernel, no UPCALL thread will be created.
Each upcall always has an owner thread. Userland can remove an upcall by
calling kse_exit, when all upcalls in ksegrp are removed, the group is
atomatically shutdown. An upcall owner thread also exits when process is
in exiting state. when an owner thread exits, the upcall it owns is also
removed.
KSE is a pure scheduler entity. it represents a virtual cpu. when a thread
is running, it always has a KSE associated with it. scheduler is free to
assign a KSE to thread according thread priority, if thread priority is changed,
KSE can be moved from one thread to another.
When a ksegrp is created, there is always N KSEs created in the group. the
N is the number of physical cpu in the current system. This makes it is
possible that even an userland UTS is single CPU safe, threads in kernel still
can execute on different cpu in parallel. Userland calls kse_create to add more
upcall structures into ksegrp to increase concurrent in userland itself, kernel
is not restricted by number of upcalls userland provides.
The code hasn't been tested under SMP by author due to lack of hardware.
Reviewed by: julian
2003-01-26 11:41:35 +00:00
|
|
|
/*
|
|
|
|
* Charge system time if profiling.
|
|
|
|
*
|
|
|
|
* XXX should move PS_PROFIL to a place that can obviously be
|
|
|
|
* accessed safely without sched_lock.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (p->p_sflag & PS_PROFIL) {
|
|
|
|
ticks = td->td_sticks - oticks;
|
|
|
|
addupc_task(td, TRAPF_PC(frame), (u_int)ticks * psratio);
|
|
|
|
}
|
|
|
|
|
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-26 04:44:17 +00:00
|
|
|
* We need to check to see if we have to exit or wait due to a
|
|
|
|
* single threading requirement or some other STOP condition.
|
|
|
|
* Don't bother doing all the work if the stop bits are not set
|
|
|
|
* at this time.. If we miss it, we miss it.. no big deal.
|
|
|
|
*/
|
|
|
|
if (P_SHOULDSTOP(p)) {
|
|
|
|
PROC_LOCK(p);
|
|
|
|
thread_suspend_check(0); /* Can suspend or kill */
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do special thread processing, e.g. upcall tweaking and such.
|
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_KSES) {
|
2002-09-23 06:14:30 +00:00
|
|
|
thread_userret(td, frame);
|
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
|
|
|
}
|
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
|
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
|
|
|
ast(struct trapframe *framep)
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
2002-10-01 14:16:50 +00:00
|
|
|
struct thread *td;
|
|
|
|
struct proc *p;
|
2002-09-23 06:14:30 +00:00
|
|
|
struct kse *ke;
|
2002-10-01 14:16:50 +00:00
|
|
|
struct ksegrp *kg;
|
2002-09-30 21:13:54 +00:00
|
|
|
struct rlimit *rlim;
|
2001-08-10 22:53:32 +00:00
|
|
|
u_int prticks, sticks;
|
|
|
|
int sflag;
|
2001-09-12 08:38:13 +00:00
|
|
|
int flags;
|
Move UPCALL related data structure out of kse, introduce a new
data structure called kse_upcall to manage UPCALL. All KSE binding
and loaning code are gone.
A thread owns an upcall can collect all completed syscall contexts in
its ksegrp, turn itself into UPCALL mode, and takes those contexts back
to userland. Any thread without upcall structure has to export their
contexts and exit at user boundary.
Any thread running in user mode owns an upcall structure, when it enters
kernel, if the kse mailbox's current thread pointer is not NULL, then
when the thread is blocked in kernel, a new UPCALL thread is created and
the upcall structure is transfered to the new UPCALL thread. if the kse
mailbox's current thread pointer is NULL, then when a thread is blocked
in kernel, no UPCALL thread will be created.
Each upcall always has an owner thread. Userland can remove an upcall by
calling kse_exit, when all upcalls in ksegrp are removed, the group is
atomatically shutdown. An upcall owner thread also exits when process is
in exiting state. when an owner thread exits, the upcall it owns is also
removed.
KSE is a pure scheduler entity. it represents a virtual cpu. when a thread
is running, it always has a KSE associated with it. scheduler is free to
assign a KSE to thread according thread priority, if thread priority is changed,
KSE can be moved from one thread to another.
When a ksegrp is created, there is always N KSEs created in the group. the
N is the number of physical cpu in the current system. This makes it is
possible that even an userland UTS is single CPU safe, threads in kernel still
can execute on different cpu in parallel. Userland calls kse_create to add more
upcall structures into ksegrp to increase concurrent in userland itself, kernel
is not restricted by number of upcalls userland provides.
The code hasn't been tested under SMP by author due to lack of hardware.
Reviewed by: julian
2003-01-26 11:41:35 +00:00
|
|
|
int tflags;
|
2002-04-04 17:49:48 +00:00
|
|
|
int sig;
|
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
|
|
|
|
2002-10-01 14:16:50 +00:00
|
|
|
td = curthread;
|
|
|
|
p = td->td_proc;
|
2002-10-02 16:39:39 +00:00
|
|
|
kg = td->td_ksegrp;
|
|
|
|
|
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
|
|
|
CTR3(KTR_SYSC, "ast: thread %p (pid %d, %s)", td, p->p_pid,
|
|
|
|
p->p_comm);
|
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);
|
2002-04-04 17:49:48 +00:00
|
|
|
mtx_assert(&sched_lock, MA_NOTOWNED);
|
2002-03-29 16:45:03 +00:00
|
|
|
td->td_frame = framep;
|
2002-10-01 14:16:50 +00:00
|
|
|
|
2002-03-29 16:45:03 +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
|
|
|
|
* ast() will be called again.
|
|
|
|
*/
|
|
|
|
mtx_lock_spin(&sched_lock);
|
2002-10-02 18:25:09 +00:00
|
|
|
ke = td->td_kse;
|
Move UPCALL related data structure out of kse, introduce a new
data structure called kse_upcall to manage UPCALL. All KSE binding
and loaning code are gone.
A thread owns an upcall can collect all completed syscall contexts in
its ksegrp, turn itself into UPCALL mode, and takes those contexts back
to userland. Any thread without upcall structure has to export their
contexts and exit at user boundary.
Any thread running in user mode owns an upcall structure, when it enters
kernel, if the kse mailbox's current thread pointer is not NULL, then
when the thread is blocked in kernel, a new UPCALL thread is created and
the upcall structure is transfered to the new UPCALL thread. if the kse
mailbox's current thread pointer is NULL, then when a thread is blocked
in kernel, no UPCALL thread will be created.
Each upcall always has an owner thread. Userland can remove an upcall by
calling kse_exit, when all upcalls in ksegrp are removed, the group is
atomatically shutdown. An upcall owner thread also exits when process is
in exiting state. when an owner thread exits, the upcall it owns is also
removed.
KSE is a pure scheduler entity. it represents a virtual cpu. when a thread
is running, it always has a KSE associated with it. scheduler is free to
assign a KSE to thread according thread priority, if thread priority is changed,
KSE can be moved from one thread to another.
When a ksegrp is created, there is always N KSEs created in the group. the
N is the number of physical cpu in the current system. This makes it is
possible that even an userland UTS is single CPU safe, threads in kernel still
can execute on different cpu in parallel. Userland calls kse_create to add more
upcall structures into ksegrp to increase concurrent in userland itself, kernel
is not restricted by number of upcalls userland provides.
The code hasn't been tested under SMP by author due to lack of hardware.
Reviewed by: julian
2003-01-26 11:41:35 +00:00
|
|
|
sticks = td->td_sticks;
|
|
|
|
tflags = td->td_flags;
|
2002-03-29 16:45:03 +00:00
|
|
|
flags = ke->ke_flags;
|
2002-10-01 14:16:50 +00:00
|
|
|
sflag = p->p_sflag;
|
2002-10-01 14:13:13 +00:00
|
|
|
p->p_sflag &= ~(PS_ALRMPEND | PS_NEEDSIGCHK | PS_PROFPEND | PS_XCPU);
|
2002-11-08 19:00:17 +00:00
|
|
|
#ifdef MAC
|
|
|
|
p->p_sflag &= ~PS_MACPEND;
|
|
|
|
#endif
|
Move UPCALL related data structure out of kse, introduce a new
data structure called kse_upcall to manage UPCALL. All KSE binding
and loaning code are gone.
A thread owns an upcall can collect all completed syscall contexts in
its ksegrp, turn itself into UPCALL mode, and takes those contexts back
to userland. Any thread without upcall structure has to export their
contexts and exit at user boundary.
Any thread running in user mode owns an upcall structure, when it enters
kernel, if the kse mailbox's current thread pointer is not NULL, then
when the thread is blocked in kernel, a new UPCALL thread is created and
the upcall structure is transfered to the new UPCALL thread. if the kse
mailbox's current thread pointer is NULL, then when a thread is blocked
in kernel, no UPCALL thread will be created.
Each upcall always has an owner thread. Userland can remove an upcall by
calling kse_exit, when all upcalls in ksegrp are removed, the group is
atomatically shutdown. An upcall owner thread also exits when process is
in exiting state. when an owner thread exits, the upcall it owns is also
removed.
KSE is a pure scheduler entity. it represents a virtual cpu. when a thread
is running, it always has a KSE associated with it. scheduler is free to
assign a KSE to thread according thread priority, if thread priority is changed,
KSE can be moved from one thread to another.
When a ksegrp is created, there is always N KSEs created in the group. the
N is the number of physical cpu in the current system. This makes it is
possible that even an userland UTS is single CPU safe, threads in kernel still
can execute on different cpu in parallel. Userland calls kse_create to add more
upcall structures into ksegrp to increase concurrent in userland itself, kernel
is not restricted by number of upcalls userland provides.
The code hasn't been tested under SMP by author due to lack of hardware.
Reviewed by: julian
2003-01-26 11:41:35 +00:00
|
|
|
ke->ke_flags &= ~(KEF_ASTPENDING | KEF_NEEDRESCHED);
|
|
|
|
td->td_flags &= ~(TDF_ASTPENDING | TDF_OWEUPC);
|
2002-03-29 16:45:03 +00:00
|
|
|
cnt.v_soft++;
|
2002-10-01 14:16:50 +00:00
|
|
|
prticks = 0;
|
Move UPCALL related data structure out of kse, introduce a new
data structure called kse_upcall to manage UPCALL. All KSE binding
and loaning code are gone.
A thread owns an upcall can collect all completed syscall contexts in
its ksegrp, turn itself into UPCALL mode, and takes those contexts back
to userland. Any thread without upcall structure has to export their
contexts and exit at user boundary.
Any thread running in user mode owns an upcall structure, when it enters
kernel, if the kse mailbox's current thread pointer is not NULL, then
when the thread is blocked in kernel, a new UPCALL thread is created and
the upcall structure is transfered to the new UPCALL thread. if the kse
mailbox's current thread pointer is NULL, then when a thread is blocked
in kernel, no UPCALL thread will be created.
Each upcall always has an owner thread. Userland can remove an upcall by
calling kse_exit, when all upcalls in ksegrp are removed, the group is
atomatically shutdown. An upcall owner thread also exits when process is
in exiting state. when an owner thread exits, the upcall it owns is also
removed.
KSE is a pure scheduler entity. it represents a virtual cpu. when a thread
is running, it always has a KSE associated with it. scheduler is free to
assign a KSE to thread according thread priority, if thread priority is changed,
KSE can be moved from one thread to another.
When a ksegrp is created, there is always N KSEs created in the group. the
N is the number of physical cpu in the current system. This makes it is
possible that even an userland UTS is single CPU safe, threads in kernel still
can execute on different cpu in parallel. Userland calls kse_create to add more
upcall structures into ksegrp to increase concurrent in userland itself, kernel
is not restricted by number of upcalls userland provides.
The code hasn't been tested under SMP by author due to lack of hardware.
Reviewed by: julian
2003-01-26 11:41:35 +00:00
|
|
|
if (tflags & TDF_OWEUPC && sflag & PS_PROFIL) {
|
|
|
|
prticks = td->td_prticks;
|
|
|
|
td->td_prticks = 0;
|
2002-03-29 16:45:03 +00:00
|
|
|
}
|
|
|
|
mtx_unlock_spin(&sched_lock);
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
/*
|
|
|
|
* XXXKSE While the fact that we owe a user profiling
|
|
|
|
* tick is stored per KSE in this code, the statistics
|
|
|
|
* themselves are still stored per process.
|
|
|
|
* This should probably change, by which I mean that
|
|
|
|
* possibly the location of both might change.
|
|
|
|
*/
|
2002-02-22 23:58:22 +00:00
|
|
|
|
2002-03-29 16:45:03 +00:00
|
|
|
if (td->td_ucred != p->p_ucred)
|
|
|
|
cred_update_thread(td);
|
Move UPCALL related data structure out of kse, introduce a new
data structure called kse_upcall to manage UPCALL. All KSE binding
and loaning code are gone.
A thread owns an upcall can collect all completed syscall contexts in
its ksegrp, turn itself into UPCALL mode, and takes those contexts back
to userland. Any thread without upcall structure has to export their
contexts and exit at user boundary.
Any thread running in user mode owns an upcall structure, when it enters
kernel, if the kse mailbox's current thread pointer is not NULL, then
when the thread is blocked in kernel, a new UPCALL thread is created and
the upcall structure is transfered to the new UPCALL thread. if the kse
mailbox's current thread pointer is NULL, then when a thread is blocked
in kernel, no UPCALL thread will be created.
Each upcall always has an owner thread. Userland can remove an upcall by
calling kse_exit, when all upcalls in ksegrp are removed, the group is
atomatically shutdown. An upcall owner thread also exits when process is
in exiting state. when an owner thread exits, the upcall it owns is also
removed.
KSE is a pure scheduler entity. it represents a virtual cpu. when a thread
is running, it always has a KSE associated with it. scheduler is free to
assign a KSE to thread according thread priority, if thread priority is changed,
KSE can be moved from one thread to another.
When a ksegrp is created, there is always N KSEs created in the group. the
N is the number of physical cpu in the current system. This makes it is
possible that even an userland UTS is single CPU safe, threads in kernel still
can execute on different cpu in parallel. Userland calls kse_create to add more
upcall structures into ksegrp to increase concurrent in userland itself, kernel
is not restricted by number of upcalls userland provides.
The code hasn't been tested under SMP by author due to lack of hardware.
Reviewed by: julian
2003-01-26 11:41:35 +00:00
|
|
|
if (tflags & TDF_OWEUPC && sflag & PS_PROFIL) {
|
|
|
|
addupc_task(td, td->td_praddr, prticks);
|
|
|
|
}
|
2002-03-29 16:45:03 +00:00
|
|
|
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)
|
2002-03-29 16:45:03 +00:00
|
|
|
if (PCPU_GET(curpcb)->pcb_flags & PCB_NPXTRAP) {
|
|
|
|
atomic_clear_int(&PCPU_GET(curpcb)->pcb_flags,
|
|
|
|
PCB_NPXTRAP);
|
|
|
|
ucode = npxtrap();
|
|
|
|
if (ucode != -1) {
|
|
|
|
trapsignal(p, SIGFPE, ucode);
|
2001-05-22 21:20:49 +00:00
|
|
|
}
|
2002-03-29 16:45:03 +00:00
|
|
|
}
|
2001-05-22 21:20:49 +00:00
|
|
|
#endif
|
2002-03-29 16:45:03 +00:00
|
|
|
if (sflag & PS_PROFPEND) {
|
|
|
|
PROC_LOCK(p);
|
|
|
|
psignal(p, SIGPROF);
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
}
|
2002-09-30 21:13:54 +00:00
|
|
|
if (sflag & PS_XCPU) {
|
|
|
|
PROC_LOCK(p);
|
|
|
|
rlim = &p->p_rlimit[RLIMIT_CPU];
|
|
|
|
if (p->p_runtime.sec >= rlim->rlim_max)
|
|
|
|
killproc(p, "exceeded maximum CPU limit");
|
|
|
|
else {
|
|
|
|
psignal(p, SIGXCPU);
|
2002-10-09 17:17:24 +00:00
|
|
|
mtx_lock_spin(&sched_lock);
|
|
|
|
if (p->p_cpulimit < rlim->rlim_max)
|
|
|
|
p->p_cpulimit += 5;
|
|
|
|
mtx_unlock_spin(&sched_lock);
|
2002-09-30 21:13:54 +00:00
|
|
|
}
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
}
|
2002-11-08 19:00:17 +00:00
|
|
|
#ifdef MAC
|
|
|
|
if (sflag & PS_MACPEND)
|
|
|
|
mac_thread_userret(td);
|
|
|
|
#endif
|
2002-04-04 17:49:48 +00:00
|
|
|
if (flags & KEF_NEEDRESCHED) {
|
|
|
|
mtx_lock_spin(&sched_lock);
|
2002-10-12 05:32:24 +00:00
|
|
|
sched_prio(td, kg->kg_user_pri);
|
2002-04-04 17:49:48 +00:00
|
|
|
p->p_stats->p_ru.ru_nivcsw++;
|
|
|
|
mi_switch();
|
|
|
|
mtx_unlock_spin(&sched_lock);
|
|
|
|
}
|
|
|
|
if (sflag & PS_NEEDSIGCHK) {
|
|
|
|
PROC_LOCK(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
|
|
|
while ((sig = cursig(td)) != 0)
|
2002-04-04 17:49:48 +00:00
|
|
|
postsig(sig);
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
}
|
1997-04-07 07:16:06 +00:00
|
|
|
|
2002-03-29 16:45:03 +00:00
|
|
|
userret(td, framep, sticks);
|
2002-07-11 02:18:33 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
cred_free_thread(td);
|
|
|
|
#endif
|
2001-08-10 22:53:32 +00:00
|
|
|
mtx_assert(&Giant, MA_NOTOWNED);
|
1997-04-07 07:16:06 +00:00
|
|
|
}
|