public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* missing vprintf in kernel.api. Interest in patch?
@ 2004-02-10 10:22 wdebruij
  2004-02-11  2:06 ` [patch] " Matt Mackall
  0 siblings, 1 reply; 2+ messages in thread
From: wdebruij @ 2004-02-10 10:22 UTC (permalink / raw)
  To: linux-kernel

Hi,

  while writing a new kernel module I needed vprintf behaviour to send
additional info to printk (e.g. __LINE__ and __FUNCTION__ preprocessor macros).
While the kernel API contains vsnprintf and vsprintf functions, it does not
contain a vprintf and since we have no access to the printk_buf structure it is
therefore impossible to directly write a formatted argument using a va_list to
the log. 

As a quick fix I wrote my own function using vsnprintf and printk, but this is
far from ideal when more people need such functionality.

Indeed, doing a quick grep on the (2.6.1) tree I noticed that I am not the only
one creating my own vprintf. In arch/um/kernel/tt/tracer.c, drivers/acpi/osl.c
and drivers/acpi/utilities/utdebug.c others have also written similar functions.
Not to mention all the DPRINTF, YYDPRINTF, etc. macros declared everywhere

Therefore my question is this: is there any interest in 

(1) a small patch that extracts the vsnprintf(printk_buf,...) from printk and
thus creates a vprintf function (trivial change, perhaps +5 lines of code).
and/or
(2) a kernel wide DPRINTK (or something) macro that adds the __FILE__,
__FUNCTION__ and __LINE__ macros to the output.
and/or
(3) an extension of 2 that also prints out clockcycles or timing statistics.

IMHO, everyone debugging and optimizing his code needs these features. It might
help clean up the codebase if everyone uses the same helper functions.
And since I already have such code laying around, sending in a patch is a
trivial task right now.

Please share your views, I don't want to create a patch if it'll be rejected
instantaneously because of some unspoken rule I haven't heard of.

cheers,

  Willem de Bruijn



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [patch] Re: missing vprintf in kernel.api. Interest in patch?
  2004-02-10 10:22 missing vprintf in kernel.api. Interest in patch? wdebruij
@ 2004-02-11  2:06 ` Matt Mackall
  0 siblings, 0 replies; 2+ messages in thread
From: Matt Mackall @ 2004-02-11  2:06 UTC (permalink / raw)
  To: wdebruij, akpm; +Cc: linux-kernel

On Tue, Feb 10, 2004 at 11:22:59AM +0100, wdebruij@dds.nl wrote:
> Therefore my question is this: is there any interest in 
> 
> (1) a small patch that extracts the vsnprintf(printk_buf,...) from printk and
> thus creates a vprintf function (trivial change, perhaps +5 lines of code).

I already have this patch in my -tiny tree as well as some other patches to
convert some would-be users like ext3_error. Andrew, interested in these? 

Add vprintk call


 tiny-mpm/include/linux/kernel.h |    1 +
 tiny-mpm/kernel/printk.c        |   14 ++++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff -puN include/linux/kernel.h~vprintk include/linux/kernel.h
--- tiny/include/linux/kernel.h~vprintk	2004-02-04 14:55:22.000000000 -0600
+++ tiny-mpm/include/linux/kernel.h	2004-02-04 14:55:22.000000000 -0600
@@ -84,6 +84,7 @@ extern unsigned long long memparse(char 
 extern int kernel_text_address(unsigned long addr);
 extern int session_of_pgrp(int pgrp);
 
+asmlinkage int vprintk(const char *fmt, va_list args);
 asmlinkage int printk(const char * fmt, ...)
 	__attribute__ ((format (printf, 1, 2)));
 
diff -puN kernel/printk.c~vprintk kernel/printk.c
--- tiny/kernel/printk.c~vprintk	2004-02-04 14:55:22.000000000 -0600
+++ tiny-mpm/kernel/printk.c	2004-02-04 14:55:22.000000000 -0600
@@ -474,6 +474,17 @@ static void emit_log_char(char c)
 asmlinkage int printk(const char *fmt, ...)
 {
 	va_list args;
+	int r;
+
+	va_start(args, fmt);
+	r = vprintk(fmt, args);
+	va_end(args);
+
+	return r;
+}
+
+asmlinkage int vprintk(const char *fmt, va_list args)
+{
 	unsigned long flags;
 	int printed_len;
 	char *p;
@@ -491,9 +502,7 @@ asmlinkage int printk(const char *fmt, .
 	spin_lock_irqsave(&logbuf_lock, flags);
 
 	/* Emit the output into the temporary buffer */
-	va_start(args, fmt);
 	printed_len = vsnprintf(printk_buf, sizeof(printk_buf), fmt, args);
-	va_end(args);
 
 	/*
 	 * Copy the output into log_buf.  If the caller didn't provide
@@ -543,6 +552,7 @@ out:
 	return printed_len;
 }
 EXPORT_SYMBOL(printk);
+EXPORT_SYMBOL(vprintk);
 
 /**
  * acquire_console_sem - lock the console system for exclusive use.

_


-- 
Matt Mackall : http://www.selenic.com : Linux development and consulting

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-02-11  2:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-10 10:22 missing vprintf in kernel.api. Interest in patch? wdebruij
2004-02-11  2:06 ` [patch] " Matt Mackall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox