Re: the printk problem

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Matthew Wilcox <matthew@...>
Cc: Linus Torvalds <torvalds@...>, Peter Anvin <hpa@...>, David S. Miller <davem@...>, <linux-ia64@...>, <linuxppc-dev@...>, <linux-kernel@...>
Date: Friday, July 4, 2008 - 6:01 pm

(heck, let's cc lkml - avoid having to go through all this again)

On Fri, 4 Jul 2008 14:42:53 -0600 Matthew Wilcox <matthew@wil.cx> wrote:


It would be excellent if gcc had an extension system so that you could
add new printf control chars and maybe even tell gcc how to check them.
But of course, if that were to happen, we couldn't use it for 4-5 years.

What I had initially proposed was to abuse %S, which takes a wchar_t*. 
gcc accepts `unsigned long *' for %S.

Then, we put the kernel-specific control char after the S, so we can
print an inode (rofl) with

	struct inode *inode;

	printk("here is an inode: %Si\n", (unsigned long *)inode);

Downsides are:

- there's a cast, so you could accidentally do

	printk("here is an inode: %Si\n", (unsigned long *)dentry);

- there's a cast, and they're ugly

- gcc cannot of course check that the arg matches the control string

Unfortunately (and this seems weird), gcc printf checking will not
accept a void* for %S: it _has_ to be wchar_t*, and the checker won't
permit void* substitution for that.

Anyway, Linus took all that and said "let's abuse %p instead".  It
_will_ accept any pointer so we can instead do:

	printk("here is an inode: %pi\n", inode);

which is nicer.


I think the main customers of this are print_symbol():

	printk("I am about to call %ps\n", fn);
	(*fn)();

and NIPQUAD and its ipv6 version.

We don't know how much interest there would be in churning NIPQUAD from
the net guys.  Interestingly, there's also %C (wint_t) which is a
32-bit quantity.  So we could just go and say "%C prints an ipv4
address" and be done with it.  But there's no way of doing that for
ipv6 addresses so things would become asymmetrical there.

Another customer is net mac addresses.  There are surely others.  One
which should have been in printf 30 years ago was %b: binary.



Yeah.  Why don't we do that?
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: the printk problem, Andrew Morton, (Fri Jul 4, 6:01 pm)
Re: the printk problem, Jan Engelhardt, (Sat Jul 5, 7:33 am)
Re: the printk problem, Vegard Nossum, (Sat Jul 5, 8:52 am)
Re: the printk problem, Linus Torvalds, (Sat Jul 5, 1:56 pm)
Re: the printk problem, Vegard Nossum, (Sat Jul 5, 2:41 pm)
Re: the printk problem, Matthew Wilcox, (Sat Jul 5, 2:52 pm)
Re: the printk problem, Pekka Enberg, (Sat Jul 5, 8:02 pm)
Re: the printk problem, Randy Dunlap, (Sun Jul 6, 1:17 am)
Re: the printk problem, Jan Engelhardt, (Sat Jul 5, 2:40 pm)
Re: the printk problem, Linus Torvalds, (Sat Jul 5, 2:44 pm)
Re: the printk problem, Jan Engelhardt, (Sat Jul 5, 9:24 am)
Re: the printk problem, Vegard Nossum, (Sat Jul 5, 9:50 am)
Re: the printk problem, Jan Engelhardt, (Sat Jul 5, 10:07 am)
Re: the printk problem, Denys Vlasenko, (Sat Jul 5, 6:20 am)
Re: the printk problem, Matthew Wilcox, (Fri Jul 4, 10:03 pm)
Re: [PATCH] Make u64 long long on all architectures (was: th..., Benjamin Herrenschmidt, (Tue Jul 22, 7:35 am)
Re: [PATCH] Make u64 long long on all architectures (was: th..., Benjamin Herrenschmidt, (Tue Jul 22, 7:36 am)