# Custom cflags etc in kernel

## dhewton

Good morning friends,

I was wondering if someone could offer some insight into using custom cflags in my kernel.  I have safely used genkernel and never had issues with kernels.  But in the spirit of getting the most out of my system, I was wondering if anyone had any "tips" for having a stable but tweaked kernel?

Thanks

Dan

----------

## sternklang

Hello,

Con Kolivas, who provides the patchset for the ck-sources kernels, has written that you should optimize the kernel for size (-Os) rather than for speed. He explains why in this mailing list thread.

The kernel build system sets up CFLAGS so you can't compile your kernel with crazy optimizations that will break it. You change from -O2 to -Os (using make menuconfig/xconfig/gconfig or whatever front-end to manual build that you use) with the option "Optimize for size" (CC_OPTIMIZE_FOR_SIZE) under "General Setup".

----------

## dhewton

So doing as you refer will simply make the kernel smaller?  I am cool with that.  I am not interested in "sexy" optimizations that make my system not stable; I was just wondering if there were simply optimizations that would give some performance without sacrificing stability.

Thanks for your input.

Dan

----------

## Primozic

 *sternklang wrote:*   

> The kernel build system sets up CFLAGS so you can't compile your kernel with crazy optimizations that will break it.

 

You could, if you modified /usr/src/linux/arch/i386/Makefile.cpu or similar, but I would advise against it.

I've been using -Os for my system and kernel for quite some time with no problems.  I would recommend it.

----------

## hiroki

 *Primozic wrote:*   

>  *sternklang wrote:*   The kernel build system sets up CFLAGS so you can't compile your kernel with crazy optimizations that will break it. 
> 
> You could, if you modified /usr/src/linux/arch/i386/Makefile.cpu or similar, but I would advise against it.
> 
> I've been using -Os for my system and kernel for quite some time with no problems.  I would recommend it.

 

i have a question about that Makefile.cpu. I am using a centrino (pentium m), but the cflag (-march) is set to i686 in the makefile. So is it safe to change it to pentium-m? (I am using gcc-4.1.0). My whole system runs with -march=pentium-m, so i was wondering whether there might be a specific reason to keep -march=i686 for the kernel. even pentium3 hast the flag -march=i686. I first thought it might be for compatibility reasons to gcc-3.3? but gcc-3.3 understands "pentium3".

so, what do you think? Can I safely (manually) change it to "pentium-m"?

----------

## Primozic

 *hiroki wrote:*   

> 
> 
> i have a question about that Makefile.cpu. I am using a centrino (pentium m), but the cflag (-march) is set to i686 in the makefile. So is it safe to change it to pentium-m? (I am using gcc-4.1.0). My whole system runs with -march=pentium-m, so i was wondering whether there might be a specific reason to keep -march=i686 for the kernel. even pentium3 hast the flag -march=i686. I first thought it might be for compatibility reasons to gcc-3.3? but gcc-3.3 understands "pentium3".
> 
> so, what do you think? Can I safely (manually) change it to "pentium-m"?

 

Sorry for the late reply.

Yes, it can be done safely.  I do it on a Shelton system (basically a Banias with no L2 cache) using GCC 3.4.6 with no problems.

----------

