linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	"David S. Miller" <davem@davemloft.net>,
	Jason Baron <jbaron@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jim Cromie <jim.cromie@gmail.com>, Kay Sievers <kay@vrfy.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/5] netdev_printk/dynamic_netdev_dbg: Directly call printk_emit
Date: Sun, 26 Aug 2012 04:25:27 -0700	[thread overview]
Message-ID: <f756fa139d9da590c667132093b4d7b7a545ee20.1345978012.git.joe@perches.com> (raw)
In-Reply-To: <cover.1345978012.git.joe@perches.com>

A lot of stack is used in recursive printks with %pV.

Using multiple levels of %pV (a logging function with %pV
that calls another logging function with %pV) can consume
more stack than necessary.

Avoid excessive stack use by not calling dev_printk from
netdev_printk and dynamic_netdev_dbg.  Duplicate the logic
and form of dev_printk instead.

Make __netdev_printk static.
Remove EXPORT_SYMBOL(__netdev_printk)
Whitespace and brace style neatening.

Signed-off-by: Joe Perches <joe@perches.com>
---
 include/linux/netdevice.h |    3 ---
 lib/dynamic_debug.c       |   26 +++++++++++++++++++++++---
 net/core/dev.c            |   24 +++++++++++++++++-------
 3 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 59dc05f3..5f49cc0 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2720,9 +2720,6 @@ static inline const char *netdev_name(const struct net_device *dev)
 	return dev->name;
 }
 
-extern int __netdev_printk(const char *level, const struct net_device *dev,
-			struct va_format *vaf);
-
 extern __printf(3, 4)
 int netdev_printk(const char *level, const struct net_device *dev,
 		  const char *format, ...);
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 29ff2e4..2a29f4e 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -611,20 +611,40 @@ EXPORT_SYMBOL(__dynamic_dev_dbg);
 #ifdef CONFIG_NET
 
 int __dynamic_netdev_dbg(struct _ddebug *descriptor,
-		      const struct net_device *dev, const char *fmt, ...)
+			 const struct net_device *dev, const char *fmt, ...)
 {
 	struct va_format vaf;
 	va_list args;
 	int res;
-	char buf[PREFIX_SIZE];
 
 	BUG_ON(!descriptor);
 	BUG_ON(!fmt);
 
 	va_start(args, fmt);
+
 	vaf.fmt = fmt;
 	vaf.va = &args;
-	res = __netdev_printk(dynamic_emit_prefix(descriptor, buf), dev, &vaf);
+
+	if (dev && dev->dev.parent) {
+		char buf[PREFIX_SIZE];
+		char dict[128];
+		size_t dictlen;
+
+		dictlen = create_syslog_header(dev->dev.parent,
+					       dict, sizeof(dict));
+
+		res = printk_emit(0, 7, dictlen ? dict : NULL, dictlen,
+				  "%s%s %s: %s: %pV",
+				  dynamic_emit_prefix(descriptor, buf),
+				  dev_driver_string(dev->dev.parent),
+				  dev_name(dev->dev.parent),
+				  netdev_name(dev), &vaf);
+	} else if (dev) {
+		res = printk(KERN_DEBUG "%s: %pV", netdev_name(dev), &vaf);
+	} else {
+		res = printk(KERN_DEBUG "(NULL net_device): %pV", &vaf);
+	}
+
 	va_end(args);
 
 	return res;
diff --git a/net/core/dev.c b/net/core/dev.c
index 8398836..a588145 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6422,22 +6422,30 @@ const char *netdev_drivername(const struct net_device *dev)
 	return empty;
 }
 
