From owner-p4-projects Fri May 10 13:24:25 2002 Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 8D2B337B400; Fri, 10 May 2002 13:24:03 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from smtp.enternet.hu (smtp.enternet.hu [62.112.192.21]) by hub.freebsd.org (Postfix) with ESMTP id D346B37B406; Fri, 10 May 2002 13:24:01 -0700 (PDT) Received: from elischer.org (3e70d297.dialin.enternet.hu [62.112.210.151]) by smtp.enternet.hu (8.11.6/8.11.6) with ESMTP id g4AKLwr59571; Fri, 10 May 2002 22:21:58 +0200 (CEST) (envelope-from julian@elischer.org) Message-ID: <3CDC2BB5.366A7BF0@elischer.org> Date: Fri, 10 May 2002 13:21:09 -0700 From: Julian Elischer X-Mailer: Mozilla 4.7 [en] (X11; U; FreeBSD 5.0-CURRENT i386) X-Accept-Language: en, hu MIME-Version: 1.0 To: Jonathan Mini Cc: Perforce Change Reviews Subject: Re: PERFORCE change 11120 for review References: <200205101530.g4AFUn510685@freefall.freebsd.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-p4-projects@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Jonathan Mini wrote: > > http://people.freebsd.org/~peter/p4db/chv.cgi?CH=11120 > > Change 11120 by mini@mini_stylus on 2002/05/10 08:30:36 > > Give UMA control over thread allocation and caching: > > - Use uma init/fini/ctor/dtor functions. good > - Instead of keeping a PCPU list of zombie threads to be > reaped at earliest convenvience, keep a single "spare" > thread in the KSE. clever.. not sure it isn't too clever.. but looks good. > - When abandoning a thread (in thread_exit()), push the > thread into its KSE's spare thread slot, and free the > thread that is already there (if any). I assume there will only be a spare thread at other times in KSE type processes. > - When performing an upcall, pull the spare thread (if > available) before allocating a new thread from uma. This > is especially useful in msleep(), where not blocking again > is highly preferable. > - When pulling the KSE spare thread, allocate a new spare > thread for the KSE before returning to userland for the > upcall. I presume only for KSE mode processes. i.e. for KSE mode processes there is always a spare thread available unless we have just used it and have not yet returned to userland. I can see some holes may need patching but should work.. > > + /* Reassign this thread's KSE. */ > + if (ke != NULL) { > + ke->ke_thread = NULL; WHOA! just because ke == td->td_kse doesn't mean that ke->ke_thread == td UNLESS you can guarantee that thread unlink is always run with td == curthread or td->td_state == TDS_RUNNING. > + td->td_kse = NULL; > + ke->ke_state = KES_UNQUEUED; > + kse_reassign(ke); > + } > > - /* put the thread back in the zone */ > - uma_zfree(thread_zone, td); > + /* Unlink this thread from its proc. */ > + if (p != NULL) { > + TAILQ_REMOVE(&p->p_threads, td, td_plist); > + if (kg != NULL) > + TAILQ_REMOVE(&kg->kg_threads, td, td_kglist); > + p->p_numthreads--; what of the kg->kg_numthreads.. > + if (P_SHOULDSTOP(p) == P_STOPPED_SNGL) { > + if (p->p_numthreads == > + ((p->p_flag & P_SINGLE_EXIT) ? 1 : (p->p_suspcount + 1))) { > + setrunqueue(p->p_singlethread); > + p->p_singlethread = NULL; > + } > + } > } > + if (kg != NULL) > + kg->kg_numthreads--; move this up? > + td->td_state = TDS_SURPLUS; > + td->td_proc = NULL; > + td->td_ksegrp = NULL; > + td->td_last_kse = NULL; > +} > + > +/* > + * Initialize global thread allocation resources. > + */ > +void > +threadinit(void) > +{ > + > + thread_zone = uma_zcreate("THREAD", sizeof (struct thread), > + thread_ctor, thread_dtor, thread_init, thread_fini, > + UMA_ALIGN_CACHE, 0); > } > plus other comments already noted by others.. (tabbing and sleeping with locks) -- +------------------------------------+ ______ _ __ | __--_|\ Julian Elischer | \ U \/ / hard at work in | / \ julian@elischer.org +------>x USA \ a very strange | ( OZ ) \___ ___ | country ! +- X_.---._/ presently in San Francisco \_/ \\ v To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message