From owner-freebsd-arch@FreeBSD.ORG Sat Nov 24 15:21:14 2012 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A14ECABB for ; Sat, 24 Nov 2012 15:21:14 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id 1F6048FC0C for ; Sat, 24 Nov 2012 15:21:13 +0000 (UTC) Received: by mail-la0-f54.google.com with SMTP id j13so9450410lah.13 for ; Sat, 24 Nov 2012 07:21:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=To96R4aSVBHzHYgz1Gs1r1rsOXAj3/gcAdLrbUCdQ1c=; b=HPfXBzP5b1k04Aa3qX2XJUfDI3sAiUg2pPRtvvdS5lurmpp+0oyolUu+3i5YFT/lf1 guCEB51eedoa7YAS+Qtyy5NJwNOkKGTKk4cNG/WGs9qVutqFHWEXbD5Dqh5w0MD29Lo5 MWmzhxqrK6vGSNpojOGeTXjuiKKwKitUpubwYWArmNNuh/3/AKRjUwskiQqGubGewTVM GP1s4zguX7hfPmdAB66qubQXDb+DUBvdh49aqkKyKv7+FmtArvCNieUeTjBTJPmS4npX V7X2rK9NXKPYi4Ov1Tpm2zqhaosliEJlvmZyQT+vy7mdzCsTL9atxEO1Im7/F75f2DTi K+MA== MIME-Version: 1.0 Received: by 10.112.87.40 with SMTP id u8mr3036585lbz.50.1353770472717; Sat, 24 Nov 2012 07:21:12 -0800 (PST) Sender: asmrookie@gmail.com Received: by 10.112.134.5 with HTTP; Sat, 24 Nov 2012 07:21:12 -0800 (PST) In-Reply-To: References: Date: Sat, 24 Nov 2012 15:21:12 +0000 X-Google-Sender-Auth: sER0tlWPXETrFZSFO04Cvx9avXU Message-ID: Subject: Re: [RFC] sema_wait_sig From: Attilio Rao To: Oleksandr Tymoshenko Content-Type: text/plain; charset=UTF-8 Cc: arch@freebsd.org X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: attilio@FreeBSD.org List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Nov 2012 15:21:14 -0000 On Sat, Nov 24, 2012 at 3:03 PM, Attilio Rao wrote: > On Fri, Nov 23, 2012 at 6:12 AM, Oleksandr Tymoshenko > wrote: >> Hello, >> >> Is there any particular reason FreeBSD does not have sema_wait_sig >> function? It seems to be easily implementable using cv_wait_sig >> function. > > The sema(9) primitive is considered obsolete/dying. > You should really use mtx + condvar (so just go using cv_wait_sig() directly). > > I had a patch to remove it all from the kernel few years ago but I > never got to commit it. > It would be good if we can remove this primitive off before 10.0. Before to start receiving bikeshead e-mails by "savers of the nation", let me explain this a bit. This cames directly from the necessity to shrunk the number of locking primitives we offer, in particular when such primitives have very naive/non-standard interface, meant as dangerous and not intuitive KPI. The biggest 2 beasts to chase are then sema(9) and lockmgr(9). The former should be replaced by a smart use of mtx + flags/counters + sleep(9)/condvar(9). I see some of the usage are the ones that want the first locker to sleep (counter as 0 at init time), for example. The latter should be replaced by sx(9) interface, but that's very tricky. lockmgr have a lot of strange patterns which require a fair bit of understanding and work to be controlled (LK_DRAIN, LK_SLEEPFAIL, interlock handling, lockmgr_disown(), etc.). I'm sure sx might grow up some further operations to cope with it (namely the interlock and maybe disowning) but that's really minor turbolence as removing redundant lockmgr would be a big win for us. Right now it is just a burden and more code to maintain for a very little gain. As a last item, we may also look at splitting the sleep-mtx and spin-mtx interface and replace all the occurence of the former with rwlocks, of course always held in write mode. This way the mtx(9) will only serve spinlocks and their implementation will be very self contained. Thanks, Attilio -- Peace can only be achieved by understanding - A. Einstein