-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathlite-more-x86-64-ISA-levels-for-kernel-6.15-rc1-6.15.x.patch
More file actions
115 lines (99 loc) · 3.94 KB
/
lite-more-x86-64-ISA-levels-for-kernel-6.15-rc1-6.15.x.patch
File metadata and controls
115 lines (99 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
From 022858052e05a2770f9ddb8190c108b6cb0f6f0d Mon Sep 17 00:00:00 2001
From: graysky <therealgraysky AT proton DOT me>
Date: Mon, 16 Sep 2024 14:47:03 -0400
FEATURES
This patch adds additional tunings via new x86-64 ISA levels to the
Linux kernel.
These are selectable under:
Processor type and features ---> x86-64 compiler ISA level
• x86-64 A value of (1) is the default
• x86-64-v2 A value of (2) brings support for vector
instructions up to Streaming SIMD Extensions 4.2 (SSE4.2)
and Supplemental Streaming SIMD Extensions 3 (SSSE3), the
POPCNT instruction, and CMPXCHG16B.
• x86-64-v3 A value of (3) adds vector instructions up to AVX2, MOVBE,
and additional bit-manipulation instructions.
There is also x86-64-v4 but including this makes little sense as
the kernel does not use any of the AVX512 instructions anyway.
Users of glibc 2.33 and above can see which level is supported by running:
/lib/ld-linux-x86-64.so.2 --help | grep supported
Or
/lib64/ld-linux-x86-64.so.2 --help | grep supported
BENEFITS
Small but real speed increases are measurable using a make endpoint comparing
a generic kernel to one built with one of the respective microarchs.
See the following experimental evidence supporting this statement:
https://github.com/graysky2/kernel_compiler_patch?tab=readme-ov-file#benchmarks
REQUIREMENTS
linux version 6.15-rc1 - 6.15.x
gcc version >=9.0 or clang version >=9.0
ACKNOWLEDGMENTS
This patch builds on the seminal work by Jeroen.[2]
REFERENCES
1. https://gitlab.com/x86-psABIs/x86-64-ABI/-/commit/77566eb03bc6a326811cb7e9
2. http://www.linuxforge.net/docs/linux/linux-gcc.php
---
arch/x86/Kconfig.cpu | 31 +++++++++++++++++++++++++++++++
arch/x86/Makefile | 7 +++++++
2 files changed, 38 insertions(+)
diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
index 753b8763abae..a28ccb8d5217 100644
--- a/arch/x86/Kconfig.cpu
+++ b/arch/x86/Kconfig.cpu
@@ -257,6 +257,37 @@ config X86_GENERIC
This is really intended for distributors who need more
generic optimizations.
+config GENERIC_CPU
+ bool "Generic-x86-64"
+ depends on X86_64
+ help
+ Generic x86-64 CPU.
+ Runs equally well on all x86-64 CPUs.
+
+config X86_64_VERSION
+ int "x86-64 compiler ISA level"
+ range 1 3
+ depends on (CC_IS_GCC && GCC_VERSION > 110000) || (CC_IS_CLANG && CLANG_VERSION >= 120000)
+ depends on X86_64 && GENERIC_CPU
+ help
+ Specify a specific x86-64 compiler ISA level.
+
+ There are three x86-64 ISA levels that work on top of
+ the x86-64 baseline, namely: x86-64-v2, x86-64-v3, and x86-64-v4.
+
+ x86-64-v2 brings support for vector instructions up to Streaming SIMD
+ Extensions 4.2 (SSE4.2) and Supplemental Streaming SIMD Extensions 3
+ (SSSE3), the POPCNT instruction, and CMPXCHG16B.
+
+ x86-64-v3 adds vector instructions up to AVX2, MOVBE, and additional
+ bit-manipulation instructions.
+
+ x86-64-v4 is not included since the kernel does not use AVX512 instructions
+
+ You can find the best version for your CPU by running one of the following:
+ /lib/ld-linux-x86-64.so.2 --help | grep supported
+ /lib64/ld-linux-x86-64.so.2 --help | grep supported
+
#
# Define implied options from the CPU selection here
config X86_INTERNODE_CACHE_SHIFT
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 594723005d95..edf5f31bfff8 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -173,8 +173,15 @@ else
# Use -mskip-rax-setup if supported.
KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)
+ifdef CONFIG_GENERIC_CPU
+ ifeq ($(CONFIG_X86_64_VERSION),1)
KBUILD_CFLAGS += -march=x86-64 -mtune=generic
KBUILD_RUSTFLAGS += -Ctarget-cpu=x86-64 -Ztune-cpu=generic
+else
+ KBUILD_CFLAGS +=-march=x86-64-v$(CONFIG_X86_64_VERSION)
+ KBUILD_RUSTFLAGS += -Ctarget-cpu=x86-64-v$(CONFIG_X86_64_VERSION)
+ endif # CONFIG_X86_64_VERSION
+endif # CONFIG_GENERIC_CPU
KBUILD_CFLAGS += -mno-red-zone
KBUILD_CFLAGS += -mcmodel=kernel
--
2.49.0