diff mbox

[v2,4/5] kernel hacking: new config DEBUG_EXPERIENCE to apply GCC -Og optimization

Message ID 1525268700-10631-5-git-send-email-changbin.du@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Du, Changbin May 2, 2018, 1:44 p.m. UTC
From: Changbin Du <changbin.du@intel.com>

This will apply GCC '-Og' optimization level which is supported
since GCC 4.8. This optimization level offers a reasonable level
of optimization while maintaining fast compilation and a good
debugging experience. It is similar to '-O1' while perfer keeping
debug ability over runtime speed.

If enabling this option breaks your kernel, you should either
disable this or find a fix (mostly in the arch code). Currently
this option has only be tested on x86_64 platform.

This option can satisfy people who was searching for a method
to disable compiler optimizations so to achieve better kernel
debugging experience with kgdb or qemu.

The main problem of '-Og' is we must not use __attribute__((error(msg))).
The compiler will report error though the call to error function
still can be optimize out. So we must fallback to array tricky.

Comparison of vmlinux size: a bit smaller.

    w/o CONFIG_DEBUG_EXPERIENCE
    $ size vmlinux
       text    data     bss     dec     hex filename
    22665554   9709674  2920908 35296136        21a9388 vmlinux

    w/ CONFIG_DEBUG_EXPERIENCE
    $ size vmlinux
       text    data     bss     dec     hex filename
    21499032   10102758 2920908 34522698        20ec64a vmlinux

Comparison of system performance: a bit drop (~6%).
    This benchmark of kernel compilation is suggested by Ingo Molnar.
    https://lkml.org/lkml/2018/5/2/74

    Preparation: Set cpufreq to 'performance'.
    for ((cpu=0; cpu<120; cpu++)); do
      G=/sys/devices/system/cpu/cpu$cpu/cpufreq/scaling_governor
      [ -f $G ] && echo performance > $G
    done

    w/o CONFIG_DEBUG_EXPERIENCE
    $ perf stat --repeat 5 --null --pre                 '\
        cp -a kernel ../kernel.copy.$(date +%s);         \
        rm -rf *;                                        \
        git checkout .;                                  \
        echo 1 > /proc/sys/vm/drop_caches;               \
        find ../kernel* -type f | xargs cat >/dev/null;  \
        make -j kernel >/dev/null;                       \
        make clean >/dev/null 2>&1;                      \
        sync                                            '\
                                                         \
        make -j8 >/dev/null

     Performance counter stats for 'make -j8' (5 runs):

        219.764246652 seconds time elapsed                   ( +-  0.78% )

    w/ CONFIG_DEBUG_EXPERIENCE
    $ perf stat --repeat 5 --null --pre                 '\
        cp -a kernel ../kernel.copy.$(date +%s);         \
        rm -rf *;                                        \
        git checkout .;                                  \
        echo 1 > /proc/sys/vm/drop_caches;               \
        find ../kernel* -type f | xargs cat >/dev/null;  \
        make -j kernel >/dev/null;                       \
        make clean >/dev/null 2>&1;                      \
        sync                                            '\
                                                         \
        make -j8 >/dev/null

    Performance counter stats for 'make -j8' (5 runs):

         233.574187771 seconds time elapsed                  ( +-  0.19% )

Signed-off-by: Changbin Du <changbin.du@intel.com>

---
v2:
  o Improve performance benchmark as suggested by Ingo.
  o Grammar updates in description. (Randy Dunlap)
---
 Makefile                     |  4 ++++
 include/linux/compiler-gcc.h |  2 +-
 include/linux/compiler.h     |  2 +-
 lib/Kconfig.debug            | 21 +++++++++++++++++++++
 4 files changed, 27 insertions(+), 2 deletions(-)

Comments

Steven Rostedt May 2, 2018, 2:17 p.m. UTC | #1
On Wed,  2 May 2018 21:44:59 +0800
changbin.du@intel.com wrote:

> From: Changbin Du <changbin.du@intel.com>
> 
> This will apply GCC '-Og' optimization level which is supported
> since GCC 4.8. This optimization level offers a reasonable level
> of optimization while maintaining fast compilation and a good
> debugging experience. It is similar to '-O1' while perfer keeping
> debug ability over runtime speed.
> 
> If enabling this option breaks your kernel, you should either
> disable this or find a fix (mostly in the arch code). Currently
> this option has only be tested on x86_64 platform.

