All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Added hacking menu for override optimization by GCC
@ 2011-07-23 10:49 Radosław Smogura
  2011-07-23 17:23 ` Randy Dunlap
  0 siblings, 1 reply; 10+ messages in thread
From: Radosław Smogura @ 2011-07-23 10:49 UTC (permalink / raw)
  To: Michal Marek, linux-kbuild

[-- Attachment #1: Type: Text/Plain, Size: 308 bytes --]

This patch gives ability for add some "-fno-..." options for GCC
and to force -O1 optimization. Supporting files, like Kconfig, Makefile
are auto-generated due to large amount of available options (not all 
included).

Patch helps to debug kernel.

Signed-off-by: Radosław Smogura <mail@smogura.eu>

[-- Attachment #2: 0001-Added-hacking-menu-for-override-optimization-by-GCC.patch --]
[-- Type: text/x-patch, Size: 9984 bytes --]

From 4d0cd0b8e84d064b4da85b16ef4cfb3a63608cf3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rados=C5=82aw=20Smogura?= <mail@smogura.eu, rsmogura@softperience.eu>
Date: Sat, 23 Jul 2011 12:26:27 +0200
Subject: [PATCH] Added hacking menu for override optimization by GCC.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch gives ability for add some "-fno-..." options for GCC
and to force -O1 optimization. Supporting files, like Kconfig, Makefile
are auto-generated due to large amount of available options.

Patch helps to debug kernel.

Signed-off-by: Radosław Smogura <mail@smogura.eu>
---
 Makefile                           |   11 ++++
 lib/Kconfig.debug                  |    2 +
 lib/Kconfig.debug.optim            |  102 ++++++++++++++++++++++++++++++++++++
 scripts/Makefile.optim.inc         |   23 ++++++++
 scripts/debug/make_config_optim.sh |   88 +++++++++++++++++++++++++++++++
 5 files changed, 226 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 86f47a0..61c39b0 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 dd373c8..3013a6b 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1259,5 +1259,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..09b1012
--- /dev/null
+++ b/lib/Kconfig.debug.optim
@@ -0,0 +1,102 @@
+# This file was auto generated. It's utility configuration
+# Distributed under GPL v2 License
+
+menuconfig HACK_OPTIM
+	bool "Allows to override GCC optimization"
+	depends on DEBUG_KERNEL && EXPERIMENTAL
+	help
+	  If you say Y here you will be able to override
+	  how GCC optimize kernel code. This will create
+	  more debug friendly, but with not guarentee
+	  about same runi, like production, kernel.
+
+	  If you say Y here probably You will want say
+	  for all suboptions
+
+if HACK_OPTIM
+
+config HACK_OPTIM_FORCE_O1_LEVEL
+	bool "Forces -O1 optimization level"
+	---help---
+	  This will change how GCC optimize code. Code
+	  may be slower and larger but will be more debug
+	  "friendly".
+
+	  In some cases there is low chance that kernel
+	  will run different then normal, reporting or not
+	  some bugs or errors. Refere 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 will change how GCC optimize code. Code
+	  may be slower and larger but will be more debug
+	  "friendly".
+
+	  In some cases there is low chance that kernel
+	  will run different then normal, reporting or not
+	  some bugs or errors. Refere 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 will change how GCC optimize code. Code
+	  may be slower and larger but will be more debug
+	  "friendly".
+
+	  In some cases there is low chance that kernel
+	  will run different then normal, reporting or not
+	  some bugs or errors. Refere 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 will change how GCC optimize code. Code
+	  may be slower and larger but will be more debug
+	  "friendly".
+
+	  In some cases there is low chance that kernel
+	  will run different then normal, reporting or not
+	  some bugs or errors. Refere 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 will change how GCC optimize code. Code
+	  may be slower and larger but will be more debug
+	  "friendly".
+
+	  In some cases there is low chance that kernel
+	  will run different then normal, reporting or not
+	  some bugs or errors. Refere 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 will change how GCC optimize code. Code
+	  may be slower and larger but will be more debug
+	  "friendly".
+
+	  In some cases there is low chance that kernel
+	  will run different then normal, reporting or not
+	  some bugs or errors. Refere 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..e78cc92
--- /dev/null
+++ b/scripts/Makefile.optim.inc
@@ -0,0 +1,23 @@
+# 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
+
diff --git a/scripts/debug/make_config_optim.sh b/scripts/debug/make_config_optim.sh
new file mode 100644
index 0000000..26865923
--- /dev/null
+++ b/scripts/debug/make_config_optim.sh
@@ -0,0 +1,88 @@
+#!/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 "
+
+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 to override GCC optimization\"" >> $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 optimize kernel code. This will create" >> $KCFG
+echo -e "\t  more debug friendly, but with not guarentee"    >> $KCFG
+echo -e "\t  about same runi, like production, kernel."      >> $KCFG
+echo >> $KCFG
+echo -e "\t  If you say Y here probably You will want say"   >> $KCFG
+echo -e "\t  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
+echo -e "\t  This will change how GCC optimize 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 low chance that kernel" >> $KCFG
+echo -e "\t  will run different then normal, reporting or not" >> $KCFG
+echo -e "\t  some bugs or errors. Refere to GCC manual for" >> $KCFG
+echo -e "\t  more details." >> $KCFG
+echo >> $KCFG
+echo -e "\t  You SHOULD say N here." >> $KCFG
+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
+	echo -e "\t  This will change how GCC optimize 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 low chance that kernel" >> $KCFG
+	echo -e "\t  will run different then normal, reporting or not" >> $KCFG
+	echo -e "\t  some bugs or errors. Refere to GCC manual for" >> $KCFG
+	echo -e "\t  more details." >> $KCFG
+	echo >> $KCFG
+	echo -e "\t  You SHOULD say N here." >> $KCFG
+	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 related	[flat|nested] 10+ messages in thread

* Re: [PATCH] Added hacking menu for override optimization by GCC
  2011-07-23 10:49 [PATCH] Added hacking menu for override optimization by GCC Radosław Smogura
@ 2011-07-23 17:23 ` Randy Dunlap
  2011-07-24 11:17   ` [PATCH 1/2] " Radosław Smogura
  2011-07-24 11:17   ` [PATCH 2/2] This patch gives ability for add some "-fno-..." options for GCC and to force -O1 optimization. Supporting files, like Kconfig, Makefile are auto-generated due to large amount of available options Radosław Smogura
  0 siblings, 2 replies; 10+ messages in thread
