Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2121449yba; Fri, 19 Apr 2019 12:33:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqw0SepAQXWCj3MkpSJAF9zLAZMXZAHJZNMaz9jBjHZtJHlq8EvvrBcrBIQwKGLKre4Y6ZKf X-Received: by 2002:a17:902:2ec5:: with SMTP id r63mr5597796plb.139.1555702398401; Fri, 19 Apr 2019 12:33:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555702398; cv=none; d=google.com; s=arc-20160816; b=dlg3lqhcwDXZVqEjk4tbiBDa0A/vn20ygX4bqZakiFRq/uG9LsLb/uzGQrUX0XgrKF OF+kIc7lIL7tdSVEwKZH9GXjBq+fdxdUq1qKfsfJwptsHkT4Sur51pGcFIrUrEo41deR FeDGzVgE/g2oeUbpOsyEQmXA6Fm59kXfsLaJrgb9cebmjbdczbVVoK7BWyxdrgJMhzEo 7D9pdY1y9fwh2J5WWoLbEYi0iQLEhL2j41dK1jqO5fOX3a+/oTpdqEfVfPdhEHwbT+Lc OgA/6FqveXIurJvEY07hHZltdGzhsU5tJADapHxpqRftnqJCSBlZ7xoAwSTtw8dAnl0r PHLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=HeRWp3SbhYmoU91Lf8c1z2p2ddTb4bDbJKsU2tWCahE=; b=WM2Q6Ha5GRBW8Go/g46qQPssqoxVkPJszZQNlGAq9CpIV1BF3YvGK/KjdcIvIx02nt zX+snOtIa0VrwOrBBFzQOj/PhXQ7kMY9zyk0xKDKxrn6NhYkelTqoDYKx8Cmu8f4mhpH V87jwuBbsGHgqZ1xv8RXBZ0p7HNDON5ZXUbvCZCn/O+dYCaeSppuWRrWjeBZzl5X2EDx j9s4Nig4lNS7RlSSd3KxycOWz7fNTE5Kys3H0QfmiM0171b4EQ56qrvAjqQZF8ztTeZU vE5ayyHj3frgdeNtgNjFd9Yz78KAYovrU0qqLZpTBsaZbSD0X06m+Kl1/L4xKgiM0qqT T3Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=tkSMhpou; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a36si5546178pgb.165.2019.04.19.12.33.02; Fri, 19 Apr 2019 12:33:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=tkSMhpou; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727974AbfDSTa4 (ORCPT + 99 others); Fri, 19 Apr 2019 15:30:56 -0400 Received: from merlin.infradead.org ([205.233.59.134]:52654 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726331AbfDSTa4 (ORCPT ); Fri, 19 Apr 2019 15:30:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=HeRWp3SbhYmoU91Lf8c1z2p2ddTb4bDbJKsU2tWCahE=; b=tkSMhpoum3YIfOBi7tKJVq9Yx UMuKJJUDWogZqua/oD58ODAPZIns9EArjYEoll3EBvu3a4aONaOnIdLDsIhfNRcrHCoC7BIokfxFY ZkoSgDs5IJS6Bk0yZUK2qTP4FIo9RYWAXiq/CLhT1RnQnweIdPjbcswLvoBcrsupCpga2XNUXQQey VpGBgUnXIB9eQA+XQ9wjGzRsSVLb1uByAfkR4TJqVCH1nd9b12r5Te6e0mdk7LxxgRGel2f52Netj gI4Q9j3VO7udHGgAkDDAES8q3p5XRjxm1QhnXTCPIcwKCkO89RDPP5jA4bKEYm0X6cBcLye24hSr4 l+ik22GoA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hHONZ-0004Rd-GR; Fri, 19 Apr 2019 07:56:14 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 7A61329B52926; Fri, 19 Apr 2019 09:56:10 +0200 (CEST) Date: Fri, 19 Apr 2019 09:56:10 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , Will Deacon , Thomas Gleixner , linux-kernel@vger.kernel.org, x86@kernel.org, Davidlohr Bueso , Linus Torvalds , Tim Chen , huang ying Subject: Re: [PATCH v4 12/16] locking/rwsem: Enable time-based spinning on reader-owned rwsem Message-ID: <20190419075610.GN4038@hirez.programming.kicks-ass.net> References: <20190413172259.2740-1-longman@redhat.com> <20190413172259.2740-13-longman@redhat.com> <20190418130611.GK4038@hirez.programming.kicks-ass.net> <52aee7c3-b8aa-a617-c1f2-34bc99c72474@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <52aee7c3-b8aa-a617-c1f2-34bc99c72474@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 18, 2019 at 11:15:33AM -0400, Waiman Long wrote: > On 04/18/2019 09:06 AM, Peter Zijlstra wrote: > >> + /* > >> + * Check time threshold every 16 iterations to > >> + * avoid calling sched_clock() too frequently. > >> + * This will make the actual spinning time a > >> + * bit more than that specified in the threshold. > >> + */ > >> + else if (!(++loop & 0xf) && > >> + (sched_clock() > rspin_threshold)) { > > Why is calling sched_clock() lots a problem? > > Actually I am more concern about the latency introduced by the > sched_clock() call. BTW, I haven't done any measurement myself. Do you > know how much cost the sched_clock() call is? > > If the cost is relatively high, the average latency period after the > lock is free and the spinner is ready to do a trylock will increase. Totally depends on the arch or course :/ For 'sane' x86 it is: RDTSC, MUL; SHRD; SHR; ADD, which is plenty fast. I know we have poll loops with sched_clock/local_clock in them, I just can't seem to find any atm.