Skip to contentSkip to conversation

scsi: lpfc: Reduce logging object code size

PATCH In review Joe Perches 1 participant 4 messages Aug 10, 2020 – Sep 9, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover scsi: lpfc: Reduce logging object code size

The logging macros are pretty heavyweight and can be consolidated to reduce overall object size.

Joe Perches (2):
scsi: lpfc: Neaten logging macro #defines
scsi: lpfc: Add logging functions to reduce object size

 drivers/scsi/lpfc/Makefile       |   2 +-
 drivers/scsi/lpfc/lpfc.h         |   5 ++
 drivers/scsi/lpfc/lpfc_attr.h    |   5 ++
 drivers/scsi/lpfc/lpfc_bsg.h     |   6 ++
 drivers/scsi/lpfc/lpfc_compat.h  |   5 ++
 drivers/scsi/lpfc/lpfc_crtn.h    |   5 ++
 drivers/scsi/lpfc/lpfc_disc.h    |   5 ++
 drivers/scsi/lpfc/lpfc_hw.h      |   5 ++
 drivers/scsi/lpfc/lpfc_hw4.h     |   5 ++
 drivers/scsi/lpfc/lpfc_ids.h     |   5 ++
 drivers/scsi/lpfc/lpfc_logmsg.c  | 112 +++++++++++++++++++++++++++++++
 drivers/scsi/lpfc/lpfc_logmsg.h  |  63 ++++++-----------
 drivers/scsi/lpfc/lpfc_nl.h      |   4 ++
 drivers/scsi/lpfc/lpfc_nvme.h    |   5 ++
 drivers/scsi/lpfc/lpfc_scsi.h    |   4 ++
 drivers/scsi/lpfc/lpfc_sli.h     |   5 ++
 drivers/scsi/lpfc/lpfc_sli4.h    |   5 ++
 drivers/scsi/lpfc/lpfc_version.h |   5 ++
 18 files changed, 208 insertions(+), 43 deletions(-)
 create mode 100644 drivers/scsi/lpfc/lpfc_logmsg.c
Signature · 1 line
2.26.0
#1 lore raw

PATCH 1/2 scsi: lpfc: Neaten logging macro #defines

Use kernel standard do {} while (0) logging macros

Miscellanea:

o Use ..., ##__VA_ARGS__
o Indent and align
o Add __printf(2, 3) to lpfc_dbg_print function declaration

---
 drivers/scsi/lpfc/lpfc_logmsg.h | 85 +++++++++++++++++++--------------
 1 file changed, 48 insertions(+), 37 deletions(-)
drivers/scsi/lpfc/lpfc_logmsg.h +48 -37
index 5660a8729462..c57adcdda258 100644
@@ -48,49 +48,60 @@
 #define LOG_ALL_MSG	0x7fffffff	/* LOG all messages */
 
 void lpfc_dmp_dbg(struct lpfc_hba *phba);
+__printf(2, 3)
 void lpfc_dbg_print(struct lpfc_hba *phba, const char *fmt, ...);
 
 /* generate message by verbose log setting or severity */