If this becomes an issue, you probably need to add an arch config that
it depends on like CONFIG_HAVE_DEBUG_EXPERIENCE (or another name, as I
mention below).

> 
> This option can satisfy people who was searching for a method
> to disable compiler optimizations so to achieve better kernel
> debugging experience with kgdb or qemu.
> 
> The main problem of '-Og' is we must not use __attribute__((error(msg))).
> The compiler will report error though the call to error function
> still can be optimize out. So we must fallback to array tricky.
> 
> Comparison of vmlinux size: a bit smaller.
> 
>     w/o CONFIG_DEBUG_EXPERIENCE

I hate the config name.

I probably can't come up with better ones but let's try:

 CONFIG_DEBUG_OPTIMIZE ?
 CONFIG_OPTIMIZE_DEBUG ?

But "EXPERIENCE" sounds like I'm on some DEBUG LSD.



>     $ size vmlinux
>        text    data     bss     dec     hex filename
>     22665554   9709674  2920908 35296136        21a9388 vmlinux
> 
>     w/ CONFIG_DEBUG_EXPERIENCE
>     $ size vmlinux
>        text    data     bss     dec     hex filename
>     21499032   10102758 2920908 34522698        20ec64a vmlinux
> 
> Comparison of system performance: a bit drop (~6%).
>     This benchmark of kernel compilation is suggested by Ingo Molnar.
>     https://lkml.org/lkml/2018/5/2/74
> 
>     Preparation: Set cpufreq to 'performance'.
>     for ((cpu=0; cpu<120; cpu++)); do
>       G=/sys/devices/system/cpu/cpu$cpu/cpufreq/scaling_governor
>       [ -f $G ] && echo performance > $G
>     done
> 
>     w/o CONFIG_DEBUG_EXPERIENCE
>     $ perf stat --repeat 5 --null --pre                 '\
>         cp -a kernel ../kernel.copy.$(date +%s);         \
>         rm -rf *;                                        \
>         git checkout .;                                  \
>         echo 1 > /proc/sys/vm/drop_caches;               \
>         find ../kernel* -type f | xargs cat >/dev/null;  \
>         make -j kernel >/dev/null;                       \
>         make clean >/dev/null 2>&1;                      \
>         sync                                            '\
>                                                          \
>         make -j8 >/dev/null
> 
>      Performance counter stats for 'make -j8' (5 runs):
> 
>         219.764246652 seconds time elapsed                   ( +-  0.78% )
> 
>     w/ CONFIG_DEBUG_EXPERIENCE
>     $ perf stat --repeat 5 --null --pre                 '\
>         cp -a kernel ../kernel.copy.$(date +%s);         \
>         rm -rf *;                                        \
>         git checkout .;                                  \
>         echo 1 > /proc/sys/vm/drop_caches;               \
>         find ../kernel* -type f | xargs cat >/dev/null;  \
>         make -j kernel >/dev/null;                       \
>         make clean >/dev/null 2>&1;                      \
>         sync                                            '\
>                                                          \
>         make -j8 >/dev/null
> 
>     Performance counter stats for 'make -j8' (5 runs):
> 
>          233.574187771 seconds time elapsed                  ( +-  0.19% )
> 
> Signed-off-by: Changbin Du <changbin.du@intel.com>
> 
> ---
> v2:
>   o Improve performance benchmark as suggested by Ingo.
>   o Grammar updates in description. (Randy Dunlap)
> ---
>  Makefile                     |  4 ++++
>  include/linux/compiler-gcc.h |  2 +-
>  include/linux/compiler.h     |  2 +-
>  lib/Kconfig.debug            | 21 +++++++++++++++++++++
>  4 files changed, 27 insertions(+), 2 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index eb694f6..6a10469 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -639,6 +639,9 @@ KBUILD_CFLAGS	+= $(call cc-disable-warning, format-truncation)
>  KBUILD_CFLAGS	+= $(call cc-disable-warning, format-overflow)
>  KBUILD_CFLAGS	+= $(call cc-disable-warning, int-in-bool-context)
>  
> +ifdef CONFIG_DEBUG_EXPERIENCE
> +KBUILD_CFLAGS	+= $(call cc-option, -Og)
> +else
>  ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
>  KBUILD_CFLAGS	+= $(call cc-option,-Oz,-Os)
>  KBUILD_CFLAGS	+= $(call cc-disable-warning,maybe-uninitialized,)
> @@ -649,6 +652,7 @@ else
>  KBUILD_CFLAGS   += -O2
>  endif
>  endif
> +endif
>  
>  KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0409, \
>  			$(call cc-disable-warning,maybe-uninitialized,))
> diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
> index b4bf73f..b8b3832 100644
> --- a/include/linux/compiler-gcc.h
> +++ b/include/linux/compiler-gcc.h
> @@ -192,7 +192,7 @@
>  
>  #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
>  
> -#ifndef __CHECKER__
> +#if !defined(__CHECKER__) && !defined(CONFIG_DEBUG_EXPERIENCE)
>  # define __compiletime_warning(message) __attribute__((warning(message)))
>  # define __compiletime_error(message) __attribute__((error(message)))
>  #endif /* __CHECKER__ */
> diff --git a/include/linux/compiler.h b/include/linux/compiler.h
> index ab4711c..952cc7f 100644
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -301,7 +301,7 @@ unsigned long read_word_at_a_time(const void *addr)
>   * sparse see a constant array size without breaking compiletime_assert on old
>   * versions of GCC (e.g. 4.2.4), so hide the array from sparse altogether.
>   */
> -# ifndef __CHECKER__
> +# if !defined(__CHECKER__) && !defined(CONFIG_DEBUG_EXPERIENCE)
>  #  define __compiletime_error_fallback(condition) \
>  	do { ((void)sizeof(char[1 - 2 * condition])); } while (0)
>  # endif
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index ab55801..e264199 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -216,6 +216,27 @@ config NO_AUTO_INLINE
>  
>  	  If unsure, select N.
>  
> +config DEBUG_EXPERIENCE
> +	bool "Optimize for better debugging experience (-Og)"
> +	default n

