Date: Thu, 10 Mar 2005 07:28:17 GMT From: David Xu <davidxu@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 72822 for review Message-ID: <200503100728.j2A7SHD9013297@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=72822 Change 72822 by davidxu@davidxu_celeron on 2005/03/10 07:27:44 * Rename thr_scope_sys to thr_scope, values: 0: respect user request. 1: force to create process scope thread. 2: force to create system scope thread. * Carefully initialize new ksegrp's concurrent level and link it into process Affected files ... .. //depot/projects/davidxu_thread/src/sys/kern/kern_thr.c#9 edit Differences ... ==== //depot/projects/davidxu_thread/src/sys/kern/kern_thr.c#9 (text+ko) ==== @@ -49,9 +49,9 @@ extern int max_groups_per_proc; SYSCTL_DECL(_kern_threads); -static int thr_scope_sys = 0; -SYSCTL_INT(_kern_threads, OID_AUTO, thr_scope_sys, CTLFLAG_RW, - &thr_scope_sys, 0, "sys or proc scope scheduling"); +static int thr_scope = 0; +SYSCTL_INT(_kern_threads, OID_AUTO, thr_scope, CTLFLAG_RW, + &thr_scope, 0, "sys or proc scope scheduling"); static int thr_concurrency = 0; SYSCTL_INT(_kern_threads, OID_AUTO, thr_concurrency, CTLFLAG_RW, @@ -70,20 +70,25 @@ int error; struct ksegrp *kg, *newkg; struct proc *p; - int scope_sys; + int scope_sys, linkkg; p = td->td_proc; kg = td->td_ksegrp; if ((error = copyin(uap->ctx, &ctx, sizeof(ctx)))) return (error); - /* Have race condition but it is cheap */ + /* Have race condition but it is cheap. */ if ((p->p_numksegrps >= max_groups_per_proc) || (p->p_numthreads >= max_threads_per_proc)) { return (EPROCLIM); } scope_sys = (uap->flags & THR_SYSTEM_SCOPE) != 0; + if (thr_scope == 1) + scope_sys = 0; + else if (thr_scope == 2) + scope_sys = 1; + /* Initialize our td and new ksegrp.. */ newtd = thread_alloc(); @@ -112,15 +117,23 @@ goto out; } - if ((td->td_proc->p_flag & P_HADTHREADS) == 0) + if ((td->td_proc->p_flag & P_HADTHREADS) == 0) { p->p_procscopegrp = kg; - + mtx_lock_spin(&sched_lock); + sched_set_concurrency(kg, + thr_concurrency ? thr_concurrency : (2*mp_ncpus)); + mtx_unlock_spin(&sched_lock); + } + + linkkg = 0; if (scope_sys) { + linkkg = 1; newkg = ksegrp_alloc(); bzero(&newkg->kg_startzero, __rangeof(struct ksegrp, kg_startzero, kg_endzero)); bcopy(&kg->kg_startcopy, &newkg->kg_startcopy, __rangeof(struct ksegrp, kg_startcopy, kg_endcopy)); + sched_init_concurrency(newkg); PROC_LOCK(td->td_proc); } else { retry: @@ -133,9 +146,13 @@ bcopy(&kg->kg_startcopy, &newkg->kg_startcopy, __rangeof(struct ksegrp, kg_startcopy, kg_endcopy)); PROC_LOCK(p); - if (p->p_procscopegrp == NULL) + if (p->p_procscopegrp == NULL) { p->p_procscopegrp = newkg; - else { + sched_init_concurrency(newkg); + sched_set_concurrency(kg, + thr_concurrency ? thr_concurrency : (2*mp_ncpus)); + linkkg = 1; + } else { PROC_UNLOCK(p); ksegrp_free(newkg); goto retry; @@ -143,35 +160,21 @@ } } - /* Link the thread and kse into the ksegrp and make it runnable. */ - if (scope_sys) { - sched_init_concurrency(newkg); - } else { - if ((td->td_proc->p_flag & P_HADTHREADS) == 0) { - sched_set_concurrency(newkg, - thr_concurrency ? thr_concurrency : (2*mp_ncpus)); - } - } - td->td_proc->p_flag |= P_HADTHREADS; newtd->td_sigmask = td->td_sigmask; mtx_lock_spin(&sched_lock); - if (scope_sys) + if (linkkg) { ksegrp_link(newkg, p); + sched_fork_ksegrp(td, newkg); + } thread_link(newtd, newkg); - mtx_unlock_spin(&sched_lock); PROC_UNLOCK(p); /* let the scheduler know about these things. */ - mtx_lock_spin(&sched_lock); - if (scope_sys) - sched_fork_ksegrp(td, newkg); sched_fork_thread(td, newtd); - TD_SET_CAN_RUN(newtd); if ((uap->flags & THR_SUSPENDED) == 0) setrunqueue(newtd, SRQ_BORING); - mtx_unlock_spin(&sched_lock); out: @@ -208,7 +211,6 @@ SIGFILLSET(td->td_siglist); sigrepost(td); mtx_lock_spin(&sched_lock); - /* * Shutting down last thread in the proc. This will actually * call exit() in the trampoline when it returns.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200503100728.j2A7SHD9013297>