-#define lpfc_vlog_msg(vport, level, mask, fmt, arg...) \
-{ if (((mask) & (vport)->cfg_log_verbose) || (level[1] <= '4')) \
-	dev_printk(level, &((vport)->phba->pcidev)->dev, "%d:(%d):" \
-		   fmt, (vport)->phba->brd_no, vport->vpi, ##arg); }
+#define lpfc_vlog_msg(vport, level, mask, fmt, ...)			\
+do {									\
+	if (((mask) & (vport)->cfg_log_verbose) || (level[1] <= '4'))	\
+		dev_printk(level, &((vport)->phba->pcidev)->dev,	\
+			   "%d:(%d):" fmt,				\
+			   (vport)->phba->brd_no, vport->vpi,		\
+			   ##__VA_ARGS__);				\
+} while (0)
 
-#define lpfc_log_msg(phba, level, mask, fmt, arg...) \
-do { \
-	{ uint32_t log_verbose = (phba)->pport ? \
-				 (phba)->pport->cfg_log_verbose : \
-				 (phba)->cfg_log_verbose; \
-	if (((mask) & log_verbose) || (level[1] <= '4')) \
-		dev_printk(level, &((phba)->pcidev)->dev, "%d:" \
-			   fmt, phba->brd_no, ##arg); \
-	} \
+#define lpfc_log_msg(phba, level, mask, fmt, ...)			\
+do {									\
+	uint32_t log_verbose = (phba)->pport ?				\
+		(phba)->pport->cfg_log_verbose :			\
+		(phba)->cfg_log_verbose;				\
+	if (((mask) & log_verbose) || (level[1] <= '4'))		\
+		dev_printk(level, &((phba)->pcidev)->dev,		\
+			   "%d:" fmt,					\
+			   phba->brd_no, ##__VA_ARGS__);		\
 } while (0)
 
-#define lpfc_printf_vlog(vport, level, mask, fmt, arg...) \
-do { \
-	{ if (((mask) & (vport)->cfg_log_verbose) || (level[1] <= '3')) { \
-		if ((mask) & LOG_TRACE_EVENT) \
-			lpfc_dmp_dbg((vport)->phba); \
-		dev_printk(level, &((vport)->phba->pcidev)->dev, "%d:(%d):" \
-			   fmt, (vport)->phba->brd_no, vport->vpi, ##arg);  \
-		} else if (!(vport)->cfg_log_verbose) \
-			lpfc_dbg_print((vport)->phba, "%d:(%d):" fmt, \
-				(vport)->phba->brd_no, (vport)->vpi, ##arg); \
-	} \
+#define lpfc_printf_vlog(vport, level, mask, fmt, ...)			\
+do {									\
+	if (((mask) & (vport)->cfg_log_verbose) || (level[1] <= '3')) { \
+		if ((mask) & LOG_TRACE_EVENT)				\
+			lpfc_dmp_dbg((vport)->phba);			\
+		dev_printk(level, &((vport)->phba->pcidev)->dev,	\
+			   "%d:(%d):" fmt,				\
+			   (vport)->phba->brd_no, vport->vpi,		\
+			   ##__VA_ARGS__);				\
+	} else if (!(vport)->cfg_log_verbose) {				\
+		lpfc_dbg_print((vport)->phba,				\
+			       "%d:(%d):" fmt,				\
+			       (vport)->phba->brd_no, (vport)->vpi,	\
+			       ##__VA_ARGS__);				\
+	}								\
 } while (0)
 
-#define lpfc_printf_log(phba, level, mask, fmt, arg...) \
-do { \
-	{ uint32_t log_verbose = (phba)->pport ? \
-				 (phba)->pport->cfg_log_verbose : \
-				 (phba)->cfg_log_verbose; \
-	if (((mask) & log_verbose) || (level[1] <= '3')) { \
-		if ((mask) & LOG_TRACE_EVENT) \
-			lpfc_dmp_dbg(phba); \
-		dev_printk(level, &((phba)->pcidev)->dev, "%d:" \
-			fmt, phba->brd_no, ##arg); \
-	} else  if (!(phba)->cfg_log_verbose)\
-		lpfc_dbg_print(phba, "%d:" fmt, phba->brd_no, ##arg); \
-	} \
+#define lpfc_printf_log(phba, level, mask, fmt, ...)			\
+do {									\
+	uint32_t log_verbose = (phba)->pport ?				\
+		(phba)->pport->cfg_log_verbose :			\
+		(phba)->cfg_log_verbose;				\
+	if (((mask) & log_verbose) || (level[1] <= '3')) {		\
+		if ((mask) & LOG_TRACE_EVENT)				\
+			lpfc_dmp_dbg(phba);				\
+		dev_printk(level, &((phba)->pcidev)->dev,		\
+			   "%d:" fmt,					\
+			   phba->brd_no, ##__VA_ARGS__);		\
+	} else if (!(phba)->cfg_log_verbose) {				\
+		lpfc_dbg_print(phba, "%d:" fmt,				\
+			       phba->brd_no, ##__VA_ARGS__);		\
+	}								\
 } while (0)
Signature · 1 line
2.26.0
#2 lore raw

PATCH 2/2 scsi: lpfc: Add logging functions to reduce object size

In reply to Joe Perches

Make functions from logging macros.

Reduces overall object size ~14% (120KB) (x86-64, defconfig, with LPFC)

$ size -t drivers/scsi/lpfc/built-in.a.old
 888552	   8910	   2900	 900362	  dbd0a	(TOTALS)
$ size -t drivers/scsi/lpfc/built-in.a.new
 766757	   8910	   2900	 778567	  be147	(TOTALS)

Miscellanea:

o Add header #ifdef guards where unused in .h files

---
 drivers/scsi/lpfc/Makefile       |   2 +-
 drivers/scsi/lpfc/lpfc.h         |   5 ++
 drivers/scsi/lpfc/lpfc_attr.h    |   5 ++
 drivers/scsi/lpfc/lpfc_bsg.h     |   6 ++
 drivers/scsi/lpfc/lpfc_compat.h  |   5 ++
 drivers/scsi/lpfc/lpfc_crtn.h    |   5 ++
 drivers/scsi/lpfc/lpfc_disc.h    |   5 ++
 drivers/scsi/lpfc/lpfc_hw.h      |   5 ++
 drivers/scsi/lpfc/lpfc_hw4.h     |   5 ++
 drivers/scsi/lpfc/lpfc_ids.h     |   5 ++
 drivers/scsi/lpfc/lpfc_logmsg.c  | 112 +++++++++++++++++++++++++++++++
 drivers/scsi/lpfc/lpfc_logmsg.h  |  72 ++++++--------------
 drivers/scsi/lpfc/lpfc_nl.h      |   4 ++
 drivers/scsi/lpfc/lpfc_nvme.h    |   5 ++
 drivers/scsi/lpfc/lpfc_scsi.h    |   4 ++
 drivers/scsi/lpfc/lpfc_sli.h     |   5 ++
 drivers/scsi/lpfc/lpfc_sli4.h    |   5 ++
 drivers/scsi/lpfc/lpfc_version.h |   5 ++
 18 files changed, 207 insertions(+), 53 deletions(-)
 create mode 100644 drivers/scsi/lpfc/lpfc_logmsg.c
drivers/scsi/lpfc/Makefile +1 -1
index 092a971d066b..ebe0d3ddee27 100644
@@ -33,4 +33,4 @@ obj-$(CONFIG_SCSI_LPFC) := lpfc.o
 lpfc-objs := lpfc_mem.o lpfc_sli.o lpfc_ct.o lpfc_els.o \
 	lpfc_hbadisc.o	lpfc_init.o lpfc_mbox.o lpfc_nportdisc.o   \
 	lpfc_scsi.o lpfc_attr.o lpfc_vport.o lpfc_debugfs.o lpfc_bsg.o \
-	lpfc_nvme.o lpfc_nvmet.o
+	lpfc_nvme.o lpfc_nvmet.o lpfc_logmsg.o
drivers/scsi/lpfc/lpfc.h +5 -0
index 549adfaa97ce..571f35826947 100644
@@ -21,6 +21,9 @@
  * included with this package.                                     *
  *******************************************************************/
 
+#ifndef _H_LPFC
+#define _H_LPFC
+
 #include <scsi/scsi_host.h>
 #include <linux/ktime.h>
 #include <linux/workqueue.h>
@@ -1409,3 +1412,5 @@ static const char *routine(enum enum_name table_key)			\
 	}								\
 	return name;							\
 }
+
+#endif
drivers/scsi/lpfc/lpfc_attr.h +5 -0
index 9659a8fff971..94a7e2231ec6 100644
@@ -21,6 +21,9 @@
  * included with this package.                                     *
  *******************************************************************/
 
+#ifndef _H_LPFC_ATTR
+#define _H_LPFC_ATTR
+
 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
 static uint lpfc_##name = defval;\
 module_param(lpfc_##name, uint, S_IRUGO);\
@@ -126,3 +129,5 @@ lpfc_vport_param_set(name, defval, minval, maxval)\
 lpfc_vport_param_store(name)\
 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
 		   lpfc_##name##_show, lpfc_##name##_store)
+
+#endif
drivers/scsi/lpfc/lpfc_bsg.h +6 -0
index 2dc71243775d..5f64584647db 100644
@@ -19,6 +19,10 @@
  * more details, a copy of which can be found in the file COPYING  *
  * included with this package.                                     *
  *******************************************************************/
+
+#ifndef _H_LPFC_BSG
+#define _H_LPFC_BSG
+
 /* bsg definitions
  * No pointers to user data are allowed, all application buffers and sizes will
  * derived through the bsg interface.
@@ -389,3 +393,5 @@ struct get_trunk_info_req {
 /* driver only */
 #define SLI_CONFIG_NOT_HANDLED		0
 #define SLI_CONFIG_HANDLED		1
+
+#endif
drivers/scsi/lpfc/lpfc_compat.h +5 -0
index 43cf46a3a71f..d6ccde39269a 100644
@@ -20,6 +20,9 @@
  * included with this package.                                     *
  *******************************************************************/
 
+#ifndef _H_LPFC_COMPAT
+#define _H_LPFC_COMPAT
+
 /*
  * This file provides macros to aid compilation in the Linux 2.4 kernel
  * over various platform architectures.
@@ -96,3 +99,5 @@ lpfc_memcpy_from_slim( void *dest, void __iomem *src, unsigned int bytes)
 }
 
 #endif	/* __BIG_ENDIAN */
+
+#endif
drivers/scsi/lpfc/lpfc_crtn.h +5 -0
index 782f6f76f18a..dd8553ecf091 100644
@@ -20,6 +20,9 @@
  * included with this package.                                     *
  *******************************************************************/
 
+#ifndef _H_LPFC_CRTN
+#define _H_LPFC_CRTN
+
 typedef int (*node_filter)(struct lpfc_nodelist *, void *);
 
 struct fc_rport;
@@ -600,3 +603,5 @@ extern int lpfc_enable_nvmet_cnt;
 extern unsigned long long lpfc_enable_nvmet[];
 extern int lpfc_no_hba_reset_cnt;
 extern unsigned long lpfc_no_hba_reset[];
+
+#endif
drivers/scsi/lpfc/lpfc_disc.h +5 -0
index 482e4a888dae..9d3f49e007fa 100644
@@ -20,6 +20,9 @@
  * included with this package.                                     *
  *******************************************************************/
 
+#ifndef _H_LPFC_DISC
+#define _H_LPFC_DISC
+
 #define FC_MAX_HOLD_RSCN     32	      /* max number of deferred RSCNs */
 #define FC_MAX_NS_RSP        64512    /* max size NameServer rsp */
 #define FC_MAXLOOP           126      /* max devices supported on a fc loop */
@@ -299,3 +302,5 @@ struct lpfc_node_rrq {
 #define NLP_EVT_DEVICE_RECOVERY   0xc	/* Device existence unknown */
 #define NLP_EVT_MAX_EVENT         0xd
 #define NLP_EVT_NOTHING_PENDING   0xff
+
+#endif
drivers/scsi/lpfc/lpfc_hw.h +5 -0
index c20034b3101c..c56a9fd0a1eb 100644
@@ -20,6 +20,9 @@
  * included with this package.                                     *
  *******************************************************************/
 
+#ifndef _H_LPFC_HW
+#define _H_LPFC_HW
+
 #define FDMI_DID        0xfffffaU
 #define NameServer_DID  0xfffffcU
 #define Fabric_Cntl_DID 0xfffffdU
@@ -4265,3 +4268,5 @@ lpfc_error_lost_link(IOCB_t *iocbp)
 #define SETVAR_MLORST 0x103007
 
 #define BPL_ALIGN_SZ 8 /* 8 byte alignment for bpl and mbufs */
+
+#endif
drivers/scsi/lpfc/lpfc_hw4.h +5 -0
index c4ba8273a63f..d9e6bf53f520 100644
@@ -20,6 +20,9 @@
  * included with this package.                                     *
  *******************************************************************/
 
+#ifndef _H_LPFC_HW4
+#define _H_LPFC_HW4
+
 #include <uapi/scsi/fc/fc_els.h>
 
 /* Macros to deal with bit fields. Each bit field must have 3 #defines
@@ -4912,3 +4915,5 @@ struct lpfc_grp_hdr {
 #define LPFC_FW_DUMP	1
 #define LPFC_FW_RESET	2
 #define LPFC_DV_RESET	3
+
+#endif
drivers/scsi/lpfc/lpfc_ids.h +5 -0
index d48414e295a0..2abb7b098a3d 100644
@@ -21,6 +21,9 @@
  * included with this package.                                     *
  *******************************************************************/
 
+#ifndef _H_LPFC_IDS
+#define _H_LPFC_IDS
+
 #include <linux/pci.h>
 
 const struct pci_device_id lpfc_id_table[] = {
@@ -124,3 +127,5 @@ const struct pci_device_id lpfc_id_table[] = {
 		PCI_ANY_ID, PCI_ANY_ID, },
 	{ 0 }
 };
+
+#endif
drivers/scsi/lpfc/lpfc_logmsg.c new file +112 -0

112 lines not on this page · raw message

drivers/scsi/lpfc/lpfc_logmsg.h +20 -52

82 lines not on this page · raw message

drivers/scsi/lpfc/lpfc_nl.h +4 -0
index 95d60ab5ebf9..eefbcd032dfe 100644
@@ -20,6 +20,9 @@
  * included with this package.                                     *
  *******************************************************************/
 
+#ifndef _H_LPFC_NL
+#define _H_LPFC_NL
+
 /* Event definitions for RegisterForEvent */
 #define FC_REG_LINK_EVENT		0x0001	/* link up / down events */
 #define FC_REG_RSCN_EVENT		0x0002	/* RSCN events */
@@ -179,3 +182,4 @@ struct temp_event {
 	uint32_t data;
 };
 
+#endif
drivers/scsi/lpfc/lpfc_nvme.h +5 -0
index 4a4c3f780e1f..09696510c3b3 100644
@@ -21,6 +21,9 @@
  * included with this package.                                     *
  ********************************************************************/
 
+#ifndef _H_LPFC_NVME
+#define _H_LPFC_NVME
+
 #include <linux/nvme.h>
 #include <linux/nvme-fc-driver.h>
 #include <linux/nvme-fc.h>
@@ -254,3 +257,5 @@ int __lpfc_nvme_xmt_ls_rsp(struct lpfc_async_xchg_ctx *axchg,
 				struct lpfc_wcqe_complete *wcqe));
 void __lpfc_nvme_xmt_ls_rsp_cmp(struct lpfc_hba *phba,
 		struct lpfc_iocbq *cmdwqe, struct lpfc_wcqe_complete *wcqe);
+
+#endif
drivers/scsi/lpfc/lpfc_scsi.h +4 -0
index f76667b7da7b..7115a3fb6acf 100644
@@ -20,6 +20,9 @@
  * included with this package.                                     *
  *******************************************************************/
 
+#ifndef _H_LPFC_SCSI
+#define _H_LPFC_SCSI
+
 #include <asm/byteorder.h>
 
 struct lpfc_hba;
@@ -147,3 +150,4 @@ struct lpfc_scsicmd_bkt {
 /* For sysfs/debugfs tmp string max len */
 #define LPFC_MAX_SCSI_INFO_TMP_LEN	79
 
+#endif
drivers/scsi/lpfc/lpfc_sli.h +5 -0
index 93d976ea8c5d..f24f875e1fe8 100644
@@ -20,6 +20,9 @@
  * included with this package.                                     *
  *******************************************************************/
 
+#ifndef _H_LPFC_SLI
+#define _H_LPFC_SLI
+
 #if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_SCSI_LPFC_DEBUG_FS)
 #define CONFIG_SCSI_LPFC_DEBUG_FS
 #endif
@@ -449,3 +452,5 @@ struct lpfc_io_buf {
 	uint64_t ts_data_io;
 #endif
 };
+
+#endif
drivers/scsi/lpfc/lpfc_sli4.h +5 -0
index a966cdeb52ee..9096b2c941e7 100644
@@ -20,6 +20,9 @@
  * included with this package.                                     *
  *******************************************************************/
 
+#ifndef _H_LPFC_SLI4
+#define _H_LPFC_SLI4
+
 #include <linux/irq_poll.h>
 #include <linux/cpufreq.h>
 
@@ -1160,3 +1163,5 @@ static inline void *lpfc_sli4_qe(struct lpfc_queue *q, uint16_t idx)
 	return q->q_pgs[idx / q->entry_cnt_per_pg] +
 		(q->entry_size * (idx % q->entry_cnt_per_pg));
 }
+
+#endif
drivers/scsi/lpfc/lpfc_version.h +5 -0
index 20adec4387f0..259c4a72db74 100644
@@ -20,6 +20,9 @@
  * included with this package.                                     *
  *******************************************************************/
 
+#ifndef _H_LPFC_VERSION
+#define _H_LPFC_VERSION
+
 #define LPFC_DRIVER_VERSION "12.8.0.3"
 #define LPFC_DRIVER_NAME		"lpfc"
 
@@ -35,3 +38,5 @@
 #define LPFC_COPYRIGHT "Copyright (C) 2017-2019 Broadcom. All Rights " \
 		"Reserved. The term \"Broadcom\" refers to Broadcom Inc. " \
 		"and/or its subsidiaries."
+
+#endif
Signature · 1 line
2.26.0
#3 lore raw
In reply to Joe Perches
Quoted 19 lines · Joe Perches

The logging macros are pretty heavyweight and can be consolidated to reduce overall object size.

Joe Perches (2):
scsi: lpfc: Neaten logging macro #defines
scsi: lpfc: Add logging functions to reduce object size

 drivers/scsi/lpfc/Makefile       |   2 +-
 drivers/scsi/lpfc/lpfc.h         |   5 ++
 drivers/scsi/lpfc/lpfc_attr.h    |   5 ++
 drivers/scsi/lpfc/lpfc_bsg.h     |   6 ++
 drivers/scsi/lpfc/lpfc_compat.h  |   5 ++
 drivers/scsi/lpfc/lpfc_crtn.h    |   5 ++
 drivers/scsi/lpfc/lpfc_disc.h    |   5 ++
 drivers/scsi/lpfc/lpfc_hw.h      |   5 ++
 drivers/scsi/lpfc/lpfc_hw4.h     |   5 ++
 drivers/scsi/lpfc/lpfc_ids.h     |   5 ++
 drivers/scsi/lpfc/lpfc_logmsg.c  | 112 +++++++++++++++++++++++++++++++
 drivers/scsi/lpfc/lpfc_logmsg.h  |  63 ++++++-----------
Quoted 8 lines
 drivers/scsi/lpfc/lpfc_nl.h      |   4 ++
 drivers/scsi/lpfc/lpfc_nvme.h    |   5 ++
 drivers/scsi/lpfc/lpfc_scsi.h    |   4 ++
 drivers/scsi/lpfc/lpfc_sli.h     |   5 ++
 drivers/scsi/lpfc/lpfc_sli4.h    |   5 ++
 drivers/scsi/lpfc/lpfc_version.h |   5 ++
 18 files changed, 208 insertions(+), 43 deletions(-)
 create mode 100644 drivers/scsi/lpfc/lpfc_logmsg.c

ping?