# Kernel patch for additional CPU for GCC optimizations

## emc

Really nice patch:

https://github.com/graysky2/kernel_gcc_patch

Kernel patch adds additional CPU options to the Linux kernel accessible under: Processor type and features ---> Processor family --->

Why a specific patch? The kernel uses its own set of CFLAGS, KCFLAGS. For exmaple, see:

arch/x86/Makefile

arch/x86/Makefile_32.cpu

arch/x86/Kconfig.cpu

CPU Family/GCC Optimization:

Native optimizations autodetected by GCC

-march=native

AMD K10-family

-march=amdfam10

AMD Family 10h (Barcelona)

-march=barcelona

AMD Family 14h (Bobcat)

-march=brver1

AMD Family 15h (Bulldozer)

-march=bdver1

Piledriver Family 15h (Piledriver)

-march=bdver2

Intel 1st Gen Core i3/i5/i7-family (Nehalem)

-march=corei7

Intel 2nd Gen Core i3/i5/i7-family (Sandybridge)

-march=corei7-avx

Intel 3rd Gen Core i3/i5/i7-family (Ivybridge)

-march=core-avx-i

Intel 4th Gen Core i3/i5/i7-family (Haswell)

-march=core-avx2

----------

## trippels

Yeah. I've been using the following on my k10 for ages:

```

diff --git a/arch/x86/Makefile b/arch/x86/Makefile

index 5c47726..748e5c8 100644

--- a/arch/x86/Makefile

+++ b/arch/x86/Makefile

@@ -61,7 +61,7 @@ else

        KBUILD_CFLAGS += $(call cc-option,-mno-sse -mpreferred-stack-boundary=3)

 

         # FIXME - should be integrated in Makefile.cpu (Makefile_32.cpu)

-        cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8)

+        cflags-$(CONFIG_MK8) += $(call cc-option,-march=native)

         cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona)

 

         cflags-$(CONFIG_MCORE2) += \

```

----------

## vexatious

Do you know how to contact the maintainer (graysky2)?  Wondering if a custom cpu option could be added (use custom cflags).  This would be beneficial for modules that require msseregparm (it is recommended to compile all libraries and modules with msseregparm if anything uses msseregparm); mfpmath might improve speed too.

----------

## PaulBredbury

 *vexatious wrote:*   

> Do you know how to contact the maintainer (graysky2)?

 

Look at the Arch Linux forums.

----------

## olutyo

Thank you very much

Finally you can configure the kernel characteristics

----------

## GFCCAE6xF

Just got round to trying this, certainly works (and is worth it) even if the returns are so small. Only bad thing is now I shall have to move pf-sources back in to my local and keep things going in there rather then clutter up and forget /etc/portage/patches/* since that's somewhat an obscure place for package patches imo. 

This patch(es) would be extra nice as an, even masked, custom-optimizations flag or similar.

Edit: Loosing my mind, corrections ahoy  :Smile: 

----------

## smartass

Sounds like ricing, if it was safe, wouldn't it be the standard procedure? I can easily imagine a poorly written driver to fail with some optimizations.

----------

## broken_chaos

 *smartass wrote:*   

> Sounds like ricing, if it was safe, wouldn't it be the standard procedure? I can easily imagine a poorly written driver to fail with some optimizations.

 

All it changes is the march option. It's completely safe, as it only adjusts the features GCC compiles for compatibility with (sse, avx, and similar), so barring some hardware problem with those features (i.e., a processor reporting it supports AVX when it doesn't, which happens under xen sometimes -- and is just as much of a problem for the march in make.conf which is considered safe), there's no danger at all.

The kernel developers are just a bit weird about what gcc optimizations they've set to be configured. (Partly because a lot of the 'major' CPU features are detected and enabled in the kernel code itself, rather than via GCC.)

----------

## smartass

broken_chaos, your arguments do make sense, but I'd still like to see some real evidence or an opinion of a kernel developer.

----------

## okias

I plan include this patch in mptcp-sources, because it seems totally safe.

Maybe it could be added to gentoo-sources with experimental USE flag enabled?

----------

## BartNL

Sorry for bumping up an old topic. How do i install the patch? Can i only apply it to gentoo-sources?

----------

## SirRobin2318

add:

```
sys-kernel/gentoo-sources experimental
```

In your use flags files.

----------

## BartNL

 *SirRobin2318 wrote:*   

> add:
> 
> ```
> sys-kernel/gentoo-sources experimental
> ```
> ...

 

Thank you. I added that to package.use, re-emerged gentoo-sources and did a make oldconfig. The only thing that came up was BFQ-scheduler. I also tried make distclean but no extra processor types showed up.

----------

## SirRobin2318

in make menuconfig

```
Processor type and features  --->

  Processor family (...) --->
```

you don't see Native optimizations autodetected by GCC?

https://wiki.gentoo.org/wiki/Project:Kernel/Experimental

The patch is listed, and I'm using it. What version are you using?

Have you selected the latest installed kernel in:

```
eselect kernel list
```

----------

## BartNL

 *SirRobin2318 wrote:*   

> in make menuconfig
> 
> ```
> Processor type and features  --->
> 
> ...

 

My kernel :

```

gbox ~ # eselect kernel list

Available kernel symlink targets:

  [1]   linux-3.10.25-gentoo 

```

I see only: generic, intel atom, core2, intel p4 and opteron. Very strange.

----------

## SirRobin2318

Check if the experimental flags are enabled using emerge -1av gentoo-sources. 

If that's the case maybe it's available for newer kernels only, I'm using 3.13.5. But I find this strange, I thought I used this with 3.10.

----------

## BartNL

 *SirRobin2318 wrote:*   

> Check if the experimental flags are enabled using emerge -1av gentoo-sources. 
> 
> If that's the case maybe it's available for newer kernels only, I'm using 3.13.5. But I find this strange, I thought I used this with 3.10.

 

Confirm. Are you using gentoo-sources unstable? I did ab emerge --sync before i installed experimental.

----------

## SirRobin2318

Yes, I am. Does emerge -1av gentoo-sources not mention the experimental flag? If it does, you should consider using 3.13.x.

----------

