summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_trap.c
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2003-01-26 11:41:35 +0000
committerdavidxu <davidxu@FreeBSD.org>2003-01-26 11:41:35 +0000
commit4b9b549ca22658196f5ef73f96b4ed8ecd37401b (patch)
treee3b6f27545368a6af5135acaa9f1002337a9fac9 /sys/kern/subr_trap.c
parenta74140ae0217edd23dbc303908778a13cf82376f (diff)
downloadFreeBSD-src-4b9b549ca22658196f5ef73f96b4ed8ecd37401b.zip
FreeBSD-src-4b9b549ca22658196f5ef73f96b4ed8ecd37401b.tar.gz
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
Diffstat (limited to 'sys/kern/subr_trap.c')
-rw-r--r--sys/kern/subr_trap.c55
1 files changed, 31 insertions, 24 deletions
diff --git a/sys/kern/subr_trap.c b/sys/kern/subr_trap.c
index eec2ae6..ecd00c1 100644
--- a/sys/kern/subr_trap.c
+++ b/sys/kern/subr_trap.c
@@ -73,15 +73,21 @@ userret(td, frame, oticks)
u_int oticks;
{
struct proc *p = td->td_proc;
- struct kse *ke = td->td_kse;
+#ifdef INVARIANTS
+ struct kse *ke;
+#endif
CTR3(KTR_SYSC, "userret: thread %p (pid %d, %s)", td, p->p_pid,
p->p_comm);
#ifdef INVARIANTS
- /* Check that we called signotify() enough. */
+ /*
+ * Check that we called signotify() enough.
+ * XXXKSE this checking is bogus for threaded program,
+ */
mtx_lock(&Giant);
PROC_LOCK(p);
mtx_lock_spin(&sched_lock);
+ ke = td->td_kse;
if (SIGPENDING(p) && ((p->p_sflag & PS_NEEDSIGCHK) == 0 ||
(td->td_kse->ke_flags & KEF_ASTPENDING) == 0))
printf("failed to set signal flags properly for ast()\n");
@@ -96,6 +102,18 @@ userret(td, frame, oticks)
sched_userret(td);
/*
+ * 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);
+ }
+
+ /*
* 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
@@ -113,21 +131,6 @@ userret(td, frame, oticks)
if (p->p_flag & P_KSES) {
thread_userret(td, frame);
}
-
- /*
- * 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) {
- quad_t ticks;
-
- mtx_lock_spin(&sched_lock);
- ticks = ke->ke_sticks - oticks;
- mtx_unlock_spin(&sched_lock);
- addupc_task(ke, TRAPF_PC(frame), (u_int)ticks * psratio);
- }
}
/*
@@ -146,6 +149,7 @@ ast(struct trapframe *framep)
u_int prticks, sticks;
int sflag;
int flags;
+ int tflags;
int sig;
#if defined(DEV_NPX) && !defined(SMP)
int ucode;
@@ -175,19 +179,21 @@ ast(struct trapframe *framep)
*/
mtx_lock_spin(&sched_lock);
ke = td->td_kse;
- sticks = ke->ke_sticks;
+ sticks = td->td_sticks;
+ tflags = td->td_flags;
flags = ke->ke_flags;
sflag = p->p_sflag;
p->p_sflag &= ~(PS_ALRMPEND | PS_NEEDSIGCHK | PS_PROFPEND | PS_XCPU);
#ifdef MAC
p->p_sflag &= ~PS_MACPEND;
#endif
- ke->ke_flags &= ~(KEF_ASTPENDING | KEF_NEEDRESCHED | KEF_OWEUPC);
+ ke->ke_flags &= ~(KEF_ASTPENDING | KEF_NEEDRESCHED);
+ td->td_flags &= ~(TDF_ASTPENDING | TDF_OWEUPC);
cnt.v_soft++;
prticks = 0;
- if (flags & KEF_OWEUPC && sflag & PS_PROFIL) {
- prticks = p->p_stats->p_prof.pr_ticks;
- p->p_stats->p_prof.pr_ticks = 0;
+ if (tflags & TDF_OWEUPC && sflag & PS_PROFIL) {
+ prticks = td->td_prticks;
+ td->td_prticks = 0;
}
mtx_unlock_spin(&sched_lock);
/*
@@ -200,8 +206,9 @@ ast(struct trapframe *framep)
if (td->td_ucred != p->p_ucred)
cred_update_thread(td);
- if (flags & KEF_OWEUPC && sflag & PS_PROFIL)
- addupc_task(ke, p->p_stats->p_prof.pr_addr, prticks);
+ if (tflags & TDF_OWEUPC && sflag & PS_PROFIL) {
+ addupc_task(td, td->td_praddr, prticks);
+ }
if (sflag & PS_ALRMPEND) {
PROC_LOCK(p);
psignal(p, SIGVTALRM);
OpenPOWER on IntegriCloud