You don't need to add "default n" because that's the default if it
isn't specified.

-- Steve

> +	select NO_AUTO_INLINE
> +	depends on !CC_OPTIMIZE_FOR_SIZE
> +	help
> +	  This will apply GCC '-Og' optimization level which is supported
> +	  since GCC 4.8. This optimization level offers a reasonable level
> +	  of optimization while maintaining fast compilation and a good
> +	  debugging experience. It is similar to '-O1' while preferring to
> +	  keep debug ability over runtime speed. The overall performance
> +	  will drop a bit (~6%).
> +
> +	  Use only if you want to debug the kernel, especially if you want
> +	  to have better kernel debugging experience with gdb facilities
> +	  like kgdb or qemu. If enabling this option breaks your kernel,
> +	  you should either disable this or find a fix (mostly in the arch
> +	  code). Currently this option has only be tested on x86_64 platform.
> +
> +	  If unsure, select N.
> +
>  config ENABLE_WARN_DEPRECATED
>  	bool "Enable __deprecated logic"
>  	default y

--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Randy Dunlap May 2, 2018, 7:26 p.m. UTC | #2
On 05/02/2018 06:44 AM, changbin.du@intel.com wrote:
> From: Changbin Du <changbin.du@intel.com>
> 

Sorry, I missed one:

> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index ab55801..e264199 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -216,6 +216,27 @@ config NO_AUTO_INLINE
>  
>  	  If unsure, select N.
>  
> +config DEBUG_EXPERIENCE
> +	bool "Optimize for better debugging experience (-Og)"
> +	default n
> +	select NO_AUTO_INLINE
> +	depends on !CC_OPTIMIZE_FOR_SIZE
> +	help
> +	  This will apply GCC '-Og' optimization level which is supported
> +	  since GCC 4.8. This optimization level offers a reasonable level
> +	  of optimization while maintaining fast compilation and a good
> +	  debugging experience. It is similar to '-O1' while preferring to
> +	  keep debug ability over runtime speed. The overall performance
> +	  will drop a bit (~6%).
> +
> +	  Use only if you want to debug the kernel, especially if you want
> +	  to have better kernel debugging experience with gdb facilities
> +	  like kgdb or qemu. If enabling this option breaks your kernel,
> +	  you should either disable this or find a fix (mostly in the arch
> +	  code). Currently this option has only be tested on x86_64 platform.

	                                        been tested

