Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1887868imm; Thu, 11 Oct 2018 01:13:51 -0700 (PDT) X-Google-Smtp-Source: ACcGV61EXGpEiLjD8KXJATgmR+yievWwtOXY2ji0ov+QcQF+e4gfdms3PG6k0ZGn5AX5TheVP1Y/ X-Received: by 2002:a65:5147:: with SMTP id g7-v6mr538615pgq.252.1539245631752; Thu, 11 Oct 2018 01:13:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539245631; cv=none; d=google.com; s=arc-20160816; b=j26R7TUCstPMdOwGw+2CVEonrWQTRq6sYslMf4yTbn3O3RcQX+tjdSHUrbV9E+awMD ODW/fX1ha7smv29L7SbxTCvv46x+ZM4OlBaso4i03Btc9aYRJMgIvNBn8d5i6tdHIKZk UWCTEmzlFlybTPhGQub3ezNzzBz5TWP7VC1bY7d46V2mlBOL3nraHIAe3d2t5UbLoT9x vyLTSbQhIxhCWJVE6R9kSPSzfr2X69IcFqx551RptzyxOPEFih1qJpIDfXOT+pnFDfsE qkDY5wqGvibwDUOOX3rjJ7HsqzGFGN8vfSX/I60exgDkSEXt7z2Ai5OfoSB5FPPneYlW 1GIA== 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=ahBK5zqI2DJ5p1osG+ETUl8gjyom6+IwguNdYgg3iCE=; b=a0kaemyBv5ayG8XOXvEoCaR/uJD4TGJ69MlDV0/CRtyvzlEomyChzdpDTRlsXmR5HR tI8NcDUWk/JBjzfiVWJqbw1tNczl7ae4rv4foIm2DQWlSnyj+AOaZnrJrc4voe1J+XDo F9yL/g2VmR3y8g/SDnG2uLI4SoQPf4+VETPYTHFLhq3WX6F9mvwFR2id2qwoWME7Hgjd emjXM2cloRWxAboZ2ecY+8GLaxuveRBAVCHqyIbgE/qAs/G6saA5BXoWGMf9HKerFvIu qD74QzYVhq5nR6hB258LxVuA2hSKOBOkirAhaSy4KWcUya9xwqW6Gm83YhxXalK6HGU3 cM1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=tFIRynzC; 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 k33-v6si29010608pld.151.2018.10.11.01.13.37; Thu, 11 Oct 2018 01:13:51 -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=bombadil.20170209 header.b=tFIRynzC; 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 S1727828AbeJKO5j (ORCPT + 99 others); Thu, 11 Oct 2018 10:57:39 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:49708 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726399AbeJKO5j (ORCPT ); Thu, 11 Oct 2018 10:57:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=ahBK5zqI2DJ5p1osG+ETUl8gjyom6+IwguNdYgg3iCE=; b=tFIRynzCbKkBSDvIcOj2gtSRT W0C2Ngej2q/jlLXpTNQmvlbGXp4kvq9YADo2oSCnKy0741QtCV3dhQxDfPRV53KDU5YuBbQ8+ydov /1I8c423SHkXslWnenfdBOsslfiFdEIZSw8CfrrWAKhGeFLf60u332ACBHNHKLan9PGzLH7LDCsRc ih7clJ09E9u990I7KusYS8GDExZ7D6ZFW9LyllPUknuxgxuFiLLwdGJcLVtriPg+boBc/Do0Q5OdQ IZHLgp5lXSSBXpFz2OveTx/CbKAQg6kJd4yl8g4c3bISoN00NjcHzhf4kNzhDlOeHnYM9D9Kzljkw 5Rf9sPoMQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gAVRY-0006ez-7w; Thu, 11 Oct 2018 07:31:36 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 74E6520291FCC; Thu, 11 Oct 2018 09:31:33 +0200 (CEST) Date: Thu, 11 Oct 2018 09:31:33 +0200 From: Peter Zijlstra To: Eric Dumazet Cc: linux-kernel , Eric Dumazet , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Subject: Re: [PATCH] x86/tsc: use real seqcount_latch in cyc2ns_read_begin() Message-ID: <20181011073133.GZ5663@hirez.programming.kicks-ass.net> References: <20181011003336.168941-1-edumazet@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181011003336.168941-1-edumazet@google.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 Wed, Oct 10, 2018 at 05:33:36PM -0700, Eric Dumazet wrote: > While looking at native_sched_clock() disassembly I had > the surprise to see the compiler (gcc 7.3 here) had > optimized out the loop, meaning the code is broken. > > Using the documented and approved API not only fixes the bug, > it also makes the code more readable. > > Replacing five this_cpu_read() by one this_cpu_ptr() makes > the generated code smaller. Does not for me, that is, the resulting asm is actually larger You're quite right the loop went missing; no idea wth that compiler is smoking (gcc-8.2 for me). In order to eliminate that loop it needs to think that two consecutive loads of this_cpu_read(cyc2ns.seq.sequence) will return the same value. But this_cpu_read() is an asm() statement, it _should_ not assume such. We assume that this_cpu_read() implies READ_ONCE() in a number of locations, this really should not happen. The reason it was written using this_cpu_read() is so that it can use %gs: prefixed instructions and avoid ever loading that percpu offset and doing manual address computation. Let me prod at this with a sharp stick.