* [PATCH] Allows Kernel developer to change optimization options making code more debug friendly.
[not found] <4E2D2689.6030500@suse.cz>
@ 2011-07-30 12:09 ` Radosław Smogura
2011-07-30 12:33 ` Radosław Smogura
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Radosław Smogura @ 2011-07-30 12:09 UTC (permalink / raw)
To: linux-kernel, Michal Marek, Randy Dunlap, linux-kbuild
Cc: Radosław Smogura
New menu under kernel hacking allows to force "-01" optimization
and gives ability to discard additional optimizations (passed
with -O1). Options are added as "-f-no-..." to GCC invoke line.
This make cause to produce additional warnings, but makes compiled
code more debug friendly.
Included new Makefile and new KConfig has been automaticly generated
by simple bash script scripts/debug/make_config_optim.sh, which
is included to simple add or remove new options.
Some options are sepcific to GCC version.
Signed-off-by: Radosław Smogura <mail@smogura.eu>
---
Makefile | 11 ++
lib/Kconfig.debug | 2 +
lib/Kconfig.debug.optim | 214 ++++++++++++++++++++++++++++++++++++
mm/Kconfig | 8 ++
mm/Makefile | 1 +
scripts/Makefile.optim.inc | 55 +++++++++
scripts/debug/make_config_optim.sh | 92 +++++++++++++++
7 files changed, 383 insertions(+), 0 deletions(-)
create mode 100644 lib/Kconfig.debug.optim
create mode 100644 scripts/Makefile.optim.inc
create mode 100644 scripts/debug/make_config_optim.sh
diff --git a/Makefile b/Makefile
index f676d15..1de2a79 100644
--- a/Makefile
+++ b/Makefile
@@ -558,12 +558,23 @@ endif # $(dot-config)
# Defaults to vmlinux, but the arch makefile usually adds further targets
all: vmlinux
+ifdef CONFIG_HACK_OPTIM_FORCE_O1_LEVEL
+KBUILD_CFLAGS += -O1
+else
+
ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
KBUILD_CFLAGS += -Os
else
KBUILD_CFLAGS += -O2
endif
+endif
+
+# Include makefile for optimization override
+ifdef CONFIG_HACK_OPTIM
+include $(srctree)/scripts/Makefile.optim.inc
+endif
+
include $(srctree)/arch/$(SRCARCH)/Makefile
ifneq ($(CONFIG_FRAME_WARN),0)
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index c0cb9c4..37976e4 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1262,5 +1262,7 @@ source "lib/Kconfig.kgdb"
source "lib/Kconfig.kmemcheck"
+source "lib/Kconfig.debug.optim"
+
config TEST_KSTRTOX
tristate "Test kstrto*() family of functions at runtime"
diff --git a/lib/Kconfig.debug.optim b/lib/Kconfig.debug.optim
new file mode 100644
index 0000000..b5c8795
--- /dev/null
+++ b/lib/Kconfig.debug.optim
@@ -0,0 +1,214 @@
+# This file was auto generated. It's utility configuration
+# Distributed under GPL v2 License
+
+menuconfig HACK_OPTIM
+ bool "Allows overriding GCC optimizations"
+ depends on DEBUG_KERNEL && EXPERIMENTAL
+ help
+ If you say Y here you will be able to override
+ how GCC optimizes kernel code. This creates
+ more debug-friendly code, but does not guarantee
+ the same running code like a production kernel.
+
+ If you say Y here probably you will want to say
+ Y for all suboptions
+
+if HACK_OPTIM
+
+config HACK_OPTIM_FORCE_O1_LEVEL
+ bool "Forces -O1 optimization level"
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_inline_functions_called_once
+ bool "Adds -fno-inline-functions-called-once parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_combine_stack_adjustments
+ bool "Adds -fno-combine-stack-adjustments parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_tree_dce
+ bool "Adds -fno-tree-dce parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_tree_dominator_opts
+ bool "Adds -fno-tree-dominator-opts parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_dse
+ bool "Adds -fno-dse parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_dce
+ bool "Adds -fno-dce parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_auto_inc_dec
+ bool "Adds -fno-auto-inc-dec parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_inline_small_functions
+ bool "Adds -fno-inline-small-functions parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_if_conversion
+ bool "Adds -fno-if-conversion parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_if_conversion2
+ bool "Adds -fno-if-conversion2 parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_tree_fre
+ bool "Adds -fno-tree-fre parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_tree_dse
+ bool "Adds -fno-tree-dse parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_tree_sra
+ bool "Adds -fno-tree-sra parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+endif #HACK_OPTIM
diff --git a/mm/Kconfig b/mm/Kconfig
index f2f1ca1..1d37e26 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -183,6 +183,14 @@ config COMPACTION
help
Allows the compaction of memory for the allocation of huge pages.
+config DEFRAG_PAGECACHE
+ bool "Allow defragmenting page cache to huge pages"
+ select MIGRATION
+ depends on MMU
+ help
+ Allows migration of page cache to huge pages. Currently only supports
+ tmpfs (/dev/shm). Selecting this will allow to use huge pages when
+ mmaping POSIX shared memory.
#
# support for page migration
#
diff --git a/mm/Makefile b/mm/Makefile
index 836e416..5736d2a 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -50,3 +50,4 @@ obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
obj-$(CONFIG_CLEANCACHE) += cleancache.o
+obj-$(CONFIG_DEFRAG_PAGECACHE) += defrag-pagecache.o
diff --git a/scripts/Makefile.optim.inc b/scripts/Makefile.optim.inc
new file mode 100644
index 0000000..6e17d53
--- /dev/null
+++ b/scripts/Makefile.optim.inc
@@ -0,0 +1,55 @@
+# This file was auto generated. It's utility configuration
+# Distributed under GPL v2 License
+
+ifdef CONFIG_HACK_OPTIM__fno_inline_functions_called_once
+ KBUILD_CFLAGS += -fno-inline-functions-called-once
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_combine_stack_adjustments
+ KBUILD_CFLAGS += -fno-combine-stack-adjustments
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_tree_dce
+ KBUILD_CFLAGS += -fno-tree-dce
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_tree_dominator_opts
+ KBUILD_CFLAGS += -fno-tree-dominator-opts
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_dse
+ KBUILD_CFLAGS += -fno-dse
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_dce
+ KBUILD_CFLAGS += -fno-dce
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_auto_inc_dec
+ KBUILD_CFLAGS += -fno-auto-inc-dec
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_inline_small_functions
+ KBUILD_CFLAGS += -fno-inline-small-functions
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_if_conversion
+ KBUILD_CFLAGS += -fno-if-conversion
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_if_conversion2
+ KBUILD_CFLAGS += -fno-if-conversion2
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_tree_fre
+ KBUILD_CFLAGS += -fno-tree-fre
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_tree_dse
+ KBUILD_CFLAGS += -fno-tree-dse
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_tree_sra
+ KBUILD_CFLAGS += -fno-tree-sra
+endif
+
diff --git a/scripts/debug/make_config_optim.sh b/scripts/debug/make_config_optim.sh
new file mode 100644
index 0000000..44736d7
--- /dev/null
+++ b/scripts/debug/make_config_optim.sh
@@ -0,0 +1,92 @@
+#!/bin/sh
+
+## Utility script for generating optimization override options
+## for kernel compilation.
+##
+## Distributed under GPL v2 license
+## (c) Radosław Smogura, 2011
+
+# Prefix added for variable
+CFG_PREFIX="HACK_OPTIM"
+
+KCFG="Kconfig.debug.optim"
+MKFI="Makefile.optim.inc"
+
+OPTIMIZATIONS_PARAMS="-fno-inline-functions-called-once \
+ -fno-combine-stack-adjustments \
+ -fno-tree-dce \
+ -fno-tree-dominator-opts \
+ -fno-dse \
+ -fno-dce \
+ -fno-auto-inc-dec \
+ -fno-inline-small-functions \
+ -fno-if-conversion \
+ -fno-if-conversion2 \
+ -fno-tree-fre \
+ -fno-tree-dse \
+ -fno-tree-sra
+"
+
+function printStandardHelp() {
+ echo -e "\t This changes how GCC optimizes code. Code" >> $KCFG
+ echo -e "\t may be slower and larger but will be more debug" >> $KCFG
+ echo -e "\t \"friendly\"." >> $KCFG
+ echo >> $KCFG
+ echo -e "\t In some cases there is a low chance that the kernel" >> $KCFG
+ echo -e "\t will run differently than normal, reporting or not" >> $KCFG
+ echo -e "\t reporting some bugs or errors." >> $KCFG
+ echo -e "\t Refer to GCC manual for more details." >> $KCFG
+ echo >> $KCFG
+ echo -e "\t You SHOULD say N here." >> $KCFG
+}
+
+echo "# This file was auto generated. It's utility configuration" > $KCFG
+echo "# Distributed under GPL v2 License" >> $KCFG
+echo >> $KCFG
+echo "menuconfig ${CFG_PREFIX}" >> $KCFG
+echo -e "\tbool \"Allows overriding GCC optimizations\"" >> $KCFG
+echo -e "\tdepends on DEBUG_KERNEL && EXPERIMENTAL" >> $KCFG
+echo -e "\thelp" >> $KCFG
+echo -e "\t If you say Y here you will be able to override" >> $KCFG
+echo -e "\t how GCC optimizes kernel code. This creates" >> $KCFG
+echo -e "\t more debug-friendly code, but does not guarantee" >> $KCFG
+echo -e "\t the same running code like a production kernel." >> $KCFG
+echo >> $KCFG
+echo -e "\t If you say Y here probably you will want to say" >> $KCFG
+echo -e "\t Y for all suboptions" >> $KCFG
+echo >> $KCFG
+echo "if ${CFG_PREFIX}" >> $KCFG
+echo >> $KCFG
+
+echo "# This file was auto generated. It's utility configuration" > $MKFI
+echo "# Distributed under GPL v2 License" >> $MKFI
+echo >> $MKFI
+
+# Insert standard override optimization level
+# This is exception, and this value will not be included
+# in auto generated makefile. Support for this value
+# is hard coded in main Makefile.
+echo -e "config ${CFG_PREFIX}_FORCE_O1_LEVEL" >> $KCFG
+echo -e "\tbool \"Forces -O1 optimization level\"" >> $KCFG
+echo -e "\t---help---" >> $KCFG
+printStandardHelp;
+echo >> $KCFG
+
+for o in $OPTIMIZATIONS_PARAMS ; do
+ cfg_o="${CFG_PREFIX}_${o//-/_}";
+ echo "Processing param ${o} config variable will be $cfg_o";
+
+ # Generate kconfig entry
+ echo -e "config ${cfg_o}" >> $KCFG
+ echo -e "\tbool \"Adds $o parameter to gcc invoke line.\"" >> $KCFG
+ echo -e "\t---help---" >> $KCFG
+ printStandardHelp;
+ echo >> $KCFG
+
+ #Generate Make for include
+ echo "ifdef CONFIG_${cfg_o}" >> $MKFI
+ echo -e "\tKBUILD_CFLAGS += $o" >> $MKFI
+ echo "endif" >> $MKFI
+ echo >> $MKFI
+done;
+echo "endif #${CFG_PREFIX}" >> $KCFG
--
1.7.3.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] Allows Kernel developer to change optimization options making code more debug friendly.
2011-07-30 12:09 ` [PATCH] Allows Kernel developer to change optimization options making code more debug friendly Radosław Smogura
@ 2011-07-30 12:33 ` Radosław Smogura
2011-07-30 14:58 ` Yann E. MORIN
2011-07-30 12:36 ` Radosław Smogura
2011-07-30 14:42 ` Alexey Dobriyan
2 siblings, 1 reply; 5+ messages in thread
From: Radosław Smogura @ 2011-07-30 12:33 UTC (permalink / raw)
To: linux-kernel, Michal Marek, Randy Dunlap, linux-kbuild
Cc: Radosław Smogura
New menu under kernel hacking allows to force "-01" optimization
and gives ability to discard additional optimizations (passed
with -O1). Options are added as "-f-no-..." to GCC invoke line.
This make cause to produce additional warnings, but makes compiled
code more debug friendly.
Included new Makefile and new KConfig has been automaticly generated
by simple bash script scripts/debug/make_config_optim.sh, which
is included to simple add or remove new options.
Some options are sepcific to GCC version.
Signed-off-by: Radosław Smogura <mail@smogura.eu>
---
Makefile | 11 ++
lib/Kconfig.debug | 2 +
lib/Kconfig.debug.optim | 214 ++++++++++++++++++++++++++++++++++++
scripts/Makefile.optim.inc | 55 +++++++++
scripts/debug/make_config_optim.sh | 92 +++++++++++++++
5 files changed, 374 insertions(+), 0 deletions(-)
create mode 100644 lib/Kconfig.debug.optim
create mode 100644 scripts/Makefile.optim.inc
create mode 100644 scripts/debug/make_config_optim.sh
diff --git a/Makefile b/Makefile
index f676d15..1de2a79 100644
--- a/Makefile
+++ b/Makefile
@@ -558,12 +558,23 @@ endif # $(dot-config)
# Defaults to vmlinux, but the arch makefile usually adds further targets
all: vmlinux
+ifdef CONFIG_HACK_OPTIM_FORCE_O1_LEVEL
+KBUILD_CFLAGS += -O1
+else
+
ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
KBUILD_CFLAGS += -Os
else
KBUILD_CFLAGS += -O2
endif
+endif
+
+# Include makefile for optimization override
+ifdef CONFIG_HACK_OPTIM
+include $(srctree)/scripts/Makefile.optim.inc
+endif
+
include $(srctree)/arch/$(SRCARCH)/Makefile
ifneq ($(CONFIG_FRAME_WARN),0)
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index c0cb9c4..37976e4 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1262,5 +1262,7 @@ source "lib/Kconfig.kgdb"
source "lib/Kconfig.kmemcheck"
+source "lib/Kconfig.debug.optim"
+
config TEST_KSTRTOX
tristate "Test kstrto*() family of functions at runtime"
diff --git a/lib/Kconfig.debug.optim b/lib/Kconfig.debug.optim
new file mode 100644
index 0000000..b5c8795
--- /dev/null
+++ b/lib/Kconfig.debug.optim
@@ -0,0 +1,214 @@
+# This file was auto generated. It's utility configuration
+# Distributed under GPL v2 License
+
+menuconfig HACK_OPTIM
+ bool "Allows overriding GCC optimizations"
+ depends on DEBUG_KERNEL && EXPERIMENTAL
+ help
+ If you say Y here you will be able to override
+ how GCC optimizes kernel code. This creates
+ more debug-friendly code, but does not guarantee
+ the same running code like a production kernel.
+
+ If you say Y here probably you will want to say
+ Y for all suboptions
+
+if HACK_OPTIM
+
+config HACK_OPTIM_FORCE_O1_LEVEL
+ bool "Forces -O1 optimization level"
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_inline_functions_called_once
+ bool "Adds -fno-inline-functions-called-once parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_combine_stack_adjustments
+ bool "Adds -fno-combine-stack-adjustments parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_tree_dce
+ bool "Adds -fno-tree-dce parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_tree_dominator_opts
+ bool "Adds -fno-tree-dominator-opts parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_dse
+ bool "Adds -fno-dse parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_dce
+ bool "Adds -fno-dce parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_auto_inc_dec
+ bool "Adds -fno-auto-inc-dec parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_inline_small_functions
+ bool "Adds -fno-inline-small-functions parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_if_conversion
+ bool "Adds -fno-if-conversion parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_if_conversion2
+ bool "Adds -fno-if-conversion2 parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_tree_fre
+ bool "Adds -fno-tree-fre parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_tree_dse
+ bool "Adds -fno-tree-dse parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+config HACK_OPTIM__fno_tree_sra
+ bool "Adds -fno-tree-sra parameter to gcc invoke line."
+ ---help---
+ This changes how GCC optimizes code. Code
+ may be slower and larger but will be more debug
+ "friendly".
+
+ In some cases there is a low chance that the kernel
+ will run differently than normal, reporting or not
+ reporting some bugs or errors.
+ Refer to GCC manual for more details.
+
+ You SHOULD say N here.
+
+endif #HACK_OPTIM
diff --git a/scripts/Makefile.optim.inc b/scripts/Makefile.optim.inc
new file mode 100644
index 0000000..6e17d53
--- /dev/null
+++ b/scripts/Makefile.optim.inc
@@ -0,0 +1,55 @@
+# This file was auto generated. It's utility configuration
+# Distributed under GPL v2 License
+
+ifdef CONFIG_HACK_OPTIM__fno_inline_functions_called_once
+ KBUILD_CFLAGS += -fno-inline-functions-called-once
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_combine_stack_adjustments
+ KBUILD_CFLAGS += -fno-combine-stack-adjustments
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_tree_dce
+ KBUILD_CFLAGS += -fno-tree-dce
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_tree_dominator_opts
+ KBUILD_CFLAGS += -fno-tree-dominator-opts
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_dse
+ KBUILD_CFLAGS += -fno-dse
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_dce
+ KBUILD_CFLAGS += -fno-dce
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_auto_inc_dec
+ KBUILD_CFLAGS += -fno-auto-inc-dec
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_inline_small_functions
+ KBUILD_CFLAGS += -fno-inline-small-functions
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_if_conversion
+ KBUILD_CFLAGS += -fno-if-conversion
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_if_conversion2
+ KBUILD_CFLAGS += -fno-if-conversion2
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_tree_fre
+ KBUILD_CFLAGS += -fno-tree-fre
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_tree_dse
+ KBUILD_CFLAGS += -fno-tree-dse
+endif
+
+ifdef CONFIG_HACK_OPTIM__fno_tree_sra
+ KBUILD_CFLAGS += -fno-tree-sra
+endif
+
diff --git a/scripts/debug/make_config_optim.sh b/scripts/debug/make_config_optim.sh
new file mode 100644
index 0000000..44736d7
--- /dev/null
+++ b/scripts/debug/make_config_optim.sh
@@ -0,0 +1,92 @@
+#!/bin/sh
+
+## Utility script for generating optimization override options
+## for kernel compilation.
+##
+## Distributed under GPL v2 license
+## (c) Radosław Smogura, 2011
+
+# Prefix added for variable
+CFG_PREFIX="HACK_OPTIM"
+
+KCFG="Kconfig.debug.optim"
+MKFI="Makefile.optim.inc"
+
+OPTIMIZATIONS_PARAMS="-fno-inline-functions-called-once \
+ -fno-combine-stack-adjustments \
+ -fno-tree-dce \
+ -fno-tree-dominator-opts \
+ -fno-dse \
+ -fno-dce \
+ -fno-auto-inc-dec \
+ -fno-inline-small-functions \
+ -fno-if-conversion \
+ -fno-if-conversion2 \
+ -fno-tree-fre \
+ -fno-tree-dse \
+ -fno-tree-sra
+"
+
+function printStandardHelp() {
+ echo -e "\t This changes how GCC optimizes code. Code" >> $KCFG
+ echo -e "\t may be slower and larger but will be more debug" >> $KCFG
+ echo -e "\t \"friendly\"." >> $KCFG
+ echo >> $KCFG
+ echo -e "\t In some cases there is a low chance that the kernel" >> $KCFG
+ echo -e "\t will run differently than normal, reporting or not" >> $KCFG
+ echo -e "\t reporting some bugs or errors." >> $KCFG
+ echo -e "\t Refer to GCC manual for more details." >> $KCFG
+ echo >> $KCFG
+ echo -e "\t You SHOULD say N here." >> $KCFG
+}
+
+echo "# This file was auto generated. It's utility configuration" > $KCFG
+echo "# Distributed under GPL v2 License" >> $KCFG
+echo >> $KCFG
+echo "menuconfig ${CFG_PREFIX}" >> $KCFG
+echo -e "\tbool \"Allows overriding GCC optimizations\"" >> $KCFG
+echo -e "\tdepends on DEBUG_KERNEL && EXPERIMENTAL" >> $KCFG
+echo -e "\thelp" >> $KCFG
+echo -e "\t If you say Y here you will be able to override" >> $KCFG
+echo -e "\t how GCC optimizes kernel code. This creates" >> $KCFG
+echo -e "\t more debug-friendly code, but does not guarantee" >> $KCFG
+echo -e "\t the same running code like a production kernel." >> $KCFG
+echo >> $KCFG
+echo -e "\t If you say Y here probably you will want to say" >> $KCFG
+echo -e "\t Y for all suboptions" >> $KCFG
+echo >> $KCFG
+echo "if ${CFG_PREFIX}" >> $KCFG
+echo >> $KCFG
+
+echo "# This file was auto generated. It's utility configuration" > $MKFI
+echo "# Distributed under GPL v2 License" >> $MKFI
+echo >> $MKFI
+
+# Insert standard override optimization level
+# This is exception, and this value will not be included
+# in auto generated makefile. Support for this value
+# is hard coded in main Makefile.
+echo -e "config ${CFG_PREFIX}_FORCE_O1_LEVEL" >> $KCFG
+echo -e "\tbool \"Forces -O1 optimization level\"" >> $KCFG
+echo -e "\t---help---" >> $KCFG
+printStandardHelp;
+echo >> $KCFG
+
+for o in $OPTIMIZATIONS_PARAMS ; do
+ cfg_o="${CFG_PREFIX}_${o//-/_}";
+ echo "Processing param ${o} config variable will be $cfg_o";
+
+ # Generate kconfig entry
+ echo -e "config ${cfg_o}" >> $KCFG
+ echo -e "\tbool \"Adds $o parameter to gcc invoke line.\"" >> $KCFG
+ echo -e "\t---help---" >> $KCFG
+ printStandardHelp;
+ echo >> $KCFG
+
+ #Generate Make for include
+ echo "ifdef CONFIG_${cfg_o}" >> $MKFI
+ echo -e "\tKBUILD_CFLAGS += $o" >> $MKFI
+ echo "endif" >> $MKFI
+ echo >> $MKFI
+done;
+echo "endif #${CFG_PREFIX}" >> $KCFG
--
1.7.3.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Allows Kernel developer to change optimization options making code more debug friendly.
2011-07-30 12:09 ` [PATCH] Allows Kernel developer to change optimization options making code more debug friendly Radosław Smogura
2011-07-30 12:33 ` Radosław Smogura
@ 2011-07-30 12:36 ` Radosław Smogura
2011-07-30 14:42 ` Alexey Dobriyan
2 siblings, 0 replies; 5+ messages in thread
From: Radosław Smogura @ 2011-07-30 12:36 UTC (permalink / raw)
To: linux-kernel; +Cc: Michal Marek, Randy Dunlap, linux-kbuild
Hello,
I would like to write sorry for unneeded mess, but I sent not cleared patch
(affected by other changes). The new mail contains cleared patch.
Regards,
Radosław Smogura
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Allows Kernel developer to change optimization options making code more debug friendly.
2011-07-30 12:09 ` [PATCH] Allows Kernel developer to change optimization options making code more debug friendly Radosław Smogura
2011-07-30 12:33 ` Radosław Smogura
2011-07-30 12:36 ` Radosław Smogura
@ 2011-07-30 14:42 ` Alexey Dobriyan
2 siblings, 0 replies; 5+ messages in thread
From: Alexey Dobriyan @ 2011-07-30 14:42 UTC (permalink / raw)
To: Radosław Smogura
Cc: linux-kernel, Michal Marek, Randy Dunlap, linux-kbuild
On Sat, Jul 30, 2011 at 02:09:09PM +0200, Radosław Smogura wrote:
> Included new Makefile and new KConfig has been automaticly generated
> by simple bash script scripts/debug/make_config_optim.sh, which
> +ifdef CONFIG_HACK_OPTIM_FORCE_O1_LEVEL
> +KBUILD_CFLAGS += -O1
> +else
Just patch top level Makefile.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Allows Kernel developer to change optimization options making code more debug friendly.
2011-07-30 12:33 ` Radosław Smogura
@ 2011-07-30 14:58 ` Yann E. MORIN
0 siblings, 0 replies; 5+ messages in thread
From: Yann E. MORIN @ 2011-07-30 14:58 UTC (permalink / raw)
To: Radosław Smogura
Cc: linux-kernel, Michal Marek, Randy Dunlap, linux-kbuild
Radosław, all,
On Saturday 30 July 2011 14:33:54 Radosław Smogura wrote:
> New menu under kernel hacking allows to force "-01" optimization
> and gives ability to discard additional optimizations (passed
> with -O1). Options are added as "-f-no-..." to GCC invoke line.
> This make cause to produce additional warnings, but makes compiled
> code more debug friendly.
>
> Included new Makefile and new KConfig has been automaticly generated
> by simple bash script scripts/debug/make_config_optim.sh, which
> is included to simple add or remove new options.
For what they are worth, see my comments below.
Note: I'm not commenting the usefulness or not of such a change,
just suggesting readability changes.
[--SNIP--]
> diff --git a/Makefile b/Makefile
> index f676d15..1de2a79 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -558,12 +558,23 @@ endif # $(dot-config)
>
> # Defaults to vmlinux, but the arch makefile usually adds further targets
> all: vmlinux
>
> +ifdef CONFIG_HACK_OPTIM_FORCE_O1_LEVEL
> +KBUILD_CFLAGS += -O1
> +else
> +
>
> ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
> KBUILD_CFLAGS += -Os
> else
> KBUILD_CFLAGS += -O2
> endif
>
> +endif
endif # ! CONFIG_HACK_OPTIM_FORCE_O1_LEVEL
Thus, it's easier to spot the corresponding if/else.
> +# Include makefile for optimization override
> +ifdef CONFIG_HACK_OPTIM
> +include $(srctree)/scripts/Makefile.optim.inc
> +endif
> +
>
> include $(srctree)/arch/$(SRCARCH)/Makefile
>
> ifneq ($(CONFIG_FRAME_WARN),0)
[--SNIP--]
> diff --git a/scripts/debug/make_config_optim.sh b/scripts/debug/make_config_optim.sh
> new file mode 100644
> index 0000000..44736d7
> --- /dev/null
> +++ b/scripts/debug/make_config_optim.sh
> @@ -0,0 +1,92 @@
> +#!/bin/sh
> +
> +## Utility script for generating optimization override options
> +## for kernel compilation.
> +##
> +## Distributed under GPL v2 license
> +## (c) Radosław Smogura, 2011
> +
> +# Prefix added for variable
> +CFG_PREFIX="HACK_OPTIM"
> +
> +KCFG="Kconfig.debug.optim"
> +MKFI="Makefile.optim.inc"
> +OPTIMIZATIONS_PARAMS="-fno-inline-functions-called-once \
> + -fno-combine-stack-adjustments \
> + -fno-tree-dce \
> + -fno-tree-dominator-opts \
> + -fno-dse \
> + -fno-dce \
> + -fno-auto-inc-dec \
> + -fno-inline-small-functions \
> + -fno-if-conversion \
> + -fno-if-conversion2 \
> + -fno-tree-fre \
> + -fno-tree-dse \
> + -fno-tree-sra
> +"
> +
> +function printStandardHelp() {
> + echo -e "\t This changes how GCC optimizes code. Code" >> $KCFG
> + echo -e "\t may be slower and larger but will be more debug" >> $KCFG
> + echo -e "\t \"friendly\"." >> $KCFG
> + echo >> $KCFG
> + echo -e "\t In some cases there is a low chance that the kernel" >> $KCFG
> + echo -e "\t will run differently than normal, reporting or not" >> $KCFG
> + echo -e "\t reporting some bugs or errors." >> $KCFG
> + echo -e "\t Refer to GCC manual for more details." >> $KCFG
> + echo >> $KCFG
> + echo -e "\t You SHOULD say N here." >> $KCFG
> +}
To redirect output iun the function, but only when you call it:
printStandardHelp >>$KCFG
Don't use 'echo -e', its not protable. Prefer using printf:
printf "\t blabla\n"
In this case, you may even prefer using here-document:
cat <<_EOF_ >>"${KCFG}"
[TAB] blabla
[TAB] blabla
_EOF_
Also, enclose file names with double-quotes, it guards against future
changes where a file name would gain a space in it:
blabla >"$KCFG"
> +echo "# This file was auto generated. It's utility configuration" > $KCFG
> +echo "# Distributed under GPL v2 License" >> $KCFG
> +echo >> $KCFG
> +echo "menuconfig ${CFG_PREFIX}" >> $KCFG
With variables, use smthg like:
printf "menuconfig %s\n" "${CFG_PREFIX}"
Variables are expanded in here-documents:
cat <<_EOF_ >>"${KCFG}"
menuconfig ${CFG_PREFIX}
_EOF_
Also, be consistent in the way you /dereference/ variables. Either use one
the ${foo} or $foo, not both. Eg, you use $KCFG, but you use ${CFG_PREFIX}
I personnaly prefer ${foo} because it makes it explicit what the variable
name is.
> +echo -e "\tbool \"Allows overriding GCC optimizations\"" >> $KCFG
> +echo -e "\tdepends on DEBUG_KERNEL && EXPERIMENTAL" >> $KCFG
> +echo -e "\thelp" >> $KCFG
> +echo -e "\t If you say Y here you will be able to override" >> $KCFG
> +echo -e "\t how GCC optimizes kernel code. This creates" >> $KCFG
> +echo -e "\t more debug-friendly code, but does not guarantee" >> $KCFG
> +echo -e "\t the same running code like a production kernel." >> $KCFG
> +echo >> $KCFG
> +echo -e "\t If you say Y here probably you will want to say" >> $KCFG
> +echo -e "\t Y for all suboptions" >> $KCFG
> +echo >> $KCFG
> +echo "if ${CFG_PREFIX}" >> $KCFG
> +echo >> $KCFG
Make this a function that just sends to stdout, and call it with stdout
redirected to $KCFG :
printDotInHeader() {
cat <<_EOF_
[TAB]blabla
[TAB]help
[TAB] blabla
_EOF_
}
printDotInHeader >$KCFG
> +echo "# This file was auto generated. It's utility configuration" > $MKFI
> +echo "# Distributed under GPL v2 License" >> $MKFI
> +echo >> $MKFI
Ditto.
> +# Insert standard override optimization level
> +# This is exception, and this value will not be included
> +# in auto generated makefile. Support for this value
> +# is hard coded in main Makefile.
> +echo -e "config ${CFG_PREFIX}_FORCE_O1_LEVEL" >> $KCFG
> +echo -e "\tbool \"Forces -O1 optimization level\"" >> $KCFG
> +echo -e "\t---help---" >> $KCFG
> +printStandardHelp;
> +echo >> $KCFG
Ditto.
Also, it should be better to change the way 'CONFIG_CC_OPTIMIZE_FOR_SIZE'
works. For example:
choice
bool "Optimise level"
default CC_OPTIMIZE_O2
config CC_OPTIMIZE_O2
bool "O2, for speed"
config CC_OPTIMIZE_OS
bool "Os, for size"
config CC_OPTIMIZE_O1
bool "O1 (for debug only)"
endchoice
config CC_O_LEVEL
string
default "-O2" if CC_OPTIMIZE_O2
default "-Os" if CC_OPTIMIZE_Os
default "-O1" if CC_OPTIMIZE_O1
Then:
KBUILD_CFLAGS += "${CONFIG_CC_O_LEVEL}"
> +for o in $OPTIMIZATIONS_PARAMS ; do
> + cfg_o="${CFG_PREFIX}_${o//-/_}";
This is a bashism, and is not portable. If /bin/sh is not bash, this does
not work. Use sed:
cfg_o="$( printf "${o}" |sed -r -e 's/-/_/g;' )"
No need for a trailing ';'.
> + echo "Processing param ${o} config variable will be $cfg_o";
> +
> + # Generate kconfig entry
> + echo -e "config ${cfg_o}" >> $KCFG
> + echo -e "\tbool \"Adds $o parameter to gcc invoke line.\"" >> $KCFG
> + echo -e "\t---help---" >> $KCFG
'---help---' should be written as simply 'help'.
> + printStandardHelp;
> + echo >> $KCFG
Move this to a function (eg. printOption), with $1 being the name of the
option. Eg.:
printOption() {
cfg_o="$( printf "${o}" |sed -r -e 's/-/_/g;' )"
printf 'config %s%s\n' "${CFG_PREFIX" "${cfg_o}"
printf '\tbool "Adds %s prm to gcc\n' "${1}"
printf '\thelp\n'
printfStandardHelp
printf '\n'
}
for o in $OPTIMIZATIONS_PARAMS ; do
printOption "${o}" >>"${KCFG}"
printMakeVar "${o}" >> "${MKFI}"
done
> + #Generate Make for include
> + echo "ifdef CONFIG_${cfg_o}" >> $MKFI
> + echo -e "\tKBUILD_CFLAGS += $o" >> $MKFI
> + echo "endif" >> $MKFI
> + echo >> $MKFI
> +done;
> +echo "endif #${CFG_PREFIX}" >> $KCFG
>
Regards,
Yann E. MORIN.
--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ |
| +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |
'------------------------------^-------^------------------^--------------------'
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-07-30 15:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <4E2D2689.6030500@suse.cz>
2011-07-30 12:09 ` [PATCH] Allows Kernel developer to change optimization options making code more debug friendly Radosław Smogura
2011-07-30 12:33 ` Radosław Smogura
2011-07-30 14:58 ` Yann E. MORIN
2011-07-30 12:36 ` Radosław Smogura
2011-07-30 14:42 ` Alexey Dobriyan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®