Skip to contentSkip to conversation

qla2xxx: Don't memset buffer unless debug level is enabled

PATCH In review Nicholas A. Bellinger 4 participants 7 messages Nov 30, 2011 – Dec 1, 2011

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

PATCH 1/1 qla2xxx: Don't memset buffer unless debug level is enabled

From: Nicholas Bellinger <[email protected]>

During recent perf testing with qla_target.c logic, dl_dbg() appeared as one of the top CPU consumers (~5% CPU) with small block random I/O even when no debug levels have been enabled.

This patch moves the explict memset() in four qla_dbc.c functions within code blocks to where we know it will actually be used to save the extra wasted cycles.

Cc Andrew Vasquez <[email protected]>
Cc Giridhar Malavali <[email protected]>
Cc Roland Dreier <[email protected]>
Cc Joern Engel <[email protected]>
Cc James Bottomley <[email protected]>
---
 drivers/scsi/qla2xxx/qla_dbg.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
drivers/scsi/qla2xxx/qla_dbg.c +8 -8
index 07372de..cc32ec8 100644
@@ -1676,11 +1676,11 @@ ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) {
 	uint32_t len;
 	struct pci_dev *pdev = NULL;
 
-	memset(pbuf, 0, QL_DBG_BUF_LEN);
-
 	va_start(ap, msg);
 
 	if ((level & ql2xextended_error_logging) == level) {
+		memset(pbuf, 0, QL_DBG_BUF_LEN);
+		
 		if (vha != NULL) {
 			pdev = vha->hw->pdev;
 			/* <module-name> <pci-name> <msg-id>:<host> Message */
@@ -1724,11 +1724,11 @@ ql_dbg_pci(uint32_t level, struct pci_dev *pdev, int32_t id, char *msg, ...) {
 	if (pdev == NULL)
 		return;
 
-	memset(pbuf, 0, QL_DBG_BUF_LEN);
-
 	va_start(ap, msg);
 
 	if ((level & ql2xextended_error_logging) == level) {
+		memset(pbuf, 0, QL_DBG_BUF_LEN);
+		
 		/* <module-name> <dev-name>:<msg-id> Message */
 		sprintf(pbuf, "%s [%s]-%04x: : ", QL_MSGHDR,
 		    dev_name(&(pdev->dev)), id + ql_dbg_offset);
@@ -1763,11 +1763,11 @@ ql_log(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) {
 	uint32_t len;
 	struct pci_dev *pdev = NULL;
 
-	memset(pbuf, 0, QL_DBG_BUF_LEN);
-
 	va_start(ap, msg);
 
 	if (level <= ql_errlev) {
+		memset(pbuf, 0, QL_DBG_BUF_LEN);
+
 		if (vha != NULL) {
 			pdev = vha->hw->pdev;
 			/* <module-name> <msg-id>:<host> Message */
@@ -1823,11 +1823,11 @@ ql_log_pci(uint32_t level, struct pci_dev *pdev, int32_t id, char *msg, ...) {
 	if (pdev == NULL)
 		return;
 
-	memset(pbuf, 0, QL_DBG_BUF_LEN);
-
 	va_start(ap, msg);
 
 	if (level <= ql_errlev) {
+		memset(pbuf, 0, QL_DBG_BUF_LEN);
+
 		/* <module-name> <dev-name>:<msg-id> Message */
 		sprintf(pbuf, "%s [%s]-%04x: : ", QL_MSGHDR,
 		    dev_name(&(pdev->dev)), id);
Signature · 1 line
1.7.2.5
Acked-by on v1 1/1
#1 lore raw

Looks good. Thanks for the find.

Quoted 71 lines · Nicholas A. Bellinger

From: Nicholas Bellinger <[email protected]>

During recent perf testing with qla_target.c logic, dl_dbg() appeared as one of the top CPU consumers (~5% CPU) with small block random I/O even when no debug levels have been enabled.

This patch moves the explict memset() in four qla_dbc.c functions within code blocks to where we know it will actually be used to save the extra wasted cycles.

Cc Andrew Vasquez <[email protected]>
Cc Giridhar Malavali <[email protected]>
Cc Roland Dreier <[email protected]>
Cc Joern Engel <[email protected]>
Cc James Bottomley <[email protected]>

---
drivers/scsi/qla2xxx/qla_dbg.c | 16 ++++++++--------

1 files changed, 8 insertions(+), 8 deletions(-)
drivers/scsi/qla2xxx/qla_dbg.c +6 -6
index 07372de..cc32ec8 100644
@@ -1676,11 +1676,11 @@ ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) {
      uint32_t len;
      struct pci_dev *pdev = NULL;
 
-     memset(pbuf, 0, QL_DBG_BUF_LEN);
-
      va_start(ap, msg);
 
      if ((level & ql2xextended_error_logging) == level) {
+             memset(pbuf, 0, QL_DBG_BUF_LEN);
+
              if (vha != NULL) {
                      pdev = vha->hw->pdev;
                      /* <module-name> <pci-name> <msg-id>:<host> Message */
@@ -1724,11 +1724,11 @@ ql_dbg_pci(uint32_t level, struct pci_dev *pdev, int32_t id, char *msg, ...) {
      if (pdev == NULL)
              return;
 
-     memset(pbuf, 0, QL_DBG_BUF_LEN);
-
      va_start(ap, msg);
 
      if ((level & ql2xextended_error_logging) == level) {
+             memset(pbuf, 0, QL_DBG_BUF_LEN);
+
              /* <module-name> <dev-name>:<msg-id> Message */
              sprintf(pbuf, "%s [%s]-%04x: : ", QL_MSGHDR,
                  dev_name(&(pdev->dev)), id + ql_dbg_offset);
@@ -1763,11 +1763,11 @@ ql_log(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) {
      uint32_t len;
      struct pci_dev *pdev = NULL;
 
-     memset(pbuf, 0, QL_DBG_BUF_LEN);
-
      va_start(ap, msg);
 
      if (level <= ql_errlev) {
+             memset(pbuf, 0, QL_DBG_BUF_LEN);
+
              if (vha != NULL) {
                      pdev = vha->hw->pdev;
                      /* <module-name> <msg-id>:<host> Message */
@@ -1823,11 +1823,11 @@ ql_log_pci(uint32_t level, struct pci_dev *pdev, int32_t id, char *msg, ...) {
      if (pdev == NULL)
              return;
 

drivers/scsi/qla2xxx/qla_dbg.c ql_log_pci(uint32_t level, struct pci_dev *pdev, int32_t id, char *msg, ...) { · line 1833

Quoted 10 lines
drivers/scsi/qla2xxx/qla_dbg.c +2 -2
-     memset(pbuf, 0, QL_DBG_BUF_LEN);
-
      va_start(ap, msg);
 
      if (level <= ql_errlev) {
+             memset(pbuf, 0, QL_DBG_BUF_LEN);
+
              /* <module-name> <dev-name>:<msg-id> Message */
              sprintf(pbuf, "%s [%s]-%04x: : ", QL_MSGHDR,
                  dev_name(&(pdev->dev)), id);

This message and any attached documents contain information from QLogic Corporation or its wholly-owned subsidiaries that may be confidential. If you are not the intended recipient, you may not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.

#2 lore raw
In reply to Nicholas A. Bellinger
Quoted 5 lines · Nicholas A. Bellinger
drivers/scsi/qla2xxx/qla_dbg.c +0 -0
index 07372de..cc32ec8 100644

drivers/scsi/qla2xxx/qla_dbg.c ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) { · line 1683

Quoted 10 lines
drivers/scsi/qla2xxx/qla_dbg.c +2 -2
@@ -1676,11 +1676,11 @@ ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) {
  	uint32_t len;
  	struct pci_dev *pdev = NULL;
 
-	memset(pbuf, 0, QL_DBG_BUF_LEN);
-
  	va_start(ap, msg);
 
  	if ((level&  ql2xextended_error_logging) == level) {
+		memset(pbuf, 0, QL_DBG_BUF_LEN);
+		

512bytes on the stack is brave. Anyway, why do you memset the whole buffer? As far the string processing is concerned, setting the first byte to zero is enough.

Sebastian

#3 lore raw
Quoted 18 lines · Sebastian Andrzej Siewior
Quoted 5 lines · Nicholas A. Bellinger
drivers/scsi/qla2xxx/qla_dbg.c +0 -0
index 07372de..cc32ec8 100644

drivers/scsi/qla2xxx/qla_dbg.c ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) { · line 1683

Quoted 10 lines
drivers/scsi/qla2xxx/qla_dbg.c +2 -2
@@ -1676,11 +1676,11 @@ ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) {
  	uint32_t len;
  	struct pci_dev *pdev = NULL;
 
-	memset(pbuf, 0, QL_DBG_BUF_LEN);
-
  	va_start(ap, msg);
 
  	if ((level&  ql2xextended_error_logging) == level) {
+		memset(pbuf, 0, QL_DBG_BUF_LEN);
+		

512bytes on the stack is brave.

...

Quoted 4 lines

Anyway, why do you memset the whole
buffer? As far the string processing is concerned, setting the first byte to zero is enough.

After converting qla_target.c in a few hundred locations to use qla_dbg() my wrists are still hurting, so you can imagine I'm not real eager to look into this code. ;)

Anyways, memset of the whole buffer is overkill. Since sprintf() is being used for qla_dbg.c cases, even the 1 byte memset is unnecessary.

--nab

Quoted 1 line

From 25541e7f09b87de0000b11506d49695183aab4f1 Mon Sep 17 00:00:00 2001

From: Nicholas Bellinger <[email protected]>
Date: Wed, 30 Nov 2011 13:57:02 -0800
Subject: [PATCH] qla2xxx: Remove memset debug buffer with sprintf usage

During recent perf testing with qla_target.c logic, dl_dbg() appeared as one of the top CPU consumers (~5% CPU) with small block random I/O even when no debug levels have been enabled.

This patch drops the explict memset() in four qla_dbc.c functions as we expect sprintf() to add the trailing NULL when debug is enabled.

Cc Andrew Vasquez <[email protected]>
Cc Giridhar Malavali <[email protected]>
Cc Roland Dreier <[email protected]>
Cc Joern Engel <[email protected]>
Cc James Bottomley <[email protected]>
---
 drivers/scsi/qla2xxx/qla_dbg.c |    8 --------
 1 files changed, 0 insertions(+), 8 deletions(-)
drivers/scsi/qla2xxx/qla_dbg.c +0 -8
index 07372de..ef31819 100644
@@ -1676,8 +1676,6 @@ ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) {
 	uint32_t len;
 	struct pci_dev *pdev = NULL;
 
-	memset(pbuf, 0, QL_DBG_BUF_LEN);
-
 	va_start(ap, msg);
 
 	if ((level & ql2xextended_error_logging) == level) {
@@ -1724,8 +1722,6 @@ ql_dbg_pci(uint32_t level, struct pci_dev *pdev, int32_t id, char *msg, ...) {
 	if (pdev == NULL)
 		return;
 
-	memset(pbuf, 0, QL_DBG_BUF_LEN);
-
 	va_start(ap, msg);
 
 	if ((level & ql2xextended_error_logging) == level) {
@@ -1763,8 +1759,6 @@ ql_log(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) {
 	uint32_t len;
 	struct pci_dev *pdev = NULL;
 
-	memset(pbuf, 0, QL_DBG_BUF_LEN);
-
 	va_start(ap, msg);
 
 	if (level <= ql_errlev) {
@@ -1823,8 +1817,6 @@ ql_log_pci(uint32_t level, struct pci_dev *pdev, int32_t id, char *msg, ...) {
 	if (pdev == NULL)
 		return;
 
-	memset(pbuf, 0, QL_DBG_BUF_LEN);
-
 	va_start(ap, msg);
 
 	if (level <= ql_errlev) {
Signature · 3 lines
1.7.2.5

root@tifa:/usr/src/lio-core-2.6.git# 
#4 lore raw
Quoted 27 lines · Nicholas A. Bellinger
Quoted 18 lines · Sebastian Andrzej Siewior
Quoted 5 lines · Nicholas A. Bellinger
drivers/scsi/qla2xxx/qla_dbg.c +0 -0
index 07372de..cc32ec8 100644

drivers/scsi/qla2xxx/qla_dbg.c ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) { · line 1683

Quoted 10 lines
drivers/scsi/qla2xxx/qla_dbg.c +2 -2
@@ -1676,11 +1676,11 @@ ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) {
    uint32_t len;
    struct pci_dev *pdev = NULL;
 
-   memset(pbuf, 0, QL_DBG_BUF_LEN);
-
    va_start(ap, msg);
 
    if ((level&  ql2xextended_error_logging) == level) {
+           memset(pbuf, 0, QL_DBG_BUF_LEN);
+

512bytes on the stack is brave.

...

Quoted 4 lines

Anyway, why do you memset the whole
buffer? As far the string processing is concerned, setting the first byte to zero is enough.

Quoted 6 lines

After converting qla_target.c in a few hundred locations to use qla_dbg() my wrists are still hurting, so you can imagine I'm not real eager to look into this code. ;)

Anyways, memset of the whole buffer is overkill. Since sprintf() is being used for qla_dbg.c cases, even the 1 byte memset is unnecessary.

I do want to note that there is a patch posted already that removes the memset as well:
http://marc.info/?l=linux-scsi&m=132163664809856&w=2.

Quoted 58 lines

--nab

From 25541e7f09b87de0000b11506d49695183aab4f1 Mon Sep 17 00:00:00 2001
From: Nicholas Bellinger <[email protected]>
Date: Wed, 30 Nov 2011 13:57:02 -0800
Subject: [PATCH] qla2xxx: Remove memset debug buffer with sprintf usage

During recent perf testing with qla_target.c logic, dl_dbg() appeared as one of the top CPU consumers (~5% CPU) with small block random I/O even when no debug levels have been enabled.

This patch drops the explict memset() in four qla_dbc.c functions as we expect sprintf() to add the trailing NULL when debug is enabled.

Cc Andrew Vasquez <[email protected]>
Cc Giridhar Malavali <[email protected]>
Cc Roland Dreier <[email protected]>
Cc Joern Engel <[email protected]>
Cc James Bottomley <[email protected]>

---
drivers/scsi/qla2xxx/qla_dbg.c | 8 --------

1 files changed, 0 insertions(+), 8 deletions(-)
drivers/scsi/qla2xxx/qla_dbg.c +0 -6
index 07372de..ef31819 100644
@@ -1676,8 +1676,6 @@ ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) {
      uint32_t len;
      struct pci_dev *pdev = NULL;
 
-     memset(pbuf, 0, QL_DBG_BUF_LEN);
-
      va_start(ap, msg);
 
      if ((level & ql2xextended_error_logging) == level) {
@@ -1724,8 +1722,6 @@ ql_dbg_pci(uint32_t level, struct pci_dev *pdev, int32_t id, char *msg, ...) {
      if (pdev == NULL)
              return;
 
-     memset(pbuf, 0, QL_DBG_BUF_LEN);
-
      va_start(ap, msg);
 
      if ((level & ql2xextended_error_logging) == level) {
@@ -1763,8 +1759,6 @@ ql_log(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) {
      uint32_t len;
      struct pci_dev *pdev = NULL;
 
-     memset(pbuf, 0, QL_DBG_BUF_LEN);
-
      va_start(ap, msg);
 
      if (level <= ql_errlev) {

drivers/scsi/qla2xxx/qla_dbg.c ql_log_pci(uint32_t level, struct pci_dev *pdev, int32_t id, char *msg, ...) { · line 1822

Quoted 8 lines
drivers/scsi/qla2xxx/qla_dbg.c +0 -2
@@ -1823,8 +1817,6 @@ ql_log_pci(uint32_t level, struct pci_dev *pdev, int32_t id, char *msg, ...) {
      if (pdev == NULL)
              return;
 
-     memset(pbuf, 0, QL_DBG_BUF_LEN);
-
      va_start(ap, msg);
 
      if (level <= ql_errlev) {

This message and any attached documents contain information from QLogic Corporation or its wholly-owned subsidiaries that may be confidential. If you are not the intended recipient, you may not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.

#5 lore raw
Quoted 34 lines · Chad Dupuis
Quoted 31 lines · Nicholas A. Bellinger
Quoted 18 lines · Sebastian Andrzej Siewior
Quoted 5 lines · Nicholas A. Bellinger
drivers/scsi/qla2xxx/qla_dbg.c +0 -0
index 07372de..cc32ec8 100644

drivers/scsi/qla2xxx/qla_dbg.c ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) { · line 1683

Quoted 10 lines
drivers/scsi/qla2xxx/qla_dbg.c +2 -2
@@ -1676,11 +1676,11 @@ ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) {
    uint32_t len;
    struct pci_dev *pdev = NULL;
 
-   memset(pbuf, 0, QL_DBG_BUF_LEN);
-
    va_start(ap, msg);
 
    if ((level&  ql2xextended_error_logging) == level) {
+           memset(pbuf, 0, QL_DBG_BUF_LEN);
+

512bytes on the stack is brave.

...

Quoted 4 lines

Anyway, why do you memset the whole
buffer? As far the string processing is concerned, setting the first byte to zero is enough.

After converting qla_target.c in a few hundred locations to use qla_dbg() my wrists are still hurting, so you can imagine I'm not real eager to look into this code. ;)

Quoted 6 lines
Quoted 2 lines

Anyways, memset of the whole buffer is overkill. Since sprintf() is being used for qla_dbg.c cases, even the 1 byte memset is unnecessary.

I do want to note that there is a patch posted already that removes the memset as well:
http://marc.info/?l=linux-scsi&m=132163664809856&w=2.

So since that one came from you as part of a series, I was originally planning to merge it before you acked this one, which basically makes this one redundant (and conflicting), doesn't it? Which patch did you want me to take, since I can't take both?

James

#6 lore raw
Quoted 38 lines · James Bottomley
Quoted 37 lines · Chad Dupuis
Quoted 33 lines · Nicholas A. Bellinger
Quoted 18 lines · Sebastian Andrzej Siewior
Quoted 5 lines · Nicholas A. Bellinger
drivers/scsi/qla2xxx/qla_dbg.c +0 -0
index 07372de..cc32ec8 100644

drivers/scsi/qla2xxx/qla_dbg.c ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) { · line 1683

Quoted 10 lines
drivers/scsi/qla2xxx/qla_dbg.c +2 -2
@@ -1676,11 +1676,11 @@ ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, char *msg, ...) {
    uint32_t len;
    struct pci_dev *pdev = NULL;
 
-   memset(pbuf, 0, QL_DBG_BUF_LEN);
-
    va_start(ap, msg);
 
    if ((level&  ql2xextended_error_logging) == level) {
+           memset(pbuf, 0, QL_DBG_BUF_LEN);
+

512bytes on the stack is brave.

...

Quoted 4 lines

Anyway, why do you memset the whole
buffer? As far the string processing is concerned, setting the first byte to zero is enough.

After converting qla_target.c in a few hundred locations to use qla_dbg() my wrists are still hurting, so you can imagine I'm not real eager to look into this code. ;)

Anyways, memset of the whole buffer is overkill. Since sprintf() is being used for qla_dbg.c cases, even the 1 byte memset is unnecessary.

Quoted 8 lines
Quoted 3 lines

I do want to note that there is a patch posted already that removes the memset as well:
http://marc.info/?l=linux-scsi&m=132163664809856&w=2.

So since that one came from you as part of a series, I was originally planning to merge it before you acked this one, which basically makes this one redundant (and conflicting), doesn't it? Which patch did you want me to take, since I can't take both?

Apologies for that. Please take the first one that was part of the series.

Quoted 4 lines

James

This message and any attached documents contain information from QLogic Corporation or its wholly-owned subsidiaries that may be confidential. If you are not the intended recipient, you may not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.