macros for section name cleanup
Subsystems (4)
cover macros for section name cleanup
Here are the architecture-independent macro definitions needed for to clean up the kernel's section names. The overall diffstat from this section name cleanup project is:
96 files changed, 261 insertions(+), 503 deletions(-)
The decrease results from removing a lot of redundancy in the linker scripts.
The long-term goal here is to add support for building the kernel with -ffunction-sections -fdata-sections. This requires renaming all the magic section names in the kernel of the form .text.foo, .data.foo, .bss.foo, and .rodata.foo to not have collisions with sections generated for code like:
static int nosave = 0; /* -fdata-sections places in .data.nosave */ static void head(); /* -ffunction-sections places in .text.head */
Sam Ravnborg proposed that rather than just renaming all the sections outright, we should start by first getting more control over the section names used in the kernel so that we can later rename sections without touching too many files. These patch series implement that cleanup. Later, there will be another patch series to actually rename the sections.
I'm hoping we can get just these macro definitions into 2.6.30 so that the arch maintainers don't have to grab the macro definitions for their trees while reviewing the patches for 2.6.31.
Shortly, I'm going to send one patch series for each of the architectures updating those architectures to use these new macros (and otherwise cleaning up section names on those architectures).
-Tim Abbott
Tim Abbott (6):
Add new macros for page-aligned data and bss sections. Add new NOSAVE_DATA linker script macro.
Add new CACHELINE_ALIGNED_DATA linker script macro. Add new INIT_TASK_DATA() linker script macro. Add new READ_MOSTLY_DATA(align) linker script macro. Add support for __read_mostly to linux/cache.h
include/asm-generic/vmlinux.lds.h | 27 +++++++++++++++++++++++++++ include/linux/cache.h | 6 ++++++ include/linux/init_task.h | 3 +++ include/linux/linkage.h | 9 +++++++++ 4 files changed, 45 insertions(+), 0 deletions(-)
PATCH 1/6 Add new macros for page-aligned data and bss sections.
This patch is preparation for replacing most uses of ".bss.page_aligned" and ".data.page_aligned" in the kernel with macros, so that the section name can later be changed without having to touch a lot of the kernel.
The long-term goal here is to be able to change the kernel's magic section names to those that are compatible with -ffunction-sections -fdata-sections. This requires renaming all magic sections with names of the form ".data.foo".
--- include/asm-generic/vmlinux.lds.h | 8 ++++++++ include/linux/linkage.h | 9 +++++++++ 2 files changed, 17 insertions(+), 0 deletions(-)
include/asm-generic/vmlinux.lds.h +8 -0
@@ -116,6 +116,14 @@ FTRACE_EVENTS() \ TRACE_SYSCALLS() +#define PAGE_ALIGNED_DATA \ + . = ALIGN(PAGE_SIZE); \ + *(.data.page_aligned) + +#define PAGE_ALIGNED_BSS \ + . = ALIGN(PAGE_SIZE); \ + *(.bss.page_aligned) +#define RO_DATA (align) \ . = ALIGN((align)); \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
include/linux/linkage.h +9 -0
@@ -22,6 +22,15 @@#define __page_aligned_bss __section(.bss.page_aligned) __aligned(PAGE_SIZE)/* +* For assembly routines. +* +* Note when using these that you must specify the appropriate +* alignment directives yourself +*/ +#define __PAGE_ALIGNED_DATA .section ".data.page_aligned", "aw", @progbits +#define __PAGE_ALIGNED_BSS .section ".bss.page_aligned", "aw", @nobits + +/* * This is used by architectures to keep arguments on the stack * untouched by the compiler by keeping them live until the end. * The argument stack may be owned by the assembly-language
Signature · 1 line
1.6.2.1
PATCH 2/6 Add new NOSAVE_DATA linker script macro.
This patch is preparation for replacing most ".data.nosave" in the kernel with macros, so that the section name can later be changed without having to touch a lot of the kernel.
The long-term goal here is to be able to change the kernel's magic section names to those that are compatible with -ffunction-sections -fdata-sections. This requires renaming all magic sections with names of the form ".data.foo".
--- include/asm-generic/vmlinux.lds.h | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
include/asm-generic/vmlinux.lds.h +7 -0
@@ -124,6 +124,13 @@ . = ALIGN(PAGE_SIZE); \ *(.bss.page_aligned) +#define NOSAVE_DATA \ + . = ALIGN(PAGE_SIZE); \ + __nosave_begin = .; \ + *(.data.nosave) \ + . = ALIGN(PAGE_SIZE); \ + __nosave_end = .; +#define RO_DATA (align) \ . = ALIGN((align)); \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
Signature · 1 line
1.6.2.1
PATCH 3/6 Add new CACHELINE_ALIGNED_DATA linker script macro.
This patch is preparation for replacing most ".data.cacheline_aligned" in the kernel with macros, so that the section name can later be changed without having to touch a lot of the kernel.
The long-term goal here is to be able to change the kernel's magic section names to those that are compatible with -ffunction-sections -fdata-sections. This requires renaming all magic sections with names of the form ".data.foo".
--- include/asm-generic/vmlinux.lds.h | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
include/asm-generic/vmlinux.lds.h +4 -0
@@ -131,6 +131,10 @@ . = ALIGN(PAGE_SIZE); \ __nosave_end = .; +#define CACHELINE_ALIGNED_DATA (alignment) \ + . = ALIGN(alignment); \ + *(.data.cacheline_aligned) +#define RO_DATA (align) \ . = ALIGN((align)); \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
Signature · 1 line
1.6.2.1
PATCH 4/6 Add new INIT_TASK_DATA() linker script macro.
This patch is preparation for replacing most ".data.init_task" in the kernel with macros, so that the section name can later be changed without having to touch a lot of the kernel.
The long-term goal here is to be able to change the kernel's magic section names to those that are compatible with -ffunction-sections -fdata-sections. This requires renaming all magic sections with names of the form ".data.foo".
--- include/asm-generic/vmlinux.lds.h | 4 ++++ include/linux/init_task.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
include/asm-generic/vmlinux.lds.h +4 -0
@@ -135,6 +135,10 @@ . = ALIGN(alignment); \ *(.data.cacheline_aligned) +#define INIT_TASK_DATA (alignment) \ + . = ALIGN(alignment); \ + *(.data.init_task) +#define RO_DATA (align) \ . = ALIGN((align)); \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
include/linux/init_task.h +3 -0
@@ -184,5 +184,8 @@ extern struct cred init_cred; LIST_HEAD_INIT(cpu_timers[2]), \ } +/* Attach to the init_task data structure for proper alignment */ +#define __init_task_data __attribute__((__section__(".data.init_task"))) +#endif
Signature · 1 line
1.6.2.1
PATCH 5/6 Add new READ_MOSTLY_DATA(align) linker script macro.
This patch is preparation for replacing most ".data.read_mostly" in the kernel with macros, so that the section name can later be changed without having to touch a lot of the kernel.
The long-term goal here is to be able to change the kernel's magic section names to those that are compatible with -ffunction-sections -fdata-sections. This requires renaming all magic sections with names of the form ".data.foo".
--- include/asm-generic/vmlinux.lds.h | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
include/asm-generic/vmlinux.lds.h +4 -0
@@ -139,6 +139,10 @@ . = ALIGN(alignment); \ *(.data.init_task) +#define READ_MOSTLY_DATA (alignment) \ + . = ALIGN(alignment); \ + *(.data.read_mostly) +#define RO_DATA (align) \ . = ALIGN((align)); \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
Signature · 1 line
1.6.2.1
PATCH 6/6 Add support for __read_mostly to linux/cache.h
--- include/linux/cache.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
include/linux/cache.h +6 -0
@@ -13,7 +13,13 @@#endif #ifndef __read_mostly +#ifdef CONFIG_HAVE_READ_MOSTLY_DATA +#define __read_mostly __attribute__((__section__(".data.read_mostly"))) +#define __READ_MOSTLY .section ".data.read_mostly", "aw" +#else #define __read_mostly +#define __READ_MOSTLY +#endif /* CONFIG_HAVE_READ_MOSTLY_DATA */ #endif #ifndef ____cacheline_aligned
Signature · 1 line
1.6.2.1
Re: [PATCH 6/6] Add support for __read_mostly to linux/cache.h
Quoted 11 lines · Tim Abbott
Signed-off-by Tim Abbott <[email protected]>--- include/linux/cache.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)include/linux/cache.h +0
-0@@ -13,7 +13,13 @@#endif
include/linux/cache.h line 23
Quoted 10 lines
include/linux/cache.h +6
-0#ifndef __read_mostly +#ifdef CONFIG_HAVE_READ_MOSTLY_DATA +#define __read_mostly __attribute__((__section__(".data.read_mostly"))) +#define __READ_MOSTLY .section ".data.read_mostly", "aw" +#else #define __read_mostly +#define __READ_MOSTLY +#endif /* CONFIG_HAVE_READ_MOSTLY_DATA */ #endif
Are there any specific reason why we do not support read_mostly on all architectures?
read_mostly is about grouping rarely written data together so what is needed is to introduce this section in the remaining archtectures.
Christoph - git log says you did the inital implmentation. Do you agree?
Sam
Re: [PATCH 6/6] Add support for __read_mostly to linux/cache.h
In reply to a message not in the archiveQuoted 2 lines · Sam Ravnborg
Are there any specific reason why we do not support
read_mostlyon all architectures?
Not that I know of.
Quoted 6 lines
read_mostlyis about grouping rarely written data together so what is needed is to introduce this section in the remaining archtectures.Christoph - git log says you did the inital implmentation. Do you agree?
Yes.
There is some concern that __read_mostly is needlessly applied to numerous variables that are not used in hot code paths. This may make __read_mostly ineffective and actually increase the cache footprint of a function since global variables are no longer in the same cacheline. If such a function is called and the caches are cold then two cacheline fetches have to be done instead of one.
Re: [microblaze-uclinux] Re: [PATCH 6/6] Add support for __read_mostly to linux/cache.h
Quoted 14 lines · Christoph Lameter
Quoted 2 lines · Sam Ravnborg
Are there any specific reason why we do not support
read_mostlyon all architectures?Not that I know of.
Quoted 6 lines
read_mostlyis about grouping rarely written data together so what is needed is to introduce this section in the remaining archtectures.Christoph - git log says you did the inital implmentation. Do you agree?
Quoted 8 lines
Yes.
There is some concern that
__read_mostlyis needlessly applied to numerous variables that are not used in hot code paths. This may make__read_mostlyineffective and actually increase the cache footprint of a function since global variables are no longer in the same cacheline. If such a function is called and the caches are cold then two cacheline fetches have to be done instead of one.
FWIW I think that's a valid concern. Also, I think one can question the value of __read_mostly for write-through caches, given the mentioned concern it probably makes things worse for those. IMO there should be a way to turn it off for arch's that know it's no good for them.
Cheers