Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp855458rdb; Fri, 20 Oct 2023 00:59:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFcm4r11f9/aGIXgo/pOsmNhysOQ91fA7Bdwq7d7juijKFOuppk9p+ifTsDdCq8RzG+4qNn X-Received: by 2002:a17:902:e749:b0:1ca:3c63:d5cc with SMTP id p9-20020a170902e74900b001ca3c63d5ccmr1272067plf.49.1697788750943; Fri, 20 Oct 2023 00:59:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697788750; cv=none; d=google.com; s=arc-20160816; b=y4+TmVgRSB9fgFITTIeR2afSNGnul8lL1gWx2R0wfIHmKVoekoaVgFZQD+OgwIl6uq mxmjG3qPNICOPh3X68LtqTOirAKxQpPHIecgUAmpBZd5uWZup0PhLBs1Nv9hCJeefnkv kLuMAxq1HwAasWzR7hmcBYuuWfZ2zB/E6F6ie7Zs+CQu5nD+iDvQp/68XJjIcschAG/w fN6NX2D0eOGGCqNFrqQc8949pKzkzXKidfyJ1pGNiYZGUcH4ZTYFIiMJ1QbBS5Hracwa 0l1w8kk+71WvcezjnKXsxK6ng1bQPZSIcXebW50PtC+2t89D/aQyXG0V5inwcTl4gR7R 9H3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=R0CED4KL9zezq3HoQP/JfPVszwxf8r4ApnYMP0RUL/M=; fh=TuuuGpTiDGt8cLITKAD9aywCBLE/HV6krcer7Bl+EDo=; b=JO+W7IV/zEEpUOXz9i7tMpdccg+u733xbCYr/xrzcoeN3Mu+Hz+meTF4ptXW9xOp/J 8w/I3z+FWBcN1u3CWe8PTj8AQNFhyclaie5tKpAtiBrFy3pN4pQtnDc5DEqbhqO6MveG Jprj8VXj5NVLnyA06U7QCRofXWa0EXwYTMNHbEVMu3924WsB/8ukVuPtkdiyC5aR8qUf iszN7P8jz26rdue3qYoLVKb28g4OUxgGkaj/YzXM6edcVTouBY3xZLuVXQO+Vvj3uD4c XkNBCtKJzoAM6UqR15nd7U1CROmLlIjMJlhto/4IIlc3uCg7NTrHMJ3rKn0UvNpp6asQ 2VGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=C0sKfLhm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id l12-20020a170903244c00b001bdd35033efsi1412355pls.374.2023.10.20.00.59.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 00:59:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=C0sKfLhm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 5BEB58022B03; Fri, 20 Oct 2023 00:59:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376445AbjJTH67 (ORCPT + 99 others); Fri, 20 Oct 2023 03:58:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376613AbjJTH6Y (ORCPT ); Fri, 20 Oct 2023 03:58:24 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB5EF1704 for ; Fri, 20 Oct 2023 00:57:59 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-53dd752685fso683229a12.3 for ; Fri, 20 Oct 2023 00:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697788678; x=1698393478; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=R0CED4KL9zezq3HoQP/JfPVszwxf8r4ApnYMP0RUL/M=; b=C0sKfLhmKz3ZqTRasHMRE6II4Pa0r/cb1/FarnECQZORX+7hUyzcrP0gH+ObqisR64 +7ayUB/sJ4TdkroJKZXOsaW9+nk8ascirrQkusZh5IaCbDF4XNo0PadqmUtZwZBS/+w5 Fn93P4/tjpStWjH1EgRzslrs8XDW2i3FHwUCB4o9MOclzvauSjK9776AzCKB49Wx2RjE xpkx1GmHNzvmEYxx8Lsy9wynU/zDBNYU6ghaGmzSC+eZrDpaMndJUgt61Litdtd2E1vC uqPS/Ef+emPedpyXpHEQu7pvj0Eqpi0taXtKCFvEjK4cEAuI2lw09BX5mptJIHemFeCu KIgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697788678; x=1698393478; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R0CED4KL9zezq3HoQP/JfPVszwxf8r4ApnYMP0RUL/M=; b=JrY+AAdJyeJc6YFBqxYF+nCqGGv+9DLMKL4aRTyBlAH/j9LxJ/zrNHMY/SEEUkSb/N olPiXx+2CisQPaqPQh+eJcOEIIBqAw/8trA1CyOMHjzq7qIUbjymKZuUfd4aWnJzvWOW qcBLlnyUblgE/CWvLB/D+AYAHJX5OEcJN1HOYRHzHoO+S21yXHktL/3kH3a9jo3fdtb2 BYRHzbJGaEjpV8t/cxZx2DQwwykAcRmxAy9dTWRD9y73g81G8cYB17q1K3zpHaw5S0ls e5AbWUjA+h7OoSyKmIBoJh6YzXDA7nPhk1u1Tbk6Hw9N/XG0Wi8ONiOvrXpAfzNuds7G d7MQ== X-Gm-Message-State: AOJu0Yzb1AGnbJxL7d5w45EU+C9d3K7A3La0K6juEWY/24Sx1QAue+ed 5VEkUTyv6y++wOw/+9zoTKUpRn7NQ7nYPBSvSus= X-Received: by 2002:a50:ab4f:0:b0:53e:34c5:fc14 with SMTP id t15-20020a50ab4f000000b0053e34c5fc14mr844119edc.23.1697788678120; Fri, 20 Oct 2023 00:57:58 -0700 (PDT) MIME-Version: 1.0 References: <20231010164234.140750-1-ubizjak@gmail.com> <0617BB2F-D08F-410F-A6EE-4135BB03863C@vmware.com> <7D77A452-E61E-4B8B-B49C-949E1C8E257C@vmware.com> <9F926586-20D9-4979-AB7A-71124BBAABD3@vmware.com> <3F9D776E-AD7E-4814-9E3C-508550AD9287@vmware.com> <28B9471C-4FB0-4AB0-81DD-4885C3645E95@vmware.com> In-Reply-To: From: Uros Bizjak Date: Fri, 20 Oct 2023 09:57:46 +0200 Message-ID: Subject: Re: [PATCH v2 -tip] x86/percpu: Use C for arch_raw_cpu_ptr() To: Linus Torvalds Cc: peterz@infradead.org, Nadav Amit , "the arch/x86 maintainers" , Linux Kernel Mailing List , Andy Lutomirski , Brian Gerst , Denys Vlasenko , "H . Peter Anvin" , Thomas Gleixner , Josh Poimboeuf , Nick Desaulniers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Fri, 20 Oct 2023 00:59:08 -0700 (PDT) On Thu, Oct 19, 2023 at 9:07=E2=80=AFPM Linus Torvalds wrote: > > On Thu, 19 Oct 2023 at 11:49, Linus Torvalds > wrote: > > > > Honestly, I've actually never seen gcc rematerialize anything at all. > > > > I really only started worrying about remat issues in a theoretical > > sense, and because I feel it would be relatively *easy* to do for > > something where the source is a load. > > .. I started looking around, since I actually have gcc sources around. > > At least lra-remat.cc explicitly says > > o no any memory (as access to memory is non-profitable) > > so if we could just *rely* on that, it would actually allow us to use > memory ops without the volatile. > > That would be the best of all worlds, of course. I have made an experiment and changed: #define __raw_cpu_read(qual, pcp) \ ({ \ - *(qual __my_cpu_type(pcp) *)__my_cpu_ptr(&(pcp)); \ + *(__my_cpu_type(pcp) *)__my_cpu_ptr(&(pcp)); \ }) #define __raw_cpu_write(qual, pcp, val) = \ do { \ - *(qual __my_cpu_type(pcp) *)__my_cpu_ptr(&(pcp)) =3D (val); \ + *(__my_cpu_type(pcp) *)__my_cpu_ptr(&(pcp)) =3D (val); \ } while (0) Basically, I removed "volatile" from read/write accessors. With all new percpu patches in place the difference in all percpu accesses is: Reference: 15990 accesses Patched: 15976 accesses. So, the difference is 14 fewer accesses. Waaay too low of a gain for a potential pain. The code size savings are: text data bss dec hex filename 25476129 4389468 808452 30674049 1d40c81 vmlinux-new.o 25476021 4389444 808452 30673917 1d40bfd vmlinux-ref.o So, 108 bytes for the default build. Uros.