Received: by 10.192.165.148 with SMTP id m20csp689922imm; Wed, 2 May 2018 07:17:36 -0700 (PDT) X-Google-Smtp-Source: AB8JxZramiEil4/mzs20xNKx46fRTB9M9gVQvyrPGzo1ff0VP/6ine5VSPNTcBVe36sE8i6Jjbo2 X-Received: by 10.98.152.29 with SMTP id q29mr19550727pfd.65.1525270656065; Wed, 02 May 2018 07:17:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525270656; cv=none; d=google.com; s=arc-20160816; b=o2Wz1zXh4a+YA+afxIKyOjMCmsBIP7dzH5HMvIHQ1zTqKqHp5aeGLFdm0cg/Sc3sNo lUXPT5zfxGt/LRtbP33X3+5TOfru+7IRo5Zl4+HiRCfHnOla4C3ogSiKWee5ZCaV2PQ+ MrnssFHdmp7KtwYXCzt+pnLa7l2fqHwlgqEEzXHHdITxZEtqTBx+tDF9rkslG3r6HEXY bp1gn5SPVTt5B4eVZbm2fSh1sDoM10BKYZveZpNSeJExilmACHuzW/9vYdGR//dSvGZP W5nDofeDK3RE7dKT42HkTePAVJnEqkLfUAzovdZfIhE2DDJuaB/YpFJ0qYSkv1+2l4fl k5CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=MnrTEDQI2murq/xuLyRdBrk1meLwVzCOjRif6pcrA64=; b=TaEzq7U7FczsPrmANzRjzWQvGTrJhQTxsoWh9PECx3RoSBw6Q5YWis/X0SiOevgeqE XtLje0SDxoEOvEwoRmS9XIhG3uFWuXNnZa5MeoRgxWFibUtyd50bMWIIuK+S4A/P5Fu1 FGdczY1cIzjVv77Uvbmofp7ds3b6DsKkC289Dh/6y7Jte5ykEZ++FfmjYuZrfTQKl7XJ PzPVTPbYsiFLOiQvO153jGP2qwo/AEcWdmP+k+aVK9tzlqBiDTr54I0chzfhWqNT364o ZfTeBeO+p4RZvsdaP5QuGqjxoXitKu4N+WEb+f+E70/OBBjn7DM8czCDa5T0PPEddLvA d9Vw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e22-v6si11532790plj.311.2018.05.02.07.17.21; Wed, 02 May 2018 07:17:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751421AbeEBORO (ORCPT + 99 others); Wed, 2 May 2018 10:17:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:58452 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751144AbeEBORK (ORCPT ); Wed, 2 May 2018 10:17:10 -0400 Received: from gandalf.local.home (cpe-66-24-56-78.stny.res.rr.com [66.24.56.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DAF2522D73; Wed, 2 May 2018 14:17:08 +0000 (UTC) Date: Wed, 2 May 2018 10:17:07 -0400 From: Steven Rostedt To: changbin.du@intel.com Cc: yamada.masahiro@socionext.com, michal.lkml@markovi.net, tglx@linutronix.de, mingo@redhat.com, akpm@linux-foundation.org, rdunlap@infradead.org, x86@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, arnd@arndb.de, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Subject: Re: [PATCH v2 4/5] kernel hacking: new config DEBUG_EXPERIENCE to apply GCC -Og optimization Message-ID: <20180502101707.206984e9@gandalf.local.home> In-Reply-To: <1525268700-10631-5-git-send-email-changbin.du@intel.com> References: <1525268700-10631-1-git-send-email-changbin.du@intel.com> <1525268700-10631-5-git-send-email-changbin.du@intel.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2 May 2018 21:44:59 +0800 changbin.du@intel.com wrote: > From: Changbin Du > > 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 > > --- > 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