public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* kernel optimization
@ 2005-07-22 18:55 christos gentsis
  2005-07-22 19:52 ` David Lang
  2005-07-22 20:14 ` Adrian Bunk
  0 siblings, 2 replies; 14+ messages in thread
From: christos gentsis @ 2005-07-22 18:55 UTC (permalink / raw)
  To: linux-kernel

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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: kernel optimization
  2005-07-22 18:55 christos gentsis
@ 2005-07-22 19:52 ` David Lang
  2005-07-22 20:15   ` Adrian Bunk
  2005-07-22 20:14 ` Adrian Bunk
  1 sibling, 1 reply; 14+ messages in thread
From: David Lang @ 2005-07-22 19:52 UTC (permalink / raw)
  To: christos gentsis; +Cc: linux-kernel

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

On Fri, 22 Jul 2005, christos gentsis wrote:

> Date: Fri, 22 Jul 2005 19:55:48 +0100
> From: christos gentsis <christos_gentsis@yahoo.co.uk>
> To: linux-kernel@vger.kernel.org
> 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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>

-- 
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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: kernel optimization
  2005-07-22 18:55 christos gentsis
  2005-07-22 19:52 ` David Lang
@ 2005-07-22 20:14 ` Adrian Bunk
  2005-07-22 21:11   ` christos gentsis
                     ` (2 more replies)
  1 sibling, 3 replies; 14+ messages in thread
From: Adrian Bunk @ 2005-07-22 20:14 UTC (permalink / raw)
  To: christos gentsis; +Cc: linux-kernel

On Fri, Jul 22, 2005 at 07:55:48PM +0100, christos gentsis wrote:

> hello

Hi Chris,

> 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.

> 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.

> Thanks
> Chris

cu
Adrian

-- 

       "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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: kernel optimization
  2005-07-22 19:52 ` David Lang
@ 2005-07-22 20:15   ` Adrian Bunk
  0 siblings, 0 replies; 14+ messages in thread
From: Adrian Bunk @ 2005-07-22 20:15 UTC (permalink / raw)
  To: David Lang; +Cc: christos gentsis, linux-kernel

On Fri, Jul 22, 2005 at 12:52:22PM -0700, David Lang wrote:

> 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.

> David Lang

cu
Adrian

-- 

       "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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: kernel optimization
  2005-07-22 20:14 ` Adrian Bunk
@ 2005-07-22 21:11   ` christos gentsis
  2005-07-23 14:34     ` Simon Strandman
  2005-07-23  5:35   ` Al Boldi
  2005-07-23  6:30   ` cutaway
  2 siblings, 1 reply; 14+ messages in thread
From: christos gentsis @ 2005-07-22 21:11 UTC (permalink / raw)
  To: Adrian Bunk; +Cc: linux-kernel

Adrian Bunk wrote:

>On Fri, Jul 22, 2005 at 07:55:48PM +0100, christos gentsis wrote:
>
>  
>
>>hello
>>    
>>
>
>Hi Chris,
>
>  
>
>>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.
>
>  
>
>>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.
>
>  
>
>>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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: kernel optimization
  2005-07-22 20:14 ` Adrian Bunk
  2005-07-22 21:11   ` christos gentsis
@ 2005-07-23  5:35   ` Al Boldi
  2005-07-23  6:30   ` cutaway
  2 siblings, 0 replies; 14+ messages in thread
