From owner-p4-projects@FreeBSD.ORG Thu Mar 10 07:28:18 2005 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 70EFA16A4D0; Thu, 10 Mar 2005 07:28:18 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2E2F416A4CE for ; Thu, 10 Mar 2005 07:28:18 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0432743D55 for ; Thu, 10 Mar 2005 07:28:18 +0000 (GMT) (envelope-from davidxu@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j2A7SHCn013301 for ; Thu, 10 Mar 2005 07:28:17 GMT (envelope-from davidxu@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j2A7SHD9013297 for perforce@freebsd.org; Thu, 10 Mar 2005 07:28:17 GMT (envelope-from davidxu@freebsd.org) Date: Thu, 10 Mar 2005 07:28:17 GMT Message-Id: <200503100728.j2A7SHD9013297@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to davidxu@freebsd.org using -f From: David Xu To: Perforce Change Reviews Subject: PERFORCE change 72822 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Mar 2005 07:28:19 -0000 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.