[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241210144945.2325330-6-arnd@kernel.org>
Date: Tue, 10 Dec 2024 15:49:39 +0100
From: Arnd Bergmann <arnd@...nel.org>
To: linux-kernel@...r.kernel.org,
x86@...nel.org
Cc: Arnd Bergmann <arnd@...db.de>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
"H. Peter Anvin" <hpa@...or.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Andy Shevchenko <andy@...nel.org>,
Matthew Wilcox <willy@...radead.org>
Subject: [PATCH v2 05/11] x86: add CONFIG_X86_64_NATIVE option
From: Arnd Bergmann <arnd@...db.de>
As a replacement for the obsole MK8/MPSC/MCORE2 configuration options,
allow building a specialized kernel for the local CPU, which is useful
for users building their own kernels, and does not require maintaining
a list of possible CPU options.
Between -march=native and -mtune=native, I pick the former in order
to give the best performance through the use of extra instructions,
but at the cost of not being able to run on older CPUs at all. This
creates a small risk of running into illegal instruction faults when
the resulting binary ends up being run on a machine other than the
one it was built on.
Link: https://lore.kernel.org/lkml/CAHk-=wji1sV93yKbc==Z7OSSHBiDE=LAdG_d5Y-zPBrnSs0k2A@mail.gmail.com/
Signed-off-by: Arnd Bergmann <arnd@...db.de>
---
arch/x86/Kconfig.cpu | 14 ++++++++++++++
arch/x86/Makefile | 5 +++++
2 files changed, 19 insertions(+)
diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
index 8fcb8ccee44b..d634b163e913 100644
--- a/arch/x86/Kconfig.cpu
+++ b/arch/x86/Kconfig.cpu
@@ -257,6 +257,20 @@ config X86_GENERIC
This is really intended for distributors who need more
generic optimizations.
+config X86_64_NATIVE
+ bool "Build with -march=native optimization"
+ depends on X86_64
+ help
+ Make it possible to have a slightly better optimized kernel for
+ the machine it is built on, by passing -march=native instead
+ the more generic -march=x86-64 option. This lets compilers
+ use extensions to the x86-64 instruction set that were not
+ present in the original AMD Opteron and Intel Pentium4 CPUs,
+ and schedule instructions for the pipeline model.
+
+ Select this option only when building a kernel to run locally,
+ as it may be incompatible with any other processor.
+
#
# Define implied options from the CPU selection here
config X86_INTERNODE_CACHE_SHIFT
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 8120085b00a4..bf45b84c138f 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -178,8 +178,13 @@ else
# Use -mskip-rax-setup if supported.
KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)
+ifdef CONFIG_X86_64_NATIVE
+ KBUILD_CFLAGS += -march=native
+ KBUILD_RUSTFLAGS += -Ctarget-cpu=native
+else
KBUILD_CFLAGS += -march=x86-64 -mtune=generic
KBUILD_RUSTFLAGS += -Ctarget-cpu=x86-64 -Ztune-cpu=generic
+endif
KBUILD_CFLAGS += -mno-red-zone
KBUILD_CFLAGS += -mcmodel=kernel
--
2.39.5
Powered by blists - more mailing lists