Compiling x86_64 kernel as -march native

Hi all, no issue per se, just wanted to share a finding for those of us using OpenWrt on x86_64. I was searching for a way to optimize the kernel to compile as -march native instead of using one of the five or so very generic options in the stock kernel config under Processor type and features > Processor family.

I ran across this post from John Audia on the Arch forums made almost 10 years ago. It looks like he is still maintaining a kernel patch set that allows compiling the kernel as -march native "Intel-Native optimizations autodetected by the compiler" in addition to a boatload of definitions for different Intel and AMD CPU families.

Since the CPU in my build server is identical to the one in my OpenWrt x86 firewall, I wanted to get the most performance out of it as possible. No real changes in dmesg going from MCORE2 to Native, but the generated image size was noticeably different in a good way...

12,118,244 openwrt-x86-64-generic-ext4-combined.img.gz (compiled with "Core2/newer Xeon" processor family)
12,080,587 openwrt-x86-64-generic-ext4-combined.img.gz (compiled with "Intel Native" processor family)

So my -march native builds are coming in at about 37kB smaller than my previous "Core2/newer Xeon" builds.

1 Like