> +
> +	  If unsure, select N.
> +
>  config ENABLE_WARN_DEPRECATED
>  	bool "Enable __deprecated logic"
>  	default y
>
Andrew Morton May 2, 2018, 8:45 p.m. UTC | #3
On Wed, 2 May 2018 10:17:07 -0400 Steven Rostedt <rostedt@goodmis.org> wrote:

> > Comparison of vmlinux size: a bit smaller.
> > 
> >     w/o CONFIG_DEBUG_EXPERIENCE
> 
> I hate the config name.
> 
> I probably can't come up with better ones but let's try:
> 
>  CONFIG_DEBUG_OPTIMIZE ?
>  CONFIG_OPTIMIZE_DEBUG ?
> 
> But "EXPERIENCE" sounds like I'm on some DEBUG LSD.

Metoo, but the gcc people decided on "-Og: Optimize debugging
experience ..." and I think there are benefits if the kernel is to
align the naming with that.

--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Steven Rostedt May 3, 2018, 1:19 a.m. UTC | #4
On Wed, 2 May 2018 13:45:58 -0700
Andrew Morton <akpm@linux-foundation.org> wrote:

> On Wed, 2 May 2018 10:17:07 -0400 Steven Rostedt <rostedt@goodmis.org> wrote:
> 
> > > Comparison of vmlinux size: a bit smaller.
> > > 
> > >     w/o CONFIG_DEBUG_EXPERIENCE  
> > 
> > I hate the config name.
> > 
> > I probably can't come up with better ones but let's try:
> > 
> >  CONFIG_DEBUG_OPTIMIZE ?
> >  CONFIG_OPTIMIZE_DEBUG ?
> > 
> > But "EXPERIENCE" sounds like I'm on some DEBUG LSD.  
> 
> Metoo, but the gcc people decided on "-Og: Optimize debugging
> experience ..." and I think there are benefits if the kernel is to
> align the naming with that.

I still see that as "Optimize debugging" and "experience" is just the
platform of what was done.

With that gcc comment, I still think CONFIG_OPTIMIZE_DEBUG is more
inline with what it is and understandable than
CONFIG_DEBUG_EXPERIENCE. The "OPTIMIZE" is the key word there.

-- Steve
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Du, Changbin May 3, 2018, 1:45 p.m. UTC | #5
On Wed, May 02, 2018 at 09:19:56PM -0400, Steven Rostedt wrote:
> On Wed, 2 May 2018 13:45:58 -0700
> Andrew Morton <akpm@linux-foundation.org> wrote:
> 
> > On Wed, 2 May 2018 10:17:07 -0400 Steven Rostedt <rostedt@goodmis.org> wrote:
> > 
> > > > Comparison of vmlinux size: a bit smaller.
> > > > 
> > > >     w/o CONFIG_DEBUG_EXPERIENCE  
> > > 
> > > I hate the config name.
> > > 
> > > I probably can't come up with better ones but let's try:
> > > 
> > >  CONFIG_DEBUG_OPTIMIZE ?
> > >  CONFIG_OPTIMIZE_DEBUG ?
> > > 
> > > But "EXPERIENCE" sounds like I'm on some DEBUG LSD.  
> > 
> > Metoo, but the gcc people decided on "-Og: Optimize debugging
> > experience ..." and I think there are benefits if the kernel is to
> > align the naming with that.
> 
> I still see that as "Optimize debugging" and "experience" is just the
> platform of what was done.
> 
> With that gcc comment, I still think CONFIG_OPTIMIZE_DEBUG is more
> inline with what it is and understandable than
> CONFIG_DEBUG_EXPERIENCE. The "OPTIMIZE" is the key word there.
> 
> -- Steve
What about CONFIG_CC_OPTIMIZE_FOR_DEBUGGING? We alreay have
CONFIG_CC_OPTIMIZE_FOR_SIZE and CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE.

