From owner-freebsd-current@freebsd.org Mon Aug 1 20:08:49 2016 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4A9B0BAA1AB for ; Mon, 1 Aug 2016 20:08:49 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D141C160A; Mon, 1 Aug 2016 20:08:48 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-wm0-x241.google.com with SMTP id x83so27651099wma.3; Mon, 01 Aug 2016 13:08:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=/CNRVVYSM8FHt3YsnHme0b0vk1VNCE8uoo9m5mllkt8=; b=HugIoeJ7/3KaPGqaEAVHte+uZ7iDL8nfqFgZubdCrO/MObaFTVrR/363zLZuUphdO0 07NnI0DOgmZL1Rd4lE6TPYbUulLxhXzVjzCgXwXyXTn31BFsFoRYd4cQLoexHakBTX5e GZOec4RUXfQf+2hXrHGAIdClIUUmyaxXl4ObmdGIhjZtIhsS70x3/RNWtH8ozmsEZNmQ B55KbiVYRX4BtlHFeShPuppcfNdGgTGzQm6++H6+aOndZ0hqQCjwyJ4zAgeDYIdPRi3Z iAcvRwYT2dJD+BX3264+TuR4Fjt8jez3sfReVyMmk9ADW/sCBz1NNCHE2OnqmhmAc2Mt HSrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=/CNRVVYSM8FHt3YsnHme0b0vk1VNCE8uoo9m5mllkt8=; b=e+dMxN2PW0QHtw6ramAcIupgNNT9tFD61aBR/BAFXHNBLdSgJTr73f5ovGdVzIj0Eo Xahf5ZV5112hkbsJ7QpZe0QRX2cpD4LlPHuu2WeRfB8r2qpzEgj4tMhTKXxX1vvpGm8S Alby4d8KRvHpHpaeOyS25dyUGF7qLjxBjFWcSHFsAaz5dQGY8IO/rXPqvDcGi1aWUYd2 eo0jYcLnWFa2PU27bUzR0+Q2lzsHF4wOEH4duJwRTs1ABPJFXKhcgLw7TJckeZ78eDsN rxNCaOv+cw4pTrdukq2L7p+AvResMs1iHA2FjqjhvhXX5ePWkbfCe3B/odCSX9xKX+Yx jCYQ== X-Gm-Message-State: AEkoouvZFKflvbgyUhfF5VLP7/mouLMqitVwHFCzWpFEr83OHAubiWCUoHSPHcmikF1zew== X-Received: by 10.194.48.39 with SMTP id i7mr58192906wjn.173.1470082126483; Mon, 01 Aug 2016 13:08:46 -0700 (PDT) Received: from dft-labs.eu (n1x0n-1-pt.tunnel.tserv5.lon1.ipv6.he.net. [2001:470:1f08:1f7::2]) by smtp.gmail.com with ESMTPSA id r127sm18537632wmf.23.2016.08.01.13.08.44 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 01 Aug 2016 13:08:45 -0700 (PDT) Date: Mon, 1 Aug 2016 22:08:43 +0200 From: Mateusz Guzik To: John Baldwin Cc: Konstantin Belousov , freebsd-current@freebsd.org Subject: Re: [PATCH] randomized delay in locking primitives, take 2 Message-ID: <20160801200842.GC24633@dft-labs.eu> Mail-Followup-To: Mateusz Guzik , John Baldwin , Konstantin Belousov , freebsd-current@freebsd.org References: <20160731095706.GB9408@dft-labs.eu> <20160731104928.GW83214@kib.kiev.ua> <20160731124113.GE9408@dft-labs.eu> <15005477.9uZ5EJCdhW@ralph.baldwin.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <15005477.9uZ5EJCdhW@ralph.baldwin.cx> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Aug 2016 20:08:49 -0000 On Mon, Aug 01, 2016 at 11:37:50AM -0700, John Baldwin wrote: > On Sunday, July 31, 2016 02:41:13 PM Mateusz Guzik wrote: > > On Sun, Jul 31, 2016 at 01:49:28PM +0300, Konstantin Belousov wrote: > > [snip] > > > > After an irc discussion, the following was produced (also available at: > > https://people.freebsd.org/~mjg/lock_backoff_complete4.diff): > > > > Differences: > > - uint64_t usage was converted to u_int (also see r303584) > > - currently unused features (cap limit and return value) were removed > > - lock_delay args got packed into a dedicated structure > > lock_delay_enabled declaration seems to be stale? > Oops, thanks. > I would maybe just provide a "standard" lock_delay_init function that the > sysinit's use rather than duplicating the same exact code 3 times. I'm > not sure we really want to use different tunables for different lock types > anyway. (Alternatively we could even just have a single 'config' variable > that is a global. We can always revisit this in the future if we find that > we need that granularity, but it would remove an extra pointer indirection > if you just had a single 'lock_delay_config' that was exported as a global > for now and initialized in a single SYSINIT.) > The per-lock type config is partially an artifact of the real version of the patch which has different configs per state of the lock, see loops with rowner_loops in the current implementation of rw and sx locks and this is were it mattered. It was cut off from this patch for simplicity (90% of the benefit for 10% of the work). That said, fine tuned it does matter for "mere" spinning as well but here I put very low values on purpose. Putting them all in one config makes for a small compatibility issue, where debug.lock.delay_* sysctls would disappear later. So I would prefer to just keep this as I don't think it matters much. I have further optimisation to primitives not related to spinning. They boil down to the fact that KDTRACE_HOOKS-enabled kernels contain an unconditional function call to lockstat_nsecs even with the lock held. > I think the idea is fine. I'm less worried about the overhead of the > divide as you are only doing it when you are contesting (so you are already > sort of hosed anyway). Long delays in checking the lock cookie can be > bad (see my local APIC snafu which only polled once per microsecond). I > don't really think a divide is going to be that long? > This should be perfectly fine. One could argue the time wasted should be wasted efficiently, i.e. the more cpu_spinwait, the better, at least on amd64. -- Mateusz Guzik