From: Randy Dunlap @ 2011-07-23 17:23 UTC (permalink / raw)
  To: Radosław Smogura; +Cc: Michal Marek, linux-kbuild

On Sat, 23 Jul 2011 12:49:46 +0200 Radosław Smogura wrote:

> This patch gives ability for add some "-fno-..." options for GCC
> and to force -O1 optimization. Supporting files, like Kconfig, Makefile
> are auto-generated due to large amount of available options (not all 
> included).
> 
> Patch helps to debug kernel.
> 
> Signed-off-by: Radosław Smogura <mail@smogura.eu>

Hi,

If possible, please post patches inline instead of as attachments.
It makes patch review much easier.

Comments on (generated) file lib/Kconfig.debug.optim.
Please make corrections to the generating shell script.

+menuconfig HACK_OPTIM
+	bool "Allows to override GCC optimization"

	bool "Allows overriding GCC optimizations"

+	depends on DEBUG_KERNEL && EXPERIMENTAL
+	help
+	  If you say Y here you will be able to override
+	  how GCC optimize kernel code. This will create

	  how GCC optimizes kernel code. This creates

+	  more debug friendly, but with not guarentee

	  more debug-friendly code, but does not guarantee

+	  about same runi, like production, kernel.

	  the same running code like a production kernel.

+
+	  If you say Y here probably You will want say

	                             you will want to say <what>

+	  for all suboptions

	          suboptions.


+config HACK_OPTIM_FORCE_O1_LEVEL
+	bool "Forces -O1 optimization level"
+	---help---
+	  This will change how GCC optimize code. Code

	  This changes how GCC optimizes code.

+	  may be slower and larger but will be more debug
+	  "friendly".
+
+	  In some cases there is low chance that kernel

	  In some cases there is a low chance that the kernel

+	  will run different then normal, reporting or not

	           differently than normal, reporting or not reporting

+	  some bugs or errors. Refere to GCC manual for

	                       Refer to the GCC

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