-int __netdev_printk(const char *level, const struct net_device *dev,
+static int __netdev_printk(const char *level, const struct net_device *dev,
 			   struct va_format *vaf)
 {
 	int r;
 
-	if (dev && dev->dev.parent)
-		r = dev_printk(level, dev->dev.parent, "%s: %pV",
-			       netdev_name(dev), vaf);
-	else if (dev)
+	if (dev && dev->dev.parent) {
+		char dict[128];
+		size_t dictlen = create_syslog_header(dev->dev.parent,
+						      dict, sizeof(dict));
+
+		r = printk_emit(0, level[1] - '0',
+				dictlen ? dict : NULL, dictlen,
+				"%s %s: %s: %pV",
+				dev_driver_string(dev->dev.parent),
+				dev_name(dev->dev.parent),
+				netdev_name(dev), vaf);
+	} else if (dev) {
 		r = printk("%s%s: %pV", level, netdev_name(dev), vaf);
-	else
+	} else {
 		r = printk("%s(NULL net_device): %pV", level, vaf);
+	}
 
 	return r;
 }
-EXPORT_SYMBOL(__netdev_printk);
 
 int netdev_printk(const char *level, const struct net_device *dev,
 		  const char *format, ...)
@@ -6452,6 +6460,7 @@ int netdev_printk(const char *level, const struct net_device *dev,
 	vaf.va = &args;
 
 	r = __netdev_printk(level, dev, &vaf);
+
 	va_end(args);
 
 	return r;
@@ -6471,6 +6480,7 @@ int func(const struct net_device *dev, const char *fmt, ...)	\
 	vaf.va = &args;						\
 								\
 	r = __netdev_printk(level, dev, &vaf);			\
+								\
 	va_end(args);						\
 								\
 	return r;						\
-- 
1.7.8.111.gad25c.dirty


  parent reply	other threads:[~2012-08-26 11:25 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-26 11:25 [PATCH 0/5] dev_<level> and dynamic_debug cleanups Joe Perches
2012-08-26 11:25 ` [PATCH 1/5] dev_dbg/dynamic_debug: Update to use printk_emit, optimize stack Joe Perches
2012-08-26 11:25 ` Joe Perches [this message]
2012-08-26 11:25 ` [PATCH 3/5] netdev_printk/netif_printk: Remove a superfluous logging colon Joe Perches
2012-08-26 11:25 ` [PATCH 4/5] dev: Add dev_vprintk_emit and dev_printk_emit Joe Perches
2012-09-25 21:05   ` Geert Uytterhoeven
2012-09-26  1:19     ` [PATCH -next] device.h: Add missing inline to #ifndef CONFIG_PRINTK dev_vprintk_emit Joe Perches
2012-08-26 11:25 ` [PATCH 5/5] device and dynamic_debug: Use dev_vprintk_emit and dev_printk_emit Joe Perches
2012-08-30 17:16 ` [PATCH 0/5] dev_<level> and dynamic_debug cleanups David Miller
2012-08-30 17:43 ` Jim Cromie
2012-08-30 18:25   ` Joe Perches
2012-08-31  3:48   ` Jim Cromie
2012-09-06 16:13     ` Greg Kroah-Hartman
2012-09-06 17:53       ` Jason Baron
2012-09-13  1:13         ` Joe Perches
2012-09-13  2:39           ` Jason Baron
2012-09-13  2:55             ` Greg Kroah-Hartman
2012-09-06 17:51 ` Jason Baron
2012-09-06 18:43   ` Joe Perches
2012-09-07 14:52     ` Jason Baron
2012-09-07 15:12       ` Joe Perches
2012-09-07 15:35         ` Jason Baron
2012-09-08  1:55           ` Joe Perches
2012-09-10 20:56             ` Jason Baron
2012-09-07 14:58     ` Joe Perches
2012-09-13  3:11 ` [PATCH 1/5] dev_dbg/dynamic_debug: Update to use printk_emit, optimize stack Joe Perches
2012-09-13  3:12 ` [PATCH 2/5] netdev_printk/dynamic_netdev_dbg: Directly call printk_emit Joe Perches
2012-09-13  3:13 ` [PATCH 3/5] netdev_printk/netif_printk: Remove a superfluous logging colon Joe Perches
2012-09-13  3:13 ` [PATCH 4/5] dev: Add dev_vprintk_emit and dev_printk_emit Joe Perches
2012-09-13  3:14 ` [PATCH 5/5] device and dynamic_debug: Use " Joe Perches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f756fa139d9da590c667132093b4d7b7a545ee20.1345978012.git.joe@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=jbaron@redhat.com \
    --cc=jim.cromie@gmail.com \
    --cc=kay@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).