From owner-freebsd-hackers@FreeBSD.ORG Tue Jan 31 11:50:10 2012 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 B87791065670; Tue, 31 Jan 2012 11:50:10 +0000 (UTC) (envelope-from dmitry.krivenok@emc.com) Received: from mexforward.lss.emc.com (mexforward.lss.emc.com [128.222.32.20]) by mx1.freebsd.org (Postfix) with ESMTP id 6C02D8FC15; Tue, 31 Jan 2012 11:50:09 +0000 (UTC) Received: from hop04-l1d11-si03.isus.emc.com (HOP04-L1D11-SI03.isus.emc.com [10.254.111.23]) by mexforward.lss.emc.com (Switch-3.4.3/Switch-3.4.3) with ESMTP id q0VBZTnS008545 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 31 Jan 2012 06:35:29 -0500 Received: from mailhub.lss.emc.com (mailhub.lss.emc.com [10.254.222.226]) by hop04-l1d11-si03.isus.emc.com (RSA Interceptor); Tue, 31 Jan 2012 06:35:11 -0500 Received: from mxhub32.corp.emc.com (mxhub32.corp.emc.com [128.222.70.172]) by mailhub.lss.emc.com (Switch-3.4.3/Switch-3.4.3) with ESMTP id q0VBZAfj020058; Tue, 31 Jan 2012 06:35:11 -0500 Received: from mx19a.corp.emc.com ([169.254.1.78]) by mxhub32.corp.emc.com ([128.222.70.172]) with mapi; Tue, 31 Jan 2012 06:35:10 -0500 From: To: Date: Tue, 31 Jan 2012 06:35:08 -0500 Thread-Topic: mtx_trylock() on a spin mutex Thread-Index: AczgDGJ5vIba+6zzTaS8HmtVqYBAVg== Message-ID: <9C7BACB01B839A499792154E76C9ADE5563FDD39ED@MX19A.corp.emc.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-EMM-MHVC: 1 X-Mailman-Approved-At: Tue, 31 Jan 2012 12:11:30 +0000 Cc: Subject: mtx_trylock() on a spin mutex 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, 31 Jan 2012 11:50:10 -0000 Hello, Could someone please explain why mtx_trylock() must not be called on a spin= mutex? Is it conceptually wrong or is it a restriction of FreeBSD kernel implement= ation? I've written slightly modified version of mtx_trylock (mtx_trylock_spin) wh= ich calls=20 spinlock_enter/spinlock_exit and doesn't have KASSERT checking for lock cla= ss: KASSERT(m->mtx_object.lo_class =3D=3D &lock_class_mtx_sleep, ("mtx_trylock() of spin mutex %s @ %s:%d", m->mtx_object.= lo_name, file, line)); but, to my surprise, all my tests passed w/o any errors/warnings on FreeBSD= -8 with WITNESS/INVARIANTS/etc enabled. I admit that my tests may not cover all possible use cases or scenarios tho= ugh. I did a quick google search but didn't find anything useful, so your help i= s greatly appreciated. Thanks in advance! P.S. The assertion was added in the following revision: Revision 149737 - (view) (annotate) - [select for diffs]=20 Modified Fri Sep 2 20:21:49 2005 UTC (6 years, 4 months ago) by jhb=20 File length: 24623 byte(s)=20 Diff to previous 148557=20 - Add an assertion to panic if one tries to call mtx_trylock() on a spin mutex. - Don't panic if a spin lock is held too long inside _mtx_lock_spin() if panicstr is set (meaning that we are already in a panic). Just keep spinning forever instead.