All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: linux-kernel@vger.kernel.org, x86@kernel.org
Cc: Arnd Bergmann <arnd@arndb.de>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andy Shevchenko <andy@kernel.org>,
	Matthew Wilcox <willy@infradead.org>
Subject: [PATCH v2 05/11] x86: add CONFIG_X86_64_NATIVE option
Date: Tue, 10 Dec 2024 15:49:39 +0100	[thread overview]
Message-ID: <20241210144945.2325330-6-arnd@kernel.org> (raw)
In-Reply-To: <20241210144945.2325330-1-arnd@kernel.org>

From: Arnd Bergmann <arnd@arndb.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@arndb.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


  parent reply	other threads:[~2024-12-10 14:50 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-10 14:49 [PATCH v2 00/11] x86: 32-bit cleanups Arnd Bergmann
2024-12-10 14:49 ` [PATCH v2 01/11] x86/Kconfig: Geode CPU has cmpxchg8b Arnd Bergmann
2024-12-10 16:00   ` Brian Gerst
2024-12-10 14:49 ` [PATCH v2 02/11] x86: drop 32-bit "bigsmp" machine support Arnd Bergmann
2024-12-10 14:49 ` [PATCH v2 03/11] x86: rework CONFIG_GENERIC_CPU compiler flags Arnd Bergmann
2024-12-10 14:49 ` [PATCH v2 04/11] x86: drop configuration options for early 64-bit CPUs Arnd Bergmann
2024-12-10 14:49 ` Arnd Bergmann [this message]
2024-12-10 19:05   ` [PATCH v2 05/11] x86: add CONFIG_X86_64_NATIVE option irecca.kun
2024-12-10 20:56     ` Arnd Bergmann
2024-12-10 21:08       ` irecca.kun
2024-12-10 21:02   ` Josh Triplett
2024-12-10 14:49 ` [PATCH v2 06/11] x86: remove HIGHMEM64G support Arnd Bergmann
2024-12-10 14:49 ` [PATCH v2 07/11] x86: drop SWIOTLB and PHYS_ADDR_T_64BIT for PAE Arnd Bergmann
2024-12-20  2:52   ` kernel test robot
2024-12-22 21:19     ` Arnd Bergmann
2024-12-10 14:49 ` [PATCH v2 08/11] x86: drop support for CONFIG_HIGHPTE Arnd Bergmann
2024-12-10 14:49 ` [PATCH v2 09/11] x86: document X86_INTEL_MID as 64-bit-only Arnd Bergmann
2024-12-10 14:49 ` [PATCH v2 10/11] x86: remove old STA2x11 support Arnd Bergmann
2024-12-10 15:39   ` Andy Shevchenko
2024-12-10 14:49 ` [PATCH v2 11/11] x86: Move platforms to Kconfig.platforms Arnd Bergmann
2024-12-10 15:43 ` [PATCH v2 00/11] x86: 32-bit cleanups Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241210144945.2325330-6-arnd@kernel.org \
    --to=arnd@kernel.org \
    --cc=andy@kernel.org \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=willy@infradead.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.