From owner-p4-projects Tue Jun 4 15:11:12 2002 Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id DDD9737B40E; Tue, 4 Jun 2002 15:10:33 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mail.speakeasy.net (mail12.speakeasy.net [216.254.0.212]) by hub.freebsd.org (Postfix) with ESMTP id EE12937B412 for ; Tue, 4 Jun 2002 15:09:46 -0700 (PDT) Received: (qmail 19339 invoked from network); 4 Jun 2002 22:09:43 -0000 Received: from unknown (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender ) by mail12.speakeasy.net (qmail-ldap-1.03) with DES-CBC3-SHA encrypted SMTP for ; 4 Jun 2002 22:09:43 -0000 Received: from laptop.baldwin.cx (gw1.twc.weather.com [216.133.140.1]) by server.baldwin.cx (8.11.6/8.11.6) with ESMTP id g54M9fF54603; Tue, 4 Jun 2002 18:09:41 -0400 (EDT) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.5.2 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: Date: Tue, 04 Jun 2002 18:09:36 -0400 (EDT) From: John Baldwin To: Julian Elischer Subject: Re: PERFORCE change 12362 for review Cc: Perforce Change Reviews 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 On 04-Jun-2002 Julian Elischer wrote: > > > On Tue, 4 Jun 2002, John Baldwin wrote: > >> http://people.freebsd.org/~peter/p4db/chv.cgi?CH=12362 >> >> Change 12362 by jhb@jhb_laptop on 2002/06/04 10:45:42 >> >> - Add a thread_runnable() macro to make some code more readable >> and make the KSE diff easier. >> - Fix the adaptive mutex spin optimization. We need to stop >> spinning not just when mtx_owner(m) changes, but also if the >> owner stops running. >> >> Affected files ... >> >> ... //depot/projects/smpng/sys/kern/kern_mutex.c#36 edit >> >> Differences ... >> >> ==== //depot/projects/smpng/sys/kern/kern_mutex.c#36 (text+ko) ==== >> >> @@ -70,6 +70,9 @@ >> #define mtx_owner(m) (mtx_unowned((m)) ? NULL \ >> : (struct thread *)((m)->mtx_lock & MTX_FLAGMASK)) >> >> +#define thread_runnable(td) \ >> + ((td)->td_kse != NULL && (td)->td_kse->ke_oncpu != NOCPU) >> + > > this actually checks for "thread_running" not "thread_runnable". > Since you are mentioning KSE diffs, in KSE this test is performed by: Duh, good point. I'll fix. > if (td->td_state == TDS_RUNNING) > > and if you want to check for both running and runnable, you need: > > if ((td->td_state == TDS_RUNNING) || (td->td_state == TDS_RUNQ)) > > >> /* >> * Lock classes for sleep and spin mutexes. >> */ >> @@ -129,7 +132,7 @@ >> * If lock holder is actually running, just bump priority. >> */ >> /* XXXKSE this test is not sufficient */ >> - if (td->td_kse && (td->td_kse->ke_oncpu != NOCPU)) { >> + if (thread_runnable(td)) { >> MPASS(td->td_proc->p_stat == SRUN >> || td->td_proc->p_stat == SZOMB >> || td->td_proc->p_stat == SSTOP); >> @@ -531,10 +534,10 @@ >> * CPU, spin instead of blocking. >> */ >> owner = (struct thread *)(v & MTX_FLAGMASK); >> - if (m != &Giant && owner->td_kse != NULL && >> - owner->td_kse->ke_oncpu != NOCPU) { >> + if (m != &Giant && thread_runnable(owner)) { >> mtx_unlock_spin(&sched_lock); >> - while (mtx_owner(m) == owner) { >> + while (mtx_owner(m) == owner && >> + thread_runnable(owner)) { >> #ifdef __i386__ >> ia32_pause(); >> #endif >> > -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message