PERFORCE change 61116 for review
Julian Elischer
julian at FreeBSD.org
Mon Sep 6 23:16:51 PDT 2004
http://perforce.freebsd.org/chv.cgi?CH=61116
Change 61116 by julian at julian_ref on 2004/09/07 06:16:38
give libthr the choice of being scope_system or scope_process.
Affected files ...
.. //depot/projects/nsched/sys/kern/kern_thr.c#15 edit
Differences ...
==== //depot/projects/nsched/sys/kern/kern_thr.c#15 (text+ko) ====
@@ -34,6 +34,7 @@
#include <sys/proc.h>
#include <sys/resourcevar.h>
#include <sys/sched.h>
+#include <sys/sysctl.h>
#include <sys/smp.h>
#include <sys/sysent.h>
#include <sys/systm.h>
@@ -47,6 +48,11 @@
extern int max_threads_per_proc;
extern int max_groups_per_proc;
+static int thr_scope_sys = 0;
+SYSCTL_DECL(_kern_threads);
+SYSCTL_INT(_kern_threads, OID_AUTO, thr_scope_sys, CTLFLAG_RW,
+ &thr_scope_sys, 0, "sys or proc scope scheduling");
+
/*
* Back end support functions.
*/
@@ -79,14 +85,18 @@
}
/* Initialize our td and new ksegrp.. */
newtd = thread_alloc();
- newkg = ksegrp_alloc();
+ if (thr_scope_sys)
+ newkg = ksegrp_alloc();
+ else
+ newkg = kg;
/*
* Try the copyout as soon as we allocate the td so we don't have to
* tear things down in a failure case below.
*/
id = newtd->td_tid;
if ((error = copyout(&id, uap->id, sizeof(long)))) {
- ksegrp_free(newkg);
+ if (thr_scope_sys)
+ ksegrp_free(newkg);
thread_free(newtd);
return (error);
}
@@ -96,10 +106,12 @@
bcopy(&td->td_startcopy, &newtd->td_startcopy,
(unsigned) RANGEOF(struct thread, td_startcopy, td_endcopy));
- bzero(&newkg->kg_startzero,
- (unsigned) RANGEOF(struct ksegrp, kg_startzero, kg_endzero));
- bcopy(&kg->kg_startcopy, &newkg->kg_startcopy,
- (unsigned) RANGEOF(struct ksegrp, kg_startcopy, kg_endcopy));
+ if (thr_scope_sys) {
+ bzero(&newkg->kg_startzero,
+ (unsigned)RANGEOF(struct ksegrp, kg_startzero, kg_endzero));
+ bcopy(&kg->kg_startcopy, &newkg->kg_startcopy,
+ (unsigned)RANGEOF(struct ksegrp, kg_startcopy, kg_endcopy));
+ }
newtd->td_proc = td->td_proc;
newtd->td_ucred = crhold(td->td_ucred);
@@ -108,7 +120,8 @@
cpu_set_upcall(newtd, td);
error = set_mcontext(newtd, &ctx.uc_mcontext);
if (error != 0) {
- ksegrp_free(newkg);
+ if (thr_scope_sys)
+ ksegrp_free(newkg);
thread_free(newtd);
crfree(td->td_ucred);
goto out;
@@ -116,18 +129,27 @@
/* Link the thread and kse into the ksegrp and make it runnable. */
PROC_LOCK(td->td_proc);
+ if (thr_scope_sys) {
+ sched_init_concurrency(newkg);
+ } else {
+ if ((td->td_proc->p_flag & P_HADTHREADS) == 0) {
+ sched_set_concurrency(kg, mp_ncpus);
+ }
+ }
+
td->td_proc->p_flag |= P_HADTHREADS;
newtd->td_sigmask = td->td_sigmask;
mtx_lock_spin(&sched_lock);
- ksegrp_link(newkg, p);
+ if (thr_scope_sys)
+ ksegrp_link(newkg, p);
thread_link(newtd, newkg);
mtx_unlock_spin(&sched_lock);
PROC_UNLOCK(p);
- sched_init_concurrency(newkg);
/* let the scheduler know about these things. */
mtx_lock_spin(&sched_lock);
- sched_fork_ksegrp(td, newkg);
+ if (thr_scope_sys)
+ sched_fork_ksegrp(td, newkg);
sched_fork_thread(td, newtd);
TD_SET_CAN_RUN(newtd);
More information about the p4-projects
mailing list