|
|
Log in / Subscribe / Register

pr_unwanted()?

By Jonathan Corbet
December 22, 2009
One of a kernel developer's best friends is the printk() function, which works much like printf() in user-space programs. There are some differences, though, including the existence of various levels of logging. The convention used is a little funny, with the logging level being a short string prepended to the format string. So a warning might be printed this way:

    printk(KERN_WARNING "Core meltdown imminent\n");

This form is not universally loved, though; some call it verbose, making it hard to make lines fit within 80 columns, and the severity string is easy to forget. As an alternative, the 2.6.28-rc5 kernel saw the addition of a set of pr_*() macros, written by Martin Schwidefsky, which are designed to make life a little easier. So, for example, the above warning could be rewritten as:

    pr_warning("Software patents detected\n");

These macros sat in relative obscurity for a few development cycles until Joe Perches decided to switch a number of printk() statements in the core kernel. That led to an outburst from Peter Zijlstra and the eventual reverting of the change. Peter says:

I might be strange, but if I want to print something in C I write print[fk]() and be done with it, there's no reason what so ever to introduce fancy wankery for this. We try to stick to ANSI-C as much as possible, we've got kalloc,kfree,strcmp,strnlen and all the other 'regular' C bits, deviating from that serves no purpose but seed confusion.

Chances are, there won't be any more such conversions near that part of the kernel. But the pr_*() macros won't be going away either. Their real purpose, perhaps, was best expressed by Arjan van de Ven: "pr_ is really just for 'I am a driver and want a single line message out in a standardized format'. Nothing wrong with that."


to post comments

pr_unwanted()?

Posted Dec 24, 2009 8:53 UTC (Thu) by flewellyn (subscriber, #5047) [Link] (3 responses)

I think their real purpose was actually best expressed by Al Viro:

"leveraging the synergy between make-work job and commit count masturbation"

pr_unwanted()?

Posted Dec 24, 2009 9:21 UTC (Thu) by liljencrantz (guest, #28458) [Link] (2 responses)

Less typing and more explicit code sounds like two very reasonable reasons to use a bit of code to me.

pr_unwanted()?

Posted Dec 24, 2009 16:31 UTC (Thu) by grmd (guest, #4391) [Link]

The trouble is it's the thin end of the wedge; it's not any more specific,
and it means that developers needlessly have something extra to learn.

Having worked on project that layer macros upon macros it rapidly becomes a
nightmare to maintain despite the original good intentions, turning C into a
write-once language.

pr_unwanted()?

Posted Dec 24, 2009 19:14 UTC (Thu) by vonbrand (subscriber, #4458) [Link]

"More explicit" as long as there are very few functions/macros around. If there are more than a dozen, you start wondering if what you think it does is right... and the kernel is already huge, with its own set of non-standard stuff and rules.

Better leave them out.


Copyright © 2009, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds