From owner-svn-src-head@FreeBSD.ORG Mon Dec 14 17:02:56 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 49ED81065670; Mon, 14 Dec 2009 17:02:56 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from mail-fx0-f228.google.com (mail-fx0-f228.google.com [209.85.220.228]) by mx1.freebsd.org (Postfix) with ESMTP id 579168FC0C; Mon, 14 Dec 2009 17:02:54 +0000 (UTC) Received: by fxm28 with SMTP id 28so1564120fxm.13 for ; Mon, 14 Dec 2009 09:02:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=W2xRpXMey+cd37jIZyWYza8uUQCBzPYZBhEfk5ymopQ=; b=wEtbrsBPbgokXHcIE85NHiCJgBO6Pgj5Ij0d3PCZadyw92ZW5DQMArBxu5lPe7o6jT hLXY2L88HumZrCXtgOY/4hj7AkjY3sn54lz5anK6Tv83QAVxnJRjBlYDIz4nrDsW+G6C YirgV/izcy7eqGX5dDByzewFyhid6+vJ5qdAA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=MxVBbD8sp5+pEhAIHahXpB5TxpbU8vfwrKzkJ5hYtNWnv9mX+b5fREkYNTdSt2pqFs JdPPFc3nOD+YT/PCe/MVcG9CspRNEIqAUAu0+/buaypGnpr7h8+e/613gDnkK6xLIpLV bWXL/lVoBiM0FlRjhfgfaEdp12JMdVUcu7LYg= MIME-Version: 1.0 Sender: asmrookie@gmail.com Received: by 10.223.29.193 with SMTP id r1mr475972fac.29.1260810174202; Mon, 14 Dec 2009 09:02:54 -0800 (PST) In-Reply-To: <200912141013.32839.jhb@freebsd.org> References: <200912122131.nBCLV71f064304@svn.freebsd.org> <200912141013.32839.jhb@freebsd.org> Date: Mon, 14 Dec 2009 18:02:54 +0100 X-Google-Sender-Auth: f0750340a242f4b8 Message-ID: <3bbf2fe10912140902m407fa766q3a5e5bb6993723f9@mail.gmail.com> From: Attilio Rao To: John Baldwin Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r200447 - in head: share/man/man9 sys/kern sys/sys X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Dec 2009 17:02:56 -0000 2009/12/14 John Baldwin : > On Saturday 12 December 2009 4:31:07 pm Attilio Rao wrote: >> Author: attilio >> Date: Sat Dec 12 21:31:07 2009 >> New Revision: 200447 >> URL: http://svn.freebsd.org/changeset/base/200447 >> >> Log: >> =C2=A0 In current code, threads performing an interruptible sleep (on bo= th >> =C2=A0 sxlock, via the sx_{s, x}lock_sig() interface, or plain lockmgr),= will >> =C2=A0 leave the waiters flag on forcing the owner to do a wakeup even w= hen if >> =C2=A0 the waiter queue is empty. >> =C2=A0 That operation may lead to a deadlock in the case of doing a fake= wakeup >> =C2=A0 on the "preferred" (based on the wakeup algorithm) queue while th= e other >> =C2=A0 queue has real waiters on it, because nobody is going to wakeup t= he 2nd >> =C2=A0 queue waiters and they will sleep indefinitively. >> >> =C2=A0 A similar bug, is present, for lockmgr in the case the waiters ar= e >> =C2=A0 sleeping with LK_SLEEPFAIL on. =C2=A0In this case, even if the wa= iters queue >> =C2=A0 is not empty, the waiters won't progress after being awake but th= ey will >> =C2=A0 just fail, still not taking care of the 2nd queue waiters (as ins= tead the >> =C2=A0 lock owned doing the wakeup would expect). >> >> =C2=A0 In order to fix this bug in a cheap way (without adding too much = locking >> =C2=A0 and complicating too much the semantic) add a sleepqueue interfac= e which >> =C2=A0 does report the actual number of waiters on a specified queue of = a >> =C2=A0 waitchannel (sleepq_sleepcnt()) and use it in order to determine = if the >> =C2=A0 exclusive waiters (or shared waiters) are actually present on the= lockmgr >> =C2=A0 (or sx) before to give them precedence in the wakeup algorithm. >> =C2=A0 This fix alone, however doesn't solve the LK_SLEEPFAIL bug. In or= der to >> =C2=A0 cope with it, add the tracking of how many exclusive LK_SLEEPFAIL= waiters >> =C2=A0 a lockmgr has and if all the waiters on the exclusive waiters que= ue are >> =C2=A0 LK_SLEEPFAIL just wake both queues. >> >> =C2=A0 The sleepq_sleepcnt() introduction and ABI breakage require >> =C2=A0 __FreeBSD_version bumping. > > Hmm, do you need an actual count of waiters or would a 'sleepq_empty()' > (similar to turnstile_empty()) method be sufficient? I need the count in order to fix properly LK_SLEEPFAIL case (the idea is: track exclusive waiters with LK_SLEEPFAIL on; if the number is equal to the actual sleepers on the queue then wake up both queues, otherwise nobody is going to take care of the shared waiters queue). Attilio --=20 Peace can only be achieved by understanding - A. Einstein