Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp293227rdb; Tue, 31 Oct 2023 07:43:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYD/FBqLONzRMjZ5ctEJL+ywHbqHg8bC4nEUGrXh9AAt+L52GUCGTN8d8JUzEPl8ueS5NZ X-Received: by 2002:a17:90b:1e0d:b0:27d:d9a:be8b with SMTP id pg13-20020a17090b1e0d00b0027d0d9abe8bmr3831171pjb.6.1698763406414; Tue, 31 Oct 2023 07:43:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698763406; cv=none; d=google.com; s=arc-20160816; b=XAse0RvCIrAT9ADNXnA0AmgO0sskT5oewRoW00I1iKym90wFJqz6m7qNTOZhLb/UF7 SdeeV3YSj++BRJFnedOiu5Czj2yJ/QVvN2bxg6KQOi24H0tqHskJiCdOawU0rt2Z1qSu Dx0mWa7UPvETIkkPnSv2kXpSyY8R8CoOanmAaTcf5m4jEsLhFidk3e4opp/wjqw7khcf 3vPOln+aN510YjY8M16rY8Y5EQKVQ3w5OrUmEFGP3deR1sTygUKcjn5Oss0WuOKXeZO1 +WK/rdG0r+GrWhI2hXvvnV3gwv62HjDXXHJeZ3KTPGFY5hfoHzt89dv76co9iHNOVWIC zL3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=zzKZPpB03DjuvGsfZUJZZwQa84u6HUL2qAa+tTRQe6M=; fh=Ekc3+fT9slvGDh8+L4faR4fmlPCLU3c7OlF0Aq/sX4U=; b=b7c9d8Nr2TejkgCFrhtIOlXgqGY7DXQVdWDFbr3Pz/abYRAq6bBQKscuQRZ9qv3LM2 mL6mU7erLqBa33U67nEckec0rEaUz52xV+Ci5GXnA6QWBP4ZpSjdzLxy/t9YEveUJU7Z 0KMDEfQRcXImbirHbQVU+LNg9nve21sdGGO4XBhSj5baIPfJacLYQ5ZuO2JOk7Yif7X9 UY1532MUAFVcRmWTB/3K4b8+rKvDIBBWILbqM3EnwsYdIg0wizE68HiPViprUN9QdQud W4gTjpZgzLNG3VCriPa3Q/iIz1doZQocl2BcFrUxzTz2yq5lIQQdSH1XQaOhsNrwz4LC 8WHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eGR5BWYv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id lt12-20020a17090b354c00b00263860e1f4csi1048951pjb.16.2023.10.31.07.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 07:43:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eGR5BWYv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 5D235801D493; Tue, 31 Oct 2023 07:43:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344327AbjJaOnX (ORCPT + 99 others); Tue, 31 Oct 2023 10:43:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344322AbjJaOnW (ORCPT ); Tue, 31 Oct 2023 10:43:22 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B094FC; Tue, 31 Oct 2023 07:43:19 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9EB0C433C7; Tue, 31 Oct 2023 14:43:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698763398; bh=66H98ojSE2UwXLJ24lU6oCRIUNq2Jb+IHbwCuZbB8TY=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=eGR5BWYv6XFZNxTD5fRj3kTzBpnaoPAJ/PTVG0FFXt+YYXsKJo1wgK1PN41f1Le1i x/842rZAkDr/D7vTwTRr4kAeJNM9wU09m//BHCh+7RP/DeXUpgAOFgfXrK6gOdLWb7 +IXYhCcKqjlNYG32xrmzqmi4LuAsdnBxttv5OXKMxfufuNSSxTBredT/+6/4dK7Bdb JNuyoOCqI99bYOi5mZqfKOTFtaAD3er27HBTAldfdsEDUO6PKwy+zMQNkOqMBMQPuR DM60W7qPoTvtMs4xMx4LQYaVnmljoseZSitkQUJ9loR+fn32v9ZMjUV884acgfRXOy stbGC7DEEAoQg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 6B32DCE0DD0; Tue, 31 Oct 2023 07:43:18 -0700 (PDT) Date: Tue, 31 Oct 2023 07:43:18 -0700 From: "Paul E. McKenney" To: Michael Matz Cc: Peter Zijlstra , Frederic Weisbecker , LKML , Boqun Feng , Joel Fernandes , Josh Triplett , Mathieu Desnoyers , Neeraj Upadhyay , Steven Rostedt , Uladzislau Rezki , rcu , Zqiang , "Liam R . Howlett" , ubizjak@gmail.com Subject: Re: [PATCH 2/4] rcu/tasks: Handle new PF_IDLE semantics Message-ID: Reply-To: paulmck@kernel.org References: <20231027144050.110601-1-frederic@kernel.org> <20231027144050.110601-3-frederic@kernel.org> <20231027192026.GG26550@noisy.programming.kicks-ass.net> <2a0d52a5-5c28-498a-8df7-789f020e36ed@paulmck-laptop> <20231027224628.GI26550@noisy.programming.kicks-ass.net> <200c57ce-90a7-418b-9527-602dbf64231f@paulmck-laptop> <20231030082138.GJ26550@noisy.programming.kicks-ass.net> <622438a5-4d20-4bc9-86b9-f3de55ca6cda@paulmck-laptop> <20231031095202.GC35651@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 31 Oct 2023 07:43:24 -0700 (PDT) On Tue, Oct 31, 2023 at 02:16:34PM +0000, Michael Matz wrote: > Hello, > > On Tue, 31 Oct 2023, Peter Zijlstra wrote: > > (I can't say anything about the WRITE_ONCE/rcu code, just about the below > codegen part) > > > Welcome is not the right word. What bugs me most is that this was never > > raised when this code was written :/ > > > > Mostly my problem is that GCC generates such utter shite when you > > mention volatile. See, the below patch changes the perfectly fine and > > non-broken: > > > > 0148 1d8: 49 83 06 01 addq $0x1,(%r14) > > What is non-broken here that is ... > > > into: > > > > 0148 1d8: 49 8b 06 mov (%r14),%rax > > 014b 1db: 48 83 c0 01 add $0x1,%rax > > 014f 1df: 49 89 06 mov %rax,(%r14) > > ... broken here? (Sure code size and additional register use, but I don't > think you mean this with broken). > > > For absolutely no reason :-( > > The reason is simple (and should be obvious): to adhere to the abstract > machine regarding volatile. When x is volatile then x++ consists of a > read and a write, in this order. The easiest way to ensure this is to > actually generate a read and a write instruction. Anything else is an > optimization, and for each such optimization you need to actively find an > argument why this optimization is correct to start with (and then if it's > an optimization at all). In this case the argument needs to somehow > involve arguing that an rmw instruction on x86 is in fact completely > equivalent to the separate instructions, from read cycle to write cycle > over all pipeline stages, on all implementations of x86. I.e. that a rmw > instruction is spec'ed to be equivalent. > > You most probably can make that argument in this specific case, I'll give > you that. But why bother to start with, in a piece of software that is > already fairly complex (the compiler)? It's much easier to just not do > much anything with volatile accesses at all and be guaranteed correct. > Even more so as the software author, when using volatile, most likely is > much more interested in correct code (even from a abstract machine > perspective) than micro optimizations. I suspect that Peter cares because the code in question is on a fast path within the scheduler. > > At least clang doesn't do this, it stays: > > > > 0403 413: 49 ff 45 00 incq 0x0(%r13) > > > > irrespective of the volatile. > > And, are you 100% sure that this is correct? Even for x86 CPU > pipeline implementations that you aren't intimately knowing about? ;-) Me, I am not even sure that the load-increment-store is always faithfully executed by the hardware. ;-) > But all that seems to be a side-track anyway, what's your real worry with > the code sequence generated by GCC? Again, my guess is that Peter cares deeply about the speed of the fast path on which this increment occurs. Thanx, Paul