Skip to contentSkip to conversation

kernel optimization

DISCUSSION christos gentsis 7 participants 10 messages Jul 22, 2005 – Jul 23, 2005

lore
Share & tools
lore
#0 lore raw

hello

i would like to ask if it possible to change the optimization of the kernel from -O2 to -O3 :D, how can i do that? if i change it to the top level Makefile does it change to all the Makefiles?

And let's say that i change it... does this generate any problems with the space that the kernel will take? (the kernel will be much larger)

Thanks
Chris

#1 lore raw

This is a airly frequent question

the short answer is 'don't try'

the longer answer is that all the additional optimization options that are part of O3+ are considered individually and if they make sense for the kernel they are explicitly enabled (in some cases the optimizations need to be explicitly turned off for proper functionality of the kernel under all versions of GCC)

David Lang

Quoted 20 lines · christos gentsis

Date: Fri, 22 Jul 2005 19:55:48 +0100
From: christos gentsis <[email protected]>
To: [email protected]
Subject: kernel optimization

hello

i would like to ask if it possible to change the optimization of the kernel from -O2 to -O3 :D, how can i do that? if i change it to the top level Makefile does it change to all the Makefiles?

And let's say that i change it... does this generate any problems with the space that the kernel will take? (the kernel will be much larger)

Thanks
Chris

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 2 lines
There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.
 -- C.A.R. Hoare
#3 lore raw
In reply to christos gentsis
Quoted 1 line · christos gentsis

hello

Hi Chris,

Quoted 3 lines

i would like to ask if it possible to change the optimization of the kernel from -O2 to -O3 :D, how can i do that? if i change it to the top level Makefile does it change to all the Makefiles?

search for the line with
CFLAGS += -O2
and change this to -O3.

This works for most Makefile's except for the one's that manually set -Os.

Quoted 2 lines

And let's say that i change it... does this generate any problems with the space that the kernel will take? (the kernel will be much larger)

It's completely untested.
And since it's larger, it's also slower.

Quoted 2 lines

Thanks
Chris

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#2 lore raw
In reply to David Lang
Quoted 9 lines · David Lang

This is a airly frequent question

the short answer is 'don't try'

the longer answer is that all the additional optimization options that are part of O3+ are considered individually and if they make sense for the kernel they are explicitly enabled (in some cases the optimizations need to be explicitly turned off for proper functionality of the kernel under all versions of GCC)

As far as I can see, none of the additional optimizations with -O3 is enabled in the kernel.

Quoted 1 line

David Lang

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#4 lore raw
In reply to Adrian Bunk
Quoted 34 lines · Adrian Bunk
Quoted 3 lines · christos gentsis

hello

Hi Chris,

Quoted 3 lines

i would like to ask if it possible to change the optimization of the kernel from -O2 to -O3 :D, how can i do that? if i change it to the top level Makefile does it change to all the Makefiles?

search for the line with
CFLAGS += -O2
and change this to -O3.

This works for most Makefile's except for the one's that manually set -Os.

Quoted 3 lines

And let's say that i change it... does this generate any problems with the space that the kernel will take? (the kernel will be much larger)

It's completely untested.
And since it's larger, it's also slower.

Quoted 10 lines
Quoted 4 lines

Thanks
Chris

cu
Adrian

so if i want to play with and see what happens i have to change it manually in each make file... good i may create a kernel like that to see what will happens (just for test) ;)

thanks
Chris

#6 lore raw
In reply to Adrian Bunk

Adrian Bunk wrote: {

Quoted 3 lines · christos gentsis

i would like to ask if it possible to change the optimization of the kernel from -O2 to -O3 :D, how can i do that? if i change it to the top level Makefile does it change to all the Makefiles?

And since it's larger, it's also slower.
}

It's faster but it's flawed. Root-NFS boot failed!

#7 lore raw
In reply to Adrian Bunk

----- Original Message -----
From: "Adrian Bunk" <[email protected]>
To: "christos gentsis" <[email protected]>
Cc: <[email protected]>
Sent: Friday, July 22, 2005 16:14
Subject: Re: kernel optimization

Quoted 3 lines

It's completely untested.
And since it's larger, it's also slower.

Larger does not always mean slower. If it did, nobody would implement a loop unrolling optimization.

ex. Look at how GCC generates jump tables for switch() when there's about 10-12 (or more) case's sparsely scattered in the rage from 0 through 255. It generates a 256 element directly indexed jump table (obviously with many duplicate entries). This is faster than a cascaded if/else construct(particularly for those that would have been on the end of the if/else chain), but it is a very large construct. You'll see some of these "plump" switches generated in various SCSI drivers and in the VT102 emulation if you disassemble them.

#5 lore raw
In reply to christos gentsis

christos gentsis skrev:

Quoted 6 lines

so if i want to play with and see what happens i have to change it manually in each make file... good i may create a kernel like that to see what will happens (just for test) ;)

thanks
Chris

Just edit the top level Makefile and add your custom CFLAGS there. But you are risking the stability of your system and don't expect it to be faster.

Signature · 1 line
Simon Strandman <[email protected]>
#8 lore raw
In reply to [email protected]
Quoted 2 lines · On Sad, 2005-07-23 at 02:30 -0400, [email protected] wrote:

Larger does not always mean slower. If it did, nobody would implement a loop unrolling optimization.

Generally speaking nowdays it does. Almost all loop unrolls are a loss on PIV.

Quoted 2 lines

ex. Look at how GCC generates jump tables for switch() when there's about 10-12 (or more) case's sparsely scattered in the rage from 0 through 255.

You are comparing with very expensive jump operations its an unusual case. For the majority of situations the TLB/cache overhead of misses vastly outweighs the odd clock cycle gained by verbose output.

#9 lore raw

I submit that sparse switch jump table's are not an "unusual" construct in the Linux kernel/drivers. GCC only creates a table large enough to cover the largest of the sparse values - it doesn't have to be 0...255. 0...60 with 10 values sparsely scattered would generate a 61 element jump table.

There's many K of locked memory in these sparse jump tables. About 2K worth in the VT102 code alone.

----- Original Message -----
From: "Alan Cox" <[email protected]>
To: <[email protected]>
Cc: "Adrian Bunk" <[email protected]>; <[email protected]>
Sent: Saturday, July 23, 2005 15:50
Subject: Re: kernel optimization

Quoted 8 lines · On Sad, 2005-07-23 at 02:30 -0400, [email protected] wrote:
Quoted 2 lines

Larger does not always mean slower. If it did, nobody would implement a loop unrolling optimization.

Generally speaking nowdays it does. Almost all loop unrolls are a loss on PIV.

Quoted 1 line

ex. Look at how GCC generates jump tables for switch() when there's

about

Quoted 1 line
Quoted 1 line

10-12 (or more) case's sparsely scattered in the rage from 0 through

255.

Quoted 6 lines

You are comparing with very expensive jump operations its an unusual case. For the majority of situations the TLB/cache overhead of misses vastly outweighs the odd clock cycle gained by verbose output.