Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1131547pxk; Fri, 4 Sep 2020 01:05:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8hMpA6/z8XjIMlSgdYkHhNOs4UYGsBkclvLuvC7SMSTlNcncnbAQQzUVIDp7Gzc559FsU X-Received: by 2002:a50:b946:: with SMTP id m64mr7427021ede.92.1599206705040; Fri, 04 Sep 2020 01:05:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599206705; cv=none; d=google.com; s=arc-20160816; b=L1vMPgKNYo6rEIV0bZzeFRIvPsvOdwrHGutCd9P1vItRk5Y7wmRR2NjCuKQaWlsfZB MVKVFDwrfekXHAQfkIoPJ2V6pmJlRVLhHFsJLFSW0joyB9eUeZvjuAcPVZ+BAalZm+Ur UaH10F5zpkQrimtiKtslPCRBTAv1sZxNW/TpDFsYd3XAFkvO7sOjP61GSfgFpj4nh5Gv l+ZUVJQNF7ljkq+rXRrGNKGJ6toCLkPTpIeqMthhb8eP2U11xbf0S/C53f+zFhPPj/6J QQan8/fup4vluGJKj6X31HWkDR1z3bIbORAqnGN6kTtpZlPr8RKPyGF5esON2Q/X0ZN4 8HhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=KoEt7dwJzHzc0zmg3gPZoBe1ae26mzuh+FezXIxiqQ4=; b=VkfL6gFQj4bcK2O963b7rqJGLQ6CB29ZMai22MWVDSXbWYsi3prSJ+W8wHSaJAA5AA zowN/8KPOpE7OiJDa5iTjQ4/6G4CRm0IZbNqpeAwZychNO4v8vTas0VzVoATlgbZ0vk6 S/P/14n6Fiq/nNWLt9twydA67E8bnXVUR6KVpo+Iv2vO1wKbU2XnJmSL+Mv7TU1lLoGA lp5AgNMEu3TfD2pf5i1jtr9JYmoEN8CJoLVt1l4FK10CQ1S9jrzN3gts3iDHojiOc1TQ j8U0HbuvnGs5d28tsz7/JjrJqensoZf0E0Xx2UdCfKV/P9rs4iLen8k0yiSrCxQTw3W1 V5NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=CdtkJPlL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si3323706edp.462.2020.09.04.01.04.41; Fri, 04 Sep 2020 01:05:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=CdtkJPlL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729779AbgIDID0 (ORCPT + 99 others); Fri, 4 Sep 2020 04:03:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729683AbgIDIDY (ORCPT ); Fri, 4 Sep 2020 04:03:24 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A6F8C061244 for ; Fri, 4 Sep 2020 01:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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; bh=KoEt7dwJzHzc0zmg3gPZoBe1ae26mzuh+FezXIxiqQ4=; b=CdtkJPlLhr2CA3JmAOmUGekyb3 DIIv5ks3CQQDGi4J+JV/C0PqE0iFZYr3tF/ucWUhCFwq4Vp15IunEDl0mcDEO2Eed1cQpLwNQCpPj jKzZH7sKBErtd3axqGdsvBJg3hz+t0pezWAHXhzmOi35uqsEhV8leOLYkWaapLAFetGCeAZeWmucK i63UgVjO/VXapEiN8vdPz+PyTTCSAj8CVWc44bBSMe3FWmFUOZ4YapKEEayRHv/MjBNRLTdAhNtQQ DRtAqzlTdqpWI6+y7+ZgJuvBrCnF+nGleYyJZdL/DlrpgGVVuOLcpUonnPaSODsIEDnsX1yiWCZdI G+kSouGg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kE6gm-0000Uk-8l; Fri, 04 Sep 2020 08:03:16 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id C1C52301179; Fri, 4 Sep 2020 10:03:12 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B14A32B9A6885; Fri, 4 Sep 2020 10:03:12 +0200 (CEST) Date: Fri, 4 Sep 2020 10:03:12 +0200 From: peterz@infradead.org To: "Ahmed S. Darwish" Cc: Ingo Molnar , Will Deacon , Thomas Gleixner , "Sebastian A. Siewior" , LKML , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: Re: [PATCH v1 6/8] x86/tsc: Use seqcount_latch_t Message-ID: <20200904080312.GZ35926@hirez.programming.kicks-ass.net> References: <20200827114044.11173-1-a.darwish@linutronix.de> <20200827114044.11173-7-a.darwish@linutronix.de> <20200904074142.GL2674@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200904074142.GL2674@hirez.programming.kicks-ass.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 04, 2020 at 09:41:42AM +0200, peterz@infradead.org wrote: > On Thu, Aug 27, 2020 at 01:40:42PM +0200, Ahmed S. Darwish wrote: > > > __always_inline void cyc2ns_read_begin(struct cyc2ns_data *data) > > { > > + seqcount_latch_t *seqcount; > > int seq, idx; > > > > preempt_disable_notrace(); > > > > + seqcount = &this_cpu_ptr(&cyc2ns)->seq; > > do { > > - seq = this_cpu_read(cyc2ns.seq.sequence); > > + seq = raw_read_seqcount_latch(seqcount); > > idx = seq & 1; > > > > data->cyc2ns_offset = this_cpu_read(cyc2ns.data[idx].cyc2ns_offset); > > data->cyc2ns_mul = this_cpu_read(cyc2ns.data[idx].cyc2ns_mul); > > data->cyc2ns_shift = this_cpu_read(cyc2ns.data[idx].cyc2ns_shift); > > > > - } while (unlikely(seq != this_cpu_read(cyc2ns.seq.sequence))); > > + } while (read_seqcount_latch_retry(seqcount, seq)); > > } > > So I worried about this change, it obviously generates worse code. But I > was not expecting this: > > Before: > > 196: 0000000000000110 189 FUNC GLOBAL DEFAULT 1 native_sched_clock > > After: > > 195: 0000000000000110 399 FUNC GLOBAL DEFAULT 1 native_sched_clock > > That's _210_ bytes extra!! > > If you look at the disassembly of the thing after it's a complete > trainwreck. The below delta fixes it again. --- --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -68,21 +68,19 @@ early_param("tsc_early_khz", tsc_early_k __always_inline void cyc2ns_read_begin(struct cyc2ns_data *data) { - seqcount_latch_t *seqcount; int seq, idx; preempt_disable_notrace(); - seqcount = &this_cpu_ptr(&cyc2ns)->seq; do { - seq = raw_read_seqcount_latch(seqcount); + seq = this_cpu_read(cyc2ns.seq.seqcount.sequence); idx = seq & 1; data->cyc2ns_offset = this_cpu_read(cyc2ns.data[idx].cyc2ns_offset); data->cyc2ns_mul = this_cpu_read(cyc2ns.data[idx].cyc2ns_mul); data->cyc2ns_shift = this_cpu_read(cyc2ns.data[idx].cyc2ns_shift); - } while (read_seqcount_latch_retry(seqcount, seq)); + } while (unlikely(seq != this_cpu_read(cyc2ns.seq.seqcount.sequence))); } __always_inline void cyc2ns_read_end(void)