And do we need to move it to existing configuration menu "General setup->
Compiler optimization level"? But I also want it appear in "kernel hacking"
since this is a debug option.
Steven Rostedt May 3, 2018, 2:28 p.m. UTC | #6
On Thu, 3 May 2018 21:45:46 +0800
"Du, Changbin" <changbin.du@intel.com> wrote:

> > With that gcc comment, I still think CONFIG_OPTIMIZE_DEBUG is more
> > inline with what it is and understandable than
> > CONFIG_DEBUG_EXPERIENCE. The "OPTIMIZE" is the key word there.
> > 
> > -- Steve  
> What about CONFIG_CC_OPTIMIZE_FOR_DEBUGGING? We alreay have
> CONFIG_CC_OPTIMIZE_FOR_SIZE and CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE.

Yes I like that much better.

> 
> And do we need to move it to existing configuration menu "General setup->
> Compiler optimization level"? But I also want it appear in "kernel hacking"
> since this is a debug option.

I understand why you would want it by debugging, but I think it does
make more sense to be included with the above two other options, as
they are all mutually exclusive.

This brings up the topic of creating config paradigms. That is, a way
of saying "I want a debug kernel" and select one option that selects
everything you would expect. Or perhaps we should have a:

 make debug_config

that does it.

But that's a different topic. For now, I would just included it in
init/Kconfig, and not worry about it not showing up in kernel hacking.


-- Steve
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Du, Changbin May 5, 2018, 11:57 p.m. UTC | #7
On Thu, May 03, 2018 at 10:28:23AM -0400, Steven Rostedt wrote:
> On Thu, 3 May 2018 21:45:46 +0800
> "Du, Changbin" <changbin.du@intel.com> wrote:
> 
> > > With that gcc comment, I still think CONFIG_OPTIMIZE_DEBUG is more
> > > inline with what it is and understandable than
> > > CONFIG_DEBUG_EXPERIENCE. The "OPTIMIZE" is the key word there.
> > > 
> > > -- Steve  
> > What about CONFIG_CC_OPTIMIZE_FOR_DEBUGGING? We alreay have
> > CONFIG_CC_OPTIMIZE_FOR_SIZE and CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE.
> 
> Yes I like that much better.
> 
> > 
> > And do we need to move it to existing configuration menu "General setup->
> > Compiler optimization level"? But I also want it appear in "kernel hacking"
> > since this is a debug option.
> 
> I understand why you would want it by debugging, but I think it does
> make more sense to be included with the above two other options, as
> they are all mutually exclusive.
> 
> This brings up the topic of creating config paradigms. That is, a way
> of saying "I want a debug kernel" and select one option that selects
> everything you would expect. Or perhaps we should have a:
> 
>  make debug_config
> 
Agree, I accomplish this by running script scripts/kconfig/merge_config.sh.

> that does it.
> 
> But that's a different topic. For now, I would just included it in
> init/Kconfig, and not worry about it not showing up in kernel hacking.
> 
> 
> -- Steve
Randy Dunlap May 6, 2018, 12:27 a.m. UTC | #8
On 05/05/2018 04:57 PM, Du, Changbin wrote:
> On Thu, May 03, 2018 at 10:28:23AM -0400, Steven Rostedt wrote:
>> On Thu, 3 May 2018 21:45:46 +0800
>> "Du, Changbin" <changbin.du@intel.com> wrote:
>>
>>>> With that gcc comment, I still think CONFIG_OPTIMIZE_DEBUG is more
>>>> inline with what it is and understandable than
>>>> CONFIG_DEBUG_EXPERIENCE. The "OPTIMIZE" is the key word there.
>>>>
>>>> -- Steve  
>>> What about CONFIG_CC_OPTIMIZE_FOR_DEBUGGING? We alreay have
>>> CONFIG_CC_OPTIMIZE_FOR_SIZE and CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE.
>>
>> Yes I like that much better.
>>
>>>
>>> And do we need to move it to existing configuration menu "General setup->
>>> Compiler optimization level"? But I also want it appear in "kernel hacking"
>>> since this is a debug option.
>>
>> I understand why you would want it by debugging, but I think it does
>> make more sense to be included with the above two other options, as
>> they are all mutually exclusive.

