Skip to contentSkip to conversation

add new code section for kernel code

DISCUSSION saeed bishara 5 participants 13 messages Apr 6, 2006 – Apr 12, 2006 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

Hi,
I'm developing linux kernel for ARM cpu with direct-mapped
instruction cache, sometimes I notice that the pefromance of the kernel (for some test) is highly dependent on the code layout, in order to fix that I added new code section, and for each kernel function that highly invokerd I added compiler attribute so it will allocated in that section (exactly as the __init section). but it bothers me that I need to change the kernel source code, so is there any way to do that externally (without touching C code)?

saeed

#1 lore raw
Quoted 6 lines · On Thu, 6 Apr 2006 15:45:47 +0300 "saeed bishara" <[email protected]>…

I'm developing linux kernel for ARM cpu with direct-mapped
instruction cache, sometimes I notice that the pefromance of the kernel (for some test) is highly dependent on the code layout, in order to fix that I added new code section, and for each kernel function that highly invokerd I added compiler attribute so it will allocated in that section (exactly as the __init section)

It's already done in 2.6.17-rc1 for x86_64:

Processor type and feature --> Function reordering

arch/x86_64/Kconfig:

config REORDER
bool "Function reordering"
default n
help
This option enables the toolchain to reorder functions for a more optimal TLB usage. If you have pretty much any version of binutils, this can increase your kernel build time by roughly one minute.

http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=4bdc3b7f1b730c07f5a6ccca77ee68e044036ffc

Signature · 2 lines
	Paolo Ornati
	Linux 2.6.16.1 on x86_64
#2 lore raw

very cooooooooool!!
regarding the readprofile, I think it's recommended to mention that functions called within spinlocks won't show up.

Quoted 30 lines · Paolo Ornati
Quoted 6 lines · On Thu, 6 Apr 2006 15:45:47 +0300 "saeed bishara" <[email protected]>…

I'm developing linux kernel for ARM cpu with direct-mapped
instruction cache, sometimes I notice that the pefromance of the kernel (for some test) is highly dependent on the code layout, in order to fix that I added new code section, and for each kernel function that highly invokerd I added compiler attribute so it will allocated in that section (exactly as the __init section)

It's already done in 2.6.17-rc1 for x86_64:

Processor type and feature --> Function reordering

arch/x86_64/Kconfig:

config REORDER
bool "Function reordering"
default n
help
This option enables the toolchain to reorder functions for a more optimal TLB usage. If you have pretty much any version of binutils, this can increase your kernel build time by roughly one minute.

http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=4bdc3b7f1b730c07f5a6ccca77ee68e044036ffc

--

        Paolo Ornati
        Linux 2.6.16.1 on x86_64
#3 lore raw
In reply to Paolo Ornati

Hi,
I've tried to port this to my kernel (2.6.12.6), but the kenel
fails to boot; it stops after Starting kernel ....
I tried to add only the CFLAGS += -ffunction-sections to the
arch/arm/Makefile, and it still fails. my tool chains is "gcc version 3.4.4 (release) (CodeSourcery ARM 2005q3-2)"
any ideas?

saeed

Quoted 30 lines · Paolo Ornati
Quoted 6 lines · On Thu, 6 Apr 2006 15:45:47 +0300 "saeed bishara" <[email protected]>…

I'm developing linux kernel for ARM cpu with direct-mapped
instruction cache, sometimes I notice that the pefromance of the kernel (for some test) is highly dependent on the code layout, in order to fix that I added new code section, and for each kernel function that highly invokerd I added compiler attribute so it will allocated in that section (exactly as the __init section)

It's already done in 2.6.17-rc1 for x86_64:

Processor type and feature --> Function reordering

arch/x86_64/Kconfig:

config REORDER
bool "Function reordering"
default n
help
This option enables the toolchain to reorder functions for a more optimal TLB usage. If you have pretty much any version of binutils, this can increase your kernel build time by roughly one minute.

http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=4bdc3b7f1b730c07f5a6ccca77ee68e044036ffc

--

        Paolo Ornati
        Linux 2.6.16.1 on x86_64
#4 lore raw

I noticed the arch/arm/boot/compressed/ files compiled with ffunction-sections switch, so I added the -fno-function-sections to the EXTRA_CFLAGS of the compressed/Makefile. And this solved the problem.

