[lkml]   [2007]   [Sep]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [RFC] New kernel-message logging API
Hi Vegard,

On Sat, 2007-09-22 at 21:27 +0200, Vegard Nossum wrote:
> After recent discussions on LKML and a general dissatisfaction at the
> current printk() kernel-message logging interface, I've decided to
> write down some of the ideas for a better system.

Good luck :-)


> Example: {
> struct kprint_buffer buf;
> kprint_buffer_init(&buf, KPRINT_DEBUG);
> kprint_buffer(&buf, "Stack trace:");
> while(unwind_stack()) {
> kprint_buffer(&buf, "%p %s", address, symbol);
> }
> kprint_buffer_flush(&buf);
> }

Together with the idea of not allowing multiple lines in the kprint_xxx
functions, that would go with our approach having message numbers to
identify a message. Multiple lines are combined explicitly to one
message. I think it is a good idea to be able to identify, which lines
of a message belong together.


> With such a modular interface, message attributes (for example the
> current time) and arguments can be recorded separately from the actual
> format string, instead of written formatted to a ring buffer as a
> sequence of characters. Parameters would be formatted to their own
> strings (regardless of the original type) and saved in an array.
> Example: {
> struct kprint_message {
> const char *format;
> unsigned int argc;
> char **argv;
> unsigned long long timestamp;
> #endif
> const char *file;
> unsigned int line;
> const char *function;
> #endif
> };
> }


> The message entry and a message's arguments are kept separately. Most
> likely, there will be a huge number of tiny allocations. I am not sure
> how well this is handled in the kernel. Or we could try to merge the
> allocation of the struct kprint_message and its arguments into a
> single allocation by looking at the arguments before they're
> formatted. After all, the arguments cannot exist without the message
> or vice versa. Alternatively, a statically-sized ring buffer of struct
> kprint_message objects could be used, and then only arguments would
> need to be allocated dynamically. Either way, I think it should be
> possible to come up with a fairly memory-efficient system even for
> this method of storing the kernel log.

Would be nice to have some code here. How do you want to implement that?
You have to allocate / preallocate memory for the argv array. Something

kprint_err(const char* fmt, ...)
va_list ap;
struct kprint_message *msg;

msg = &message_arry[current];

va_start(ap, fmt);
msg->argv = kmalloc(sizeof(long) * argc, GFP_KERNEL);
for (i = 0; i < argc, i++) {
msg->argv[i] = va_arg(ap, long);

If you do it like that, you can't support "%s", since then you would
store only the pointer and not the whole string. I think, that we can't
live without %s.


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2007-09-24 11:27    [W:0.066 / U:11.584 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site