Same comments as above.

and same comments for all suboptions.


---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

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

* [PATCH 1/2] Added hacking menu for override optimization by GCC.
  2011-07-23 17:23 ` Randy Dunlap
@ 2011-07-24 11:17   ` Radosław Smogura
  2011-07-24 11:17   ` [PATCH 2/2] This patch gives ability for add some "-fno-..." options for GCC and to force -O1 optimization. Supporting files, like Kconfig, Makefile are auto-generated due to large amount of available options Radosław Smogura
  1 sibling, 0 replies; 10+ messages in thread
From: Radosław Smogura @ 2011-07-24 11:17 UTC (permalink / raw)
  To: Randy Dunlap, Michal Marek, linux-kbuild

From: Radosław Smogura <mail@smogura.eu, rsmogura@softperience.eu>

This patch gives ability for add some "-fno-..." options for GCC
and to force -O1 optimization. Supporting files, like Kconfig, Makefile
are auto-generated due to large amount of available options.

Patch helps to debug kernel.

Signed-off-by: Radosław Smogura <mail@smogura.eu>
---
 Makefile                           |   11 ++++
 lib/Kconfig.debug                  |    2 +
 lib/Kconfig.debug.optim            |  102 ++++++++++++++++++++++++++++++++++++
 scripts/Makefile.optim.inc         |   23 ++++++++
 scripts/debug/make_config_optim.sh |   88 +++++++++++++++++++++++++++++++
 5 files changed, 226 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 86f47a0..61c39b0 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 dd373c8..3013a6b 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1259,5 +1259,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..09b1012
--- /dev/null
+++ b/lib/Kconfig.debug.optim
@@ -0,0 +1,102 @@
+# This file was auto generated. It's utility configuration
+# Distributed under GPL v2 License
+
+menuconfig HACK_OPTIM
+	bool "Allows to override GCC optimization"
+	depends on DEBUG_KERNEL && EXPERIMENTAL
+	help
+	  If you say Y here you will be able to override
+	  how GCC optimize kernel code. This will create
+	  more debug friendly, but with not guarentee
+	  about same runi, like production, kernel.
+
+	  If you say Y here probably You will want say
+	  for all suboptions
+
+if HACK_OPTIM
+
+config HACK_OPTIM_FORCE_O1_LEVEL
+	bool "Forces -O1 optimization level"
+	---help---
+	  This will change how GCC optimize code. Code
+	  may be slower and larger but will be more debug
+	  "friendly".
+
+	  In some cases there is low chance that kernel
+	  will run different then normal, reporting or not
+	  some bugs or errors. Refere 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 will change how GCC optimize code. Code
+	  may be slower and larger but will be more debug
+	  "friendly".
+
+	  In some cases there is low chance that kernel
+	  will run different then normal, reporting or not
+	  some bugs or errors. Refere 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 will change how GCC optimize code. Code
+	  may be slower and larger but will be more debug
+	  "friendly".
+
+	  In some cases there is low chance that kernel
+	  will run different then normal, reporting or not
+	  some bugs or errors. Refere 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 will change how GCC optimize code. Code
+	  may be slower and larger but will be more debug
+	  "friendly".
+
+	  In some cases there is low chance that kernel
+	  will run different then normal, reporting or not
+	  some bugs or errors. Refere 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 will change how GCC optimize code. Code
+	  may be slower and larger but will be more debug
+	  "friendly".
+
+	  In some cases there is low chance that kernel
+	  will run different then normal, reporting or not
+	  some bugs or errors. Refere 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 will change how GCC optimize code. Code
+	  may be slower and larger but will be more debug
+	  "friendly".
+
+	  In some cases there is low chance that kernel
+	  will run different then normal, reporting or not
+	  some bugs or errors. Refere 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..e78cc92
--- /dev/null
+++ b/scripts/Makefile.optim.inc
@@ -0,0 +1,23 @@
+# 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
+
diff --git a/scripts/debug/make_config_optim.sh b/scripts/debug/make_config_optim.sh
new file mode 100644
index 0000000..26865923
--- /dev/null
+++ b/scripts/debug/make_config_optim.sh
@@ -0,0 +1,88 @@
+#!/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 "
+
+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 to override GCC optimization\"" >> $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 optimize kernel code. This will create" >> $KCFG
+echo -e "\t  more debug friendly, but with not guarentee"    >> $KCFG
+echo -e "\t  about same runi, like production, kernel."      >> $KCFG
+echo >> $KCFG
+echo -e "\t  If you say Y here probably You will want say"   >> $KCFG
+echo -e "\t  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
+echo -e "\t  This will change how GCC optimize 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 low chance that kernel" >> $KCFG
+echo -e "\t  will run different then normal, reporting or not" >> $KCFG
+echo -e "\t  some bugs or errors. Refere to GCC manual for" >> $KCFG
+echo -e "\t  more details." >> $KCFG
+echo >> $KCFG
+echo -e "\t  You SHOULD say N here." >> $KCFG
+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
+	echo -e "\t  This will change how GCC optimize 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 low chance that kernel" >> $KCFG
+	echo -e "\t  will run different then normal, reporting or not" >> $KCFG
+	echo -e "\t  some bugs or errors. Refere to GCC manual for" >> $KCFG
+	echo -e "\t  more details." >> $KCFG
+	echo >> $KCFG
+	echo -e "\t  You SHOULD say N here." >> $KCFG
+	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 related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] This patch gives ability for add some "-fno-..." options for GCC and to force -O1 optimization. Supporting files, like Kconfig, Makefile are auto-generated due to large amount of available options.
  2011-07-23 17:23 ` Randy Dunlap
  2011-07-24 11:17   ` [PATCH 1/2] " Radosław Smogura
@ 2011-07-24 11:17   ` Radosław Smogura
  2011-07-25  8:17     ` Michal Marek
  1 sibling, 1 reply; 10+ messages in thread
From: Radosław Smogura @ 2011-07-24 11:17 UTC (permalink / raw)
  To: Randy Dunlap, Michal Marek, linux-kbuild

Patch helps to debug kernel.

Fixed some language mistakes and added few -f-no-... options.

Signed-off-by: Radosław Smogura <mail@smogura.eu>
---
 lib/Kconfig.debug.optim            |  156 +++++++++++++++++++++++++++--------
 scripts/Makefile.optim.inc         |   24 ++++++
 scripts/debug/make_config_optim.sh |   66 ++++++++--------
 3 files changed, 178 insertions(+), 68 deletions(-)

diff --git a/lib/Kconfig.debug.optim b/lib/Kconfig.debug.optim
index 09b1012..99dcde0 100644
--- a/lib/Kconfig.debug.optim
+++ b/lib/Kconfig.debug.optim
@@ -2,100 +2,184 @@
 # Distributed under GPL v2 License
 
 menuconfig HACK_OPTIM
-	bool "Allows to override GCC optimization"
+	bool "Allows overriding GCC optimizations"
 	depends on DEBUG_KERNEL && EXPERIMENTAL
 	help
 	  If you say Y here you will be able to override
-	  how GCC optimize kernel code. This will create
-	  more debug friendly, but with not guarentee
-	  about same runi, like production, kernel.
+	  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 say
-	  for all suboptions
+	  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 will change how GCC optimize code. Code
+	  This changes how GCC optimizes code. Code
 	  may be slower and larger but will be more debug
 	  "friendly".
 
-	  In some cases there is low chance that kernel
-	  will run different then normal, reporting or not
-	  some bugs or errors. Refere to GCC manual for
-	  more details.
+	  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 will change how GCC optimize code. Code
+	  This changes how GCC optimizes code. Code
 	  may be slower and larger but will be more debug
 	  "friendly".
 
-	  In some cases there is low chance that kernel
-	  will run different then normal, reporting or not
-	  some bugs or errors. Refere to GCC manual for
-	  more details.
+	  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 will change how GCC optimize code. Code
+	  This changes how GCC optimizes code. Code
 	  may be slower and larger but will be more debug
 	  "friendly".
 
-	  In some cases there is low chance that kernel
-	  will run different then normal, reporting or not
-	  some bugs or errors. Refere to GCC manual for
-	  more details.
+	  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 will change how GCC optimize code. Code
+	  This changes how GCC optimizes code. Code
 	  may be slower and larger but will be more debug
 	  "friendly".
 
-	  In some cases there is low chance that kernel
-	  will run different then normal, reporting or not
-	  some bugs or errors. Refere to GCC manual for
-	  more details.
+	  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 will change how GCC optimize code. Code
+	  This changes how GCC optimizes code. Code
 	  may be slower and larger but will be more debug
 	  "friendly".
 
-	  In some cases there is low chance that kernel
-	  will run different then normal, reporting or not
-	  some bugs or errors. Refere to GCC manual for
-	  more details.
+	  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 will change how GCC optimize code. Code
+	  This changes how GCC optimizes code. Code
 	  may be slower and larger but will be more debug
 	  "friendly".
 
-	  In some cases there is low chance that kernel
-	  will run different then normal, reporting or not
-	  some bugs or errors. Refere to GCC manual for
-	  more details.
+	  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.
 
diff --git a/scripts/Makefile.optim.inc b/scripts/Makefile.optim.inc
index e78cc92..1bd219d 100644
--- a/scripts/Makefile.optim.inc
+++ b/scripts/Makefile.optim.inc
@@ -21,3 +21,27 @@ 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
+
diff --git a/scripts/debug/make_config_optim.sh b/scripts/debug/make_config_optim.sh
index 26865923..4db8419 100644
--- a/scripts/debug/make_config_optim.sh
+++ b/scripts/debug/make_config_optim.sh
@@ -16,22 +16,42 @@ OPTIMIZATIONS_PARAMS="-fno-inline-functions-called-once \
  -fno-combine-stack-adjustments \
  -fno-tree-dce \
  -fno-tree-dominator-opts \
- -fno-dse "
+ -fno-dse \
+ -fno-dce \
+ -fno-auto-inc-dec \
+ -fno-inline-small-functions \
+ -fno-if-conversion \
+ -fno-if-conversion2 \
+ -fno-tree-fre
+"
+
+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 to override GCC optimization\"" >> $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 optimize kernel code. This will create" >> $KCFG
-echo -e "\t  more debug friendly, but with not guarentee"    >> $KCFG
-echo -e "\t  about same runi, like production, kernel."      >> $KCFG
-echo >> $KCFG
-echo -e "\t  If you say Y here probably You will want say"   >> $KCFG
-echo -e "\t  for all suboptions" >> $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
@@ -47,16 +67,7 @@ echo >> $MKFI
 echo -e "config ${CFG_PREFIX}_FORCE_O1_LEVEL" >> $KCFG
 echo -e "\tbool \"Forces -O1 optimization level\"" >> $KCFG
 echo -e "\t---help---" >> $KCFG
-echo -e "\t  This will change how GCC optimize 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 low chance that kernel" >> $KCFG
-echo -e "\t  will run different then normal, reporting or not" >> $KCFG
-echo -e "\t  some bugs or errors. Refere to GCC manual for" >> $KCFG
-echo -e "\t  more details." >> $KCFG
-echo >> $KCFG
-echo -e "\t  You SHOULD say N here." >> $KCFG
+printStandardHelp;
 echo >> $KCFG
 
 for o in $OPTIMIZATIONS_PARAMS ; do
@@ -67,16 +78,7 @@ for o in $OPTIMIZATIONS_PARAMS ; do
 	echo -e "config ${cfg_o}" >> $KCFG
 	echo -e "\tbool \"Adds $o parameter to gcc invoke line.\"" >> $KCFG
 	echo -e "\t---help---" >> $KCFG
-	echo -e "\t  This will change how GCC optimize 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 low chance that kernel" >> $KCFG
-	echo -e "\t  will run different then normal, reporting or not" >> $KCFG
-	echo -e "\t  some bugs or errors. Refere to GCC manual for" >> $KCFG
-	echo -e "\t  more details." >> $KCFG
-	echo >> $KCFG
-	echo -e "\t  You SHOULD say N here." >> $KCFG
+	printStandardHelp;
 	echo >> $KCFG
 
 	#Generate Make for include
-- 
1.7.3.4


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

* Re: [PATCH 2/2] This patch gives ability for add some "-fno-..." options for GCC and to force -O1 optimization. Supporting files, like Kconfig, Makefile are auto-generated due to large amount of available options.
  2011-07-24 11:17   ` [PATCH 2/2] This patch gives ability for add some "-fno-..." options for GCC and to force -O1 optimization. Supporting files, like Kconfig, Makefile are auto-generated due to large amount of available options Radosław Smogura
@ 2011-07-25  8:17     ` Michal Marek
  2011-07-30 12:09       ` [PATCH] Allows Kernel developer to change optimization options making code more debug friendly Radosław Smogura
  0 siblings, 1 reply; 10+ messages in thread
From: Michal Marek @ 2011-07-25  8:17 UTC (permalink / raw)
  To: Radosław Smogura; +Cc: Randy Dunlap, linux-kbuild

On 24.7.2011 13:17, Radosław Smogura wrote:
> Patch helps to debug kernel.
>
> Fixed some language mistakes and added few -f-no-... options.

Hi,

please fix the first patch directly. And please also cc 
linux-kernel@vger.kernel.org.

Michal
>
> Signed-off-by: Radosław Smogura<mail@smogura.eu>
> ---
>   lib/Kconfig.debug.optim            |  156 +++++++++++++++++++++++++++--------
>   scripts/Makefile.optim.inc         |   24 ++++++
>   scripts/debug/make_config_optim.sh |   66 ++++++++--------
>   3 files changed, 178 insertions(+), 68 deletions(-)
>
> diff --git a/lib/Kconfig.debug.optim b/lib/Kconfig.debug.optim
> index 09b1012..99dcde0 100644
> --- a/lib/Kconfig.debug.optim
> +++ b/lib/Kconfig.debug.optim
> @@ -2,100 +2,184 @@
>   # Distributed under GPL v2 License
>
>   menuconfig HACK_OPTIM
> -	bool "Allows to override GCC optimization"
> +	bool "Allows overriding GCC optimizations"
>   	depends on DEBUG_KERNEL&&  EXPERIMENTAL
>   	help
>   	  If you say Y here you will be able to override
> -	  how GCC optimize kernel code. This will create
> -	  more debug friendly, but with not guarentee
> -	  about same runi, like production, kernel.
> +	  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 say
> -	  for all suboptions
> +	  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 will change how GCC optimize code. Code
> +	  This changes how GCC optimizes code. Code
>   	  may be slower and larger but will be more debug
>   	  "friendly".
>
> -	  In some cases there is low chance that kernel
> -	  will run different then normal, reporting or not
> -	  some bugs or errors. Refere to GCC manual for
> -	  more details.
> +	  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 will change how GCC optimize code. Code
> +	  This changes how GCC optimizes code. Code
>   	  may be slower and larger but will be more debug
>   	  "friendly".
>
> -	  In some cases there is low chance that kernel
> -	  will run different then normal, reporting or not
> -	  some bugs or errors. Refere to GCC manual for
> -	  more details.
> +	  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 will change how GCC optimize code. Code
> +	  This changes how GCC optimizes code. Code
>   	  may be slower and larger but will be more debug
>   	  "friendly".
>
> -	  In some cases there is low chance that kernel
> -	  will run different then normal, reporting or not
> -	  some bugs or errors. Refere to GCC manual for
> -	  more details.
> +	  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 will change how GCC optimize code. Code
> +	  This changes how GCC optimizes code. Code
>   	  may be slower and larger but will be more debug
>   	  "friendly".
>
> -	  In some cases there is low chance that kernel
> -	  will run different then normal, reporting or not
> -	  some bugs or errors. Refere to GCC manual for
> -	  more details.
> +	  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 will change how GCC optimize code. Code
> +	  This changes how GCC optimizes code. Code
>   	  may be slower and larger but will be more debug
>   	  "friendly".
>
> -	  In some cases there is low chance that kernel
> -	  will run different then normal, reporting or not
> -	  some bugs or errors. Refere to GCC manual for
> -	  more details.
> +	  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 will change how GCC optimize code. Code
> +	  This changes how GCC optimizes code. Code
>   	  may be slower and larger but will be more debug
>   	  "friendly".
>
> -	  In some cases there is low chance that kernel
> -	  will run different then normal, reporting or not
> -	  some bugs or errors. Refere to GCC manual for
> -	  more details.
> +	  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.
>
> diff --git a/scripts/Makefile.optim.inc b/scripts/Makefile.optim.inc
> index e78cc92..1bd219d 100644
> --- a/scripts/Makefile.optim.inc
> +++ b/scripts/Makefile.optim.inc
> @@ -21,3 +21,27 @@ 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
> +
> diff --git a/scripts/debug/make_config_optim.sh b/scripts/debug/make_config_optim.sh
> index 26865923..4db8419 100644
> --- a/scripts/debug/make_config_optim.sh
> +++ b/scripts/debug/make_config_optim.sh
> @@ -16,22 +16,42 @@ OPTIMIZATIONS_PARAMS="-fno-inline-functions-called-once \
>    -fno-combine-stack-adjustments \
>    -fno-tree-dce \
>    -fno-tree-dominator-opts \
> - -fno-dse "
> + -fno-dse \
> + -fno-dce \
> + -fno-auto-inc-dec \
> + -fno-inline-small-functions \
> + -fno-if-conversion \
> + -fno-if-conversion2 \
> + -fno-tree-fre
> +"
> +
> +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 to override GCC optimization\"">>  $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 optimize kernel code. This will create">>  $KCFG
> -echo -e "\t  more debug friendly, but with not guarentee">>  $KCFG
> -echo -e "\t  about same runi, like production, kernel.">>  $KCFG
> -echo>>  $KCFG
> -echo -e "\t  If you say Y here probably You will want say">>  $KCFG
> -echo -e "\t  for all suboptions">>  $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
> @@ -47,16 +67,7 @@ echo>>  $MKFI
>   echo -e "config ${CFG_PREFIX}_FORCE_O1_LEVEL">>  $KCFG
>   echo -e "\tbool \"Forces -O1 optimization level\"">>  $KCFG
>   echo -e "\t---help---">>  $KCFG
> -echo -e "\t  This will change how GCC optimize 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 low chance that kernel">>  $KCFG
> -echo -e "\t  will run different then normal, reporting or not">>  $KCFG
> -echo -e "\t  some bugs or errors. Refere to GCC manual for">>  $KCFG
> -echo -e "\t  more details.">>  $KCFG
> -echo>>  $KCFG
> -echo -e "\t  You SHOULD say N here.">>  $KCFG
> +printStandardHelp;
>   echo>>  $KCFG
>
>   for o in $OPTIMIZATIONS_PARAMS ; do
> @@ -67,16 +78,7 @@ for o in $OPTIMIZATIONS_PARAMS ; do
>   	echo -e "config ${cfg_o}">>  $KCFG
>   	echo -e "\tbool \"Adds $o parameter to gcc invoke line.\"">>  $KCFG
>   	echo -e "\t---help---">>  $KCFG
> -	echo -e "\t  This will change how GCC optimize 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 low chance that kernel">>  $KCFG
> -	echo -e "\t  will run different then normal, reporting or not">>  $KCFG
> -	echo -e "\t  some bugs or errors. Refere to GCC manual for">>  $KCFG
> -	echo -e "\t  more details.">>  $KCFG
> -	echo>>  $KCFG
> -	echo -e "\t  You SHOULD say N here.">>  $KCFG
> +	printStandardHelp;
>   	echo>>  $KCFG
>
>   	#Generate Make for include


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

* [PATCH] Allows Kernel developer to change optimization options making code more debug friendly.
  2011-07-25  8:17     ` Michal Marek
@ 2011-07-30 12:09       ` Radosław Smogura
  2011-07-30 12:33         ` Radosław Smogura
                           ` (2 more replies)
  0 siblings, 3 replies; 10+ 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 related	[flat|nested] 10+ 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; 10+ 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 related	[flat|nested] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ messages in thread

end of thread, other threads:[~2011-07-30 15:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-23 10:49 [PATCH] Added hacking menu for override optimization by GCC Radosław Smogura
2011-07-23 17:23 ` Randy Dunlap
2011-07-24 11:17   ` [PATCH 1/2] " Radosław Smogura
2011-07-24 11:17   ` [PATCH 2/2] This patch gives ability for add some "-fno-..." options for GCC and to force -O1 optimization. Supporting files, like Kconfig, Makefile are auto-generated due to large amount of available options Radosław Smogura
2011-07-25  8:17     ` Michal Marek
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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.