mm, sounds good.

>> This brings up the topic of creating config paradigms. That is, a way
>> of saying "I want a debug kernel" and select one option that selects
>> everything you would expect. Or perhaps we should have a:
>>
>>  make debug_config

Sometimes I want to build allmodconfig-minus-debug options ... but not
all debug options.  I still want debugfs but most options that end with
_DEBUG are disabled.  I.e., I don't want the options that cause big
run-time slowdowns. (unless I cause that by printing some debugfs
contents)

Can merge_config.sh (or one of its cousins) help with that?

> Agree, I accomplish this by running script scripts/kconfig/merge_config.sh.
> 
>> that does it.
>>
>> But that's a different topic. For now, I would just included it in
>> init/Kconfig, and not worry about it not showing up in kernel hacking.

Ack.


thanks.
diff mbox

Patch

diff --git a/Makefile b/Makefile
index eb694f6..6a10469 100644
--- a/Makefile
+++ b/Makefile
@@ -639,6 +639,9 @@  KBUILD_CFLAGS	+= $(call cc-disable-warning, format-truncation)
 KBUILD_CFLAGS	+= $(call cc-disable-warning, format-overflow)
 KBUILD_CFLAGS	+= $(call cc-disable-warning, int-in-bool-context)
 
+ifdef CONFIG_DEBUG_EXPERIENCE
+KBUILD_CFLAGS	+= $(call cc-option, -Og)
+else
 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
 KBUILD_CFLAGS	+= $(call cc-option,-Oz,-Os)
 KBUILD_CFLAGS	+= $(call cc-disable-warning,maybe-uninitialized,)
@@ -649,6 +652,7 @@  else
 KBUILD_CFLAGS   += -O2
 endif
 endif
+endif
 
 KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0409, \
 			$(call cc-disable-warning,maybe-uninitialized,))
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index b4bf73f..b8b3832 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -192,7 +192,7 @@ 
 
 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
 
-#ifndef __CHECKER__
+#if !defined(__CHECKER__) && !defined(CONFIG_DEBUG_EXPERIENCE)
 # define __compiletime_warning(message) __attribute__((warning(message)))
 # define __compiletime_error(message) __attribute__((error(message)))
 #endif /* __CHECKER__ */
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index ab4711c..952cc7f 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -301,7 +301,7 @@  unsigned long read_word_at_a_time(const void *addr)
  * sparse see a constant array size without breaking compiletime_assert on old
  * versions of GCC (e.g. 4.2.4), so hide the array from sparse altogether.
  */
-# ifndef __CHECKER__
+# if !defined(__CHECKER__) && !defined(CONFIG_DEBUG_EXPERIENCE)
 #  define __compiletime_error_fallback(condition) \
 	do { ((void)sizeof(char[1 - 2 * condition])); } while (0)
 # endif
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index ab55801..e264199 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -216,6 +216,27 @@  config NO_AUTO_INLINE
 
 	  If unsure, select N.
 
+config DEBUG_EXPERIENCE
+	bool "Optimize for better debugging experience (-Og)"
+	default n
+	select NO_AUTO_INLINE
+	depends on !CC_OPTIMIZE_FOR_SIZE
+	help
+	  This will apply GCC '-Og' optimization level which is supported
+	  since GCC 4.8. This optimization level offers a reasonable level
+	  of optimization while maintaining fast compilation and a good
+	  debugging experience. It is similar to '-O1' while preferring to
+	  keep debug ability over runtime speed. The overall performance
+	  will drop a bit (~6%).
+
+	  Use only if you want to debug the kernel, especially if you want
+	  to have better kernel debugging experience with gdb facilities
+	  like kgdb or qemu. If enabling this option breaks your kernel,
+	  you should either disable this or find a fix (mostly in the arch
+	  code). Currently this option has only be tested on x86_64 platform.
+
+	  If unsure, select N.
+
 config ENABLE_WARN_DEPRECATED
 	bool "Enable __deprecated logic"
 	default y