mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Jason Baron <jbaron@redhat.com>
Cc: gregkh@suse.de, joe@perches.com, jim.cromie@gmail.com,
	bvanassche@acm.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] dynamic_debug: use a single printk() to emit msgs
Date: Thu, 8 Sep 2011 16:52:39 -0700	[thread overview]
Message-ID: <20110908165239.120f25c5.akpm@linux-foundation.org> (raw)
In-Reply-To: <c106d5b6978b550e3a98b5425cc2ba00b090c9eb.1314725877.git.jbaron@redhat.com>

On Tue, 30 Aug 2011 14:28:50 -0400
Jason Baron <jbaron@redhat.com> wrote:

> We were using KERN_CONT to combine msgs with their prefix. However,
> KERN_CONT is not smp safe, in the sense that it can interleave messages.
> This interleaving can result in printks coming out at the wrong loglevel.
> With the high frequency of printks, that dynamic debug can produce, this
> is not desirable.
> 
> Thus, make dynamic_emit_prefix(), fill a char buf[64], instead
> of doing a printk directly. If we enable printing out of
> function, module, line, or pid info, they are placed in this
> 64 byte buffer. In my testing 64 bytes was enough size to fulfill
> all requests. Even if its not, we can match up the printk itself
> to see where its from, so to me this is no big deal.
> 
> ...
>
> +#define LEFT(wrote) ((PREFIX_SIZE - wrote) > 0) ? (PREFIX_SIZE - wrote) : 0

This macro will misbehave if passed an expression with side effects and
is rather ugly and didn't actually need to be implemented as a macro at
all.

This?

--- a/lib/dynamic_debug.c~dynamic_debug-use-a-single-printk-to-emit-messages-fix
+++ a/lib/dynamic_debug.c
@@ -423,31 +423,39 @@ static int ddebug_exec_query(char *query
 }
 
 #define PREFIX_SIZE 64
-#define LEFT(wrote) ((PREFIX_SIZE - wrote) > 0) ? (PREFIX_SIZE - wrote) : 0
+
+static int remaining(int wrote)
+{
+	if (PREFIX_SIZE - wrote > 0)
+		return PREFIX_SIZE - wrote;
+	return 0;
+}
 
 static char *dynamic_emit_prefix(const struct _ddebug *desc, char *buf)
 {
 	int pos_after_tid;
 	int pos = 0;
 
-	pos += snprintf(buf + pos, LEFT(pos), "%s", KERN_DEBUG);
+	pos += snprintf(buf + pos, remaining(pos), "%s", KERN_DEBUG);
 	if (desc->flags & _DPRINTK_FLAGS_INCL_TID) {
 		if (in_interrupt())
-			pos += snprintf(buf + pos, LEFT(pos), "%s ",
+			pos += snprintf(buf + pos, remaining(pos), "%s ",
 						"<intr>");
 		else
-			pos += snprintf(buf + pos, LEFT(pos), "[%d] ",
+			pos += snprintf(buf + pos, remaining(pos), "[%d] ",
 						task_pid_vnr(current));
 	}
 	pos_after_tid = pos;
 	if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME)
-		pos += snprintf(buf + pos, LEFT(pos), "%s:", desc->modname);
+		pos += snprintf(buf + pos, remaining(pos), "%s:",
+					desc->modname);
 	if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME)
-		pos += snprintf(buf + pos, LEFT(pos), "%s:", desc->function);
+		pos += snprintf(buf + pos, remaining(pos), "%s:",
+					desc->function);
 	if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO)
-		pos += snprintf(buf + pos, LEFT(pos), "%d:", desc->lineno);
+		pos += snprintf(buf + pos, remaining(pos), "%d:", desc->lineno);
 	if (pos - pos_after_tid)
-		pos += snprintf(buf + pos, LEFT(pos), " ");
+		pos += snprintf(buf + pos, remaining(pos), " ");
 	if (pos >= PREFIX_SIZE)
 		buf[PREFIX_SIZE - 1] = '\0';
 
_


  reply	other threads:[~2011-09-08 23:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-30 18:28 [PATCH 0/4] dynamic debug: cleanups + compile fix v2 Jason Baron
2011-08-30 18:28 ` [PATCH 1/4] dynamic_debug: consolidate repetitive struct _ddebug descriptor definitions Jason Baron
2011-09-08 23:52   ` Andrew Morton
2011-09-09  2:13     ` Joe Perches
2011-09-09  3:42       ` Andrew Morton
2011-09-09  4:02         ` Joe Perches
2011-09-09  4:20           ` Andrew Morton
2011-09-09  4:35             ` Joe Perches
2011-09-09 10:31           ` Bart Van Assche
2011-09-09 19:23             ` Jim Cromie
2011-09-09 21:04               ` Joe Perches
2011-09-09 22:06                 ` Jim Cromie
2011-09-09 22:32                   ` Joe Perches
2011-09-12 14:47                     ` Jason Baron
2011-09-12 18:15                       ` Jim Cromie
2011-09-12 15:00               ` Jason Baron
2011-08-30 18:28 ` [PATCH 2/4] dynamic_debug: remove num_enabled accounting Jason Baron
2011-08-30 18:28 ` [PATCH 3/4] dynamic_debug: use a single printk() to emit msgs Jason Baron
2011-09-08 23:52   ` Andrew Morton [this message]
2011-08-30 18:28 ` [PATCH 4/4] dynamic_debug: fix undefined reference to `__netdev_printk' Jason Baron
2011-09-01 16:16   ` Arnd Bergmann
  -- strict thread matches above, loose matches on Subject: below --
2011-08-25 17:34 [PATCH 0/4] dynamic debug: cleanups + compile fix Jason Baron
2011-08-25 17:34 ` [PATCH 3/4] dynamic_debug: use a single printk() to emit msgs Jason Baron
2011-08-25 17:42   ` Bart Van Assche
2011-08-26 21:47   ` Jim Cromie
2011-08-29 19:14     ` Jason Baron

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=20110908165239.120f25c5.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=bvanassche@acm.org \
    --cc=gregkh@suse.de \
    --cc=jbaron@redhat.com \
    --cc=jim.cromie@gmail.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@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

Powered by JetHome