Quoted 7 lines · saeed bishara

Hi,
I've tried to port this to my kernel (2.6.12.6), but the kenel
fails to boot; it stops after Starting kernel ....
I tried to add only the CFLAGS += -ffunction-sections to the
arch/arm/Makefile, and it still fails. my tool chains is "gcc version 3.4.4 (release) (CodeSourcery ARM 2005q3-2)"
any ideas?

#5 lore raw
Quoted 4 lines · saeed bishara

I noticed the arch/arm/boot/compressed/ files compiled with ffunction-sections switch, so I added the -fno-function-sections to the EXTRA_CFLAGS of the compressed/Makefile. And this solved the problem.

can you send a patch for this to Russell ?

#6 lore raw
Quoted 7 lines · Arjan van de Ven
Quoted 4 lines · saeed bishara

I noticed the arch/arm/boot/compressed/ files compiled with ffunction-sections switch, so I added the -fno-function-sections to the EXTRA_CFLAGS of the compressed/Makefile. And this solved the problem.

can you send a patch for this to Russell ?

I'd prefer not to paper over such bugs. Maybe the following patch will fix the decompressor for saeed?

arch/arm/boot/compressed/vmlinux.lds.in +1 -0
@@ -18,6 +18,7 @@ SECTIONS
     _start = .;
     *(.start)
     *(.text)
+    *(.text.*)
     *(.fixup)
     *(.gnu.warning)
     *(.rodata)
Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#7 lore raw
Quoted 2 lines

I'd prefer not to paper over such bugs. Maybe the following patch will fix the decompressor for saeed?

yes, this patch fixed the problem.

Quoted 19 lines
arch/arm/boot/compressed/vmlinux.lds.in +1 -1
@@ -18,6 +18,7 @@ SECTIONS
     _start = .;
     *(.start)
     *(.text)
+    *(.text.*)
     *(.fixup)
     *(.gnu.warning)
     *(.rodata)
 
 
--

Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 Serial core

#8 lore raw
Quoted 4 lines · saeed bishara
Quoted 2 lines

I'd prefer not to paper over such bugs. Maybe the following patch will fix the decompressor for saeed?

yes, this patch fixed the problem.

Thanks for testing; I've applied this patch so 2.6.17-rc2 onwards will have this fixed.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#9 lore raw

I just want to say that this code reordering reduced the I cache misses of my system that includes direct mapped caches, and the perforamance of a the optimezed tests increased up to 10% and in some case it improved by 20%.

saeed

Quoted 3 lines

Thanks for testing; I've applied this patch so 2.6.17-rc2 onwards will have this fixed.

#10 lore raw
In reply to Russell King
Quoted 2 lines · Russell King

Thanks for testing; I've applied this patch so 2.6.17-rc2 onwards will have this fixed.

Maybe this can also be applied to the data sections, for people who compile with -fdata-sections? As in the following patch (note that the .rodata sections are already wildcarded):

diff -urNd a/arch/arm/boot/compressed/vmlinux.lds.in b/arch/arm/boot/compressed/vmlinux.lds.in
--- a/arch/arm/boot/compressed/vmlinux.lds.in 2006-03-20
06:53:29.000000000 +0100
+++ b/arch/arm/boot/compressed/vmlinux.lds.in 2006-04-10
11:06:03.000000000 +0200
@@ -34,7 +35,7 @@
.got : { *(.got) }
_got_end = .;
.got.plt : { *(.got.plt) }
- .data : { *(.data) }
+ .data : { *(.data) *(.data.*) }
_edata = .;

   . = BSS_START;
#11 lore raw

inorder to reduce image size of the kenrel I added the --gc-secions
flag to the LDFALGS_vmlinux, the image size reduced by 120KB (out of
1.8M), but the kernel failed to boot ( after the uncompression stage). any idea?
I see that the fvr arch aleady using those flags.

#12 lore raw
Quoted 5 lines · saeed bishara

inorder to reduce image size of the kenrel I added the --gc-secions
flag to the LDFALGS_vmlinux, the image size reduced by 120KB (out of
1.8M), but the kernel failed to boot ( after the uncompression stage). any idea?
I see that the fvr arch aleady using those flags.

there are some known binutils "issues" (or better "interactions") that make this not yet practical.