From: Al Boldi @ 2005-07-23  5:35 UTC (permalink / raw)
  To: 'Adrian Bunk'
  Cc: linux-kernel, 'christos gentsis', david.lang

 Adrian Bunk wrote: {
On Fri, Jul 22, 2005 at 07:55:48PM +0100, christos gentsis wrote:
> 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!


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: kernel optimization
  2005-07-22 20:14 ` Adrian Bunk
  2005-07-22 21:11   ` christos gentsis
  2005-07-23  5:35   ` Al Boldi
@ 2005-07-23  6:30   ` cutaway
  2005-07-23 19:50     ` Alan Cox
  2 siblings, 1 reply; 14+ messages in thread
From: cutaway @ 2005-07-23  6:30 UTC (permalink / raw)
  To: Adrian Bunk; +Cc: linux-kernel

----- Original Message ----- 
From: "Adrian Bunk" <bunk@stusta.de>
To: "christos gentsis" <christos_gentsis@yahoo.co.uk>
Cc: <linux-kernel@vger.kernel.org>
Sent: Friday, July 22, 2005 16:14
Subject: Re: kernel optimization
>
> 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.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: kernel optimization
  2005-07-22 21:11   ` christos gentsis
@ 2005-07-23 14:34     ` Simon Strandman
  0 siblings, 0 replies; 14+ messages in thread
From: Simon Strandman @ 2005-07-23 14:34 UTC (permalink / raw)
  To: christos gentsis; +Cc: linux-kernel

christos gentsis skrev:

>
> 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.

-- 
Simon Strandman <simon.strandman@telia.com>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: kernel optimization
  2005-07-23  6:30   ` cutaway
@ 2005-07-23 19:50     ` Alan Cox
  2005-07-23 22:03       ` cutaway
  0 siblings, 1 reply; 14+ messages in thread
From: Alan Cox @ 2005-07-23 19:50 UTC (permalink / raw)
  To: cutaway; +Cc: Adrian Bunk, linux-kernel

On Sad, 2005-07-23 at 02:30 -0400, cutaway@bellsouth.net 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.

> 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.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: kernel optimization
  2005-07-23 19:50     ` Alan Cox
@ 2005-07-23 22:03       ` cutaway
  0 siblings, 0 replies; 14+ messages in thread
From: cutaway @ 2005-07-23 22:03 UTC (permalink / raw)
  To: Alan Cox; +Cc: Adrian Bunk, linux-kernel

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" <alan@lxorguk.ukuu.org.uk>
To: <cutaway@bellsouth.net>
Cc: "Adrian Bunk" <bunk@stusta.de>; <linux-kernel@vger.kernel.org>
Sent: Saturday, July 23, 2005 15:50
Subject: Re: kernel optimization


> On Sad, 2005-07-23 at 02:30 -0400, cutaway@bellsouth.net 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.
>
> > 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.
>
>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: kernel optimization
       [not found] <200507231849.j6NInMPO003728@laptop11.inf.utfsm.cl>
@ 2005-07-26  5:22 ` Al Boldi
  2005-07-26  9:22   ` Adrian Bunk
  0 siblings, 1 reply; 14+ messages in thread
From: Al Boldi @ 2005-07-26  5:22 UTC (permalink / raw)
  To: 'Horst von Brand'; +Cc: linux-kernel

Dr. Horst H. von Brand wrote: {
Al Boldi <a1426z@gawab.com> wrote:
>  Adrian Bunk wrote: {
> On Fri, Jul 22, 2005 at 07:55:48PM +0100, christos gentsis wrote:
> > 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!

How do you know that it is faster if it is busted?
}

The -O3 compile produces a faster kernel, which seems to work perfectly,
albeit the Root-NFS boot flaw!

--
Al


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: kernel optimization
  2005-07-26  5:22 ` kernel optimization Al Boldi
@ 2005-07-26  9:22   ` Adrian Bunk
  0 siblings, 0 replies; 14+ messages in thread
From: Adrian Bunk @ 2005-07-26  9:22 UTC (permalink / raw)
  To: Al Boldi; +Cc: 'Horst von Brand', linux-kernel

On Tue, Jul 26, 2005 at 08:22:59AM +0300, Al Boldi wrote:
> Dr. Horst H. von Brand wrote: {
> Al Boldi <a1426z@gawab.com> wrote:
> >  Adrian Bunk wrote: {
> > On Fri, Jul 22, 2005 at 07:55:48PM +0100, christos gentsis wrote:
> > > 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!
> 
> How do you know that it is faster if it is busted?
> }
> 
> The -O3 compile produces a faster kernel, which seems to work perfectly,
> albeit the Root-NFS boot flaw!

How did you measure that you that your -O3 kernel isn't slower?

> Al

cu
Adrian

-- 

       "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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: kernel optimization
@ 2005-07-27  3:53 Al Boldi
  2005-07-27  4:20 ` Lee Revell
  0 siblings, 1 reply; 14+ messages in thread
From: Al Boldi @ 2005-07-27  3:53 UTC (permalink / raw)
  To: 'Adrian Bunk'; +Cc: 'Linux kernel', 'Horst von Brand'

Adrian Bunk wrote: {
On Tue, Jul 26, 2005 at 08:22:59AM +0300, Al Boldi wrote:
> Dr. Horst H. von Brand wrote: {
> Al Boldi <a1426z@gawab.com> wrote:
> >  Adrian Bunk wrote: {
> > On Fri, Jul 22, 2005 at 07:55:48PM +0100, christos gentsis wrote:
> > > 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!
> 
> How do you know that it is faster if it is busted?
> }
> 
> The -O3 compile produces a faster kernel, which seems to work perfectly,
> albeit the Root-NFS boot flaw!

How did you measure that you that your -O3 kernel isn't slower?
}

Gettimeofday loops using gcc-3.2.2 on 2.4.31 and 2.6.12.

Also, 2.4 is faster than 2.6!

Try this:

#define __USE_GNU
#include <stdio.h>
#include <sys/time.h>

unsigned long elapsed(int start) {

	static struct timeval s,e;

	if (start) return gettimeofday(&s, NULL);

	gettimeofday(&e, NULL);

	return ((e.tv_sec - s.tv_sec) * 1000 + (e.tv_usec - s.tv_usec) /
1000);

}

int main(int argc, char *argv[]) {

	int i;
	
	elapsed(1);
	for (i = 0; elapsed(0) < 100; i++) {
		int ret = i;

		if (ret > i)
			break;
		else if (ret < 0) {
			perror("not here");
			break;
		}
		ret++;
	}

	printf("Elapsed: %lu in %lums %lu/ms",i,elapsed(0),i/elapsed(0));

	int tmo=i;

	elapsed(1);
	for (i = 0; i < 100*tmo ; i++) {
		int ret = i;

		if (ret > i)
			break;
		else if (ret < 0) {
			perror("not here");
			break;
		}
		ret++;
	}

	printf(" - %lu/ms",i/elapsed(0));

	elapsed(1);
	for (i = 0; i < 100*tmo ; i++);

	printf(" - %lu/ms\n",i/elapsed(0));

	return 0;
}

--
Al


^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: kernel optimization
  2005-07-27  3:53 Al Boldi
@ 2005-07-27  4:20 ` Lee Revell
  0 siblings, 0 replies; 14+ messages in thread
From: Lee Revell @ 2005-07-27  4:20 UTC (permalink / raw)
  To: Al Boldi
  Cc: 'Adrian Bunk', 'Linux kernel',
	'Horst von Brand'

On Wed, 2005-07-27 at 06:53 +0300, Al Boldi wrote:
> Gettimeofday loops using gcc-3.2.2 on 2.4.31 and 2.6.12.
> 
> Also, 2.4 is faster than 2.6!

All this proves is that gettimeofday() is faster on 2.4 than 2.6.
Hardly surprising.

Lee


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2005-07-27  4:20 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <200507231849.j6NInMPO003728@laptop11.inf.utfsm.cl>
2005-07-26  5:22 ` kernel optimization Al Boldi
2005-07-26  9:22   ` Adrian Bunk
2005-07-27  3:53 Al Boldi
2005-07-27  4:20 ` Lee Revell
  -- strict thread matches above, loose matches on Subject: below --
2005-07-22 18:55 christos gentsis
2005-07-22 19:52 ` David Lang
2005-07-22 20:15   ` Adrian Bunk
2005-07-22 20:14 ` Adrian Bunk
2005-07-22 21:11   ` christos gentsis
2005-07-23 14:34     ` Simon Strandman
2005-07-23  5:35   ` Al Boldi
2005-07-23  6:30   ` cutaway
2005-07-23 19:50     ` Alan Cox
2005-07-23 22:03       ` cutaway

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox