[tip:,x86/percpu] x86/percpu: Rewrite arch_raw_cpu_ptr() to be easier for compilers to optimize
Message ID | 169745455266.3135.6448612613186875465.tip-bot2@tip-bot2 |
---|---|
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 ib8csp3379835vqb; Mon, 16 Oct 2023 04:09:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFpAx07oKXGpqXcY+2YkiyysJ+FE9GkezXCLbOL5b3RMc4IuYtBOosoY1NU+YGLsFZbi76 X-Received: by 2002:a05:6a00:391c:b0:690:d0d4:6fb0 with SMTP id fh28-20020a056a00391c00b00690d0d46fb0mr36943091pfb.3.1697454572228; Mon, 16 Oct 2023 04:09:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697454572; cv=none; d=google.com; s=arc-20160816; b=Jca6yR9FiJhZE8CXyS8KpHLEc5M7MFeKHtgWHVMQk0L7SRLk3dMuP4GovpCkcAVWQt Hf1zWBx3UTEAc0cD6B9TpUZbvAf/ADGi16qZ7AlHBj5Oj+AeeEoiguWJ/EB2DGnSo+V9 pb/DKDbAOuRWW8lhSM9No+H2Yy+EeY1OeaFwdV1jf1I/BglwUOFq9lG7fSO9tLOd29hJ 7ROxVYN9haSVvZeeI7cUo92bhodiEum2XPJpFj7gvwZy/R61sntpz+wKntxLoMcgN9Jy 5frSEq5+YTpMH+r+31A5pmL/6Rc3iyV4SS+03Eslun65fqRQKCvv/k5qBo9Re4anoGxH ZN3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=KivpYjCswqmyMYmTza1UAeGN464mC4l6senqCmFquu8=; fh=tvbVHyBz6fYNpPd9lR6KhyGo+sIKwbwfrlsRtiNOb3I=; b=V5iwMR/b+zt0xkIiI35TkotPSJODhEbuVXuj6bTtTNkAlxv+Xhc+kCnJ/gTiibeZRP wDfhkPDEA5uo1VZamBUYpUPAKevUi64h64o9T6ntDf8q0sOsiwzTD5+Ulj123r1PxYW8 9Em9vgTFoRwSJSsOuJCYnHUjtEL+NaO7NaUyJJaxuIqqBLczTQ7eMzlQQFUEkAc1G/et WGAuTtMqs+1f/zC3NPuRtM94EEyT4JCYF1v+uPmY1vCAE2drOJ6Ka+uAeec00zvJKHb3 dgVRNqxRBDCQFSBt3QBS5cjRXsiZxaHoCCgKOWs3mw0qKtrjv8kEHZ6mbx/sBweQKq1y 5oeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fI6PaVP9; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id u14-20020a056a00124e00b006b857d490b7si5660773pfi.87.2023.10.16.04.09.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 04:09:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fI6PaVP9; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 8F9E180A21B0; Mon, 16 Oct 2023 04:09:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230116AbjJPLJT (ORCPT <rfc822;hjfbswb@gmail.com> + 18 others); Mon, 16 Oct 2023 07:09:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232778AbjJPLJQ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 16 Oct 2023 07:09:16 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7CF5B4; Mon, 16 Oct 2023 04:09:14 -0700 (PDT) Date: Mon, 16 Oct 2023 11:09:12 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697454553; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KivpYjCswqmyMYmTza1UAeGN464mC4l6senqCmFquu8=; b=fI6PaVP9NU+p2uNPtQBRh4gnuEP7BcedBxqSj3DGCisTSA+QDRcPJ2GUgkbQzaTXPhp13y ZGn1n1yP5nZ/OKiAZ0L8qsbCukrFUqvGOfY5BuoF3SYJL08ArkOyj9aIZbfxZTjVkyRuuK +6so6zHi4RNcI2Hr3C1pO5372i74mdFxMsIHSYeVt3eTFciInP4xggdzhFPVz6hHAuMkNZ S9pOVedE0aSB6iJtL1X0Xkx/US79Z75cOD/jrwpA0DhAKyNHzA7Fll5B7f1lskVrIsxc0W tWONISxx+8SUkd6rP7bKx0kRm+z1ALh6NGU+Xlgs68jffoU+gDFDp66/vQ+r/g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697454553; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KivpYjCswqmyMYmTza1UAeGN464mC4l6senqCmFquu8=; b=n6Vq4wjfv+CRpFo1rEh/6R/ocpVQJwTbnbpA86R6rt8VAgmU8AqZrIRO3r32xst0OZCcV7 NCmr+FT5KgW2JwAA== From: "tip-bot2 for Uros Bizjak" <tip-bot2@linutronix.de> Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/percpu] x86/percpu: Rewrite arch_raw_cpu_ptr() to be easier for compilers to optimize Cc: Uros Bizjak <ubizjak@gmail.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>, Josh Poimboeuf <jpoimboe@redhat.com>, Sean Christopherson <seanjc@google.com>, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231015202523.189168-1-ubizjak@gmail.com> References: <20231015202523.189168-1-ubizjak@gmail.com> MIME-Version: 1.0 Message-ID: <169745455266.3135.6448612613186875465.tip-bot2@tip-bot2> Robot-ID: <tip-bot2@linutronix.de> Robot-Unsubscribe: Contact <mailto:tglx@linutronix.de> to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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 howler.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 (howler.vger.email [0.0.0.0]); Mon, 16 Oct 2023 04:09:29 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779910125759322282 X-GMAIL-MSGID: 1779910125759322282 |
Series |
[tip:,x86/percpu] x86/percpu: Rewrite arch_raw_cpu_ptr() to be easier for compilers to optimize
|
|
Commit Message
tip-bot2 for Thomas Gleixner
Oct. 16, 2023, 11:09 a.m. UTC
The following commit has been merged into the x86/percpu branch of tip: Commit-ID: a048d3abae7c33f0a3f4575fab15ac5504d443f7 Gitweb: https://git.kernel.org/tip/a048d3abae7c33f0a3f4575fab15ac5504d443f7 Author: Uros Bizjak <ubizjak@gmail.com> AuthorDate: Sun, 15 Oct 2023 22:24:39 +02:00 Committer: Ingo Molnar <mingo@kernel.org> CommitterDate: Mon, 16 Oct 2023 12:51:58 +02:00 x86/percpu: Rewrite arch_raw_cpu_ptr() to be easier for compilers to optimize 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 on a test build, a -1.3% reduction. Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Signed-off-by: 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: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Uros Bizjak <ubizjak@gmail.com> Cc: Sean Christopherson <seanjc@google.com> Link: https://lore.kernel.org/r/20231015202523.189168-1-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 60ea775..915675f 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 */