From owner-freebsd-hackers@FreeBSD.ORG Tue Feb 23 19:12:21 2010 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 831B21065676 for ; Tue, 23 Feb 2010 19:12:21 +0000 (UTC) (envelope-from julian@elischer.org) Received: from out-0.mx.aerioconnect.net (out-0-9.mx.aerioconnect.net [216.240.47.69]) by mx1.freebsd.org (Postfix) with ESMTP id 671438FC1F for ; Tue, 23 Feb 2010 19:12:21 +0000 (UTC) Received: from idiom.com (postfix@mx0.idiom.com [216.240.32.160]) by out-0.mx.aerioconnect.net (8.13.8/8.13.8) with ESMTP id o1NJCKXQ031244; Tue, 23 Feb 2010 11:12:20 -0800 X-Client-Authorized: MaGic Cook1e X-Client-Authorized: MaGic Cook1e X-Client-Authorized: MaGic Cook1e Received: from julian-mac.elischer.org (h-67-100-89-137.snfccasy.static.covad.net [67.100.89.137]) by idiom.com (Postfix) with ESMTP id 4ABA92D6019; Tue, 23 Feb 2010 11:12:20 -0800 (PST) Message-ID: <4B8428C7.8010705@elischer.org> Date: Tue, 23 Feb 2010 11:13:11 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.23 (Macintosh/20090812) MIME-Version: 1.0 To: Shrivatsan References: <986041.3700.qm@web112005.mail.gq1.yahoo.com> In-Reply-To: <986041.3700.qm@web112005.mail.gq1.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.67 on 216.240.47.51 Cc: freebsd-hackers@FreeBSD.org, shrivatsan@gmail.com Subject: Re: sched_lock mutex and sleepq_wait X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Feb 2010 19:12:21 -0000 Shrivatsan wrote: > Hi, > > I am trying to understand how msleep() routine suspends the currently > executing thread. I see that msleep() calls sleepq_wait(). > > What I don't understand here is the way in which sched_lock mutex is > handled. > > I took the following snippet from FreeBSD 6: > > sleepq_wait(void *wchan) > { > MPASS(!(curthread->td_flags & TDF_SINTR)); > mtx_lock_spin(&sched_lock); > sleepq_switch(wchan); ----we sleep here----- some other thread runs, When it wakes up it magicall owns the schedlock which it releases. then it sleeps and locks schedlock again.A ----- we get run.. magically the schedlock is changed so that we own it. now we return, maybe 5 minutes later and must free it. > mtx_unlock_spin(&sched_lock); > } > > sched_lock mutex is held, and sleepq_switch() eventually calls > cpu_switch() which switches to a new thread. > > I don't exactly understand when the sched_lock mutex is released. > > Can someone please help me? > > Thanks, > -shrivatsan > > > > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"