mbod
August 30, 2021, 9:40am
1
I am struggling to compile a customized arch kernel with specific AMD optimizations with -march=znver2
Whatever I do, it ends up compiling it with -march=x86-64 -mtune=generic
I followed the instructions given here: https://wiki.archlinux.org/title/Kernel/Traditional_compilation
Where it suggests to edit arch/x86/Makefile
. I tried that, but somehow this file gets overwritten back to the default settings every time I run makepkg.
I also tried it with these config options:
scripts/config --disable CONFIG_GENERIC_CPU
scripts/config --enable CONFIG_MZEN2
This works fine for linux-zen but not for the vanilla arch kernel. Something is special about the arch kernel.
The AUR package linux-amd-znver2
is not an option because it uses the unpatched kernel from kernel.org . And I tried to use the same build instructions for the vanilla arch kernel:
build() {
cd "${_srcname}"
#Force zenv2 architecture optimisation.
export CFLAGS="-march=znver2 -mtune=znver2 -O2 -pipe -fstack-protector-strong"
export CXXFLAGS="${CFLAGS}"
make ${MAKEFLAGS} LOCALVERSION= bzImage modules
}
But that does not work either. Any idea what I need to do to get a vanilla arch kernel with AMD optimizations?
moson
September 4, 2021, 8:21am
2
But then you use ABS (makepkg) and not manual / traditional compilation I assume?
Each time you run makepkg it will extract the sources again. If you want to modify sources prior to build, you could first run “makepkg -o” to extract the sources and then run “makepkg -e” to build after modifying source files.
Yes, arch uses the vanilla kernel sources. There is no CONFIG_MZEN2 in them.
In the linux-zen kernel they have this though.
In my kernel build files I use the graysky2 patch . With that you can use CONFIG_MZEN2 (which in turn makes it compiling with -march=znver2)
Here my current files (5.14.1):
PKGBUILD
config
cpu_patch
GenToo also use a kernel patch, which is adding more CPU options to choose, including native instead of e.g. skylake.
genpatches-(experimental) >>> enable-cpu-optimizations-universal-patch
GenToo Optional Kernel Patches
1 Like
moson
September 4, 2021, 9:01am
4
2 Likes
mbod
September 14, 2021, 8:18pm
6
I forgot to close this thread with solution. The solution has first been mentioned by @moson :
A kernel patch is needed.
I personally use the patch that is also being used by linux-zen:
committed 10:28PM - 28 Jun 21 UTC
WARNING
This patch works with all gcc versions 9.0+ and with kernel version 5.8+… and should
NOT be applied when compiling on older versions of gcc due to key name changes
of the march flags introduced with the version 4.9 release of gcc.[1]
FEATURES
This patch adds additional CPU options to the Linux kernel accessible under:
Processor type and features --->
Processor family --->
With the release of gcc 11.0, several generic 64-bit levels are offered which
are good for supported Intel or AMD CPUs:
• x86-64-v2
• x86-64-v3
• x86-64-v4
Users of glibc 2.33 and above can see which level is supported by current
hardware by running:
/lib/ld-linux-x86-64.so.2 --help | grep supported
Alternatively, compare the flags from /proc/cpuinfo to this list.[2]
CPU-specific microarchitectures include:
• AMD Improved K8-family
• AMD K10-family
• AMD Family 10h (Barcelona)
• AMD Family 14h (Bobcat)
• AMD Family 16h (Jaguar)
• AMD Family 15h (Bulldozer)
• AMD Family 15h (Piledriver)
• AMD Family 15h (Steamroller)
• AMD Family 15h (Excavator)
• AMD Family 17h (Zen)
• AMD Family 17h (Zen 2)
• AMD Family 19h (Zen 3)†
• Intel Silvermont low-power processors
• Intel Goldmont low-power processors (Apollo Lake and Denverton)
• Intel Goldmont Plus low-power processors (Gemini Lake)
• Intel 1st Gen Core i3/i5/i7 (Nehalem)
• Intel 1.5 Gen Core i3/i5/i7 (Westmere)
• Intel 2nd Gen Core i3/i5/i7 (Sandybridge)
• Intel 3rd Gen Core i3/i5/i7 (Ivybridge)
• Intel 4th Gen Core i3/i5/i7 (Haswell)
• Intel 5th Gen Core i3/i5/i7 (Broadwell)
• Intel 6th Gen Core i3/i5/i7 (Skylake)
• Intel 6th Gen Core i7/i9 (Skylake X)
• Intel 8th Gen Core i3/i5/i7 (Cannon Lake)
• Intel 10th Gen Core i7/i9 (Ice Lake)
• Intel Xeon (Cascade Lake)
• Intel Xeon (Cooper Lake)*
• Intel 3rd Gen 10nm++ i3/i5/i7/i9-family (Tiger Lake)*
• Intel 3rd Gen 10nm++ Xeon (Sapphire Rapids)‡
• Intel 11th Gen i3/i5/i7/i9-family (Rocket Lake)‡
• Intel 12th Gen i3/i5/i7/i9-family (Alder Lake)‡
Notes: If not otherwise noted, gcc >=9.1 is required for support.
*Requires gcc >=10.1 †Required gcc >=10.3 ‡Required gcc >=11.0
It also offers to compile passing the 'native' option which, "selects the CPU
to generate code for at compilation time by determining the processor type of
the compiling machine. Using -march=native enables all instruction subsets
supported by the local machine and will produce code optimized for the local
machine under the constraints of the selected instruction set."[3]
Users of Intel CPUs should select the 'Intel-Native' option and users of AMD
CPUs should select the 'AMD-Native' option.
MINOR NOTES RELATING TO INTEL ATOM PROCESSORS
This patch also changes -march=atom to -march=bonnell in accordance with the
gcc v4.9 changes. Upstream is using the deprecated -match=atom flags when I
believe it should use the newer -march=bonnell flag for atom processors.[4]
It is not recommended to compile on Atom-CPUs with the 'native' option.[5] The
recommendation is to use the 'atom' option instead.
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_gcc_patch
REQUIREMENTS
linux version >=5.8
gcc version >=9.0
ACKNOWLEDGMENTS
This patch builds on the seminal work by Jeroen.[6]
REFERENCES
1. https://gcc.gnu.org/gcc-4.9/changes.html
2. https://gitlab.com/x86-psABIs/x86-64-ABI/-/commit/77566eb03bc6a326811cb7e9
3. https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#index-x86-Options
4. https://bugzilla.kernel.org/show_bug.cgi?id=77461
5. https://github.com/graysky2/kernel_gcc_patch/issues/15
6. http://www.linuxforge.net/docs/linux/linux-gcc.php
system
Closed
September 16, 2021, 8:18pm
7
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.