Message ID | 20231015202523.189168-1-ubizjak@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3087693vqb; Sun, 15 Oct 2023 13:25:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGtk8FVL8uVduFAtI2jRveOodjEUBgw7Uv+suSZkmWj7O5/jFnQaQr4K+iLF4pwcAiSfQv0 X-Received: by 2002:a17:90b:1e50:b0:27d:32d8:5f23 with SMTP id pi16-20020a17090b1e5000b0027d32d85f23mr7602915pjb.2.1697401553012; Sun, 15 Oct 2023 13:25:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697401553; cv=none; d=google.com; s=arc-20160816; b=sow1MXYwlZyYRV9/ZjlzQoEH66eCs4hIENsmrzzS+UhHTCJxzgCjZjH3iIXWxnf3BI 5/cDyD04DZ/aNa5mt4LNHfqy+g8N7UsQ/eAb0XyuUddW4q+2u1gjPI9/r4wKc/XOnL0w y3yXQmWv2sTc/HCaRg7XVC+544DaXTbYWHgRcK2LiVxhbeT8t0ApJ8HQxVMwJCoRCa7X bb2mSly/JVlAGPhFJJ3xnJt8nE4xsjNvo4mJHPRPywMrWcI1OwcbevVuvhEtCr98dCP7 14h0aqd2e5w+9X2A5m0iU8+CrceIpfXtLoj7vQj6dgAsVt4QATcaEptOdvbXebQTxL24 6NUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=b31YTUQEfZpOY+PzyS5wCBrwfTvZYZf58DeFB/h6Ek8=; fh=AQVdqJHqAftOv+1G5h1b8K5LLkLRAGwFRpgvn75L/tw=; b=X5q7qhfqgDf6RmzzMBfbbrRCBcOaBbX6g/IPtqimDyhYtPi8PBmN09HBZcUJRbTsiM eQuiqDi2AXO+LKdp515zlLgDWXCa6n1MK87ySc4UPIxajo21/nhgTxIT0tjfYDevQ0NC dMCk/2qST8u54PLXxtE9ob49RUTuIzS1KkflsWbsyTGywSXHtLyQdRnbjWkE5uemoOil NZPPy97GGM9qeVGZy8qhdwifobeH3Z4DAAOnccm7num1c6OjPygeWCtNMOxQLXj9SOyS GMRGNkBH7hohciYBLsq24odENFMEl2L5ZGZJTIChMxs9zfqKsQp19Gs/pSEl6gvvelUD 4utg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=YHiM0Jdt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id l5-20020a17090aec0500b00276c4e7b5e2si4763727pjy.146.2023.10.15.13.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 13:25:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=YHiM0Jdt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id A0CDC80B8221; Sun, 15 Oct 2023 13:25:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229990AbjJOUZi (ORCPT <rfc822;hjfbswb@gmail.com> + 19 others); Sun, 15 Oct 2023 16:25:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbjJOUZh (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 15 Oct 2023 16:25:37 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2CF6C1 for <linux-kernel@vger.kernel.org>; Sun, 15 Oct 2023 13:25:35 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-9be02fcf268so289564466b.3 for <linux-kernel@vger.kernel.org>; Sun, 15 Oct 2023 13:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697401534; x=1698006334; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=b31YTUQEfZpOY+PzyS5wCBrwfTvZYZf58DeFB/h6Ek8=; b=YHiM0Jdt3Ptd77vKD6c/DnEOSQPaKS++jQed4Shg6isVepl0d7hPQk44UlmtIBAfva oJEKLNZ6GhUp5qwH+DoWeKOp/a0WliMFMCv6n4D0wOF7H/RZsH4mtdH7frQxlXb+owTU HHQxROeTBR+45v6C9puk8G58l7TTGZQKuNznJpS5v71oxGdNaY9vCdTB0Z3wEfx9ZBtv A3RPIJg1hd5+7u2Pi3Q+LaxqIMHF76VGtdwqSo2RASZKGhijRlrTB08nLvm6cFOqiZfw 4lM24ny8PooIcRcY5ZlEGrwcc743xRbw/gELUKxRkSUfRv63QEJ8sylNlZj6jkjAKCox Vvqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697401534; x=1698006334; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=b31YTUQEfZpOY+PzyS5wCBrwfTvZYZf58DeFB/h6Ek8=; b=GXG5DKgA+xnY5KWR7PVW5w6HZa+UHFPcLdyqCnCbrZalHpj/K+VDZRKYnpOXZ3g6ra 1NSNTHkBwNm1T+Frx9wQW/sTA6NZB4Wl3bMEoA9vX9UkOZZiVrhEY8suaA1mdq76f0Mw c34pzK3uVSEQy5btHMIGjonDA0RQAAiyWrRctmFhALPu5r08pfx1TvqQ9KRzEt/VBw5K xVHjZrc17OKQPYmZrc1jQosfqgBs3223AQCXTh8UQ8356fHdmP2VS9lXqUKObpkDZV6H hwaLb4dIMJOscZCh26axkQdwIpgI7nKIamdKn7/jOxS/XZ3rLPlf+HkY9y3xPBT69KMB bsMw== X-Gm-Message-State: AOJu0YzikPI2+TttyEEyS7kGWsX4oASce7ziJT1Uoss1Po1LzQggS9Sa IFhm5683iuDy1Jmg7TWSJWM= X-Received: by 2002:a17:907:724b:b0:9b2:b9ff:dc35 with SMTP id ds11-20020a170907724b00b009b2b9ffdc35mr33586268ejc.70.1697401534174; Sun, 15 Oct 2023 13:25:34 -0700 (PDT) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id v23-20020a1709067d9700b009b97d9ae329sm2686943ejo.198.2023.10.15.13.25.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 13:25:33 -0700 (PDT) From: Uros Bizjak <ubizjak@gmail.com> To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak <ubizjak@gmail.com>, Nadav Amit <namit@vmware.com>, Ingo Molnar <mingo@kernel.org>, Andy Lutomirski <luto@kernel.org>, Brian Gerst <brgerst@gmail.com>, Denys Vlasenko <dvlasenk@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>, Linus Torvalds <torvalds@linux-foundation.org>, Peter Zijlstra <peterz@infradead.org>, Thomas Gleixner <tglx@linutronix.de>, Josh Poimboeuf <jpoimboe@redhat.com> Subject: [PATCH -tip 1/3] x86/percpu: Rewrite arch_raw_cpu_ptr() Date: Sun, 15 Oct 2023 22:24:39 +0200 Message-ID: <20231015202523.189168-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 morse.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sun, 15 Oct 2023 13:25:50 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779854530993552717 X-GMAIL-MSGID: 1779854530993552717 |
Series |
[-tip,1/3] x86/percpu: Rewrite arch_raw_cpu_ptr()
|
|
Commit Message
Uros Bizjak
Oct. 15, 2023, 8:24 p.m. UTC
Implement arch_raw_cpu_ptr() as a load from this_cpu_off and then
add the ptr value to the base. This way, the compiler can propagate
addend to the following instruction and simplify address calculation.
E.g.: address calcuation in amd_pmu_enable_virt() improves from:
48 c7 c0 00 00 00 00 mov $0x0,%rax
87b7: R_X86_64_32S cpu_hw_events
65 48 03 05 00 00 00 add %gs:0x0(%rip),%rax
00
87bf: R_X86_64_PC32 this_cpu_off-0x4
48 c7 80 28 13 00 00 movq $0x0,0x1328(%rax)
00 00 00 00
to:
65 48 8b 05 00 00 00 mov %gs:0x0(%rip),%rax
00
8798: R_X86_64_PC32 this_cpu_off-0x4
48 c7 80 00 00 00 00 movq $0x0,0x0(%rax)
00 00 00 00
87a6: R_X86_64_32S cpu_hw_events+0x1328
The compiler also eliminates additional redundant loads from
this_cpu_off, reducing the number of percpu offset reads
from 1668 to 1646.
Cc: Nadav Amit <namit@vmware.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
arch/x86/include/asm/percpu.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 60ea7755c0fe..915675f3ad60 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -56,9 +56,11 @@ #define arch_raw_cpu_ptr(ptr) \ ({ \ unsigned long tcp_ptr__; \ - asm ("add " __percpu_arg(1) ", %0" \ + asm ("mov " __percpu_arg(1) ", %0" \ : "=r" (tcp_ptr__) \ - : "m" (__my_cpu_var(this_cpu_off)), "0" (ptr)); \ + : "m" (__my_cpu_var(this_cpu_off))); \ + \ + tcp_ptr__ += (unsigned long)(ptr); \ (typeof(*(ptr)) __kernel __force *)tcp_ptr__; \ }) #else /* CONFIG_SMP */