diff mbox

[v3,3/5] kernel hacking: new config NO_AUTO_INLINE to disable compiler auto-inline optimizations

Message ID 1525566016-30172-4-git-send-email-changbin.du@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Du, Changbin May 6, 2018, 12:20 a.m. UTC
From: Changbin Du <changbin.du@intel.com>

This patch add a new kernel hacking option NO_AUTO_INLINE. Selecting
this option will prevent the compiler from optimizing the kernel by
auto-inlining functions not marked with the inline keyword.

With this option, only functions explicitly marked with "inline" will
be inlined. This will allow the function tracer to trace more functions
because it only traces functions that the compiler has not inlined.

Signed-off-by: Changbin Du <changbin.du@intel.com>
Cc: Steven Rostedt <rostedt@goodmis.org>

---
v2: Some grammar updates from Steven.
---
 Makefile          |  6 ++++++
 lib/Kconfig.debug | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)

Comments

kernel test robot May 6, 2018, 5:50 a.m. UTC | #1
Hi Changbin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v4.17-rc3 next-20180504]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/changbin-du-intel-com/kernel-hacking-GCC-optimization-for-better-debug-experience-Og/20180506-110946
config: arm64-allmodconfig (attached as .config)
compiler: aarch64-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=arm64 

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

   drivers/pci/host/pci-xgene.c: In function 'xgene_pcie_setup_ib_reg':
>> drivers/pci/host/pci-xgene.c:532:2: warning: 'pim_reg' may be used uninitialized in this function [-Wmaybe-uninitialized]
     xgene_pcie_setup_pims(port, pim_reg, pci_addr, ~(size - 1));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
   drivers/scsi/ufs/ufs-qcom.c: In function 'ufs_qcom_testbus_config':
>> drivers/scsi/ufs/ufs-qcom.c:1527:6: warning: 'offset' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int offset;
         ^~~~~~
>> drivers/scsi/ufs/ufs-qcom.c:1526:6: warning: 'reg' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int reg;
         ^~~

vim +/pim_reg +532 drivers/pci/host/pci-xgene.c

5f6b6ccd Tanmay Inamdar 2014-10-01  484  
5f6b6ccd Tanmay Inamdar 2014-10-01  485  static void xgene_pcie_setup_ib_reg(struct xgene_pcie_port *port,
5f6b6ccd Tanmay Inamdar 2014-10-01  486  				    struct of_pci_range *range, u8 *ib_reg_mask)
5f6b6ccd Tanmay Inamdar 2014-10-01  487  {
5f6b6ccd Tanmay Inamdar 2014-10-01  488  	void __iomem *cfg_base = port->cfg_base;
d963ab22 Bjorn Helgaas  2016-10-06  489  	struct device *dev = port->dev;
5f6b6ccd Tanmay Inamdar 2014-10-01  490  	void *bar_addr;
4ecf6b0f Bjorn Helgaas  2016-10-06  491  	u32 pim_reg;
5f6b6ccd Tanmay Inamdar 2014-10-01  492  	u64 cpu_addr = range->cpu_addr;
5f6b6ccd Tanmay Inamdar 2014-10-01  493  	u64 pci_addr = range->pci_addr;
5f6b6ccd Tanmay Inamdar 2014-10-01  494  	u64 size = range->size;
5f6b6ccd Tanmay Inamdar 2014-10-01  495  	u64 mask = ~(size - 1) | EN_REG;
5f6b6ccd Tanmay Inamdar 2014-10-01  496  	u32 flags = PCI_BASE_ADDRESS_MEM_TYPE_64;
5f6b6ccd Tanmay Inamdar 2014-10-01  497  	u32 bar_low;
5f6b6ccd Tanmay Inamdar 2014-10-01  498  	int region;
5f6b6ccd Tanmay Inamdar 2014-10-01  499  
5f6b6ccd Tanmay Inamdar 2014-10-01  500  	region = xgene_pcie_select_ib_reg(ib_reg_mask, range->size);
5f6b6ccd Tanmay Inamdar 2014-10-01  501  	if (region < 0) {
d963ab22 Bjorn Helgaas  2016-10-06  502  		dev_warn(dev, "invalid pcie dma-range config\n");
5f6b6ccd Tanmay Inamdar 2014-10-01  503  		return;
5f6b6ccd Tanmay Inamdar 2014-10-01  504  	}
5f6b6ccd Tanmay Inamdar 2014-10-01  505  
5f6b6ccd Tanmay Inamdar 2014-10-01  506  	if (range->flags & IORESOURCE_PREFETCH)
5f6b6ccd Tanmay Inamdar 2014-10-01  507  		flags |= PCI_BASE_ADDRESS_MEM_PREFETCH;
5f6b6ccd Tanmay Inamdar 2014-10-01  508  
5f6b6ccd Tanmay Inamdar 2014-10-01  509  	bar_low = pcie_bar_low_val((u32)cpu_addr, flags);
5f6b6ccd Tanmay Inamdar 2014-10-01  510  	switch (region) {
5f6b6ccd Tanmay Inamdar 2014-10-01  511  	case 0:
4ecf6b0f Bjorn Helgaas  2016-10-06  512  		xgene_pcie_set_ib_mask(port, BRIDGE_CFG_4, flags, size);
5f6b6ccd Tanmay Inamdar 2014-10-01  513  		bar_addr = cfg_base + PCI_BASE_ADDRESS_0;
5f6b6ccd Tanmay Inamdar 2014-10-01  514  		writel(bar_low, bar_addr);
5f6b6ccd Tanmay Inamdar 2014-10-01  515  		writel(upper_32_bits(cpu_addr), bar_addr + 0x4);
4ecf6b0f Bjorn Helgaas  2016-10-06  516  		pim_reg = PIM1_1L;
5f6b6ccd Tanmay Inamdar 2014-10-01  517  		break;
5f6b6ccd Tanmay Inamdar 2014-10-01  518  	case 1:
8e93c513 Bjorn Helgaas  2016-10-06  519  		xgene_pcie_writel(port, IBAR2, bar_low);
8e93c513 Bjorn Helgaas  2016-10-06  520  		xgene_pcie_writel(port, IR2MSK, lower_32_bits(mask));
4ecf6b0f Bjorn Helgaas  2016-10-06  521  		pim_reg = PIM2_1L;
5f6b6ccd Tanmay Inamdar 2014-10-01  522  		break;
5f6b6ccd Tanmay Inamdar 2014-10-01  523  	case 2:
8e93c513 Bjorn Helgaas  2016-10-06  524  		xgene_pcie_writel(port, IBAR3L, bar_low);
8e93c513 Bjorn Helgaas  2016-10-06  525  		xgene_pcie_writel(port, IBAR3L + 0x4, upper_32_bits(cpu_addr));
8e93c513 Bjorn Helgaas  2016-10-06  526  		xgene_pcie_writel(port, IR3MSKL, lower_32_bits(mask));
8e93c513 Bjorn Helgaas  2016-10-06  527  		xgene_pcie_writel(port, IR3MSKL + 0x4, upper_32_bits(mask));
4ecf6b0f Bjorn Helgaas  2016-10-06  528  		pim_reg = PIM3_1L;
5f6b6ccd Tanmay Inamdar 2014-10-01  529  		break;
5f6b6ccd Tanmay Inamdar 2014-10-01  530  	}
5f6b6ccd Tanmay Inamdar 2014-10-01  531  
4ecf6b0f Bjorn Helgaas  2016-10-06 @532  	xgene_pcie_setup_pims(port, pim_reg, pci_addr, ~(size - 1));
5f6b6ccd Tanmay Inamdar 2014-10-01  533  }
5f6b6ccd Tanmay Inamdar 2014-10-01  534  

