public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Aligning function on a page boundary
@ 2008-02-27 13:09 Igor Bukanov
  2008-02-27 14:00 ` Sam Ravnborg
  0 siblings, 1 reply; 4+ messages in thread
From: Igor Bukanov @ 2008-02-27 13:09 UTC (permalink / raw)
  To: gcc-help

Hi,

is it possible with GCC 4.1 to align one single function on a CPU page
boundary for ELF targets? This is very desired since the function in
question is an interpreter loop . It has 50K of code and is executed
very often. Aligning it on the page boundary should reduce TLB misses.

It seems the forthcoming GCC 4.3 allows that as it supports the align
attribute for functions,  but it would be nice to do that with GCC
4.1.

Thanks in advance, Igor

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

* Re: Aligning function on a page boundary
  2008-02-27 13:09 Aligning function on a page boundary Igor Bukanov
@ 2008-02-27 14:00 ` Sam Ravnborg
  2008-02-27 14:08   ` Igor Bukanov
  0 siblings, 1 reply; 4+ messages in thread
From: Sam Ravnborg @ 2008-02-27 14:00 UTC (permalink / raw)
  To: Igor Bukanov; +Cc: gcc-help

On Wed, Feb 27, 2008 at 01:51:10PM +0100, Igor Bukanov wrote:
> Hi,
> 
> is it possible with GCC 4.1 to align one single function on a CPU page
> boundary for ELF targets? This is very desired since the function in
> question is an interpreter loop . It has 50K of code and is executed
> very often. Aligning it on the page boundary should reduce TLB misses.
> 
> It seems the forthcoming GCC 4.3 allows that as it supports the align
> attribute for functions,  but it would be nice to do that with GCC
> 4.1.

One way is to use the section attribute to tell gcc to put the
function in a specific section and then in the linker script
page align said section.
This is used extensively in the linux kernel.

	Sam

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

* Re: Aligning function on a page boundary
  2008-02-27 14:00 ` Sam Ravnborg
@ 2008-02-27 14:08   ` Igor Bukanov
  2008-02-27 17:43     ` Sam Ravnborg
  0 siblings, 1 reply; 4+ messages in thread
From: Igor Bukanov @ 2008-02-27 14:08 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: gcc-help

Hi Sam,

I have tried to use __attribute__((section("xxx")), but it seems there
are no linker options to force a particular alignment for a section
for ELF. All those nice alignment options refers to Windows:

--section-alignment
           Sets  the  section alignment.  Sections in memory will
always begin at addresses which are a multiple of this number.
Defaults to 0x1000.  [This option is specific to the i386 PE targeted
port of the linker]

I can only force the section to start on a particular address when
loaded. Then it works. But this is not what as I have no idea what the
address should be.

Have I missed something?

Regards, Igor

On 27/02/2008, Sam Ravnborg <sam@ravnborg.org> wrote:
> On Wed, Feb 27, 2008 at 01:51:10PM +0100, Igor Bukanov wrote:
>  > Hi,
>  >
>  > is it possible with GCC 4.1 to align one single function on a CPU page
>  > boundary for ELF targets? This is very desired since the function in
>  > question is an interpreter loop . It has 50K of code and is executed
>  > very often. Aligning it on the page boundary should reduce TLB misses.
>  >
>  > It seems the forthcoming GCC 4.3 allows that as it supports the align
>  > attribute for functions,  but it would be nice to do that with GCC
>  > 4.1.
>
>
> One way is to use the section attribute to tell gcc to put the
>  function in a specific section and then in the linker script
>  page align said section.
>  This is used extensively in the linux kernel.
>
>
>         Sam
>

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

* Re: Aligning function on a page boundary
  2008-02-27 14:08   ` Igor Bukanov
@ 2008-02-27 17:43     ` Sam Ravnborg
  0 siblings, 0 replies; 4+ messages in thread
From: Sam Ravnborg @ 2008-02-27 17:43 UTC (permalink / raw)
  To: Igor Bukanov; +Cc: gcc-help

On Wed, Feb 27, 2008 at 02:59:41PM +0100, Igor Bukanov wrote:
> Hi Sam,
> 
> I have tried to use __attribute__((section("xxx")), but it seems there
> are no linker options to force a particular alignment for a section
> for ELF. All those nice alignment options refers to Windows:
> 
> --section-alignment
>            Sets  the  section alignment.  Sections in memory will
> always begin at addresses which are a multiple of this number.
> Defaults to 0x1000.  [This option is specific to the i386 PE targeted
> port of the linker]
> 
> I can only force the section to start on a particular address when
> loaded. Then it works. But this is not what as I have no idea what the
> address should be.
> 
> Have I missed something?

You need to provide your own linker script and then you can
adjust '.' to a page aligned address.

Sample from the kernel linker script:

 /* read-only */
  .text : AT(ADDR(.text) - LOAD_OFFSET) {
        . = ALIGN(4096);
        *(.text.page_aligned)



ld can generate the current default linekr script that you can base
your changes upon.

	Sam

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

end of thread, other threads:[~2008-02-27 14:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-27 13:09 Aligning function on a page boundary Igor Bukanov
2008-02-27 14:00 ` Sam Ravnborg
2008-02-27 14:08   ` Igor Bukanov
2008-02-27 17:43     ` Sam Ravnborg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).