summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>2002-09-23 06:14:30 +0000
committerjulian <julian@FreeBSD.org>2002-09-23 06:14:30 +0000
commitbcb38a31ff0d92c47ebc284b3704fa8f94de02ba (patch)
treef505371e70c97ad9695c39108f12bdbc6ed43148 /sys/kern
parenta7014de16e80c2864b6f25c7a67c110184c0cb5e (diff)
downloadFreeBSD-src-bcb38a31ff0d92c47ebc284b3704fa8f94de02ba.zip
FreeBSD-src-bcb38a31ff0d92c47ebc284b3704fa8f94de02ba.tar.gz
slightly clean up the thread_userret() and thread_consider_upcall() calls.
also some slight changes for TDF_BOUND testing and small style changes Should ONLY affect KSE programs Submitted by: davidxu
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_kse.c36
-rw-r--r--sys/kern/kern_thread.c36
-rw-r--r--sys/kern/subr_trap.c7
3 files changed, 52 insertions, 27 deletions
diff --git a/sys/kern/kern_kse.c b/sys/kern/kern_kse.c
index b5703cc..6417f9b 100644
--- a/sys/kern/kern_kse.c
+++ b/sys/kern/kern_kse.c
@@ -67,7 +67,7 @@ static int oiks_debug = 1; /* 0 disable, 1 printf, 2 enter debugger */
SYSCTL_INT(_kern_threads, OID_AUTO, oiks, CTLFLAG_RW,
&oiks_debug, 0, "OIKS thread debug");
-static int max_threads_per_proc = 4;
+static int max_threads_per_proc = 6;
SYSCTL_INT(_kern_threads, OID_AUTO, max_per_proc, CTLFLAG_RW,
&max_threads_per_proc, 0, "Limit on threads per proc");
@@ -330,7 +330,10 @@ thread_export_context(struct thread *td)
void *addr2;
int error;
ucontext_t uc;
+ int unbound;
+ unbound = (td->td_flags & TDF_UNBOUND);
+ td->td_flags &= ~TDF_UNBOUND;
#ifdef __ia64__
td2_mbx = 0; /* pacify gcc (!) */
#endif
@@ -365,6 +368,7 @@ thread_export_context(struct thread *td)
error = suword(addr1, (u_long)td->td_mailbox);
if (error == -1)
error = EFAULT;
+ td->td_flags |= unbound;
return (error);
}
@@ -574,9 +578,10 @@ signal_upcall(struct proc *p, int sig)
* no other completed threads.
*/
static int
-thread_consider_upcalling(struct proc *p, struct ksegrp *kg, struct kse *ke,
- struct thread *td, struct trapframe *frame)
+thread_consider_upcalling(struct thread *td)
{
+ struct proc *p;
+ struct ksegrp *kg;
int error;
/*
@@ -597,7 +602,14 @@ thread_consider_upcalling(struct proc *p, struct ksegrp *kg, struct kse *ke,
* Decide whether to perfom an upcall now.
*/
/* Make sure there are no other threads waiting to run. */
- if (TAILQ_FIRST(&kg->kg_runq)) {
+ p = td->td_proc;
+ kg = td->td_ksegrp;
+ PROC_LOCK(p);
+ mtx_lock_spin(&sched_lock);
+ /* bogus test, ok for testing though */
+ if (TAILQ_FIRST(&kg->kg_runq) &&
+ (TAILQ_LAST(&kg->kg_runq, threadqueue)
+ != kg->kg_last_assigned)) {
/*
* Another thread in this KSEG needs to run.
* Switch to it instead of performing an upcall,
@@ -621,8 +633,6 @@ thread_consider_upcalling(struct proc *p, struct ksegrp *kg, struct kse *ke,
* the next upcall to any KSE in this KSEG.
*
*/
- PROC_LOCK(p);
- mtx_lock_spin(&sched_lock);
thread_exit(); /* Abandon current thread. */
/* NOTREACHED */
} else
@@ -633,6 +643,8 @@ thread_consider_upcalling(struct proc *p, struct ksegrp *kg, struct kse *ke,
* nested in the kernel.
*/
td->td_flags |= TDF_UPCALLING;
+ mtx_unlock_spin(&sched_lock);
+ PROC_UNLOCK(p);
return (0);
}
@@ -649,11 +661,11 @@ thread_consider_upcalling(struct proc *p, struct ksegrp *kg, struct kse *ke,
* We will clear it here.
*/
int
-thread_userret(struct proc *p, struct ksegrp *kg, struct kse *ke,
- struct thread *td, struct trapframe *frame)
+thread_userret(struct thread *td, struct trapframe *frame)
{
int error;
+#if 0
/*
* Ensure that we have a spare thread available.
*/
@@ -662,19 +674,18 @@ thread_userret(struct proc *p, struct ksegrp *kg, struct kse *ke,
ke->ke_tdspare = thread_alloc();
mtx_unlock(&Giant);
}
-
+#endif
/*
* Bound threads need no additional work.
*/
if ((td->td_flags & TDF_UNBOUND) == 0)
return (0);
error = 0;
-
/*
* Decide whether or not we should perform an upcall now.
*/
if (((td->td_flags & TDF_UPCALLING) == 0) && td->td_mailbox) {
- error = thread_consider_upcalling(p, kg, ke, td, frame);
+ error = thread_consider_upcalling(td);
if (error != 0)
/*
* Failing to do the KSE operation just defaults
@@ -694,7 +705,8 @@ thread_userret(struct proc *p, struct ksegrp *kg, struct kse *ke,
/*
* Set user context to the UTS.
*/
- cpu_set_upcall_kse(td, ke);
+ td->td_flags &= ~TDF_UNBOUND;
+ cpu_set_upcall_kse(td, td->td_kse);
if (error)
/*
* Failing to do the KSE operation just defaults
diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c
index b5703cc..6417f9b 100644
--- a/sys/kern/kern_thread.c
+++ b/sys/kern/kern_thread.c
@@ -67,7 +67,7 @@ static int oiks_debug = 1; /* 0 disable, 1 printf, 2 enter debugger */
SYSCTL_INT(_kern_threads, OID_AUTO, oiks, CTLFLAG_RW,
&oiks_debug, 0, "OIKS thread debug");
-static int max_threads_per_proc = 4;
+static int max_threads_per_proc = 6;
SYSCTL_INT(_kern_threads, OID_AUTO, max_per_proc, CTLFLAG_RW,
&max_threads_per_proc, 0, "Limit on threads per proc");
@@ -330,7 +330,10 @@ thread_export_context(struct thread *td)
void *addr2;
int error;
ucontext_t uc;
+ int unbound;
+ unbound = (td->td_flags & TDF_UNBOUND);
+ td->td_flags &= ~TDF_UNBOUND;
#ifdef __ia64__
td2_mbx = 0; /* pacify gcc (!) */
#endif
@@ -365,6 +368,7 @@ thread_export_context(struct thread *td)
error = suword(addr1, (u_long)td->td_mailbox);
if (error == -1)
error = EFAULT;
+ td->td_flags |= unbound;
return (error);
}
@@ -574,9 +578,10 @@ signal_upcall(struct proc *p, int sig)
* no other completed threads.
*/
static int
-thread_consider_upcalling(struct proc *p, struct ksegrp *kg, struct kse *ke,
- struct thread *td, struct trapframe *frame)
+thread_consider_upcalling(struct thread *td)
{
+ struct proc *p;
+ struct ksegrp *kg;
int error;
/*
@@ -597,7 +602,14 @@ thread_consider_upcalling(struct proc *p, struct ksegrp *kg, struct kse *ke,
* Decide whether to perfom an upcall now.
*/
/* Make sure there are no other threads waiting to run. */
- if (TAILQ_FIRST(&kg->kg_runq)) {
+ p = td->td_proc;
+ kg = td->td_ksegrp;
+ PROC_LOCK(p);
+ mtx_lock_spin(&sched_lock);
+ /* bogus test, ok for testing though */
+ if (TAILQ_FIRST(&kg->kg_runq) &&
+ (TAILQ_LAST(&kg->kg_runq, threadqueue)
+ != kg->kg_last_assigned)) {
/*
* Another thread in this KSEG needs to run.
* Switch to it instead of performing an upcall,
@@ -621,8 +633,6 @@ thread_consider_upcalling(struct proc *p, struct ksegrp *kg, struct kse *ke,
* the next upcall to any KSE in this KSEG.
*
*/
- PROC_LOCK(p);
- mtx_lock_spin(&sched_lock);
thread_exit(); /* Abandon current thread. */
/* NOTREACHED */
} else
@@ -633,6 +643,8 @@ thread_consider_upcalling(struct proc *p, struct ksegrp *kg, struct kse *ke,
* nested in the kernel.
*/
td->td_flags |= TDF_UPCALLING;
+ mtx_unlock_spin(&sched_lock);
+ PROC_UNLOCK(p);
return (0);
}
@@ -649,11 +661,11 @@ thread_consider_upcalling(struct proc *p, struct ksegrp *kg, struct kse *ke,
* We will clear it here.
*/
int
-thread_userret(struct proc *p, struct ksegrp *kg, struct kse *ke,
- struct thread *td, struct trapframe *frame)
+thread_userret(struct thread *td, struct trapframe *frame)
{
int error;
+#if 0
/*
* Ensure that we have a spare thread available.
*/
@@ -662,19 +674,18 @@ thread_userret(struct proc *p, struct ksegrp *kg, struct kse *ke,
ke->ke_tdspare = thread_alloc();
mtx_unlock(&Giant);
}
-
+#endif
/*
* Bound threads need no additional work.
*/
if ((td->td_flags & TDF_UNBOUND) == 0)
return (0);
error = 0;
-
/*
* Decide whether or not we should perform an upcall now.
*/
if (((td->td_flags & TDF_UPCALLING) == 0) && td->td_mailbox) {
- error = thread_consider_upcalling(p, kg, ke, td, frame);
+ error = thread_consider_upcalling(td);
if (error != 0)
/*
* Failing to do the KSE operation just defaults
@@ -694,7 +705,8 @@ thread_userret(struct proc *p, struct ksegrp *kg, struct kse *ke,
/*
* Set user context to the UTS.
*/
- cpu_set_upcall_kse(td, ke);
+ td->td_flags &= ~TDF_UNBOUND;
+ cpu_set_upcall_kse(td, td->td_kse);
if (error)
/*
* Failing to do the KSE operation just defaults
diff --git a/sys/kern/subr_trap.c b/sys/kern/subr_trap.c
index ac14292..f120141 100644
--- a/sys/kern/subr_trap.c
+++ b/sys/kern/subr_trap.c
@@ -81,7 +81,7 @@ userret(td, frame, oticks)
PROC_LOCK(p);
mtx_lock_spin(&sched_lock);
if (SIGPENDING(p) && ((p->p_sflag & PS_NEEDSIGCHK) == 0 ||
- (ke->ke_flags & KEF_ASTPENDING) == 0))
+ (td->td_kse->ke_flags & KEF_ASTPENDING) == 0))
printf("failed to set signal flags properly for ast()\n");
mtx_unlock_spin(&sched_lock);
PROC_UNLOCK(p);
@@ -119,7 +119,7 @@ userret(td, frame, oticks)
* DO special thread processing, e.g. upcall tweaking and such
*/
if (p->p_flag & P_KSES) {
- thread_userret(p, kg, ke, td, frame);
+ thread_userret(td, frame);
/* printf("KSE thread returned"); */
}
@@ -149,7 +149,7 @@ ast(struct trapframe *framep)
{
struct thread *td = curthread;
struct proc *p = td->td_proc;
- struct kse *ke = td->td_kse;
+ struct kse *ke;
struct ksegrp *kg = td->td_ksegrp;
u_int prticks, sticks;
int sflag;
@@ -178,6 +178,7 @@ ast(struct trapframe *framep)
* ast() will be called again.
*/
mtx_lock_spin(&sched_lock);
+ ke = td->td_kse;
sticks = ke->ke_sticks;
sflag = p->p_sflag;
flags = ke->ke_flags;
OpenPOWER on IntegriCloud