:::::: The code at line 532 was first introduced by commit
:::::: 4ecf6b0f83523fb186dd1de9e2f1d324a2a413d9 PCI: xgene: Pass struct xgene_pcie_port to setup functions

:::::: TO: Bjorn Helgaas <bhelgaas@google.com>
:::::: CC: Bjorn Helgaas <bhelgaas@google.com>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox

Patch

diff --git a/Makefile b/Makefile
index 619a85a..eb694f6 100644
--- a/Makefile
+++ b/Makefile
@@ -775,6 +775,12 @@  KBUILD_CFLAGS 	+= $(call cc-option, -femit-struct-debug-baseonly) \
 		   $(call cc-option,-fno-var-tracking)
 endif
 
+ifdef CONFIG_NO_AUTO_INLINE
+KBUILD_CFLAGS   += $(call cc-option, -fno-inline-functions) \
+		   $(call cc-option, -fno-inline-small-functions) \
+		   $(call cc-option, -fno-inline-functions-called-once)
+endif
+
 ifdef CONFIG_FUNCTION_TRACER
 ifndef CC_FLAGS_FTRACE
 CC_FLAGS_FTRACE := -pg
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index c40c7b7..da52243 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -198,6 +198,23 @@  config GDB_SCRIPTS
 	  instance. See Documentation/dev-tools/gdb-kernel-debugging.rst
 	  for further details.
 
+config NO_AUTO_INLINE
+	bool "Disable compiler auto-inline optimizations"
+	help
+	  This will prevent the compiler from optimizing the kernel by
+	  auto-inlining functions not marked with the inline keyword.
+	  With this option, only functions explicitly marked with
+	  "inline" will be inlined. This will allow the function tracer
+	  to trace more functions because it only traces functions that
+	  the compiler has not inlined.
+
+	  Enabling this function can help debugging a kernel if using
+	  the function tracer. But it can also change how the kernel
+	  works, because inlining functions may change the timing,
+	  which could make it difficult while debugging race conditions.
+
+	  If unsure, select N.
+
 config ENABLE_WARN_DEPRECATED
 	bool "Enable __deprecated logic"
 	default y