<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://www.elinux.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.elinux.org/api.php?action=feedcontributions&amp;user=Peter+Huewe&amp;feedformat=atom</id>
		<title>eLinux.org - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://www.elinux.org/api.php?action=feedcontributions&amp;user=Peter+Huewe&amp;feedformat=atom"/>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Special:Contributions/Peter_Huewe"/>
		<updated>2013-05-18T19:13:55Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.21alpha</generator>

	<entry>
		<id>http://www.elinux.org/Talk:Session:_Developer%27s_Diary:_It%27s_About_Time_ELCE_2011</id>
		<title>Talk:Session: Developer's Diary: It's About Time ELCE 2011</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Talk:Session:_Developer%27s_Diary:_It%27s_About_Time_ELCE_2011"/>
				<updated>2012-11-07T08:19:55Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Created page with &amp;quot;work on formatting :/--~~~~&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;work on formatting :/--[[User:Peter Huewe|Peter Huewe]] ([[User talk:Peter Huewe|talk]]) 08:19, 7 November 2012 (UTC)&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Session:_Developer%27s_Diary:_It%27s_About_Time_ELCE_2011</id>
		<title>Session: Developer's Diary: It's About Time ELCE 2011</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Session:_Developer%27s_Diary:_It%27s_About_Time_ELCE_2011"/>
				<updated>2012-11-07T08:19:17Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Added first 10 minures of transcript-&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Session Details ==&lt;br /&gt;
; Event : [[ELCE 2011]], Prague&lt;br /&gt;
; Date : 28.10.2011&lt;br /&gt;
; Presenter :  Wolfram Sang&lt;br /&gt;
; Organization: Pengutronix&lt;br /&gt;
; Slides : [[Media:elce11_sang.pdf|PDF]]&lt;br /&gt;
; Video : [http://free-electrons.com/pub/video/2011/elce/elce-2011-sang-developer-diary.webm | HD] [http://free-electrons.com/pub/video/2011/elce/elce-2011-sang-developer-diary-450p.webm | SD ] thanks to [http://free-electrons.com/blog/elce-2011-videos/ | Free Electrons]&lt;br /&gt;
; Duration : 00:49:00&lt;br /&gt;
&lt;br /&gt;
=== Abstract ===&lt;br /&gt;
 A Talk about timeouts and delays.&lt;br /&gt;
=== Biography ===&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
== Transcript ==&lt;br /&gt;
; Transcribed by: Peter Huewe&lt;br /&gt;
; Verified by: 1 - &lt;br /&gt;
&lt;br /&gt;
''Introduction of and by Wolfram Sang''&lt;br /&gt;
&lt;br /&gt;
My talks which I usually entitle “Developers Diary” I want to share experiences I made in my everyday work I want to [show you] problems I encountered, things I've found out [and] try to give best practices.&lt;br /&gt;
As Linux in general is a very huge project and I pretty much want [...]&lt;br /&gt;
&lt;br /&gt;
A lot of people think “oh my problem [fits here] as well” - so if you have something to add, feel free to do so.&lt;br /&gt;
I hope at the end of the talk we're all a bit enlightened than before.&lt;br /&gt;
&lt;br /&gt;
This time I want to talk about dealing with time in device drivers and I chose to talk about two groups:&lt;br /&gt;
&lt;br /&gt;
The first I will be talking about [are] delays, when you deal with hardware and sometime you activate something and have to wait for a certain amount of time until something happens.&lt;br /&gt;
&lt;br /&gt;
And the second will be timeouts, you do something and if it not does something in a certain time you'll have to deal with it.&lt;br /&gt;
&lt;br /&gt;
Both are not very complicated matters [on their own] but let's have a look:&lt;br /&gt;
&lt;br /&gt;
-&lt;br /&gt;
The basics of delays:&lt;br /&gt;
&lt;br /&gt;
There are two kinds, usually, &lt;br /&gt;
One [called] busy waiting: the cpu burns cycles while waiting &lt;br /&gt;
and the other one is &lt;br /&gt;
blocking:  you say “okay I’m going to wait, let me go to sleep, and you’ll come back later so the cpu can do something in between”.&lt;br /&gt;
&lt;br /&gt;
[''Poll:''] Who knew this before? &lt;br /&gt;
Okay that's what I kinda expected, so I'm not telling you rocket science. I know that.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[''Poll:'']Who is writing device drivers for the linux kernel here? [''few hands rise'']&lt;br /&gt;
Great! That's the audience I was hoping for.&lt;br /&gt;
So let's get a bit interactive - [''Q''] What kind of delay functions do you know&lt;br /&gt;
[''responses by the audience'']&lt;br /&gt;
- schedule&lt;br /&gt;
Does it delay? &lt;br /&gt;
- udelay&lt;br /&gt;
- mdelay&lt;br /&gt;
- sleep – which ones&lt;br /&gt;
- usleep&lt;br /&gt;
-msleep &lt;br /&gt;
we're getting into discussion already &lt;br /&gt;
-usleep_range&lt;br /&gt;
-ndelay ?&lt;br /&gt;
- nanosleep?&lt;br /&gt;
- msleep_interruptible&lt;br /&gt;
Not bad – was it all?&lt;br /&gt;
[''Guy in the audience joking''] a for cycle loop&lt;br /&gt;
Is there an sdelay`?&lt;br /&gt;
&lt;br /&gt;
So let’start with the solution:&lt;br /&gt;
 - ndelay&lt;br /&gt;
 - udelay&lt;br /&gt;
 - mdelay&lt;br /&gt;
 luckily no sdelay&lt;br /&gt;
 no usleep&lt;br /&gt;
 - usleep_range  which you can give a time frame&lt;br /&gt;
 - msleep&lt;br /&gt;
 - msleep_interruptible&lt;br /&gt;
 - ssleep&lt;br /&gt;
&lt;br /&gt;
But it's already interesting to see that here, as you just recognized here are quite a bunch of people doing kernel code and there seems to be some agreements and disagreements of what is available.&lt;br /&gt;
&lt;br /&gt;
And now think about implicit things which might happen in the back[ground] [...]&lt;br /&gt;
&lt;br /&gt;
There can be things happening you're not expecting or whatever so it's really pays off to have a look at this once in a while so you get the foundations right so you're really knowing what you're doing when you're using such functions.&lt;br /&gt;
&lt;br /&gt;
Let’s have a short look at the delay headers. [''opens include/linux/delay.h'']&lt;br /&gt;
&lt;br /&gt;
I’ll call this talk a little bit ARM specific - I hope nobody will be angry about being ARM specific, but it basically applies to all platform - because one of the thing that’s interesting is that the delay functions for ARM are architecture specific.&lt;br /&gt;
&lt;br /&gt;
So this is a general Linux header file – and you can see here in those lines that [...] for mdelay there is a fallback so if the architecture does not define it basically falls back to udelay.&lt;br /&gt;
&lt;br /&gt;
There’s also an ndelay, the general fall back if the architecture does not define one is based on udelay – so that udelay seems to be a pretty important function in all that.&lt;br /&gt;
&lt;br /&gt;
We see msleep, msleep_interruptible, usleep_range and ssleep, they are all defined here, so they are independent of the architecture. If we look at the architecture specific implementation of udelay, which we just found out is a very core function, you see that in the arm case it’s not even a function but the first […] encounter with a define, which tracks if it’s a constant value or not.&lt;br /&gt;
&lt;br /&gt;
That’s the places where you have to look if you want to dive in deeper.&lt;br /&gt;
&lt;br /&gt;
--------------------&lt;br /&gt;
&lt;br /&gt;
So how I got interested in the topic was we had a customer problem and he said “yeah the system is working fine but when we press the touch the system becomes unusable and further analysis have shown that 25% of the cpu was busy doing something”.&lt;br /&gt;
&lt;br /&gt;
I first expected an interrupt storm or whatever but that couldn’t be found out so I started looking at code, especially at the touchscreen driver and this was the thing I found. [''slide shows the function in drivers/input/touchscreen/wm9712.c'']&lt;br /&gt;
&lt;br /&gt;
This is a delay inside the driver, which takes a value from the [lookup]table and [the] array offset is given to the function, which is (as you can see on the next slide) more or less a module parameter.&lt;br /&gt;
It says “okay we need that to get the correct value. The delay can be set by setting the delay to n where n is the array position of the delay in the array table below.”&lt;br /&gt;
This is not very transparent to the user; it is said “long delays for 1ms are supported for completeness but are not recommended” – that’s a very useful comment but it’s totally invisible for the user using the module.&lt;br /&gt;
&lt;br /&gt;
That’s what happened to our customer – I think it was also caused little bit broken hardware – he didn’t get the touch[screen] working so here’s the “mighty table” which is feeding the udelay.&lt;br /&gt;
The standard is this one [indicating 200us], so it will in general burn like 200 us, our customer ended up being here [indicating 3ms] – so on a regular basis for every poll this routine was nearly burning 3ms – and this was indeed the cause for the total cpu loss, so it just lost all the cpu power doing nothing.&lt;br /&gt;
Sadly this is still in the kernel – because once the problem was found out, the customer said “yeah we can fix that”, and took the hardware away from me, so I think they did some nasty stuff to get it working – so this is still present in the kernel, sadly.&lt;br /&gt;
&lt;br /&gt;
So this gave me the idea – udelay is a pretty dangerous function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
0:00 - 1:00:&lt;br /&gt;
&lt;br /&gt;
1:00 - 2:00:&lt;br /&gt;
&lt;br /&gt;
2:00 - 3:00:&lt;br /&gt;
&lt;br /&gt;
3:00 - 4:00:&lt;br /&gt;
&lt;br /&gt;
4:00 - 5:00:&lt;br /&gt;
&lt;br /&gt;
5:00 - 6:00:&lt;br /&gt;
&lt;br /&gt;
6:00 - 7:00:&lt;br /&gt;
&lt;br /&gt;
7:00 - 8:00:&lt;br /&gt;
&lt;br /&gt;
8:00 - 9:00:&lt;br /&gt;
&lt;br /&gt;
9:00 - 10:00:&lt;br /&gt;
&lt;br /&gt;
10:00 - 11:00:&lt;br /&gt;
&lt;br /&gt;
11:00 - 12:00:&lt;br /&gt;
&lt;br /&gt;
12:00 - 13:00:&lt;br /&gt;
&lt;br /&gt;
13:00 - 14:00:&lt;br /&gt;
&lt;br /&gt;
14:00 - 15:00:&lt;br /&gt;
&lt;br /&gt;
15:00 - 16:00:&lt;br /&gt;
&lt;br /&gt;
16:00 - 17:00:&lt;br /&gt;
&lt;br /&gt;
17:00 - 18:00:&lt;br /&gt;
&lt;br /&gt;
18:00 - 19:00:&lt;br /&gt;
&lt;br /&gt;
19:00 - 20:00:&lt;br /&gt;
&lt;br /&gt;
20:00 - 21:00:&lt;br /&gt;
&lt;br /&gt;
21:00 - 22:00:&lt;br /&gt;
&lt;br /&gt;
22:00 - 23:00:&lt;br /&gt;
&lt;br /&gt;
23:00 - 24:00:&lt;br /&gt;
&lt;br /&gt;
24:00 - 25:00:&lt;br /&gt;
&lt;br /&gt;
25:00 - 26:00:&lt;br /&gt;
&lt;br /&gt;
26:00 - 27:00:&lt;br /&gt;
&lt;br /&gt;
27:00 - 28:00:&lt;br /&gt;
&lt;br /&gt;
28:00 - 29:00:&lt;br /&gt;
&lt;br /&gt;
29:00 - 30:00:&lt;br /&gt;
&lt;br /&gt;
30:00 - 31:00:&lt;br /&gt;
&lt;br /&gt;
31:00 - 32:00:&lt;br /&gt;
&lt;br /&gt;
32:00 - 33:00:&lt;br /&gt;
&lt;br /&gt;
33:00 - 34:00:&lt;br /&gt;
&lt;br /&gt;
34:00 - 35:00:&lt;br /&gt;
&lt;br /&gt;
35:00 - 36:00:&lt;br /&gt;
&lt;br /&gt;
36:00 - 37:00:&lt;br /&gt;
&lt;br /&gt;
37:00 - 38:00:&lt;br /&gt;
&lt;br /&gt;
38:00 - 39:00:&lt;br /&gt;
&lt;br /&gt;
39:00 - 40:00:&lt;br /&gt;
&lt;br /&gt;
40:00 - 41:00:&lt;br /&gt;
&lt;br /&gt;
41:00 - 42:00:&lt;br /&gt;
&lt;br /&gt;
42:00 - 43:00:&lt;br /&gt;
&lt;br /&gt;
43:00 - 44:00:&lt;br /&gt;
&lt;br /&gt;
44:00 - 45:00:&lt;br /&gt;
&lt;br /&gt;
45:00 - 46:00:&lt;br /&gt;
&lt;br /&gt;
46:00 - 47:00:&lt;br /&gt;
&lt;br /&gt;
47:00 - 48:00:&lt;br /&gt;
&lt;br /&gt;
48:00 - 49:00:&lt;br /&gt;
&lt;br /&gt;
49:00 - 50:00:&lt;br /&gt;
&lt;br /&gt;
50:00 - 51:00:&lt;br /&gt;
&lt;br /&gt;
51:00 - 52:00:&lt;br /&gt;
&lt;br /&gt;
52:00 - 53:00:&lt;br /&gt;
&lt;br /&gt;
53:00 - 54:00:&lt;br /&gt;
&lt;br /&gt;
54:00 - 55:00:&lt;br /&gt;
&lt;br /&gt;
55:00 - 56:00:&lt;br /&gt;
&lt;br /&gt;
56:00 - 57:00:&lt;br /&gt;
&lt;br /&gt;
57:00 - 58:00:&lt;br /&gt;
&lt;br /&gt;
58:00 - 59:00:&lt;br /&gt;
&lt;br /&gt;
59:00 - 60:00:&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Session:_Developer%27s_Diary:_It%27s_About_Time_ELCE_2011</id>
		<title>Session: Developer's Diary: It's About Time ELCE 2011</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Session:_Developer%27s_Diary:_It%27s_About_Time_ELCE_2011"/>
				<updated>2012-11-06T12:28:01Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Created page with &amp;quot;== Session Details == ; Event : ELCE 2011, Prague ; Date : 28.10.2011 ; Presenter :  Wolfram Sang ; Organization: Pengutronix ; Slides : PDF ; Vi...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Session Details ==&lt;br /&gt;
; Event : [[ELCE 2011]], Prague&lt;br /&gt;
; Date : 28.10.2011&lt;br /&gt;
; Presenter :  Wolfram Sang&lt;br /&gt;
; Organization: Pengutronix&lt;br /&gt;
; Slides : [[Media:elce11_sang.pdf|PDF]]&lt;br /&gt;
; Video : [http://free-electrons.com/pub/video/2011/elce/elce-2011-sang-developer-diary.webm | HD] [http://free-electrons.com/pub/video/2011/elce/elce-2011-sang-developer-diary-450p.webm | SD ] thanks to [http://free-electrons.com/blog/elce-2011-videos/ | Free Electrons]&lt;br /&gt;
; Duration : 00:49:00&lt;br /&gt;
&lt;br /&gt;
=== Abstract ===&lt;br /&gt;
 A Talk about timeouts and delays.&lt;br /&gt;
=== Biography ===&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
== Transcript ==&lt;br /&gt;
; Transcribed by: Peter Huewe&lt;br /&gt;
; Verified by: 1 - &lt;br /&gt;
&lt;br /&gt;
0:00 - 1:00:&lt;br /&gt;
&lt;br /&gt;
1:00 - 2:00:&lt;br /&gt;
&lt;br /&gt;
2:00 - 3:00:&lt;br /&gt;
&lt;br /&gt;
3:00 - 4:00:&lt;br /&gt;
&lt;br /&gt;
4:00 - 5:00:&lt;br /&gt;
&lt;br /&gt;
5:00 - 6:00:&lt;br /&gt;
&lt;br /&gt;
6:00 - 7:00:&lt;br /&gt;
&lt;br /&gt;
7:00 - 8:00:&lt;br /&gt;
&lt;br /&gt;
8:00 - 9:00:&lt;br /&gt;
&lt;br /&gt;
9:00 - 10:00:&lt;br /&gt;
&lt;br /&gt;
10:00 - 11:00:&lt;br /&gt;
&lt;br /&gt;
11:00 - 12:00:&lt;br /&gt;
&lt;br /&gt;
12:00 - 13:00:&lt;br /&gt;
&lt;br /&gt;
13:00 - 14:00:&lt;br /&gt;
&lt;br /&gt;
14:00 - 15:00:&lt;br /&gt;
&lt;br /&gt;
15:00 - 16:00:&lt;br /&gt;
&lt;br /&gt;
16:00 - 17:00:&lt;br /&gt;
&lt;br /&gt;
17:00 - 18:00:&lt;br /&gt;
&lt;br /&gt;
18:00 - 19:00:&lt;br /&gt;
&lt;br /&gt;
19:00 - 20:00:&lt;br /&gt;
&lt;br /&gt;
20:00 - 21:00:&lt;br /&gt;
&lt;br /&gt;
21:00 - 22:00:&lt;br /&gt;
&lt;br /&gt;
22:00 - 23:00:&lt;br /&gt;
&lt;br /&gt;
23:00 - 24:00:&lt;br /&gt;
&lt;br /&gt;
24:00 - 25:00:&lt;br /&gt;
&lt;br /&gt;
25:00 - 26:00:&lt;br /&gt;
&lt;br /&gt;
26:00 - 27:00:&lt;br /&gt;
&lt;br /&gt;
27:00 - 28:00:&lt;br /&gt;
&lt;br /&gt;
28:00 - 29:00:&lt;br /&gt;
&lt;br /&gt;
29:00 - 30:00:&lt;br /&gt;
&lt;br /&gt;
30:00 - 31:00:&lt;br /&gt;
&lt;br /&gt;
31:00 - 32:00:&lt;br /&gt;
&lt;br /&gt;
32:00 - 33:00:&lt;br /&gt;
&lt;br /&gt;
33:00 - 34:00:&lt;br /&gt;
&lt;br /&gt;
34:00 - 35:00:&lt;br /&gt;
&lt;br /&gt;
35:00 - 36:00:&lt;br /&gt;
&lt;br /&gt;
36:00 - 37:00:&lt;br /&gt;
&lt;br /&gt;
37:00 - 38:00:&lt;br /&gt;
&lt;br /&gt;
38:00 - 39:00:&lt;br /&gt;
&lt;br /&gt;
39:00 - 40:00:&lt;br /&gt;
&lt;br /&gt;
40:00 - 41:00:&lt;br /&gt;
&lt;br /&gt;
41:00 - 42:00:&lt;br /&gt;
&lt;br /&gt;
42:00 - 43:00:&lt;br /&gt;
&lt;br /&gt;
43:00 - 44:00:&lt;br /&gt;
&lt;br /&gt;
44:00 - 45:00:&lt;br /&gt;
&lt;br /&gt;
45:00 - 46:00:&lt;br /&gt;
&lt;br /&gt;
46:00 - 47:00:&lt;br /&gt;
&lt;br /&gt;
47:00 - 48:00:&lt;br /&gt;
&lt;br /&gt;
48:00 - 49:00:&lt;br /&gt;
&lt;br /&gt;
49:00 - 50:00:&lt;br /&gt;
&lt;br /&gt;
50:00 - 51:00:&lt;br /&gt;
&lt;br /&gt;
51:00 - 52:00:&lt;br /&gt;
&lt;br /&gt;
52:00 - 53:00:&lt;br /&gt;
&lt;br /&gt;
53:00 - 54:00:&lt;br /&gt;
&lt;br /&gt;
54:00 - 55:00:&lt;br /&gt;
&lt;br /&gt;
55:00 - 56:00:&lt;br /&gt;
&lt;br /&gt;
56:00 - 57:00:&lt;br /&gt;
&lt;br /&gt;
57:00 - 58:00:&lt;br /&gt;
&lt;br /&gt;
58:00 - 59:00:&lt;br /&gt;
&lt;br /&gt;
59:00 - 60:00:&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/ELCE_2011_Presentations_redirect</id>
		<title>ELCE 2011 Presentations redirect</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/ELCE_2011_Presentations_redirect"/>
				<updated>2012-11-06T12:21:49Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Added link to transcript&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Presenters, Demo-ers, Participants:&lt;br /&gt;
Thanks very much for your participation in Linux Foundation's [http://events.linuxfoundation.org/events/embedded-linux-conference-europe Embedded Linux Conference Europe 2011].&lt;br /&gt;
&lt;br /&gt;
This page is for collecting the presentations that were made at the conference. During and&lt;br /&gt;
after the conference we will collect materials from the presenters and place them here.&lt;br /&gt;
Please watch this page if you are interested in a particular presentation - and if it&lt;br /&gt;
doesn't show up, please [[Special:EmailUser/Wmat | send me and email]] and we'll try to track it down.&lt;br /&gt;
&lt;br /&gt;
== Videos ==&lt;br /&gt;
&lt;br /&gt;
Once again, through the diligent work of the [http://free-electrons.com/ Free Electrons] team, all videos for ELCE2011 can be found at [http://free-electrons.com/blog/elce-2011-videos/ ELCE2011 Videos].&lt;br /&gt;
&lt;br /&gt;
== Instructions ==&lt;br /&gt;
'''Presenters:''' Please post your technical conference presentations on this page.&lt;br /&gt;
(See Instructions below the tables)&lt;br /&gt;
&lt;br /&gt;
= Table of Presentations =&lt;br /&gt;
&lt;br /&gt;
NOTE:  If you add a wikilink to your presentation and attempt to upload it via the link, it may fail.  If it does, use the [[Special:Upload]] page to upload your file.&lt;br /&gt;
&lt;br /&gt;
== Keynotes ==&lt;br /&gt;
{|  border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;4&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#c0e0e0&amp;quot;&lt;br /&gt;
|+ '''Keynotes'''&lt;br /&gt;
|- bgcolor=&amp;quot;#c0e0e0&amp;quot;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | '''Presenter(s)'''&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | '''Session Description'''                                  &lt;br /&gt;
| align=&amp;quot;center&amp;quot; | '''Presentation'''&lt;br /&gt;
|-&lt;br /&gt;
| Jim Zemlin, Executive Director of The Linux Foundation&lt;br /&gt;
| Imagine a World Without Linux&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| Linus Torvalds, Alan Cox, Thomas Gleixner, Paul McKenney&lt;br /&gt;
| Kernel Developer Panel&lt;br /&gt;
| No presentation.&lt;br /&gt;
|-&lt;br /&gt;
| Antti Aumo, President of Global Solutions at Ixonos&lt;br /&gt;
| Re-Defining the Cloud Phone&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| Dirk Hohndel, Chief Linux and Open Source Technologist at Intel&lt;br /&gt;
| Reflection on 20 Years of Linux&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| Jonathan Corbet, Editor at LWN&lt;br /&gt;
| The Kernel Report: 20th Anniversary Edition&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| Wim Coekaerts, Senior Vice President, Linux and Vistualization Engineering at Oracle&lt;br /&gt;
| Engineered Systems With Linux&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| Matt Jones, Vice President, GENIVI Alliance &amp;amp; Technical Lead - Next Generation Infotainment, Jaguar Land Rover&lt;br /&gt;
| Linux for In Car Infotainment&lt;br /&gt;
| &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Presenters ==&lt;br /&gt;
{|  border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;4&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#c0e0e0&amp;quot;&lt;br /&gt;
|+ '''Presentations'''&lt;br /&gt;
|- bgcolor=&amp;quot;#c0e0e0&amp;quot;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | '''Presenter(s)'''&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | '''Session Description'''                                  &lt;br /&gt;
| align=&amp;quot;center&amp;quot; | '''Presentation'''&lt;br /&gt;
|-&lt;br /&gt;
|- bgcolor=&amp;quot;#a0c0c0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | Day 1, 10:45am&lt;br /&gt;
|-&lt;br /&gt;
| Zach Pfeffer (Linaro)&lt;br /&gt;
| Linaro's Android Platform&lt;br /&gt;
| [[Media:Linaro Android Presentation 5.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Thomas Gleixner (Linutronix)&lt;br /&gt;
| Another Mile Down the RT Road&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| Jessica Zhang (Intel)&lt;br /&gt;
| The Yocto Project Eclipse PlugIn: An Effective IDE Environment for both Embedded Application and System Developers&lt;br /&gt;
| [[Media:ELCE Yocto Plugin 2011 latest.pdf|PDF]]&lt;br /&gt;
|- bgcolor=&amp;quot;#a0c0c0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | Day 1, 11:45am&lt;br /&gt;
|-&lt;br /&gt;
| Satoru Ueda (Sony/Japan OSS Promotion Forum)&lt;br /&gt;
| Contributing to the Community?  Does your manager support you?&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| Benjamin Zores (Alcatel-Lucent)&lt;br /&gt;
| Embedded Linux Optimization Techniques: How Not To Be Slow&lt;br /&gt;
| [[Media:ELCE_2011_-_BZ_-_Embedded_Linux_Optimization_Techniques_-_How_Not_to_Be_Slow.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Ohad Ben-Cohen (Texas Instruments/Wizery)&lt;br /&gt;
| Asymmetric Multiprocessing using VirtIO (was: &amp;quot;Remote Processor Messaging&amp;quot;)&lt;br /&gt;
| [[Media:AMP_ELCE2011.pdf|PDF]]&lt;br /&gt;
|- bgcolor=&amp;quot;#a0c0c0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | Day 1, 2:00pm&lt;br /&gt;
|-&lt;br /&gt;
| Jeff Osier-Mixon (Intel)&lt;br /&gt;
| Collaborative Initiatives in Embedded Linux&lt;br /&gt;
| [[Media:ELCE2011-Collaborative-Initiatives.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Karim Yaghmour (Opersys, Inc.)&lt;br /&gt;
| Leveraging Android's Linux Heritage&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| Pierre Tardy (Intel)&lt;br /&gt;
| Using pytimechart For Real World Analysis&lt;br /&gt;
| [[Media:elce11_tardy.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
|- bgcolor=&amp;quot;#a0c0c0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | Day 1, 3:00pm&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Arnd Bergmann (Linaro)&lt;br /&gt;
| Optimizations for Cheap Flash Media&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| Vitaly Wool (Sony Ericsson)&lt;br /&gt;
| Saving Power With Wi-Fi: How to Prolong Your Battery Life and Still Stay Connected&lt;br /&gt;
| [[Media:elce11_wool.odp|ODP]]&lt;br /&gt;
|-&lt;br /&gt;
| David Stewart (Intel)&lt;br /&gt;
| Developing Embedded Linux Devices Using the Yocto Project and What's New in 1.1&lt;br /&gt;
| [[Media:elce11_stewart.pdf|PDF]]&lt;br /&gt;
|- bgcolor=&amp;quot;#a0c0c0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | Day 1, 4:15pm&lt;br /&gt;
|-&lt;br /&gt;
| Tetsuyuki Kobayashi (Kyoto Micro Computer)&lt;br /&gt;
| Android is NOT Just &amp;quot;Java On Linux&amp;quot;&lt;br /&gt;
| [[Media:elce11_kobayashi.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Thomas Petazzoni (Free Electrons)&lt;br /&gt;
| Using Buildroot for a Real Project&lt;br /&gt;
| [[Media:Using-buildroot-real-project.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Rajesh Lal (Nokia)&lt;br /&gt;
| Qt Quick: The Most Advanced UI Technology for Mobile&lt;br /&gt;
| Talk was canceled&lt;br /&gt;
|-&lt;br /&gt;
|- bgcolor=&amp;quot;#a0c0c0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | Day 1, 5:15pm&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Tim Bird (Sony)&lt;br /&gt;
| Status of Embedded Linux BoFs&lt;br /&gt;
| [[media:Status-of-Embedded-Linux-2011-10-ELCE.pdf|Status-of-Embedded-Linux-2011-10-ELCE.pdf]]&lt;br /&gt;
|-&lt;br /&gt;
| Lauro Ramos Venancio (Instituto Nokia de Technologia) &amp;amp; Samuel Ortiz (Intel)&lt;br /&gt;
| The Linux NFC Subsystem&lt;br /&gt;
| [[Media:elce11_venancio_ortiz.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| David Anders (Texas Instruments)&lt;br /&gt;
| Board BringUp: LCD and Display Interfaces&lt;br /&gt;
| [[media:elce-2011-anders.pdf|PDF]] [[media:elce-2011-anders.odp|ODP]] [[BoardBringupLCD|Resource Page]]&lt;br /&gt;
|- bgcolor=&amp;quot;#a0c0c0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | Day 2, 10:15am&lt;br /&gt;
|-&lt;br /&gt;
| Grant Likely (Secret Lab)&lt;br /&gt;
| Device Tree Status Report&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| Laurent Pinchart (Ideas on Board)&lt;br /&gt;
| Success Story of the Open Source Camera Stack: The Nokia N9 Case&lt;br /&gt;
| [[Media:elce11_pinchart.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Avinash Mahadeva &amp;amp; Vishwanth Sripathy (Texas Instruments)&lt;br /&gt;
| SOC Power Management - Debugging and Optimization Techniques&lt;br /&gt;
| [[Media:Omap-power-management-debugging.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Tia Cassett (Qualcomm) &amp;amp; Mike Chalupa (BSquare)&lt;br /&gt;
| Android Development with the Snapdragon Processor&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
|- bgcolor=&amp;quot;#a0c0c0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | Day 2, 11:15am&lt;br /&gt;
|-&lt;br /&gt;
| Rafael J. Wysocki (Faculty of Physics, U. Warsaw/SUSE Labs)&lt;br /&gt;
| Power Management Using PM Domains on SH7372&lt;br /&gt;
| [[Media:elce11_wysocki.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Sascha Hauer (Pengutronix e.K.)&lt;br /&gt;
| A Generic Clock Framework in the Kernel: Why We Need It &amp;amp; Why We Still Don't Have It&lt;br /&gt;
| [[Media:elce11_hauer.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Ruud Derwig (Synopsys)&lt;br /&gt;
| Android Platform Optimizations&lt;br /&gt;
| [[Media:Android_Platform_Optimizations_SNPS_20111027.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Tia Cassett &amp;amp; David Brown (Qualcomm)&lt;br /&gt;
| Kernel Development Using the Dragonboard with the Snapdragon Processor&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
|- bgcolor=&amp;quot;#a0c0c0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | Day 2, 3:00pm&lt;br /&gt;
|-&lt;br /&gt;
| Inki Dae (Samsung Electronics)&lt;br /&gt;
| DRM Driver Development For Embedded Systems&lt;br /&gt;
| [[Media:elce11_dae.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Lorenzo Pieralisi (ARM Ltd.)&lt;br /&gt;
| Consolidating Linux Power Management on ARM Multiprocessor Systems&lt;br /&gt;
| [[Media:elce11_pieralisi.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Thomas Petazzoni (Free Electrons)&lt;br /&gt;
| Using Qt For Non-Graphical Applications&lt;br /&gt;
| [[Media:qt-for-non-graphical-applications.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| David Anders (Texas Instruments)&lt;br /&gt;
| PandaBoard Workshop: Booting the PandaBoard&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|- bgcolor=&amp;quot;#a0c0c0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | Day 2, 4:00pm&lt;br /&gt;
|-&lt;br /&gt;
| Marek Szyprowski &amp;amp; Kyungmin Park (Samsung)&lt;br /&gt;
| ARM DMA-Mapping Framework Redesign and IOMMU Integration&lt;br /&gt;
| [[Media:elce11_szyprowski_park.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Keerthy Jagadeesh &amp;amp; Vishwanath Sripathy (Texas Instruments)&lt;br /&gt;
| Thermal Framework for ARM based SOCs&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| Marc Titinger (ST Microelectronics)&lt;br /&gt;
| Efficient JTAG-Based Linux Kernel Debugging&lt;br /&gt;
| [[Media:elce11_titinger.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| David Anders (Texas Instruments)&lt;br /&gt;
| PandaBoard Workshop: PandaBoard Expansion I/O&lt;br /&gt;
|&lt;br /&gt;
|- bgcolor=&amp;quot;#a0c0c0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | Day 2, 5:00pm&lt;br /&gt;
|-&lt;br /&gt;
| Tsugikazu Shibata (NEC &amp;amp; Linux Foundation Board Member)&lt;br /&gt;
| Toward the Long Term Stable Kernel Tree for The Embedded Industry&lt;br /&gt;
| [[Media:LTSI_ELCE2011.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Lisko Lappalainen (MontaVista Software)&lt;br /&gt;
| Secure Virtualization in Automotive&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| Jeff Osier-Mixon (Intel)&lt;br /&gt;
| Yocto Project Community BoFs&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| Luca Coelho (Texas Instruments)&lt;br /&gt;
| PandaBoard Workshop: WLAN Kernel Hacking with PandaBoard&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|- bgcolor=&amp;quot;#a0c0c0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | Day 3, 10:15am&lt;br /&gt;
|-&lt;br /&gt;
| Andrea Gallo (ST-Ericsson)&lt;br /&gt;
| ARM Linux Kernel Alignment &amp;amp; Benefits for Snowball&lt;br /&gt;
| [[Media:elce11_gallo.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Liam Girdwood &amp;amp; Peter Ujfalusi (Texas Instruments)&lt;br /&gt;
| Smart Audio: Next-Generation A SoC For Smart Phones&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| Pawel Moll (ARM Ltd)&lt;br /&gt;
| Linux on Non-Existing SoCs&lt;br /&gt;
|&lt;br /&gt;
|- bgcolor=&amp;quot;#a0c0c0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | Day 3, 11:15am&lt;br /&gt;
|-&lt;br /&gt;
| Koen Kooi (The Angstrom Distribution)&lt;br /&gt;
| Integrating Systemd: Booting Userspace in Less Than 1 Second&lt;br /&gt;
| [[Media:elce11_koen.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Sylvain Leroy &amp;amp; Philippe Thierry&lt;br /&gt;
| Grsecurity in Embedded Linux Used in Android&lt;br /&gt;
| [[Media:elce11_thierry_leroy.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| MyungJoo Ham (Samsung))&lt;br /&gt;
| Charger Manager: Aggregating Chargers, Fuel Gauges and Batteries&lt;br /&gt;
| [[Media:elce11_ham.pdf|PDF]]&lt;br /&gt;
|- bgcolor=&amp;quot;#a0c0c0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | Day 3, 2:30pm&lt;br /&gt;
|-&lt;br /&gt;
| Frank Rowand (Sony)&lt;br /&gt;
| How Linux PREEMPT_RT Works&lt;br /&gt;
| [[Media:elce11_rowand.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Catalin Marinas (ARM Ltd.)&lt;br /&gt;
| Linux Support For the Large Physical Address Extensions&lt;br /&gt;
| [[Media:elce11_marinas.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Jim Huang (0xlab)&lt;br /&gt;
| Build Community Android Distribution and Ensure the Quality&lt;br /&gt;
| [[Media:community-android.pdf|PDF]]&lt;br /&gt;
|- bgcolor=&amp;quot;#a0c0c0&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; | Day 3, 3:45pm&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Till Jaeger (JBB Rechtsanwalte)&lt;br /&gt;
| The Case AVM v. Cybits: The GPL and Embedded Systems&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| Darren Hart (Intel)&lt;br /&gt;
| Tuning Linux For Embedded Systems: When Less Is More&lt;br /&gt;
| [[Media:elce11_hart.pdf|PDF]]&lt;br /&gt;
|-&lt;br /&gt;
| Wolfram Sang (Pengutronix e.K.)&lt;br /&gt;
| [[Session: Developer's Diary: It's About Time ELCE 2011| Developer's Diary: It's About Time]]&lt;br /&gt;
| [[Media:elce11_sang.pdf|PDF]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Workshops ==&lt;br /&gt;
{|  border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;4&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#c0e0e0&amp;quot;&lt;br /&gt;
|+ '''Workshops'''&lt;br /&gt;
|- bgcolor=&amp;quot;#c0e0e0&amp;quot;&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | '''Presenter(s)'''&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | '''Session Description'''                                  &lt;br /&gt;
| align=&amp;quot;center&amp;quot; | '''Presentation'''&lt;br /&gt;
|-&lt;br /&gt;
| Chris Simmonds, Freelance Embedded Linux Consultant&lt;br /&gt;
| Workshop 1: Outside the Box: An Introduction to Embedded Linux and Hardware Interfacing Using the Snowball Board&lt;br /&gt;
| [[Media:Outside-the-box-elce-2011.tar.gz|tar.gz]]&lt;br /&gt;
|-&lt;br /&gt;
| Karim J. Yaghmour&lt;br /&gt;
| Workshop 2: Embedded Android Workshop&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
== Instructions for Presenters ==&lt;br /&gt;
Please create a link in the table for your presentation, copying the style of other links.&lt;br /&gt;
(You may need to create an account in order to edit the wiki or upload files.)&lt;br /&gt;
&lt;br /&gt;
When you have created the link, click on it to upload the file containing your slides.&lt;br /&gt;
[[Category:ELCE]]&lt;br /&gt;
[[Category:2011]]&lt;br /&gt;
[[Category:Events]]&lt;br /&gt;
[[Category:Presentations]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/LTTng</id>
		<title>LTTng</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/LTTng"/>
				<updated>2012-04-26T22:33:55Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: /* External Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Linux Trace Toolkit Viewer/Next Generation&lt;br /&gt;
&lt;br /&gt;
LTTV is a modular viewer/analysis tool specifically designed to deal with very&lt;br /&gt;
large traces generated by a production system.&lt;br /&gt;
&lt;br /&gt;
It comes with a Linux kernel tracer, Linux Trace Toolkit Next Generation&lt;br /&gt;
(LTTng), which builds on the existing LTT tracepoints and RelayFS delivery&lt;br /&gt;
mechanism but is a complete rewrite of LTT tracing module and daemon.&lt;br /&gt;
&lt;br /&gt;
The design aims at facilitating contributions from the community. We know that&lt;br /&gt;
the vast quantity of analysis that can be performed on trace data is&lt;br /&gt;
practically unlimited, so we want to make it as easy and fun as possible to add&lt;br /&gt;
those to the project.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can get it at http://www.lttng.org. Follow the Quickstart guide to know how&lt;br /&gt;
to get it from Debian packages, RPM or sources.&lt;br /&gt;
&lt;br /&gt;
LTTV key features :&lt;br /&gt;
&lt;br /&gt;
*Support for large traces (it has been tested with 15GB traces). I has been designed from the start to deal with huge traces.&lt;br /&gt;
*Information from several tracefiles can be combined in a single view on the fly.&lt;br /&gt;
*Deals with traces coming from any architecture size or endianness.&lt;br /&gt;
*Text command line interface supporting plugins for trace batch analysis.&lt;br /&gt;
*Graphical interface supporting visualisation plugins.&lt;br /&gt;
*Flexible event filter.&lt;br /&gt;
*Modular architecture :&lt;br /&gt;
  - dynamically loadable plugins : each specific view/analysis becomes a plugin.&lt;br /&gt;
  - module dependencies architecture for maximum functionality reuse and easier testing.&lt;br /&gt;
*Addition of new instrumentations (or any kind of trace point) becomes easier with an event description parser and a tracing code generator (genevent).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also get LTTng from http://www.lttng.org . Available in Debian, RPM and&lt;br /&gt;
sources packages. See the Quickstart guide.&lt;br /&gt;
&lt;br /&gt;
LTTng key features :&lt;br /&gt;
&lt;br /&gt;
*Easy addition of new instrumentations by supporting the genevent code generator.&lt;br /&gt;
*Very precise timestamps on events by using the processor cycle counter as an unique monotonic time reference.&lt;br /&gt;
*Minimal impact on the traced system : instrumentation does not disable interrupts or take locks. It uses RCU and cmpxchg atomic operations instead.&lt;br /&gt;
*Non maskable interrupts (NMI) reentrancy.&lt;br /&gt;
*Supports many nestable types : structures, unions, arrays, sequences.&lt;br /&gt;
*Supports host dependent types.&lt;br /&gt;
*Makes dynamic alignment of trace data with a low overhead.&lt;br /&gt;
*Integration with LTTV viewer so tracing can be controlled directly from the graphical interface.&lt;br /&gt;
*Can record many (n) independent traces at once.&lt;br /&gt;
*Modular architecture.&lt;br /&gt;
&lt;br /&gt;
http://lwn.net/Articles/166952/&lt;br /&gt;
 &lt;br /&gt;
== External Links ==&lt;br /&gt;
* [http://lwn.net/Articles/491510/ lwn.net: LTTng 2.0: Tracing for power users and developers - part 1]&lt;br /&gt;
* [http://lwn.net/Articles/492296/ lwn.net: LTTng 2.0: Tracing for power users and developers - part 2]&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/LTTng</id>
		<title>LTTng</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/LTTng"/>
				<updated>2012-04-26T22:33:35Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Added Links&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Linux Trace Toolkit Viewer/Next Generation&lt;br /&gt;
&lt;br /&gt;
LTTV is a modular viewer/analysis tool specifically designed to deal with very&lt;br /&gt;
large traces generated by a production system.&lt;br /&gt;
&lt;br /&gt;
It comes with a Linux kernel tracer, Linux Trace Toolkit Next Generation&lt;br /&gt;
(LTTng), which builds on the existing LTT tracepoints and RelayFS delivery&lt;br /&gt;
mechanism but is a complete rewrite of LTT tracing module and daemon.&lt;br /&gt;
&lt;br /&gt;
The design aims at facilitating contributions from the community. We know that&lt;br /&gt;
the vast quantity of analysis that can be performed on trace data is&lt;br /&gt;
practically unlimited, so we want to make it as easy and fun as possible to add&lt;br /&gt;
those to the project.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can get it at http://www.lttng.org. Follow the Quickstart guide to know how&lt;br /&gt;
to get it from Debian packages, RPM or sources.&lt;br /&gt;
&lt;br /&gt;
LTTV key features :&lt;br /&gt;
&lt;br /&gt;
*Support for large traces (it has been tested with 15GB traces). I has been designed from the start to deal with huge traces.&lt;br /&gt;
*Information from several tracefiles can be combined in a single view on the fly.&lt;br /&gt;
*Deals with traces coming from any architecture size or endianness.&lt;br /&gt;
*Text command line interface supporting plugins for trace batch analysis.&lt;br /&gt;
*Graphical interface supporting visualisation plugins.&lt;br /&gt;
*Flexible event filter.&lt;br /&gt;
*Modular architecture :&lt;br /&gt;
  - dynamically loadable plugins : each specific view/analysis becomes a plugin.&lt;br /&gt;
  - module dependencies architecture for maximum functionality reuse and easier testing.&lt;br /&gt;
*Addition of new instrumentations (or any kind of trace point) becomes easier with an event description parser and a tracing code generator (genevent).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also get LTTng from http://www.lttng.org . Available in Debian, RPM and&lt;br /&gt;
sources packages. See the Quickstart guide.&lt;br /&gt;
&lt;br /&gt;
LTTng key features :&lt;br /&gt;
&lt;br /&gt;
*Easy addition of new instrumentations by supporting the genevent code generator.&lt;br /&gt;
*Very precise timestamps on events by using the processor cycle counter as an unique monotonic time reference.&lt;br /&gt;
*Minimal impact on the traced system : instrumentation does not disable interrupts or take locks. It uses RCU and cmpxchg atomic operations instead.&lt;br /&gt;
*Non maskable interrupts (NMI) reentrancy.&lt;br /&gt;
*Supports many nestable types : structures, unions, arrays, sequences.&lt;br /&gt;
*Supports host dependent types.&lt;br /&gt;
*Makes dynamic alignment of trace data with a low overhead.&lt;br /&gt;
*Integration with LTTV viewer so tracing can be controlled directly from the graphical interface.&lt;br /&gt;
*Can record many (n) independent traces at once.&lt;br /&gt;
*Modular architecture.&lt;br /&gt;
&lt;br /&gt;
http://lwn.net/Articles/166952/&lt;br /&gt;
 &lt;br /&gt;
== External Links ==&lt;br /&gt;
[http://lwn.net/Articles/491510/ lwn.net: LTTng 2.0: Tracing for power users and developers - part 1]&lt;br /&gt;
[http://lwn.net/Articles/492296/ lwn.net: LTTng 2.0: Tracing for power users and developers - part 2]&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Perf</id>
		<title>Perf</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Perf"/>
				<updated>2012-04-15T14:18:50Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Installation ==&lt;br /&gt;
&lt;br /&gt;
=== Documentation ===&lt;br /&gt;
The documentation is written in asciidoc syntax and needs asciidoc installed to be converted into html/manpages.&lt;br /&gt;
You can create the documentation of perf by typing 'make' in 'tools/perf/Documentation'.&lt;br /&gt;
&lt;br /&gt;
== Usage == &lt;br /&gt;
Perf has a [[git]]-like interface, so &lt;br /&gt;
 perf help&lt;br /&gt;
shows you the basic usage and a list of the most common subcommands and e.g. &lt;br /&gt;
 perf top help&lt;br /&gt;
shows you the help for 'perf top' command&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References and external links =&lt;br /&gt;
* [https://perf.wiki.kernel.org/ Perf Wiki at Kernel.org]&lt;br /&gt;
&lt;br /&gt;
* [https://events.linuxfoundation.org/events/collaboration-summit/de-melo Collaboration Submit 2012: The Linux Perf Tools: Overview and Current Developments] [https://events.linuxfoundation.org/images/stories/pdf/lfcs2012_melo.pdf slides] [http://video.linux.com/videos/the-linux-perf-tools-overview-and-developments video]&lt;br /&gt;
* [https://events.linuxfoundation.org/events/collaboration-summit/weisbecker Collaboration Submit 2012: Stacktraces / Callchains in Perf Events: What's Now? What's Next?] [https://events.linuxfoundation.org/images/stories/pdf/lfcs2012_weisbecker.pdf slides] [http://video.linux.com/videos/stacktraces--callchains-in-perf-events video]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/System_Tap</id>
		<title>System Tap</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/System_Tap"/>
				<updated>2012-04-14T01:35:41Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page has information about [[System Tap]], which is of interest to embedded developers,&lt;br /&gt;
because tracers are a useful tool for diagnosing problems during product development.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
SystemTap is a flexible and extensible system for adding trace collection and&lt;br /&gt;
analysis to a running Linux kernel.&lt;br /&gt;
&lt;br /&gt;
SystemTap is designed to be very flexible (allowing for the insertion of &lt;br /&gt;
arbitrary C code), yet also easy-to-use (most trace statements are written&lt;br /&gt;
in a simple scripting language, with useful data collection and aggregation&lt;br /&gt;
routines available in (essentially) library form).&lt;br /&gt;
&lt;br /&gt;
A key aspect of SystemTap is that it is intended to allow you to create&lt;br /&gt;
a trace set (a &amp;quot;tapset&amp;quot;), and run it on a running Linux system, with&lt;br /&gt;
no modification or re-compilation of the system required.  To do this, it&lt;br /&gt;
uses the kernel [http://www-users.cs.umn.edu/~boutcher/kprobes/ KProbes] interface and loadable kernel modules to dynamically&lt;br /&gt;
add probe points and newly generated code to the running kernel.&lt;br /&gt;
&lt;br /&gt;
== Open Source Projects/Mailing Lists ==&lt;br /&gt;
The main SystemTap site is at: http://sourceware.org/systemtap/&lt;br /&gt;
&lt;br /&gt;
The SystemTap mail list archives are at: http://sourceware.org/ml/systemtap/&lt;br /&gt;
&lt;br /&gt;
The tutorial, which gives a good overview of the system, is at:&lt;br /&gt;
http://sourceware.org/systemtap/tutorial/&lt;br /&gt;
&lt;br /&gt;
== Miscellaneous notes ==&lt;br /&gt;
=== Probe types ===&lt;br /&gt;
There are several types of probes:&lt;br /&gt;
* kprobe &amp;amp; kretprobe, for dynamically insterted probes&lt;br /&gt;
* timers&lt;br /&gt;
* static instrumentation markers&lt;br /&gt;
* performance counter events&lt;br /&gt;
&lt;br /&gt;
In the future, there may be:&lt;br /&gt;
* user-space probes,&lt;br /&gt;
* user-space return probes, and&lt;br /&gt;
* watchpoint probes (kernel &amp;amp; user)&lt;br /&gt;
* and more&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
Note that SystemTap is one of the major tracing systems for the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
There is work afoot (as of spring 2006) to try to collaborate on different&lt;br /&gt;
parts of the tracing problem, between some of the major tracing projects.&lt;br /&gt;
See the [[Tracing Collaboration Project]] page for more information.&lt;br /&gt;
&lt;br /&gt;
=== ARM Support ===&lt;br /&gt;
System Tap works on ARM &amp;amp; OMAP platforms instructions are available [http://omappedia.org/wiki/Systemtap here]&lt;br /&gt;
&lt;br /&gt;
== Some Performance measurements ==&lt;br /&gt;
Jian Gui writes (in July 2006 on the [[System Tap]] mailing list):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hi, we've tested the overhead of systemtap/LKET with some benchmarks&lt;br /&gt;
on a ppc64 machine.&lt;br /&gt;
&lt;br /&gt;
It shows the overhead of systemtap/LKET is acceptable generally.&lt;br /&gt;
But it will also cause significant overhead for some benchmark of&lt;br /&gt;
special behavior, e.g. dbench. Dbench calls kill() in a very high&lt;br /&gt;
frequency to check whether a task is complete, thus leads to a high&lt;br /&gt;
overhead.&lt;br /&gt;
&lt;br /&gt;
We categorized the event hooks into five groups in the testing:&lt;br /&gt;
grp1 - syscall.entry, process&lt;br /&gt;
grp2 - syscall.return, process&lt;br /&gt;
grp3 - iosyscall, ioscheduler, scsi, aio, process&lt;br /&gt;
grp4 - tskdispatch, pagefault, netdev, process&lt;br /&gt;
grp5 - syscall.entry, syscall.return, process&lt;br /&gt;
&lt;br /&gt;
All the results are&lt;br /&gt;
   (score1 - score2)/score2 * 100%,  where:&lt;br /&gt;
score1: the benchmark score when probed by systemtap&lt;br /&gt;
score2: the benchmark score without probing&lt;br /&gt;
&lt;br /&gt;
dbench (&amp;lt;3% is noise)&lt;br /&gt;
--------------------&lt;br /&gt;
grp1            -14.4%&lt;br /&gt;
grp2            -33.1%&lt;br /&gt;
grp3            -7.92%&lt;br /&gt;
grp4            -13.6%&lt;br /&gt;
grp5            -43.3%&lt;br /&gt;
&lt;br /&gt;
specjbb (&amp;lt;3% is noise)&lt;br /&gt;
---------------------&lt;br /&gt;
grp 1           -0.87%&lt;br /&gt;
grp 2           -0.67%&lt;br /&gt;
grp 4           +0.47%&lt;br /&gt;
grp 5           +0.05%&lt;br /&gt;
&lt;br /&gt;
tiobench (&amp;lt;3% is noise)&lt;br /&gt;
----------------------&lt;br /&gt;
grp1       sequential reads      +1.45%&lt;br /&gt;
           sequential writes     -6.98%&lt;br /&gt;
           random reads          +0.57%&lt;br /&gt;
           random writes         -2.11%&lt;br /&gt;
grp2       sequential reads      +0.11%&lt;br /&gt;
           sequential writes     -5.81%&lt;br /&gt;
           random reads          +0.03%&lt;br /&gt;
           random writes         -2.11%&lt;br /&gt;
grp3       sequential reads      +1.42%&lt;br /&gt;
           sequential writes     -6.98%&lt;br /&gt;
           random reads          +0.51%&lt;br /&gt;
           random writes         -2.11%&lt;br /&gt;
grp4       sequential reads      +1.38%&lt;br /&gt;
           sequential writes     -5.81%&lt;br /&gt;
           random reads          +0.60%&lt;br /&gt;
           random writes         -2.11%&lt;br /&gt;
grp5       sequential reads      +0.22%&lt;br /&gt;
           sequential writes     -8.14%&lt;br /&gt;
           random reads          -0.10%&lt;br /&gt;
           random writes         -1.05%&lt;br /&gt;
&lt;br /&gt;
Rawiobench (&amp;lt;3% is noise)&lt;br /&gt;
------------------------&lt;br /&gt;
grp1       sequential aioread()     0%&lt;br /&gt;
           sequential aiowrite()    0%&lt;br /&gt;
           random aioread()         0%&lt;br /&gt;
           random aiowrite()        0%&lt;br /&gt;
grp2       sequential aioread()     0%&lt;br /&gt;
           sequential aiowrite()    0%&lt;br /&gt;
           random aioread()         0%&lt;br /&gt;
           random aiowrite()        -0.82%&lt;br /&gt;
grp3       sequential aioread()     0%&lt;br /&gt;
           sequential aiowrite()    0%&lt;br /&gt;
           random aioread()         0%&lt;br /&gt;
           random aiowrite()        0%&lt;br /&gt;
grp4       sequential aioread()     0%&lt;br /&gt;
           sequential aiowrite()    0%&lt;br /&gt;
           random aioread()         +0.79%&lt;br /&gt;
           random aiowrite()        -0.82%&lt;br /&gt;
grp5       sequential aioread()     0%&lt;br /&gt;
           sequential aiowrite()    -6.41%&lt;br /&gt;
           random aioread()         +0.79%&lt;br /&gt;
           random aiowrite()        0%&lt;br /&gt;
&lt;br /&gt;
Test environment:&lt;br /&gt;
Machine:  Open Power 720/ 8 cpus/ 2 cores/ 6GB RAM (tiobench use 1G)&lt;br /&gt;
Software: RHEL4-U3GA/ 2.6.17.2/ systemtap-20060718/ elfutils-0.122-0.4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* [https://events.linuxfoundation.org/events/collaboration-summit/stone SystemTap Sans Kernel: A Pure Userspace Backend]    [https://events.linuxfoundation.org/images/stories/pdf/lfcs2012_jstone.pdf Slides] [http://video.linux.com/videos/systemtap-sans-kernel-a-pure-userspace-backend Video]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/System_Tap</id>
		<title>System Tap</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/System_Tap"/>
				<updated>2012-04-14T01:35:20Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Added videos&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page has information about [[System Tap]], which is of interest to embedded developers,&lt;br /&gt;
because tracers are a useful tool for diagnosing problems during product development.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
SystemTap is a flexible and extensible system for adding trace collection and&lt;br /&gt;
analysis to a running Linux kernel.&lt;br /&gt;
&lt;br /&gt;
SystemTap is designed to be very flexible (allowing for the insertion of &lt;br /&gt;
arbitrary C code), yet also easy-to-use (most trace statements are written&lt;br /&gt;
in a simple scripting language, with useful data collection and aggregation&lt;br /&gt;
routines available in (essentially) library form).&lt;br /&gt;
&lt;br /&gt;
A key aspect of SystemTap is that it is intended to allow you to create&lt;br /&gt;
a trace set (a &amp;quot;tapset&amp;quot;), and run it on a running Linux system, with&lt;br /&gt;
no modification or re-compilation of the system required.  To do this, it&lt;br /&gt;
uses the kernel [http://www-users.cs.umn.edu/~boutcher/kprobes/ KProbes] interface and loadable kernel modules to dynamically&lt;br /&gt;
add probe points and newly generated code to the running kernel.&lt;br /&gt;
&lt;br /&gt;
== Open Source Projects/Mailing Lists ==&lt;br /&gt;
The main SystemTap site is at: http://sourceware.org/systemtap/&lt;br /&gt;
&lt;br /&gt;
The SystemTap mail list archives are at: http://sourceware.org/ml/systemtap/&lt;br /&gt;
&lt;br /&gt;
The tutorial, which gives a good overview of the system, is at:&lt;br /&gt;
http://sourceware.org/systemtap/tutorial/&lt;br /&gt;
&lt;br /&gt;
== Miscellaneous notes ==&lt;br /&gt;
=== Probe types ===&lt;br /&gt;
There are several types of probes:&lt;br /&gt;
* kprobe &amp;amp; kretprobe, for dynamically insterted probes&lt;br /&gt;
* timers&lt;br /&gt;
* static instrumentation markers&lt;br /&gt;
* performance counter events&lt;br /&gt;
&lt;br /&gt;
In the future, there may be:&lt;br /&gt;
* user-space probes,&lt;br /&gt;
* user-space return probes, and&lt;br /&gt;
* watchpoint probes (kernel &amp;amp; user)&lt;br /&gt;
* and more&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
Note that SystemTap is one of the major tracing systems for the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
There is work afoot (as of spring 2006) to try to collaborate on different&lt;br /&gt;
parts of the tracing problem, between some of the major tracing projects.&lt;br /&gt;
See the [[Tracing Collaboration Project]] page for more information.&lt;br /&gt;
&lt;br /&gt;
=== ARM Support ===&lt;br /&gt;
System Tap works on ARM &amp;amp; OMAP platforms instructions are available [http://omappedia.org/wiki/Systemtap here]&lt;br /&gt;
&lt;br /&gt;
== Some Performance measurements ==&lt;br /&gt;
Jian Gui writes (in July 2006 on the [[System Tap]] mailing list):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hi, we've tested the overhead of systemtap/LKET with some benchmarks&lt;br /&gt;
on a ppc64 machine.&lt;br /&gt;
&lt;br /&gt;
It shows the overhead of systemtap/LKET is acceptable generally.&lt;br /&gt;
But it will also cause significant overhead for some benchmark of&lt;br /&gt;
special behavior, e.g. dbench. Dbench calls kill() in a very high&lt;br /&gt;
frequency to check whether a task is complete, thus leads to a high&lt;br /&gt;
overhead.&lt;br /&gt;
&lt;br /&gt;
We categorized the event hooks into five groups in the testing:&lt;br /&gt;
grp1 - syscall.entry, process&lt;br /&gt;
grp2 - syscall.return, process&lt;br /&gt;
grp3 - iosyscall, ioscheduler, scsi, aio, process&lt;br /&gt;
grp4 - tskdispatch, pagefault, netdev, process&lt;br /&gt;
grp5 - syscall.entry, syscall.return, process&lt;br /&gt;
&lt;br /&gt;
All the results are&lt;br /&gt;
   (score1 - score2)/score2 * 100%,  where:&lt;br /&gt;
score1: the benchmark score when probed by systemtap&lt;br /&gt;
score2: the benchmark score without probing&lt;br /&gt;
&lt;br /&gt;
dbench (&amp;lt;3% is noise)&lt;br /&gt;
--------------------&lt;br /&gt;
grp1            -14.4%&lt;br /&gt;
grp2            -33.1%&lt;br /&gt;
grp3            -7.92%&lt;br /&gt;
grp4            -13.6%&lt;br /&gt;
grp5            -43.3%&lt;br /&gt;
&lt;br /&gt;
specjbb (&amp;lt;3% is noise)&lt;br /&gt;
---------------------&lt;br /&gt;
grp 1           -0.87%&lt;br /&gt;
grp 2           -0.67%&lt;br /&gt;
grp 4           +0.47%&lt;br /&gt;
grp 5           +0.05%&lt;br /&gt;
&lt;br /&gt;
tiobench (&amp;lt;3% is noise)&lt;br /&gt;
----------------------&lt;br /&gt;
grp1       sequential reads      +1.45%&lt;br /&gt;
           sequential writes     -6.98%&lt;br /&gt;
           random reads          +0.57%&lt;br /&gt;
           random writes         -2.11%&lt;br /&gt;
grp2       sequential reads      +0.11%&lt;br /&gt;
           sequential writes     -5.81%&lt;br /&gt;
           random reads          +0.03%&lt;br /&gt;
           random writes         -2.11%&lt;br /&gt;
grp3       sequential reads      +1.42%&lt;br /&gt;
           sequential writes     -6.98%&lt;br /&gt;
           random reads          +0.51%&lt;br /&gt;
           random writes         -2.11%&lt;br /&gt;
grp4       sequential reads      +1.38%&lt;br /&gt;
           sequential writes     -5.81%&lt;br /&gt;
           random reads          +0.60%&lt;br /&gt;
           random writes         -2.11%&lt;br /&gt;
grp5       sequential reads      +0.22%&lt;br /&gt;
           sequential writes     -8.14%&lt;br /&gt;
           random reads          -0.10%&lt;br /&gt;
           random writes         -1.05%&lt;br /&gt;
&lt;br /&gt;
Rawiobench (&amp;lt;3% is noise)&lt;br /&gt;
------------------------&lt;br /&gt;
grp1       sequential aioread()     0%&lt;br /&gt;
           sequential aiowrite()    0%&lt;br /&gt;
           random aioread()         0%&lt;br /&gt;
           random aiowrite()        0%&lt;br /&gt;
grp2       sequential aioread()     0%&lt;br /&gt;
           sequential aiowrite()    0%&lt;br /&gt;
           random aioread()         0%&lt;br /&gt;
           random aiowrite()        -0.82%&lt;br /&gt;
grp3       sequential aioread()     0%&lt;br /&gt;
           sequential aiowrite()    0%&lt;br /&gt;
           random aioread()         0%&lt;br /&gt;
           random aiowrite()        0%&lt;br /&gt;
grp4       sequential aioread()     0%&lt;br /&gt;
           sequential aiowrite()    0%&lt;br /&gt;
           random aioread()         +0.79%&lt;br /&gt;
           random aiowrite()        -0.82%&lt;br /&gt;
grp5       sequential aioread()     0%&lt;br /&gt;
           sequential aiowrite()    -6.41%&lt;br /&gt;
           random aioread()         +0.79%&lt;br /&gt;
           random aiowrite()        0%&lt;br /&gt;
&lt;br /&gt;
Test environment:&lt;br /&gt;
Machine:  Open Power 720/ 8 cpus/ 2 cores/ 6GB RAM (tiobench use 1G)&lt;br /&gt;
Software: RHEL4-U3GA/ 2.6.17.2/ systemtap-20060718/ elfutils-0.122-0.4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* [https://events.linuxfoundation.org/events/collaboration-summit/stone SystemTap Sans Kernel: A Pure Userspace Backend]    [https://events.linuxfoundation.org/images/stories/pdf/lfcs2012_jstone.pdf Slides][http://video.linux.com/videos/systemtap-sans-kernel-a-pure-userspace-backend Video]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/User:Peter_Huewe</id>
		<title>User:Peter Huewe</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/User:Peter_Huewe"/>
				<updated>2012-04-14T01:32:31Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Thanks for visiting my page.&lt;br /&gt;
&lt;br /&gt;
I'm a 26 year old Embedded Linux Software Developer from Germany.&lt;br /&gt;
&lt;br /&gt;
Don't hesitate to contact me if you have any questions.&lt;br /&gt;
I'm always open to new ideas and interesting projects.&lt;br /&gt;
&lt;br /&gt;
Contact:&lt;br /&gt;
* Email: broeggle &amp;lt;at&amp;gt; scheissprovider &amp;lt;dot&amp;gt; de&lt;br /&gt;
* Email: PeterHuewe &amp;lt;at&amp;gt; linux &amp;lt;dot&amp;gt; com&lt;br /&gt;
* Jabber: broeggle &amp;lt;at&amp;gt; jabber &amp;lt;dot&amp;gt; ccc &amp;lt;dot&amp;gt; de&lt;br /&gt;
* ICQ : 137 1111 59&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of articles I'm currently working on / will be working on:&lt;br /&gt;
* [[Debugging by printing]]&lt;br /&gt;
* [[Debugging by querying]]&lt;br /&gt;
* [[Debugging OOPS]]&lt;br /&gt;
* [[JTAG]]&lt;br /&gt;
* [[MagicSysRq]]&lt;br /&gt;
* [[gcov]]&lt;br /&gt;
* [[profiling]]&lt;br /&gt;
* [[tracing]]&lt;br /&gt;
* [[Kernel Debug Support]]&lt;br /&gt;
* [[KGDB]]\[[KDB]]&lt;br /&gt;
* [[FTrace]] -&amp;gt; [[kernelshark]]&lt;br /&gt;
* [[LTTng]]&lt;br /&gt;
* [[oprofile]]&lt;br /&gt;
* [[System Tap]]&lt;br /&gt;
* [[Kprobes]]&lt;br /&gt;
* [[perf]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [[Debugging Portal]]&lt;br /&gt;
&lt;br /&gt;
Please feel free to help me ;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Currently missing articles on elinux.org&lt;br /&gt;
[[Coreboot]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Links:&lt;br /&gt;
https://events.linuxfoundation.org/images/stories/pdf/lfcs2012_hiramatsu.pdf&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Tracing</id>
		<title>Tracing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Tracing"/>
				<updated>2012-04-14T01:31:19Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* https://events.linuxfoundation.org/events/collaboration-summit/rostedt&lt;br /&gt;
* https://events.linuxfoundation.org/images/stories/pdf/lfcs2012_rostedt.pdf&lt;br /&gt;
* http://video.linux.com/videos/removing-stop-machine-from-the-tracing-infrastructure&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* https://events.linuxfoundation.org/images/stories/pdf/lfcs2012_zannoni_hees.pdf&lt;br /&gt;
* http://video.linux.com/videos/dtrace&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Tracing</id>
		<title>Tracing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Tracing"/>
				<updated>2012-04-14T01:30:09Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Created page with &amp;quot;* https://events.linuxfoundation.org/events/collaboration-summit/rostedt * https://events.linuxfoundation.org/images/stories/pdf/lfcs2012_rostedt.pdf * http://video.linux.com/vid...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* https://events.linuxfoundation.org/events/collaboration-summit/rostedt&lt;br /&gt;
* https://events.linuxfoundation.org/images/stories/pdf/lfcs2012_rostedt.pdf&lt;br /&gt;
* http://video.linux.com/videos/removing-stop-machine-from-the-tracing-infrastructure&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Perf</id>
		<title>Perf</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Perf"/>
				<updated>2012-04-14T01:29:07Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Created page with &amp;quot;https://events.linuxfoundation.org/images/stories/pdf/lfcs2012_melo.pdf http://video.linux.com/videos/the-linux-perf-tools-overview-and-developments https://events.linuxfoundatio...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;https://events.linuxfoundation.org/images/stories/pdf/lfcs2012_melo.pdf&lt;br /&gt;
http://video.linux.com/videos/the-linux-perf-tools-overview-and-developments&lt;br /&gt;
https://events.linuxfoundation.org/images/stories/pdf/lfcs2012_weisbecker.pdf&lt;br /&gt;
http://video.linux.com/videos/stacktraces--callchains-in-perf-events&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_Tips</id>
		<title>Debugging Tips</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_Tips"/>
				<updated>2012-04-03T21:37:55Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* See the [[Debugging_Portal]] page&lt;br /&gt;
* See the [[Kernel Debugging Tips]] page&lt;br /&gt;
* See also [[Debugging Makefiles]]&lt;br /&gt;
* [[Debugging by printing]]&lt;br /&gt;
* Debug user-space initialization:&lt;br /&gt;
** If you get a panic - &amp;quot;not syncing: Attempted to kill init!&amp;quot; it can be for many different reasons. Try setting CONFIG_DEBUG_USER=y in your .config and pass 'user_debug=255' in the kernel command line. That will give you a more verbose output about why user space programs crash. Thanks to Daniel Mack on the linux-arm-kernel mailing list for this tip.&lt;br /&gt;
[[Category: Tips and Tricks]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Talk:Debugging_by_printing</id>
		<title>Talk:Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Talk:Debugging_by_printing"/>
				<updated>2012-04-03T21:35:23Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Created page with &amp;quot;TODO: &amp;quot;&amp;quot;&amp;quot;We should probably add the scripts/bootgraph.pl information to that page (or to the initcall_debug page).  I don't think very many people are using that yet.&amp;quot;&amp;quot;&amp;quot;  Consoli...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;TODO:&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;We should probably add the scripts/bootgraph.pl information&lt;br /&gt;
to that page (or to the initcall_debug page).  I don't think very many people&lt;br /&gt;
are using that yet.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Consolidate remaining stuff from debugging tips&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Kernel_Debugging_Tips</id>
		<title>Kernel Debugging Tips</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Kernel_Debugging_Tips"/>
				<updated>2012-04-03T21:33:21Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Added links to content consolidated with Debugging_by_printing&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some miscellaneous tips for debugging a kernel:&lt;br /&gt;
&lt;br /&gt;
== Using printks ==&lt;br /&gt;
To add your own debug message to the kernel, you can place a &amp;quot;printk()&amp;quot; in the kernel code.&lt;br /&gt;
&lt;br /&gt;
See [[Debugging_by_printing#Usage| Debugging by printing -&amp;gt; Usage]] for more details.&lt;br /&gt;
&lt;br /&gt;
=== Log levels ===&lt;br /&gt;
Each kernel message can be pre-pended with a tag indicating the importance of the message.&lt;br /&gt;
&lt;br /&gt;
See [[Debugging_by_printing#Log_Levels| Debugging by printing -&amp;gt; Log_Levels]] for more details.&lt;br /&gt;
&lt;br /&gt;
=== Adding timing information ===&lt;br /&gt;
Sometimes, it is useful to add timing information to the printk values, so you can see when a particular event occurred.  The kernel includes an feature for doing&lt;br /&gt;
this called printk times.&lt;br /&gt;
&lt;br /&gt;
See the help for CONFIG_PRINTK_TIMES in the file lib/Kconfig.debug for more information on this feature.  This option is found on the &amp;quot;Kernel Hacking&amp;quot; menu when configuring the kernel.&lt;br /&gt;
&lt;br /&gt;
The timestamps which are inserted into the printk output consist of seconds and microseconds, as absolute values from the start of machine operation (or from the start of kernel timekeeping).&lt;br /&gt;
&lt;br /&gt;
There is also tool in the kernel source which will convert the timestamp values to relative values (so you can see the interval between events).  This tools is called show_delta and is located in the kernel 'scripts' directory.&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== Viewing log messages ===&lt;br /&gt;
The &amp;lt;tt&amp;gt;klogd&amp;lt;/tt&amp;gt; program will extract messages from the kernel log buffer, and send them to the system log (which winds up in /var/log/messages on most systems).  This command runs in the background on most desktop or server systems, and continually transfers messages from the kernel log buffer to the system log.&lt;br /&gt;
&lt;br /&gt;
You can view the contents of the log buffer directly, using the &amp;lt;tt&amp;gt;dmesg&amp;lt;/tt&amp;gt; command.  Note that by default &amp;lt;tt&amp;gt;dmesg&amp;lt;/tt&amp;gt; displays the messages from the buffer, but does not remove them.  So this command can be run multiple times to view the kernel printk messages.  See the dmesg man page for more things you can do with this tool.&lt;br /&gt;
&lt;br /&gt;
=== Controlling console output ===&lt;br /&gt;
In order to have the kernel boot be less &amp;quot;noisy&amp;quot;, or in order to boot more quickly, it is sometimes useful to control the amount of messages displayed to the console during boot.  You can do this by setting the kernel log level at boot time via a kernel command line option. See the &amp;quot;loglevel=&amp;quot; argument in &amp;lt;tt&amp;gt;Documentation/kernel-parameters.txt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You can turn off all messages using the kernel command line option &amp;quot;quiet&amp;quot;. See [[Disable Console]] for information on how much time this can save at boot up.&lt;br /&gt;
&lt;br /&gt;
Note that even if the log level is changed, or &amp;quot;quiet&amp;quot; is used, although the printk messages are not print to console, they are still entered into the log buffer, and they can still be extracted and displayed later using the &amp;lt;tt&amp;gt;dmesg&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
=== Changing the size of the printk buffer ===&lt;br /&gt;
See [[Debugging_by_printing#Internals_.2F_Changing_the_size_of_the_printk_buffer | Debugging by printing -&amp;gt; Internals / Changing the size of the printk buffer ]]&lt;br /&gt;
&lt;br /&gt;
== Using kernel symbols ==&lt;br /&gt;
You can look up the source code for a function address using your toolchain's addr2line program.&lt;br /&gt;
See [[Find a kernel function line]] or [[Addr2line for kernel debugging]].&lt;br /&gt;
&lt;br /&gt;
== Using a kernel debugger ==&lt;br /&gt;
You can use the in-kernel debugger: [[KDB]]&lt;br /&gt;
&lt;br /&gt;
Also, you can use QEMU and gdb (and a high-level IDE like eclipse).&lt;br /&gt;
&lt;br /&gt;
See [http://issaris.blogspot.com/2007/12/download-linux-kernel-sourcecode-from.html Debugging the Linux kernel using Eclipse/CDT and Qemu] for a great article on using Eclipse (with the CDT plugin) to debug the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
See [[Debugging_by_printing#Debugging_early_boot_problems]]&lt;br /&gt;
&lt;br /&gt;
== Triggering a kernel event ==&lt;br /&gt;
=== Overloading the sync system call ===&lt;br /&gt;
Sometimes, it is nice to trigger an event to happen in the kernel from user space. Instead of creating infrastructure to handle a /proc event, an ioctl() or making a new syscall, it can be quick and easy to just overload an existing function.  One function not used very often is sync.   (I have found that the sync system call is not normally called by user space programs (or during standard linux booting). &lt;br /&gt;
&lt;br /&gt;
It is quite easy to put a hook to your own kernel program in the sys_sync() routine (located in fs/sync.c) and cause it to execute by issuing 'sync' from the shell command line. This is handy as a temporary mechanism to test things that you have put in the kernel. &lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
&lt;br /&gt;
== Interpreting an Oops message ==&lt;br /&gt;
When the kernel encounters an internal fault, it will print an Oops message.&lt;br /&gt;
Here are some tips on using the Oops message to find the source of the problem.&lt;br /&gt;
* See [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob_plain;f=Documentation/oops-tracing.txt;hb=HEAD Documentation/oops-tracing.txt]&lt;br /&gt;
* See [http://vmlinux.org/jocke/linux/howto-find-oops-location.shtml HOWTO find oops location] by Denis Vlasenko&lt;br /&gt;
&lt;br /&gt;
== Compilation tricks for the kernel ==&lt;br /&gt;
Sometimes, you want to modify how the compiler builds an individual kernel file.  The following are tips for doing tasks related to this.&lt;br /&gt;
=== Build an individual file ===&lt;br /&gt;
You can build an individual output object file, with:&lt;br /&gt;
 make fs/buffer.o&lt;br /&gt;
&lt;br /&gt;
This will build JUST fs/buffer.o (if it needs rebuilding) and not the entire kernel.  To force it to need re-building, use 'touch' on the associated source file: &lt;br /&gt;
 touch fs/buffer.c&lt;br /&gt;
&lt;br /&gt;
=== Create the preprocessed file for an individual source file ===&lt;br /&gt;
Using the same technique, you can create the preprocessed file for a C source file.  This is useful if you're having trouble tracking down macro expansion or where defines/prototypes are coming from exactly.&lt;br /&gt;
 make fs/buffer.i&lt;br /&gt;
&lt;br /&gt;
=== Create the assembly file for an individual source file ===&lt;br /&gt;
Using the same technique, you can create the assembly file for a C source file.  This is useful to get an idea what actual machine instructions are generated from the C source code.&lt;br /&gt;
 make fs/buffer.s&lt;br /&gt;
&lt;br /&gt;
Another way to get the raw assembly, is to dump the object file using 'objdump'&lt;br /&gt;
 objdump -d fs/buffer.o &amp;gt; fs/buffer.disassem&lt;br /&gt;
&lt;br /&gt;
This will produce a disassembly of the object file, which should show how the assembly was translated into machine instructions.&lt;br /&gt;
&lt;br /&gt;
If the object has been compiled with debug symbols (using '-g'), then you might get more information using the '-S' option with objdump:&lt;br /&gt;
 objdump -S -d fs/buffer.o &amp;gt;fs/buffer.disassem&lt;br /&gt;
&lt;br /&gt;
You can also request that the toolchain show mixed source and assembly, by passing extra flags:&lt;br /&gt;
 make EXTRA_CFLAGS=&amp;quot;-g -Wa,-a,-ad -fverbose-asm&amp;quot; fs/buffer.o &amp;gt;fs/buffer.mixed&lt;br /&gt;
&lt;br /&gt;
=== Alter the flags for a compilation ===&lt;br /&gt;
Sometimes, you need to alter the compilation flags for an individual file.  There are two ways to do this. One is to add the extra flags on the make command line:&lt;br /&gt;
&lt;br /&gt;
 make EXTRA_CFLAGS=&amp;quot;-g -finstrument-functions&amp;quot; fs/buffer.o&lt;br /&gt;
&lt;br /&gt;
This will work if the flags can be appended to the regular set of C flags used for compiling the object.&lt;br /&gt;
&lt;br /&gt;
However, if you need to do something more complicated, like removing or modifying flags, then you can build your own command line by hand.  To do this, it is easiest to have 'make' produce the default compilation command (which will be several lines long), then copy, paste and edit it, to run on the command line directly.  To see the exact compile commands used to compile a particular object, use the V=1 option with the kernel build system:&lt;br /&gt;
&lt;br /&gt;
 make V=1 fs/buffer.o&lt;br /&gt;
&lt;br /&gt;
For me, this produced something like this:&lt;br /&gt;
&lt;br /&gt;
mipsel-linux-gcc -Wp,-MD,fs/.buffer.o.d -nostdinc -isystem /home/usr/local/mipsel-linux-glibc/bin/../lib/gcc/mipsisa32el-linux/3.4.3/include -D__KERNEL__ -Iinclude -Iinclude2 -I/home/tbird/work/linux/include -I/home/tbird/work/linux/fs -Ifs -Wall -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -ffreestanding -O2 -fomit-frame-pointer -g -I/home/tbird/work/linux/ -I /home/tbird/work/linux/include/asm/gcc -G 0 -mno-abicalls -fno-pic -pipe -finline-limit=100000 -mabi=32 -march=mips32r2 -Wa,-32 -Wa,-march=mips32r2 -Wa,-mips32r2 -Wa,--trap -I/home/tbird/work/linux/include/asm-mips/ati -Iinclude/asm-mips/ati -I/home/tbird/work/linux/include/asm-mips/mach-generic -Iinclude/asm-mips/mach-generic -Wdeclaration-after-statement  -DKBUILD_BASENAME=buffer -DKBUILD_MODNAME=buffer -c -o fs/buffer.o /home/tbird/work/linux/fs/buffer.c&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-04-03T21:30:21Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
The k in printk is used to specifically remind kernel developers that the environment is different. &lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Most of the conversion specifiers supported by the user-space library routine printf() are also available in the kernel; there are some notable additions, including &amp;quot;%pf&amp;quot;, which will print the symbol name in place of the numeric pointer value, if available.&lt;br /&gt;
&lt;br /&gt;
The supported format strings are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CONT&lt;br /&gt;
|&amp;quot;&amp;lt;c&amp;gt;&amp;quot;&lt;br /&gt;
|&amp;quot;continued&amp;quot; line of log printout (only done after a line that had no enclosing \n) [http://lwn.net/Articles/252651/]&lt;br /&gt;
|pr_cont&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''KERN_CONT'' and ''pr_cont'' are special cases since they do not specify an urgency but rather indicate a 'continued message' e.g.:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;Doing something was &amp;quot;);&lt;br /&gt;
 /* &amp;lt;100 lines of whatever&amp;gt;*/&lt;br /&gt;
 if (success)&lt;br /&gt;
    printk(KERN_CONT &amp;quot;successful\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
    printk(KERN_CONT &amp;quot;NOT successful\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
 -&amp;gt; &amp;quot;Doing something was successful&amp;quot;&lt;br /&gt;
'''Important Note:''' ''KERN_CONT'' and ''pr_cont'' should only be used by core/arch code during early bootup (a continued line is not SMP-safe otherwise).[http://lwn.net/Articles/252651/]&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals / Changing the size of the printk buffer ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' dmesg reads by default a buffer of max 16392 bytes, so if you use a larger logbuffer you have to invoke dmesg with the ''-s'' parameter e.g.:&lt;br /&gt;
 ### CONFIG_LOG_BUF_SHIFT 17 = 128k&lt;br /&gt;
 $ dmesg -s 128000&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
=== Accessing the printk buffer after a silent hang on boot ===&lt;br /&gt;
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang.  However, there may still be messages in the printk buffer, which can give you an idea of where the problem is.&lt;br /&gt;
&lt;br /&gt;
The kernel starts putting messages into the printk buffer as soon as it starts.  They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices).  Even though these messages are not printed before the hang, it is still possible in some circumstances&lt;br /&gt;
to dump the printk buffer and see the messages.&lt;br /&gt;
&lt;br /&gt;
The tricky parts of doing this are:&lt;br /&gt;
&lt;br /&gt;
# using a warm reset (if possible) so the memory contents are not lost when transitioning from the stuck kernel to the bootloader.  You ''can'' do a cold boot, but if the memory is left unpowered for very long, you will start to see memory corruption.&lt;br /&gt;
# figuring out the address to use in the bootloader, based on the address of __log_buf in System.map.  You will probably need to subtract the value of CONFIG_PAGE_OFFSET from the __log_buf address.  However, there may be other offsets present as well (such as TEXT_OFFSET).  Sometimes you can find the buffer by dumping the memory in a suspected area and locating the kernel messages visually in the dump.  Note that the mapping offset between the kernel map of memory and the bootloader map of memory should not change.  So once you figure it out you are set.&lt;br /&gt;
&lt;br /&gt;
Quinn Jensen writes:&lt;br /&gt;
&lt;br /&gt;
Something I've found handy when the console is silent is to dump the printk buffer from the boot loader.  To do it you have to know how your boot loader maps memory compared to the kernel.&lt;br /&gt;
&lt;br /&gt;
==== Redboot example on a Freescale ADS board ====&lt;br /&gt;
Quinn says: Here's what I do with Redboot on i.MX31:&lt;br /&gt;
&lt;br /&gt;
 fgrep printk_buf System.map&lt;br /&gt;
&lt;br /&gt;
this shows the linked address of the printk_buf, e.g.:&lt;br /&gt;
&lt;br /&gt;
 c02338f0 b printk_buf.16194&lt;br /&gt;
&lt;br /&gt;
The address &amp;quot;c02338f0&amp;quot; is in kernel virtual, which, in the case of i.MX31 ADS, redboot will have mapped to 0x802338f0.  So, after resetting the target board, but without letting it try to boot again, at the redboot prompt:&lt;br /&gt;
&lt;br /&gt;
 dump -b 0x802338f0 -l 10000&lt;br /&gt;
&lt;br /&gt;
And you see the printk buffer that never got flushed to the UART.  Knowing what's there can be '''very''' useful in debugging your console.&lt;br /&gt;
&lt;br /&gt;
==== U-boot example on an OMAP OSK board ====&lt;br /&gt;
Tim Bird tried these steps and they worked:&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf System.map&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf /proc/kallsyms&lt;br /&gt;
&lt;br /&gt;
These show:&lt;br /&gt;
&lt;br /&gt;
 c0352d88 B __log_buf&lt;br /&gt;
&lt;br /&gt;
In the case of the OSK, this address maps to 0x10352d88.  So I reset the target board and use the following:&lt;br /&gt;
&lt;br /&gt;
 OMAP5912 OSK # md 10352d88&lt;br /&gt;
 10352d88: 4c3e353c 78756e69 72657620 6e6f6973    &amp;lt;5&amp;gt;Linux version&lt;br /&gt;
 10352d98: 362e3220 2e32322e 612d3631 6e5f706c     2.6.22.16-alp_n&lt;br /&gt;
 10352da8: 7428206c 64726962 6d697440 6b736564    l (tbird@timdesk&lt;br /&gt;
 10352db8: 2e6d612e 796e6f73 6d6f632e 67282029    .am.sony.com) (g&lt;br /&gt;
 10352dc8: 76206363 69737265 33206e6f 342e342e    cc version 3.4.4&lt;br /&gt;
 10352dd8: 34232029 45525020 54504d45 65755420    ) #4 PREEMPT Tue&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Grub also supports a dump command which you can invoke from the grub prompt.&lt;br /&gt;
 dump  [ -s offset ] [-n length] { FILE | (mem) }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using CONFIG_DEBUG_LL and printascii() (ARM only) ===&lt;br /&gt;
If the kernel fails before the serial console is enabled, you can use CONFIG_DEBUG_LL to add extra debug output routines to the kernel.  These are printascii, printch and printhex. These routines print directly to the serial port, bypassing the console code, and are available earlier in machine initialization.&lt;br /&gt;
&lt;br /&gt;
Here is an e-mail exchange seen on the linux-embedded mailing list (with answer by George Davis):[http://www.mail-archive.com/linux-embedded@vger.kernel.org/msg00223.html] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; When we try to boot a 2.6.21 kernel after uncompressing the kernel the boot process dies somehow.&lt;br /&gt;
&amp;gt; We've figured out so far that the kernel dies somewhere between the gunzip and start_kernel.&lt;br /&gt;
&lt;br /&gt;
Try enabling DEBUG_LL to see if it's an machine ID error.  If you see:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported processor variant.&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported machine ID...&lt;br /&gt;
&lt;br /&gt;
Then you either don't have proper processor support enabled for your target or your bootloader is passing in the wrong machine number.&lt;br /&gt;
&lt;br /&gt;
If you still don't see anything, try hacking printk.c to call printascii() (enabled for the DEBUG_LL case) to print directly to the serial port w/o a driver, etc.,.  You can find more details on these low-level debugging hacks via a little googling...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg / Clearing the buffer ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
You can also specify an argument on the kernel command line to enable this, or&lt;br /&gt;
you can enable it any time at runtime by doing the following:&lt;br /&gt;
&lt;br /&gt;
  $echo 1 &amp;gt;/sys/module/printk/parameters/time&lt;br /&gt;
&lt;br /&gt;
Also, there are tools available to use the information to show relative times&lt;br /&gt;
between printks (scripts/show_delta) and create graphs of durations in the&lt;br /&gt;
kernel (scripts/bootgraph.pl)&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more details&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
== Disabling printk messages at compile time ==&lt;br /&gt;
There is a configuration option which allows you to turn off all the printk messages in the&lt;br /&gt;
whole kernel (''CONFIG_PRINTK'').  This reduces the size the kernel, usually by at least 100k, &lt;br /&gt;
since all message strings are not compiled into the kernel binary image.  &lt;br /&gt;
&lt;br /&gt;
However, it also means you get absolutely no output from the kernel while it is running.  Disabling kernel&lt;br /&gt;
printk messages is usually the last thing you do when you are tuning your kernel for size.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [http://lwn.net/Articles/487437/ LWN.net: The perils of pr_info()]&lt;br /&gt;
* [http://www.ibm.com/developerworks/linux/library/l-kernel-logging-apis/index.html Kernel logging: APIs and implementation, Tim Jones (for IBM)] (nice article)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some page related to printk:&lt;br /&gt;
* [[Printk Times]] - has information about how to turn on timestamps for each printk message&lt;br /&gt;
** [[Printk_Times_Sample_4| printk time stamps sample]]&lt;br /&gt;
* [[Printk_Size_Info|printk size information]]&lt;br /&gt;
* [[Do Printk]] - has information about a method of disabling printk messages on a per-module basis&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Kernel_Debugging_Tips</id>
		<title>Kernel Debugging Tips</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Kernel_Debugging_Tips"/>
				<updated>2012-04-03T21:28:21Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Consolidated with Debugging_by_printing&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some miscellaneous tips for debugging a kernel:&lt;br /&gt;
&lt;br /&gt;
== Using printks ==&lt;br /&gt;
To add your own debug message to the kernel, you can place a &amp;quot;printk()&amp;quot; in the kernel code.&lt;br /&gt;
&lt;br /&gt;
These messages are logged to an internal buffer, and eventually displayed by the kernel, being emitted to whatever is the active console, at the time of display.  Since the console is not initialized until part-way through the boot sequence, several messages build up in the log until the console is initialize, at which point all buffered messages are displayed at once.&lt;br /&gt;
&lt;br /&gt;
After the messages are displayed on the kernel console, they are left in the log buffer (which is a ring buffer), and they can be (and usually are) retrieved later by various commands.&lt;br /&gt;
&lt;br /&gt;
printk is a variable-argument function, just like printf.  Note that there is no &amp;quot;printf()&amp;quot; function for the kernel.  &amp;quot;printk()&amp;quot; is used to specifically remind kernel developers that the environment is different.&lt;br /&gt;
&lt;br /&gt;
printk can use many standard C-style printf format characters, but not all of them.  See the kernel source for examples of what you can do.&lt;br /&gt;
&lt;br /&gt;
=== Log levels ===&lt;br /&gt;
Each kernel message can be pre-pended with a tag indicating the importance of the message. The message tags are shown in the file include/linux/kernel.h.  The available tags are:&lt;br /&gt;
 KERN_EMERG, KERN_ALERT, KERN_CRIT, KERN_WARNING, KERN_NOTICE, KERN_INFO, KERN_DEBUG.&lt;br /&gt;
&lt;br /&gt;
Note that these tags are defined as simple strings, with angle brackets and a number:&lt;br /&gt;
 #define      KERN_INFO       &amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
You could place the tag onto front of the string without using the #define, but that is considered very bad form, and is discouraged.&lt;br /&gt;
&lt;br /&gt;
The way the tag is placed on the string is with C string concatenation:&lt;br /&gt;
 printk(KERN_DEBUG &amp;quot;This is a debug message\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Note that there is no comma between the tag macro and the message string.&lt;br /&gt;
&lt;br /&gt;
=== Adding timing information ===&lt;br /&gt;
Sometimes, it is useful to add timing information to the printk values, so you can see when a particular event occurred.  The kernel includes an feature for doing&lt;br /&gt;
this called printk times.&lt;br /&gt;
&lt;br /&gt;
See the help for CONFIG_PRINTK_TIMES in the file lib/Kconfig.debug for more information on this feature.  This option is found on the &amp;quot;Kernel Hacking&amp;quot; menu when configuring the kernel.&lt;br /&gt;
&lt;br /&gt;
The timestamps which are inserted into the printk output consist of seconds and microseconds, as absolute values from the start of machine operation (or from the start of kernel timekeeping).&lt;br /&gt;
&lt;br /&gt;
There is also tool in the kernel source which will convert the timestamp values to relative values (so you can see the interval between events).  This tools is called show_delta and is located in the kernel 'scripts' directory.&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== Viewing log messages ===&lt;br /&gt;
The &amp;lt;tt&amp;gt;klogd&amp;lt;/tt&amp;gt; program will extract messages from the kernel log buffer, and send them to the system log (which winds up in /var/log/messages on most systems).  This command runs in the background on most desktop or server systems, and continually transfers messages from the kernel log buffer to the system log.&lt;br /&gt;
&lt;br /&gt;
You can view the contents of the log buffer directly, using the &amp;lt;tt&amp;gt;dmesg&amp;lt;/tt&amp;gt; command.  Note that by default &amp;lt;tt&amp;gt;dmesg&amp;lt;/tt&amp;gt; displays the messages from the buffer, but does not remove them.  So this command can be run multiple times to view the kernel printk messages.  See the dmesg man page for more things you can do with this tool.&lt;br /&gt;
&lt;br /&gt;
=== Controlling console output ===&lt;br /&gt;
In order to have the kernel boot be less &amp;quot;noisy&amp;quot;, or in order to boot more quickly, it is sometimes useful to control the amount of messages displayed to the console during boot.  You can do this by setting the kernel log level at boot time via a kernel command line option. See the &amp;quot;loglevel=&amp;quot; argument in &amp;lt;tt&amp;gt;Documentation/kernel-parameters.txt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You can turn off all messages using the kernel command line option &amp;quot;quiet&amp;quot;. See [[Disable Console]] for information on how much time this can save at boot up.&lt;br /&gt;
&lt;br /&gt;
Note that even if the log level is changed, or &amp;quot;quiet&amp;quot; is used, although the printk messages are not print to console, they are still entered into the log buffer, and they can still be extracted and displayed later using the &amp;lt;tt&amp;gt;dmesg&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
=== Changing the size of the printk buffer ===&lt;br /&gt;
See [[Debugging_by_printing#Internals_.2F_Changing_the_size_of_the_printk_buffer | Debugging by printing -&amp;gt; Internals / Changing the size of the printk buffer ]]&lt;br /&gt;
&lt;br /&gt;
== Using kernel symbols ==&lt;br /&gt;
You can look up the source code for a function address using your toolchain's addr2line program.&lt;br /&gt;
See [[Find a kernel function line]] or [[Addr2line for kernel debugging]].&lt;br /&gt;
&lt;br /&gt;
== Using a kernel debugger ==&lt;br /&gt;
You can use the in-kernel debugger: [[KDB]]&lt;br /&gt;
&lt;br /&gt;
Also, you can use QEMU and gdb (and a high-level IDE like eclipse).&lt;br /&gt;
&lt;br /&gt;
See [http://issaris.blogspot.com/2007/12/download-linux-kernel-sourcecode-from.html Debugging the Linux kernel using Eclipse/CDT and Qemu] for a great article on using Eclipse (with the CDT plugin) to debug the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
See [[Debugging_by_printing#Debugging_early_boot_problems]]&lt;br /&gt;
&lt;br /&gt;
== Triggering a kernel event ==&lt;br /&gt;
=== Overloading the sync system call ===&lt;br /&gt;
Sometimes, it is nice to trigger an event to happen in the kernel from user space. Instead of creating infrastructure to handle a /proc event, an ioctl() or making a new syscall, it can be quick and easy to just overload an existing function.  One function not used very often is sync.   (I have found that the sync system call is not normally called by user space programs (or during standard linux booting). &lt;br /&gt;
&lt;br /&gt;
It is quite easy to put a hook to your own kernel program in the sys_sync() routine (located in fs/sync.c) and cause it to execute by issuing 'sync' from the shell command line. This is handy as a temporary mechanism to test things that you have put in the kernel. &lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
&lt;br /&gt;
== Interpreting an Oops message ==&lt;br /&gt;
When the kernel encounters an internal fault, it will print an Oops message.&lt;br /&gt;
Here are some tips on using the Oops message to find the source of the problem.&lt;br /&gt;
* See [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob_plain;f=Documentation/oops-tracing.txt;hb=HEAD Documentation/oops-tracing.txt]&lt;br /&gt;
* See [http://vmlinux.org/jocke/linux/howto-find-oops-location.shtml HOWTO find oops location] by Denis Vlasenko&lt;br /&gt;
&lt;br /&gt;
== Compilation tricks for the kernel ==&lt;br /&gt;
Sometimes, you want to modify how the compiler builds an individual kernel file.  The following are tips for doing tasks related to this.&lt;br /&gt;
=== Build an individual file ===&lt;br /&gt;
You can build an individual output object file, with:&lt;br /&gt;
 make fs/buffer.o&lt;br /&gt;
&lt;br /&gt;
This will build JUST fs/buffer.o (if it needs rebuilding) and not the entire kernel.  To force it to need re-building, use 'touch' on the associated source file: &lt;br /&gt;
 touch fs/buffer.c&lt;br /&gt;
&lt;br /&gt;
=== Create the preprocessed file for an individual source file ===&lt;br /&gt;
Using the same technique, you can create the preprocessed file for a C source file.  This is useful if you're having trouble tracking down macro expansion or where defines/prototypes are coming from exactly.&lt;br /&gt;
 make fs/buffer.i&lt;br /&gt;
&lt;br /&gt;
=== Create the assembly file for an individual source file ===&lt;br /&gt;
Using the same technique, you can create the assembly file for a C source file.  This is useful to get an idea what actual machine instructions are generated from the C source code.&lt;br /&gt;
 make fs/buffer.s&lt;br /&gt;
&lt;br /&gt;
Another way to get the raw assembly, is to dump the object file using 'objdump'&lt;br /&gt;
 objdump -d fs/buffer.o &amp;gt; fs/buffer.disassem&lt;br /&gt;
&lt;br /&gt;
This will produce a disassembly of the object file, which should show how the assembly was translated into machine instructions.&lt;br /&gt;
&lt;br /&gt;
If the object has been compiled with debug symbols (using '-g'), then you might get more information using the '-S' option with objdump:&lt;br /&gt;
 objdump -S -d fs/buffer.o &amp;gt;fs/buffer.disassem&lt;br /&gt;
&lt;br /&gt;
You can also request that the toolchain show mixed source and assembly, by passing extra flags:&lt;br /&gt;
 make EXTRA_CFLAGS=&amp;quot;-g -Wa,-a,-ad -fverbose-asm&amp;quot; fs/buffer.o &amp;gt;fs/buffer.mixed&lt;br /&gt;
&lt;br /&gt;
=== Alter the flags for a compilation ===&lt;br /&gt;
Sometimes, you need to alter the compilation flags for an individual file.  There are two ways to do this. One is to add the extra flags on the make command line:&lt;br /&gt;
&lt;br /&gt;
 make EXTRA_CFLAGS=&amp;quot;-g -finstrument-functions&amp;quot; fs/buffer.o&lt;br /&gt;
&lt;br /&gt;
This will work if the flags can be appended to the regular set of C flags used for compiling the object.&lt;br /&gt;
&lt;br /&gt;
However, if you need to do something more complicated, like removing or modifying flags, then you can build your own command line by hand.  To do this, it is easiest to have 'make' produce the default compilation command (which will be several lines long), then copy, paste and edit it, to run on the command line directly.  To see the exact compile commands used to compile a particular object, use the V=1 option with the kernel build system:&lt;br /&gt;
&lt;br /&gt;
 make V=1 fs/buffer.o&lt;br /&gt;
&lt;br /&gt;
For me, this produced something like this:&lt;br /&gt;
&lt;br /&gt;
mipsel-linux-gcc -Wp,-MD,fs/.buffer.o.d -nostdinc -isystem /home/usr/local/mipsel-linux-glibc/bin/../lib/gcc/mipsisa32el-linux/3.4.3/include -D__KERNEL__ -Iinclude -Iinclude2 -I/home/tbird/work/linux/include -I/home/tbird/work/linux/fs -Ifs -Wall -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -ffreestanding -O2 -fomit-frame-pointer -g -I/home/tbird/work/linux/ -I /home/tbird/work/linux/include/asm/gcc -G 0 -mno-abicalls -fno-pic -pipe -finline-limit=100000 -mabi=32 -march=mips32r2 -Wa,-32 -Wa,-march=mips32r2 -Wa,-mips32r2 -Wa,--trap -I/home/tbird/work/linux/include/asm-mips/ati -Iinclude/asm-mips/ati -I/home/tbird/work/linux/include/asm-mips/mach-generic -Iinclude/asm-mips/mach-generic -Wdeclaration-after-statement  -DKBUILD_BASENAME=buffer -DKBUILD_MODNAME=buffer -c -o fs/buffer.o /home/tbird/work/linux/fs/buffer.c&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-04-03T21:26:17Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: /* Internals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Most of the conversion specifiers supported by the user-space library routine printf() are also available in the kernel; there are some notable additions, including &amp;quot;%pf&amp;quot;, which will print the symbol name in place of the numeric pointer value, if available.&lt;br /&gt;
&lt;br /&gt;
The supported format strings are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CONT&lt;br /&gt;
|&amp;quot;&amp;lt;c&amp;gt;&amp;quot;&lt;br /&gt;
|&amp;quot;continued&amp;quot; line of log printout (only done after a line that had no enclosing \n) [http://lwn.net/Articles/252651/]&lt;br /&gt;
|pr_cont&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''KERN_CONT'' and ''pr_cont'' are special cases since they do not specify an urgency but rather indicate a 'continued message' e.g.:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;Doing something was &amp;quot;);&lt;br /&gt;
 /* &amp;lt;100 lines of whatever&amp;gt;*/&lt;br /&gt;
 if (success)&lt;br /&gt;
    printk(KERN_CONT &amp;quot;successful\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
    printk(KERN_CONT &amp;quot;NOT successful\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
 -&amp;gt; &amp;quot;Doing something was successful&amp;quot;&lt;br /&gt;
'''Important Note:''' ''KERN_CONT'' and ''pr_cont'' should only be used by core/arch code during early bootup (a continued line is not SMP-safe otherwise).[http://lwn.net/Articles/252651/]&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals / Changing the size of the printk buffer ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' dmesg reads by default a buffer of max 16392 bytes, so if you use a larger logbuffer you have to invoke dmesg with the ''-s'' parameter e.g.:&lt;br /&gt;
 ### CONFIG_LOG_BUF_SHIFT 17 = 128k&lt;br /&gt;
 $ dmesg -s 128000&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
=== Accessing the printk buffer after a silent hang on boot ===&lt;br /&gt;
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang.  However, there may still be messages in the printk buffer, which can give you an idea of where the problem is.&lt;br /&gt;
&lt;br /&gt;
The kernel starts putting messages into the printk buffer as soon as it starts.  They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices).  Even though these messages are not printed before the hang, it is still possible in some circumstances&lt;br /&gt;
to dump the printk buffer and see the messages.&lt;br /&gt;
&lt;br /&gt;
The tricky parts of doing this are:&lt;br /&gt;
&lt;br /&gt;
# using a warm reset (if possible) so the memory contents are not lost when transitioning from the stuck kernel to the bootloader.  You ''can'' do a cold boot, but if the memory is left unpowered for very long, you will start to see memory corruption.&lt;br /&gt;
# figuring out the address to use in the bootloader, based on the address of __log_buf in System.map.  You will probably need to subtract the value of CONFIG_PAGE_OFFSET from the __log_buf address.  However, there may be other offsets present as well (such as TEXT_OFFSET).  Sometimes you can find the buffer by dumping the memory in a suspected area and locating the kernel messages visually in the dump.  Note that the mapping offset between the kernel map of memory and the bootloader map of memory should not change.  So once you figure it out you are set.&lt;br /&gt;
&lt;br /&gt;
Quinn Jensen writes:&lt;br /&gt;
&lt;br /&gt;
Something I've found handy when the console is silent is to dump the printk buffer from the boot loader.  To do it you have to know how your boot loader maps memory compared to the kernel.&lt;br /&gt;
&lt;br /&gt;
==== Redboot example on a Freescale ADS board ====&lt;br /&gt;
Quinn says: Here's what I do with Redboot on i.MX31:&lt;br /&gt;
&lt;br /&gt;
 fgrep printk_buf System.map&lt;br /&gt;
&lt;br /&gt;
this shows the linked address of the printk_buf, e.g.:&lt;br /&gt;
&lt;br /&gt;
 c02338f0 b printk_buf.16194&lt;br /&gt;
&lt;br /&gt;
The address &amp;quot;c02338f0&amp;quot; is in kernel virtual, which, in the case of i.MX31 ADS, redboot will have mapped to 0x802338f0.  So, after resetting the target board, but without letting it try to boot again, at the redboot prompt:&lt;br /&gt;
&lt;br /&gt;
 dump -b 0x802338f0 -l 10000&lt;br /&gt;
&lt;br /&gt;
And you see the printk buffer that never got flushed to the UART.  Knowing what's there can be '''very''' useful in debugging your console.&lt;br /&gt;
&lt;br /&gt;
==== U-boot example on an OMAP OSK board ====&lt;br /&gt;
Tim Bird tried these steps and they worked:&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf System.map&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf /proc/kallsyms&lt;br /&gt;
&lt;br /&gt;
These show:&lt;br /&gt;
&lt;br /&gt;
 c0352d88 B __log_buf&lt;br /&gt;
&lt;br /&gt;
In the case of the OSK, this address maps to 0x10352d88.  So I reset the target board and use the following:&lt;br /&gt;
&lt;br /&gt;
 OMAP5912 OSK # md 10352d88&lt;br /&gt;
 10352d88: 4c3e353c 78756e69 72657620 6e6f6973    &amp;lt;5&amp;gt;Linux version&lt;br /&gt;
 10352d98: 362e3220 2e32322e 612d3631 6e5f706c     2.6.22.16-alp_n&lt;br /&gt;
 10352da8: 7428206c 64726962 6d697440 6b736564    l (tbird@timdesk&lt;br /&gt;
 10352db8: 2e6d612e 796e6f73 6d6f632e 67282029    .am.sony.com) (g&lt;br /&gt;
 10352dc8: 76206363 69737265 33206e6f 342e342e    cc version 3.4.4&lt;br /&gt;
 10352dd8: 34232029 45525020 54504d45 65755420    ) #4 PREEMPT Tue&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Grub also supports a dump command which you can invoke from the grub prompt.&lt;br /&gt;
 dump  [ -s offset ] [-n length] { FILE | (mem) }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using CONFIG_DEBUG_LL and printascii() (ARM only) ===&lt;br /&gt;
If the kernel fails before the serial console is enabled, you can use CONFIG_DEBUG_LL to add extra debug output routines to the kernel.  These are printascii, printch and printhex. These routines print directly to the serial port, bypassing the console code, and are available earlier in machine initialization.&lt;br /&gt;
&lt;br /&gt;
Here is an e-mail exchange seen on the linux-embedded mailing list (with answer by George Davis):[http://www.mail-archive.com/linux-embedded@vger.kernel.org/msg00223.html] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; When we try to boot a 2.6.21 kernel after uncompressing the kernel the boot process dies somehow.&lt;br /&gt;
&amp;gt; We've figured out so far that the kernel dies somewhere between the gunzip and start_kernel.&lt;br /&gt;
&lt;br /&gt;
Try enabling DEBUG_LL to see if it's an machine ID error.  If you see:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported processor variant.&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported machine ID...&lt;br /&gt;
&lt;br /&gt;
Then you either don't have proper processor support enabled for your target or your bootloader is passing in the wrong machine number.&lt;br /&gt;
&lt;br /&gt;
If you still don't see anything, try hacking printk.c to call printascii() (enabled for the DEBUG_LL case) to print directly to the serial port w/o a driver, etc.,.  You can find more details on these low-level debugging hacks via a little googling...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg / Clearing the buffer ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
You can also specify an argument on the kernel command line to enable this, or&lt;br /&gt;
you can enable it any time at runtime by doing the following:&lt;br /&gt;
&lt;br /&gt;
  $echo 1 &amp;gt;/sys/module/printk/parameters/time&lt;br /&gt;
&lt;br /&gt;
Also, there are tools available to use the information to show relative times&lt;br /&gt;
between printks (scripts/show_delta) and create graphs of durations in the&lt;br /&gt;
kernel (scripts/bootgraph.pl)&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more details&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
== Disabling printk messages at compile time ==&lt;br /&gt;
There is a configuration option which allows you to turn off all the printk messages in the&lt;br /&gt;
whole kernel (''CONFIG_PRINTK'').  This reduces the size the kernel, usually by at least 100k, &lt;br /&gt;
since all message strings are not compiled into the kernel binary image.  &lt;br /&gt;
&lt;br /&gt;
However, it also means you get absolutely no output from the kernel while it is running.  Disabling kernel&lt;br /&gt;
printk messages is usually the last thing you do when you are tuning your kernel for size.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [http://lwn.net/Articles/487437/ LWN.net: The perils of pr_info()]&lt;br /&gt;
* [http://www.ibm.com/developerworks/linux/library/l-kernel-logging-apis/index.html Kernel logging: APIs and implementation, Tim Jones (for IBM)] (nice article)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some page related to printk:&lt;br /&gt;
* [[Printk Times]] - has information about how to turn on timestamps for each printk message&lt;br /&gt;
** [[Printk_Times_Sample_4| printk time stamps sample]]&lt;br /&gt;
* [[Printk_Size_Info|printk size information]]&lt;br /&gt;
* [[Do Printk]] - has information about a method of disabling printk messages on a per-module basis&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-04-03T21:25:30Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: /* Internals */ added dmesg -s&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Most of the conversion specifiers supported by the user-space library routine printf() are also available in the kernel; there are some notable additions, including &amp;quot;%pf&amp;quot;, which will print the symbol name in place of the numeric pointer value, if available.&lt;br /&gt;
&lt;br /&gt;
The supported format strings are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CONT&lt;br /&gt;
|&amp;quot;&amp;lt;c&amp;gt;&amp;quot;&lt;br /&gt;
|&amp;quot;continued&amp;quot; line of log printout (only done after a line that had no enclosing \n) [http://lwn.net/Articles/252651/]&lt;br /&gt;
|pr_cont&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''KERN_CONT'' and ''pr_cont'' are special cases since they do not specify an urgency but rather indicate a 'continued message' e.g.:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;Doing something was &amp;quot;);&lt;br /&gt;
 /* &amp;lt;100 lines of whatever&amp;gt;*/&lt;br /&gt;
 if (success)&lt;br /&gt;
    printk(KERN_CONT &amp;quot;successful\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
    printk(KERN_CONT &amp;quot;NOT successful\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
 -&amp;gt; &amp;quot;Doing something was successful&amp;quot;&lt;br /&gt;
'''Important Note:''' ''KERN_CONT'' and ''pr_cont'' should only be used by core/arch code during early bootup (a continued line is not SMP-safe otherwise).[http://lwn.net/Articles/252651/]&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' dmesg reads by default a buffer of max 16392 bytes, so if you use a larger logbuffer you have to invoke dmesg with the ''-s'' parameter e.g.:&lt;br /&gt;
 ### CONFIG_LOG_BUF_SHIFT 17 = 128k&lt;br /&gt;
 $ dmesg -s 128000&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
=== Accessing the printk buffer after a silent hang on boot ===&lt;br /&gt;
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang.  However, there may still be messages in the printk buffer, which can give you an idea of where the problem is.&lt;br /&gt;
&lt;br /&gt;
The kernel starts putting messages into the printk buffer as soon as it starts.  They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices).  Even though these messages are not printed before the hang, it is still possible in some circumstances&lt;br /&gt;
to dump the printk buffer and see the messages.&lt;br /&gt;
&lt;br /&gt;
The tricky parts of doing this are:&lt;br /&gt;
&lt;br /&gt;
# using a warm reset (if possible) so the memory contents are not lost when transitioning from the stuck kernel to the bootloader.  You ''can'' do a cold boot, but if the memory is left unpowered for very long, you will start to see memory corruption.&lt;br /&gt;
# figuring out the address to use in the bootloader, based on the address of __log_buf in System.map.  You will probably need to subtract the value of CONFIG_PAGE_OFFSET from the __log_buf address.  However, there may be other offsets present as well (such as TEXT_OFFSET).  Sometimes you can find the buffer by dumping the memory in a suspected area and locating the kernel messages visually in the dump.  Note that the mapping offset between the kernel map of memory and the bootloader map of memory should not change.  So once you figure it out you are set.&lt;br /&gt;
&lt;br /&gt;
Quinn Jensen writes:&lt;br /&gt;
&lt;br /&gt;
Something I've found handy when the console is silent is to dump the printk buffer from the boot loader.  To do it you have to know how your boot loader maps memory compared to the kernel.&lt;br /&gt;
&lt;br /&gt;
==== Redboot example on a Freescale ADS board ====&lt;br /&gt;
Quinn says: Here's what I do with Redboot on i.MX31:&lt;br /&gt;
&lt;br /&gt;
 fgrep printk_buf System.map&lt;br /&gt;
&lt;br /&gt;
this shows the linked address of the printk_buf, e.g.:&lt;br /&gt;
&lt;br /&gt;
 c02338f0 b printk_buf.16194&lt;br /&gt;
&lt;br /&gt;
The address &amp;quot;c02338f0&amp;quot; is in kernel virtual, which, in the case of i.MX31 ADS, redboot will have mapped to 0x802338f0.  So, after resetting the target board, but without letting it try to boot again, at the redboot prompt:&lt;br /&gt;
&lt;br /&gt;
 dump -b 0x802338f0 -l 10000&lt;br /&gt;
&lt;br /&gt;
And you see the printk buffer that never got flushed to the UART.  Knowing what's there can be '''very''' useful in debugging your console.&lt;br /&gt;
&lt;br /&gt;
==== U-boot example on an OMAP OSK board ====&lt;br /&gt;
Tim Bird tried these steps and they worked:&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf System.map&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf /proc/kallsyms&lt;br /&gt;
&lt;br /&gt;
These show:&lt;br /&gt;
&lt;br /&gt;
 c0352d88 B __log_buf&lt;br /&gt;
&lt;br /&gt;
In the case of the OSK, this address maps to 0x10352d88.  So I reset the target board and use the following:&lt;br /&gt;
&lt;br /&gt;
 OMAP5912 OSK # md 10352d88&lt;br /&gt;
 10352d88: 4c3e353c 78756e69 72657620 6e6f6973    &amp;lt;5&amp;gt;Linux version&lt;br /&gt;
 10352d98: 362e3220 2e32322e 612d3631 6e5f706c     2.6.22.16-alp_n&lt;br /&gt;
 10352da8: 7428206c 64726962 6d697440 6b736564    l (tbird@timdesk&lt;br /&gt;
 10352db8: 2e6d612e 796e6f73 6d6f632e 67282029    .am.sony.com) (g&lt;br /&gt;
 10352dc8: 76206363 69737265 33206e6f 342e342e    cc version 3.4.4&lt;br /&gt;
 10352dd8: 34232029 45525020 54504d45 65755420    ) #4 PREEMPT Tue&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Grub also supports a dump command which you can invoke from the grub prompt.&lt;br /&gt;
 dump  [ -s offset ] [-n length] { FILE | (mem) }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using CONFIG_DEBUG_LL and printascii() (ARM only) ===&lt;br /&gt;
If the kernel fails before the serial console is enabled, you can use CONFIG_DEBUG_LL to add extra debug output routines to the kernel.  These are printascii, printch and printhex. These routines print directly to the serial port, bypassing the console code, and are available earlier in machine initialization.&lt;br /&gt;
&lt;br /&gt;
Here is an e-mail exchange seen on the linux-embedded mailing list (with answer by George Davis):[http://www.mail-archive.com/linux-embedded@vger.kernel.org/msg00223.html] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; When we try to boot a 2.6.21 kernel after uncompressing the kernel the boot process dies somehow.&lt;br /&gt;
&amp;gt; We've figured out so far that the kernel dies somewhere between the gunzip and start_kernel.&lt;br /&gt;
&lt;br /&gt;
Try enabling DEBUG_LL to see if it's an machine ID error.  If you see:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported processor variant.&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported machine ID...&lt;br /&gt;
&lt;br /&gt;
Then you either don't have proper processor support enabled for your target or your bootloader is passing in the wrong machine number.&lt;br /&gt;
&lt;br /&gt;
If you still don't see anything, try hacking printk.c to call printascii() (enabled for the DEBUG_LL case) to print directly to the serial port w/o a driver, etc.,.  You can find more details on these low-level debugging hacks via a little googling...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg / Clearing the buffer ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
You can also specify an argument on the kernel command line to enable this, or&lt;br /&gt;
you can enable it any time at runtime by doing the following:&lt;br /&gt;
&lt;br /&gt;
  $echo 1 &amp;gt;/sys/module/printk/parameters/time&lt;br /&gt;
&lt;br /&gt;
Also, there are tools available to use the information to show relative times&lt;br /&gt;
between printks (scripts/show_delta) and create graphs of durations in the&lt;br /&gt;
kernel (scripts/bootgraph.pl)&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more details&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
== Disabling printk messages at compile time ==&lt;br /&gt;
There is a configuration option which allows you to turn off all the printk messages in the&lt;br /&gt;
whole kernel (''CONFIG_PRINTK'').  This reduces the size the kernel, usually by at least 100k, &lt;br /&gt;
since all message strings are not compiled into the kernel binary image.  &lt;br /&gt;
&lt;br /&gt;
However, it also means you get absolutely no output from the kernel while it is running.  Disabling kernel&lt;br /&gt;
printk messages is usually the last thing you do when you are tuning your kernel for size.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [http://lwn.net/Articles/487437/ LWN.net: The perils of pr_info()]&lt;br /&gt;
* [http://www.ibm.com/developerworks/linux/library/l-kernel-logging-apis/index.html Kernel logging: APIs and implementation, Tim Jones (for IBM)] (nice article)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some page related to printk:&lt;br /&gt;
* [[Printk Times]] - has information about how to turn on timestamps for each printk message&lt;br /&gt;
** [[Printk_Times_Sample_4| printk time stamps sample]]&lt;br /&gt;
* [[Printk_Size_Info|printk size information]]&lt;br /&gt;
* [[Do Printk]] - has information about a method of disabling printk messages on a per-module basis&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-04-03T21:19:50Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: /* Dmesg */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Most of the conversion specifiers supported by the user-space library routine printf() are also available in the kernel; there are some notable additions, including &amp;quot;%pf&amp;quot;, which will print the symbol name in place of the numeric pointer value, if available.&lt;br /&gt;
&lt;br /&gt;
The supported format strings are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CONT&lt;br /&gt;
|&amp;quot;&amp;lt;c&amp;gt;&amp;quot;&lt;br /&gt;
|&amp;quot;continued&amp;quot; line of log printout (only done after a line that had no enclosing \n) [http://lwn.net/Articles/252651/]&lt;br /&gt;
|pr_cont&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''KERN_CONT'' and ''pr_cont'' are special cases since they do not specify an urgency but rather indicate a 'continued message' e.g.:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;Doing something was &amp;quot;);&lt;br /&gt;
 /* &amp;lt;100 lines of whatever&amp;gt;*/&lt;br /&gt;
 if (success)&lt;br /&gt;
    printk(KERN_CONT &amp;quot;successful\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
    printk(KERN_CONT &amp;quot;NOT successful\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
 -&amp;gt; &amp;quot;Doing something was successful&amp;quot;&lt;br /&gt;
'''Important Note:''' ''KERN_CONT'' and ''pr_cont'' should only be used by core/arch code during early bootup (a continued line is not SMP-safe otherwise).[http://lwn.net/Articles/252651/]&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
=== Accessing the printk buffer after a silent hang on boot ===&lt;br /&gt;
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang.  However, there may still be messages in the printk buffer, which can give you an idea of where the problem is.&lt;br /&gt;
&lt;br /&gt;
The kernel starts putting messages into the printk buffer as soon as it starts.  They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices).  Even though these messages are not printed before the hang, it is still possible in some circumstances&lt;br /&gt;
to dump the printk buffer and see the messages.&lt;br /&gt;
&lt;br /&gt;
The tricky parts of doing this are:&lt;br /&gt;
&lt;br /&gt;
# using a warm reset (if possible) so the memory contents are not lost when transitioning from the stuck kernel to the bootloader.  You ''can'' do a cold boot, but if the memory is left unpowered for very long, you will start to see memory corruption.&lt;br /&gt;
# figuring out the address to use in the bootloader, based on the address of __log_buf in System.map.  You will probably need to subtract the value of CONFIG_PAGE_OFFSET from the __log_buf address.  However, there may be other offsets present as well (such as TEXT_OFFSET).  Sometimes you can find the buffer by dumping the memory in a suspected area and locating the kernel messages visually in the dump.  Note that the mapping offset between the kernel map of memory and the bootloader map of memory should not change.  So once you figure it out you are set.&lt;br /&gt;
&lt;br /&gt;
Quinn Jensen writes:&lt;br /&gt;
&lt;br /&gt;
Something I've found handy when the console is silent is to dump the printk buffer from the boot loader.  To do it you have to know how your boot loader maps memory compared to the kernel.&lt;br /&gt;
&lt;br /&gt;
==== Redboot example on a Freescale ADS board ====&lt;br /&gt;
Quinn says: Here's what I do with Redboot on i.MX31:&lt;br /&gt;
&lt;br /&gt;
 fgrep printk_buf System.map&lt;br /&gt;
&lt;br /&gt;
this shows the linked address of the printk_buf, e.g.:&lt;br /&gt;
&lt;br /&gt;
 c02338f0 b printk_buf.16194&lt;br /&gt;
&lt;br /&gt;
The address &amp;quot;c02338f0&amp;quot; is in kernel virtual, which, in the case of i.MX31 ADS, redboot will have mapped to 0x802338f0.  So, after resetting the target board, but without letting it try to boot again, at the redboot prompt:&lt;br /&gt;
&lt;br /&gt;
 dump -b 0x802338f0 -l 10000&lt;br /&gt;
&lt;br /&gt;
And you see the printk buffer that never got flushed to the UART.  Knowing what's there can be '''very''' useful in debugging your console.&lt;br /&gt;
&lt;br /&gt;
==== U-boot example on an OMAP OSK board ====&lt;br /&gt;
Tim Bird tried these steps and they worked:&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf System.map&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf /proc/kallsyms&lt;br /&gt;
&lt;br /&gt;
These show:&lt;br /&gt;
&lt;br /&gt;
 c0352d88 B __log_buf&lt;br /&gt;
&lt;br /&gt;
In the case of the OSK, this address maps to 0x10352d88.  So I reset the target board and use the following:&lt;br /&gt;
&lt;br /&gt;
 OMAP5912 OSK # md 10352d88&lt;br /&gt;
 10352d88: 4c3e353c 78756e69 72657620 6e6f6973    &amp;lt;5&amp;gt;Linux version&lt;br /&gt;
 10352d98: 362e3220 2e32322e 612d3631 6e5f706c     2.6.22.16-alp_n&lt;br /&gt;
 10352da8: 7428206c 64726962 6d697440 6b736564    l (tbird@timdesk&lt;br /&gt;
 10352db8: 2e6d612e 796e6f73 6d6f632e 67282029    .am.sony.com) (g&lt;br /&gt;
 10352dc8: 76206363 69737265 33206e6f 342e342e    cc version 3.4.4&lt;br /&gt;
 10352dd8: 34232029 45525020 54504d45 65755420    ) #4 PREEMPT Tue&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Grub also supports a dump command which you can invoke from the grub prompt.&lt;br /&gt;
 dump  [ -s offset ] [-n length] { FILE | (mem) }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using CONFIG_DEBUG_LL and printascii() (ARM only) ===&lt;br /&gt;
If the kernel fails before the serial console is enabled, you can use CONFIG_DEBUG_LL to add extra debug output routines to the kernel.  These are printascii, printch and printhex. These routines print directly to the serial port, bypassing the console code, and are available earlier in machine initialization.&lt;br /&gt;
&lt;br /&gt;
Here is an e-mail exchange seen on the linux-embedded mailing list (with answer by George Davis):[http://www.mail-archive.com/linux-embedded@vger.kernel.org/msg00223.html] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; When we try to boot a 2.6.21 kernel after uncompressing the kernel the boot process dies somehow.&lt;br /&gt;
&amp;gt; We've figured out so far that the kernel dies somewhere between the gunzip and start_kernel.&lt;br /&gt;
&lt;br /&gt;
Try enabling DEBUG_LL to see if it's an machine ID error.  If you see:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported processor variant.&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported machine ID...&lt;br /&gt;
&lt;br /&gt;
Then you either don't have proper processor support enabled for your target or your bootloader is passing in the wrong machine number.&lt;br /&gt;
&lt;br /&gt;
If you still don't see anything, try hacking printk.c to call printascii() (enabled for the DEBUG_LL case) to print directly to the serial port w/o a driver, etc.,.  You can find more details on these low-level debugging hacks via a little googling...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg / Clearing the buffer ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
You can also specify an argument on the kernel command line to enable this, or&lt;br /&gt;
you can enable it any time at runtime by doing the following:&lt;br /&gt;
&lt;br /&gt;
  $echo 1 &amp;gt;/sys/module/printk/parameters/time&lt;br /&gt;
&lt;br /&gt;
Also, there are tools available to use the information to show relative times&lt;br /&gt;
between printks (scripts/show_delta) and create graphs of durations in the&lt;br /&gt;
kernel (scripts/bootgraph.pl)&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more details&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
== Disabling printk messages at compile time ==&lt;br /&gt;
There is a configuration option which allows you to turn off all the printk messages in the&lt;br /&gt;
whole kernel (''CONFIG_PRINTK'').  This reduces the size the kernel, usually by at least 100k, &lt;br /&gt;
since all message strings are not compiled into the kernel binary image.  &lt;br /&gt;
&lt;br /&gt;
However, it also means you get absolutely no output from the kernel while it is running.  Disabling kernel&lt;br /&gt;
printk messages is usually the last thing you do when you are tuning your kernel for size.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [http://lwn.net/Articles/487437/ LWN.net: The perils of pr_info()]&lt;br /&gt;
* [http://www.ibm.com/developerworks/linux/library/l-kernel-logging-apis/index.html Kernel logging: APIs and implementation, Tim Jones (for IBM)] (nice article)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some page related to printk:&lt;br /&gt;
* [[Printk Times]] - has information about how to turn on timestamps for each printk message&lt;br /&gt;
** [[Printk_Times_Sample_4| printk time stamps sample]]&lt;br /&gt;
* [[Printk_Size_Info|printk size information]]&lt;br /&gt;
* [[Do Printk]] - has information about a method of disabling printk messages on a per-module basis&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-04-03T21:17:24Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Printk was consolidated with Debugging_by_printing - so can be removed&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Most of the conversion specifiers supported by the user-space library routine printf() are also available in the kernel; there are some notable additions, including &amp;quot;%pf&amp;quot;, which will print the symbol name in place of the numeric pointer value, if available.&lt;br /&gt;
&lt;br /&gt;
The supported format strings are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CONT&lt;br /&gt;
|&amp;quot;&amp;lt;c&amp;gt;&amp;quot;&lt;br /&gt;
|&amp;quot;continued&amp;quot; line of log printout (only done after a line that had no enclosing \n) [http://lwn.net/Articles/252651/]&lt;br /&gt;
|pr_cont&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''KERN_CONT'' and ''pr_cont'' are special cases since they do not specify an urgency but rather indicate a 'continued message' e.g.:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;Doing something was &amp;quot;);&lt;br /&gt;
 /* &amp;lt;100 lines of whatever&amp;gt;*/&lt;br /&gt;
 if (success)&lt;br /&gt;
    printk(KERN_CONT &amp;quot;successful\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
    printk(KERN_CONT &amp;quot;NOT successful\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
 -&amp;gt; &amp;quot;Doing something was successful&amp;quot;&lt;br /&gt;
'''Important Note:''' ''KERN_CONT'' and ''pr_cont'' should only be used by core/arch code during early bootup (a continued line is not SMP-safe otherwise).[http://lwn.net/Articles/252651/]&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
=== Accessing the printk buffer after a silent hang on boot ===&lt;br /&gt;
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang.  However, there may still be messages in the printk buffer, which can give you an idea of where the problem is.&lt;br /&gt;
&lt;br /&gt;
The kernel starts putting messages into the printk buffer as soon as it starts.  They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices).  Even though these messages are not printed before the hang, it is still possible in some circumstances&lt;br /&gt;
to dump the printk buffer and see the messages.&lt;br /&gt;
&lt;br /&gt;
The tricky parts of doing this are:&lt;br /&gt;
&lt;br /&gt;
# using a warm reset (if possible) so the memory contents are not lost when transitioning from the stuck kernel to the bootloader.  You ''can'' do a cold boot, but if the memory is left unpowered for very long, you will start to see memory corruption.&lt;br /&gt;
# figuring out the address to use in the bootloader, based on the address of __log_buf in System.map.  You will probably need to subtract the value of CONFIG_PAGE_OFFSET from the __log_buf address.  However, there may be other offsets present as well (such as TEXT_OFFSET).  Sometimes you can find the buffer by dumping the memory in a suspected area and locating the kernel messages visually in the dump.  Note that the mapping offset between the kernel map of memory and the bootloader map of memory should not change.  So once you figure it out you are set.&lt;br /&gt;
&lt;br /&gt;
Quinn Jensen writes:&lt;br /&gt;
&lt;br /&gt;
Something I've found handy when the console is silent is to dump the printk buffer from the boot loader.  To do it you have to know how your boot loader maps memory compared to the kernel.&lt;br /&gt;
&lt;br /&gt;
==== Redboot example on a Freescale ADS board ====&lt;br /&gt;
Quinn says: Here's what I do with Redboot on i.MX31:&lt;br /&gt;
&lt;br /&gt;
 fgrep printk_buf System.map&lt;br /&gt;
&lt;br /&gt;
this shows the linked address of the printk_buf, e.g.:&lt;br /&gt;
&lt;br /&gt;
 c02338f0 b printk_buf.16194&lt;br /&gt;
&lt;br /&gt;
The address &amp;quot;c02338f0&amp;quot; is in kernel virtual, which, in the case of i.MX31 ADS, redboot will have mapped to 0x802338f0.  So, after resetting the target board, but without letting it try to boot again, at the redboot prompt:&lt;br /&gt;
&lt;br /&gt;
 dump -b 0x802338f0 -l 10000&lt;br /&gt;
&lt;br /&gt;
And you see the printk buffer that never got flushed to the UART.  Knowing what's there can be '''very''' useful in debugging your console.&lt;br /&gt;
&lt;br /&gt;
==== U-boot example on an OMAP OSK board ====&lt;br /&gt;
Tim Bird tried these steps and they worked:&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf System.map&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf /proc/kallsyms&lt;br /&gt;
&lt;br /&gt;
These show:&lt;br /&gt;
&lt;br /&gt;
 c0352d88 B __log_buf&lt;br /&gt;
&lt;br /&gt;
In the case of the OSK, this address maps to 0x10352d88.  So I reset the target board and use the following:&lt;br /&gt;
&lt;br /&gt;
 OMAP5912 OSK # md 10352d88&lt;br /&gt;
 10352d88: 4c3e353c 78756e69 72657620 6e6f6973    &amp;lt;5&amp;gt;Linux version&lt;br /&gt;
 10352d98: 362e3220 2e32322e 612d3631 6e5f706c     2.6.22.16-alp_n&lt;br /&gt;
 10352da8: 7428206c 64726962 6d697440 6b736564    l (tbird@timdesk&lt;br /&gt;
 10352db8: 2e6d612e 796e6f73 6d6f632e 67282029    .am.sony.com) (g&lt;br /&gt;
 10352dc8: 76206363 69737265 33206e6f 342e342e    cc version 3.4.4&lt;br /&gt;
 10352dd8: 34232029 45525020 54504d45 65755420    ) #4 PREEMPT Tue&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Grub also supports a dump command which you can invoke from the grub prompt.&lt;br /&gt;
 dump  [ -s offset ] [-n length] { FILE | (mem) }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using CONFIG_DEBUG_LL and printascii() (ARM only) ===&lt;br /&gt;
If the kernel fails before the serial console is enabled, you can use CONFIG_DEBUG_LL to add extra debug output routines to the kernel.  These are printascii, printch and printhex. These routines print directly to the serial port, bypassing the console code, and are available earlier in machine initialization.&lt;br /&gt;
&lt;br /&gt;
Here is an e-mail exchange seen on the linux-embedded mailing list (with answer by George Davis):[http://www.mail-archive.com/linux-embedded@vger.kernel.org/msg00223.html] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; When we try to boot a 2.6.21 kernel after uncompressing the kernel the boot process dies somehow.&lt;br /&gt;
&amp;gt; We've figured out so far that the kernel dies somewhere between the gunzip and start_kernel.&lt;br /&gt;
&lt;br /&gt;
Try enabling DEBUG_LL to see if it's an machine ID error.  If you see:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported processor variant.&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported machine ID...&lt;br /&gt;
&lt;br /&gt;
Then you either don't have proper processor support enabled for your target or your bootloader is passing in the wrong machine number.&lt;br /&gt;
&lt;br /&gt;
If you still don't see anything, try hacking printk.c to call printascii() (enabled for the DEBUG_LL case) to print directly to the serial port w/o a driver, etc.,.  You can find more details on these low-level debugging hacks via a little googling...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
You can also specify an argument on the kernel command line to enable this, or&lt;br /&gt;
you can enable it any time at runtime by doing the following:&lt;br /&gt;
&lt;br /&gt;
  $echo 1 &amp;gt;/sys/module/printk/parameters/time&lt;br /&gt;
&lt;br /&gt;
Also, there are tools available to use the information to show relative times&lt;br /&gt;
between printks (scripts/show_delta) and create graphs of durations in the&lt;br /&gt;
kernel (scripts/bootgraph.pl)&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more details&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
== Disabling printk messages at compile time ==&lt;br /&gt;
There is a configuration option which allows you to turn off all the printk messages in the&lt;br /&gt;
whole kernel (''CONFIG_PRINTK'').  This reduces the size the kernel, usually by at least 100k, &lt;br /&gt;
since all message strings are not compiled into the kernel binary image.  &lt;br /&gt;
&lt;br /&gt;
However, it also means you get absolutely no output from the kernel while it is running.  Disabling kernel&lt;br /&gt;
printk messages is usually the last thing you do when you are tuning your kernel for size.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [http://lwn.net/Articles/487437/ LWN.net: The perils of pr_info()]&lt;br /&gt;
* [http://www.ibm.com/developerworks/linux/library/l-kernel-logging-apis/index.html Kernel logging: APIs and implementation, Tim Jones (for IBM)] (nice article)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some page related to printk:&lt;br /&gt;
* [[Printk Times]] - has information about how to turn on timestamps for each printk message&lt;br /&gt;
** [[Printk_Times_Sample_4| printk time stamps sample]]&lt;br /&gt;
* [[Printk_Size_Info|printk size information]]&lt;br /&gt;
* [[Do Printk]] - has information about a method of disabling printk messages on a per-module basis&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_Portal</id>
		<title>Debugging Portal</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_Portal"/>
				<updated>2012-04-03T21:16:29Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Since printk and Debugging by printing are consolidated move both into one line&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is the new portal for all debugging related stuff.&lt;br /&gt;
It currently deals with Kernel topics, but feel free to add user space debugging too.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width=100%; background:#FFF;&amp;quot;&amp;gt;&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;5&amp;quot; cellpadding=&amp;quot;0&amp;quot; valign=&amp;quot;top&amp;quot; style=&amp;quot;background:inherit;&amp;quot;&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;margin: 0 0 0.5em 1em; border:1px solid #aaa; text-align:left; width: 50%;&amp;quot; cellpadding=&amp;quot;5&amp;quot;  |&lt;br /&gt;
&amp;lt;div style=&amp;quot;background: #eeeeee; border: 1px solid #2C547A; padding: 5px; margin: 3px; font-weight:bold;text-align:center;font-size:120%;&amp;quot;&amp;gt;Kernel Debugging&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0 0 1em;&amp;quot;&amp;gt;&lt;br /&gt;
;[[Debugging by printing]] / [[Printk]]&lt;br /&gt;
;[[Kernel Debugging Tips]]&lt;br /&gt;
;[[Kgdb]]&lt;br /&gt;
;[[KDB]]&lt;br /&gt;
;[[Debugging The Linux Kernel Using Gdb]]&lt;br /&gt;
;[[MagicSysRq]]&lt;br /&gt;
;External Links:&lt;br /&gt;
*[http://tree.celinuxforum.org/CelfPubWiki/ELC2009Presentations?action=AttachFile&amp;amp;do=get&amp;amp;target=DebuggingWithJtagCelf2009.pdf Embedded Linux JTAG debugging (CELF presentation)]&lt;br /&gt;
*[http://issaris.blogspot.com/2007/12/download-linux-kernel-sourcecode-from.html Debugging the Linux kernel using Eclipse/CDT and Qemu]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;margin: 0 0 0.5em 1em; border:1px solid #aaa; text-align:left; width: 50%;&amp;quot; cellpadding=&amp;quot;5&amp;quot;|&lt;br /&gt;
&amp;lt;div style=&amp;quot;background: #eeeeee; border: 1px solid #2C547A; padding: 5px; margin: 3px; font-weight:bold;text-align:center;font-size:120%;&amp;quot;&amp;gt;Kernel Tracing and Profiling&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0 0 1em;&amp;quot;&amp;gt;&lt;br /&gt;
;[[System Tap]]&lt;br /&gt;
;[[Kernel Trace Systems]]&lt;br /&gt;
;[[Linux Trace Toolkit]]&lt;br /&gt;
;[[LTTng]]&lt;br /&gt;
;[[Ftrace]]&lt;br /&gt;
*[[Measuring Function Duration with FTrace]]&lt;br /&gt;
*[[Ftrace Function Graph ARM]]&lt;br /&gt;
;[[Using Kernel Function Trace]]&lt;br /&gt;
;[[Linux Kernel State Tracer]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Printk</id>
		<title>Printk</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Printk"/>
				<updated>2012-04-03T21:15:16Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Consolidated with Debugging_by_printing&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Debugging_by_printing]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-04-03T21:14:15Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Moved / Added section about other printk pages here&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Most of the conversion specifiers supported by the user-space library routine printf() are also available in the kernel; there are some notable additions, including &amp;quot;%pf&amp;quot;, which will print the symbol name in place of the numeric pointer value, if available.&lt;br /&gt;
&lt;br /&gt;
The supported format strings are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CONT&lt;br /&gt;
|&amp;quot;&amp;lt;c&amp;gt;&amp;quot;&lt;br /&gt;
|&amp;quot;continued&amp;quot; line of log printout (only done after a line that had no enclosing \n) [http://lwn.net/Articles/252651/]&lt;br /&gt;
|pr_cont&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''KERN_CONT'' and ''pr_cont'' are special cases since they do not specify an urgency but rather indicate a 'continued message' e.g.:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;Doing something was &amp;quot;);&lt;br /&gt;
 /* &amp;lt;100 lines of whatever&amp;gt;*/&lt;br /&gt;
 if (success)&lt;br /&gt;
    printk(KERN_CONT &amp;quot;successful\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
    printk(KERN_CONT &amp;quot;NOT successful\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
 -&amp;gt; &amp;quot;Doing something was successful&amp;quot;&lt;br /&gt;
'''Important Note:''' ''KERN_CONT'' and ''pr_cont'' should only be used by core/arch code during early bootup (a continued line is not SMP-safe otherwise).[http://lwn.net/Articles/252651/]&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
=== Accessing the printk buffer after a silent hang on boot ===&lt;br /&gt;
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang.  However, there may still be messages in the printk buffer, which can give you an idea of where the problem is.&lt;br /&gt;
&lt;br /&gt;
The kernel starts putting messages into the printk buffer as soon as it starts.  They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices).  Even though these messages are not printed before the hang, it is still possible in some circumstances&lt;br /&gt;
to dump the printk buffer and see the messages.&lt;br /&gt;
&lt;br /&gt;
The tricky parts of doing this are:&lt;br /&gt;
&lt;br /&gt;
# using a warm reset (if possible) so the memory contents are not lost when transitioning from the stuck kernel to the bootloader.  You ''can'' do a cold boot, but if the memory is left unpowered for very long, you will start to see memory corruption.&lt;br /&gt;
# figuring out the address to use in the bootloader, based on the address of __log_buf in System.map.  You will probably need to subtract the value of CONFIG_PAGE_OFFSET from the __log_buf address.  However, there may be other offsets present as well (such as TEXT_OFFSET).  Sometimes you can find the buffer by dumping the memory in a suspected area and locating the kernel messages visually in the dump.  Note that the mapping offset between the kernel map of memory and the bootloader map of memory should not change.  So once you figure it out you are set.&lt;br /&gt;
&lt;br /&gt;
Quinn Jensen writes:&lt;br /&gt;
&lt;br /&gt;
Something I've found handy when the console is silent is to dump the printk buffer from the boot loader.  To do it you have to know how your boot loader maps memory compared to the kernel.&lt;br /&gt;
&lt;br /&gt;
==== Redboot example on a Freescale ADS board ====&lt;br /&gt;
Quinn says: Here's what I do with Redboot on i.MX31:&lt;br /&gt;
&lt;br /&gt;
 fgrep printk_buf System.map&lt;br /&gt;
&lt;br /&gt;
this shows the linked address of the printk_buf, e.g.:&lt;br /&gt;
&lt;br /&gt;
 c02338f0 b printk_buf.16194&lt;br /&gt;
&lt;br /&gt;
The address &amp;quot;c02338f0&amp;quot; is in kernel virtual, which, in the case of i.MX31 ADS, redboot will have mapped to 0x802338f0.  So, after resetting the target board, but without letting it try to boot again, at the redboot prompt:&lt;br /&gt;
&lt;br /&gt;
 dump -b 0x802338f0 -l 10000&lt;br /&gt;
&lt;br /&gt;
And you see the printk buffer that never got flushed to the UART.  Knowing what's there can be '''very''' useful in debugging your console.&lt;br /&gt;
&lt;br /&gt;
==== U-boot example on an OMAP OSK board ====&lt;br /&gt;
Tim Bird tried these steps and they worked:&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf System.map&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf /proc/kallsyms&lt;br /&gt;
&lt;br /&gt;
These show:&lt;br /&gt;
&lt;br /&gt;
 c0352d88 B __log_buf&lt;br /&gt;
&lt;br /&gt;
In the case of the OSK, this address maps to 0x10352d88.  So I reset the target board and use the following:&lt;br /&gt;
&lt;br /&gt;
 OMAP5912 OSK # md 10352d88&lt;br /&gt;
 10352d88: 4c3e353c 78756e69 72657620 6e6f6973    &amp;lt;5&amp;gt;Linux version&lt;br /&gt;
 10352d98: 362e3220 2e32322e 612d3631 6e5f706c     2.6.22.16-alp_n&lt;br /&gt;
 10352da8: 7428206c 64726962 6d697440 6b736564    l (tbird@timdesk&lt;br /&gt;
 10352db8: 2e6d612e 796e6f73 6d6f632e 67282029    .am.sony.com) (g&lt;br /&gt;
 10352dc8: 76206363 69737265 33206e6f 342e342e    cc version 3.4.4&lt;br /&gt;
 10352dd8: 34232029 45525020 54504d45 65755420    ) #4 PREEMPT Tue&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Grub also supports a dump command which you can invoke from the grub prompt.&lt;br /&gt;
 dump  [ -s offset ] [-n length] { FILE | (mem) }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using CONFIG_DEBUG_LL and printascii() (ARM only) ===&lt;br /&gt;
If the kernel fails before the serial console is enabled, you can use CONFIG_DEBUG_LL to add extra debug output routines to the kernel.  These are printascii, printch and printhex. These routines print directly to the serial port, bypassing the console code, and are available earlier in machine initialization.&lt;br /&gt;
&lt;br /&gt;
Here is an e-mail exchange seen on the linux-embedded mailing list (with answer by George Davis):[http://www.mail-archive.com/linux-embedded@vger.kernel.org/msg00223.html] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; When we try to boot a 2.6.21 kernel after uncompressing the kernel the boot process dies somehow.&lt;br /&gt;
&amp;gt; We've figured out so far that the kernel dies somewhere between the gunzip and start_kernel.&lt;br /&gt;
&lt;br /&gt;
Try enabling DEBUG_LL to see if it's an machine ID error.  If you see:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported processor variant.&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported machine ID...&lt;br /&gt;
&lt;br /&gt;
Then you either don't have proper processor support enabled for your target or your bootloader is passing in the wrong machine number.&lt;br /&gt;
&lt;br /&gt;
If you still don't see anything, try hacking printk.c to call printascii() (enabled for the DEBUG_LL case) to print directly to the serial port w/o a driver, etc.,.  You can find more details on these low-level debugging hacks via a little googling...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
You can also specify an argument on the kernel command line to enable this, or&lt;br /&gt;
you can enable it any time at runtime by doing the following:&lt;br /&gt;
&lt;br /&gt;
  $echo 1 &amp;gt;/sys/module/printk/parameters/time&lt;br /&gt;
&lt;br /&gt;
Also, there are tools available to use the information to show relative times&lt;br /&gt;
between printks (scripts/show_delta) and create graphs of durations in the&lt;br /&gt;
kernel (scripts/bootgraph.pl)&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more details&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
== Disabling printk messages at compile time ==&lt;br /&gt;
There is a configuration option which allows you to turn off all the printk messages in the&lt;br /&gt;
whole kernel (''CONFIG_PRINTK'').  This reduces the size the kernel, usually by at least 100k, &lt;br /&gt;
since all message strings are not compiled into the kernel binary image.  &lt;br /&gt;
&lt;br /&gt;
However, it also means you get absolutely no output from the kernel while it is running.  Disabling kernel&lt;br /&gt;
printk messages is usually the last thing you do when you are tuning your kernel for size.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [[Printk]]&lt;br /&gt;
* [http://lwn.net/Articles/487437/ LWN.net: The perils of pr_info()]&lt;br /&gt;
* [http://www.ibm.com/developerworks/linux/library/l-kernel-logging-apis/index.html Kernel logging: APIs and implementation, Tim Jones (for IBM)] (nice article)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some page related to printk:&lt;br /&gt;
* [[Printk Times]] - has information about how to turn on timestamps for each printk message&lt;br /&gt;
** [[Printk_Times_Sample_4| printk time stamps sample]]&lt;br /&gt;
* [[Printk_Size_Info|printk size information]]&lt;br /&gt;
* [[Do Printk]] - has information about a method of disabling printk messages on a per-module basis&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-04-03T21:12:27Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: /* Dynamic Debugging */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Most of the conversion specifiers supported by the user-space library routine printf() are also available in the kernel; there are some notable additions, including &amp;quot;%pf&amp;quot;, which will print the symbol name in place of the numeric pointer value, if available.&lt;br /&gt;
&lt;br /&gt;
The supported format strings are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CONT&lt;br /&gt;
|&amp;quot;&amp;lt;c&amp;gt;&amp;quot;&lt;br /&gt;
|&amp;quot;continued&amp;quot; line of log printout (only done after a line that had no enclosing \n) [http://lwn.net/Articles/252651/]&lt;br /&gt;
|pr_cont&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''KERN_CONT'' and ''pr_cont'' are special cases since they do not specify an urgency but rather indicate a 'continued message' e.g.:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;Doing something was &amp;quot;);&lt;br /&gt;
 /* &amp;lt;100 lines of whatever&amp;gt;*/&lt;br /&gt;
 if (success)&lt;br /&gt;
    printk(KERN_CONT &amp;quot;successful\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
    printk(KERN_CONT &amp;quot;NOT successful\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
 -&amp;gt; &amp;quot;Doing something was successful&amp;quot;&lt;br /&gt;
'''Important Note:''' ''KERN_CONT'' and ''pr_cont'' should only be used by core/arch code during early bootup (a continued line is not SMP-safe otherwise).[http://lwn.net/Articles/252651/]&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
=== Accessing the printk buffer after a silent hang on boot ===&lt;br /&gt;
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang.  However, there may still be messages in the printk buffer, which can give you an idea of where the problem is.&lt;br /&gt;
&lt;br /&gt;
The kernel starts putting messages into the printk buffer as soon as it starts.  They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices).  Even though these messages are not printed before the hang, it is still possible in some circumstances&lt;br /&gt;
to dump the printk buffer and see the messages.&lt;br /&gt;
&lt;br /&gt;
The tricky parts of doing this are:&lt;br /&gt;
&lt;br /&gt;
# using a warm reset (if possible) so the memory contents are not lost when transitioning from the stuck kernel to the bootloader.  You ''can'' do a cold boot, but if the memory is left unpowered for very long, you will start to see memory corruption.&lt;br /&gt;
# figuring out the address to use in the bootloader, based on the address of __log_buf in System.map.  You will probably need to subtract the value of CONFIG_PAGE_OFFSET from the __log_buf address.  However, there may be other offsets present as well (such as TEXT_OFFSET).  Sometimes you can find the buffer by dumping the memory in a suspected area and locating the kernel messages visually in the dump.  Note that the mapping offset between the kernel map of memory and the bootloader map of memory should not change.  So once you figure it out you are set.&lt;br /&gt;
&lt;br /&gt;
Quinn Jensen writes:&lt;br /&gt;
&lt;br /&gt;
Something I've found handy when the console is silent is to dump the printk buffer from the boot loader.  To do it you have to know how your boot loader maps memory compared to the kernel.&lt;br /&gt;
&lt;br /&gt;
==== Redboot example on a Freescale ADS board ====&lt;br /&gt;
Quinn says: Here's what I do with Redboot on i.MX31:&lt;br /&gt;
&lt;br /&gt;
 fgrep printk_buf System.map&lt;br /&gt;
&lt;br /&gt;
this shows the linked address of the printk_buf, e.g.:&lt;br /&gt;
&lt;br /&gt;
 c02338f0 b printk_buf.16194&lt;br /&gt;
&lt;br /&gt;
The address &amp;quot;c02338f0&amp;quot; is in kernel virtual, which, in the case of i.MX31 ADS, redboot will have mapped to 0x802338f0.  So, after resetting the target board, but without letting it try to boot again, at the redboot prompt:&lt;br /&gt;
&lt;br /&gt;
 dump -b 0x802338f0 -l 10000&lt;br /&gt;
&lt;br /&gt;
And you see the printk buffer that never got flushed to the UART.  Knowing what's there can be '''very''' useful in debugging your console.&lt;br /&gt;
&lt;br /&gt;
==== U-boot example on an OMAP OSK board ====&lt;br /&gt;
Tim Bird tried these steps and they worked:&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf System.map&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf /proc/kallsyms&lt;br /&gt;
&lt;br /&gt;
These show:&lt;br /&gt;
&lt;br /&gt;
 c0352d88 B __log_buf&lt;br /&gt;
&lt;br /&gt;
In the case of the OSK, this address maps to 0x10352d88.  So I reset the target board and use the following:&lt;br /&gt;
&lt;br /&gt;
 OMAP5912 OSK # md 10352d88&lt;br /&gt;
 10352d88: 4c3e353c 78756e69 72657620 6e6f6973    &amp;lt;5&amp;gt;Linux version&lt;br /&gt;
 10352d98: 362e3220 2e32322e 612d3631 6e5f706c     2.6.22.16-alp_n&lt;br /&gt;
 10352da8: 7428206c 64726962 6d697440 6b736564    l (tbird@timdesk&lt;br /&gt;
 10352db8: 2e6d612e 796e6f73 6d6f632e 67282029    .am.sony.com) (g&lt;br /&gt;
 10352dc8: 76206363 69737265 33206e6f 342e342e    cc version 3.4.4&lt;br /&gt;
 10352dd8: 34232029 45525020 54504d45 65755420    ) #4 PREEMPT Tue&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Grub also supports a dump command which you can invoke from the grub prompt.&lt;br /&gt;
 dump  [ -s offset ] [-n length] { FILE | (mem) }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using CONFIG_DEBUG_LL and printascii() (ARM only) ===&lt;br /&gt;
If the kernel fails before the serial console is enabled, you can use CONFIG_DEBUG_LL to add extra debug output routines to the kernel.  These are printascii, printch and printhex. These routines print directly to the serial port, bypassing the console code, and are available earlier in machine initialization.&lt;br /&gt;
&lt;br /&gt;
Here is an e-mail exchange seen on the linux-embedded mailing list (with answer by George Davis):[http://www.mail-archive.com/linux-embedded@vger.kernel.org/msg00223.html] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; When we try to boot a 2.6.21 kernel after uncompressing the kernel the boot process dies somehow.&lt;br /&gt;
&amp;gt; We've figured out so far that the kernel dies somewhere between the gunzip and start_kernel.&lt;br /&gt;
&lt;br /&gt;
Try enabling DEBUG_LL to see if it's an machine ID error.  If you see:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported processor variant.&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported machine ID...&lt;br /&gt;
&lt;br /&gt;
Then you either don't have proper processor support enabled for your target or your bootloader is passing in the wrong machine number.&lt;br /&gt;
&lt;br /&gt;
If you still don't see anything, try hacking printk.c to call printascii() (enabled for the DEBUG_LL case) to print directly to the serial port w/o a driver, etc.,.  You can find more details on these low-level debugging hacks via a little googling...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
You can also specify an argument on the kernel command line to enable this, or&lt;br /&gt;
you can enable it any time at runtime by doing the following:&lt;br /&gt;
&lt;br /&gt;
  $echo 1 &amp;gt;/sys/module/printk/parameters/time&lt;br /&gt;
&lt;br /&gt;
Also, there are tools available to use the information to show relative times&lt;br /&gt;
between printks (scripts/show_delta) and create graphs of durations in the&lt;br /&gt;
kernel (scripts/bootgraph.pl)&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more details&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
== Disabling printk messages at compile time ==&lt;br /&gt;
There is a configuration option which allows you to turn off all the printk messages in the&lt;br /&gt;
whole kernel (''CONFIG_PRINTK'').  This reduces the size the kernel, usually by at least 100k, &lt;br /&gt;
since all message strings are not compiled into the kernel binary image.  &lt;br /&gt;
&lt;br /&gt;
However, it also means you get absolutely no output from the kernel while it is running.  Disabling kernel&lt;br /&gt;
printk messages is usually the last thing you do when you are tuning your kernel for size.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [[Printk]]&lt;br /&gt;
* [http://lwn.net/Articles/487437/ LWN.net: The perils of pr_info()]&lt;br /&gt;
* [http://www.ibm.com/developerworks/linux/library/l-kernel-logging-apis/index.html Kernel logging: APIs and implementation, Tim Jones (for IBM)] (nice article)&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-04-03T21:11:22Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Added / moved section about disabling the messages&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Most of the conversion specifiers supported by the user-space library routine printf() are also available in the kernel; there are some notable additions, including &amp;quot;%pf&amp;quot;, which will print the symbol name in place of the numeric pointer value, if available.&lt;br /&gt;
&lt;br /&gt;
The supported format strings are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CONT&lt;br /&gt;
|&amp;quot;&amp;lt;c&amp;gt;&amp;quot;&lt;br /&gt;
|&amp;quot;continued&amp;quot; line of log printout (only done after a line that had no enclosing \n) [http://lwn.net/Articles/252651/]&lt;br /&gt;
|pr_cont&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''KERN_CONT'' and ''pr_cont'' are special cases since they do not specify an urgency but rather indicate a 'continued message' e.g.:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;Doing something was &amp;quot;);&lt;br /&gt;
 /* &amp;lt;100 lines of whatever&amp;gt;*/&lt;br /&gt;
 if (success)&lt;br /&gt;
    printk(KERN_CONT &amp;quot;successful\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
    printk(KERN_CONT &amp;quot;NOT successful\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
 -&amp;gt; &amp;quot;Doing something was successful&amp;quot;&lt;br /&gt;
'''Important Note:''' ''KERN_CONT'' and ''pr_cont'' should only be used by core/arch code during early bootup (a continued line is not SMP-safe otherwise).[http://lwn.net/Articles/252651/]&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
=== Accessing the printk buffer after a silent hang on boot ===&lt;br /&gt;
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang.  However, there may still be messages in the printk buffer, which can give you an idea of where the problem is.&lt;br /&gt;
&lt;br /&gt;
The kernel starts putting messages into the printk buffer as soon as it starts.  They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices).  Even though these messages are not printed before the hang, it is still possible in some circumstances&lt;br /&gt;
to dump the printk buffer and see the messages.&lt;br /&gt;
&lt;br /&gt;
The tricky parts of doing this are:&lt;br /&gt;
&lt;br /&gt;
# using a warm reset (if possible) so the memory contents are not lost when transitioning from the stuck kernel to the bootloader.  You ''can'' do a cold boot, but if the memory is left unpowered for very long, you will start to see memory corruption.&lt;br /&gt;
# figuring out the address to use in the bootloader, based on the address of __log_buf in System.map.  You will probably need to subtract the value of CONFIG_PAGE_OFFSET from the __log_buf address.  However, there may be other offsets present as well (such as TEXT_OFFSET).  Sometimes you can find the buffer by dumping the memory in a suspected area and locating the kernel messages visually in the dump.  Note that the mapping offset between the kernel map of memory and the bootloader map of memory should not change.  So once you figure it out you are set.&lt;br /&gt;
&lt;br /&gt;
Quinn Jensen writes:&lt;br /&gt;
&lt;br /&gt;
Something I've found handy when the console is silent is to dump the printk buffer from the boot loader.  To do it you have to know how your boot loader maps memory compared to the kernel.&lt;br /&gt;
&lt;br /&gt;
==== Redboot example on a Freescale ADS board ====&lt;br /&gt;
Quinn says: Here's what I do with Redboot on i.MX31:&lt;br /&gt;
&lt;br /&gt;
 fgrep printk_buf System.map&lt;br /&gt;
&lt;br /&gt;
this shows the linked address of the printk_buf, e.g.:&lt;br /&gt;
&lt;br /&gt;
 c02338f0 b printk_buf.16194&lt;br /&gt;
&lt;br /&gt;
The address &amp;quot;c02338f0&amp;quot; is in kernel virtual, which, in the case of i.MX31 ADS, redboot will have mapped to 0x802338f0.  So, after resetting the target board, but without letting it try to boot again, at the redboot prompt:&lt;br /&gt;
&lt;br /&gt;
 dump -b 0x802338f0 -l 10000&lt;br /&gt;
&lt;br /&gt;
And you see the printk buffer that never got flushed to the UART.  Knowing what's there can be '''very''' useful in debugging your console.&lt;br /&gt;
&lt;br /&gt;
==== U-boot example on an OMAP OSK board ====&lt;br /&gt;
Tim Bird tried these steps and they worked:&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf System.map&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf /proc/kallsyms&lt;br /&gt;
&lt;br /&gt;
These show:&lt;br /&gt;
&lt;br /&gt;
 c0352d88 B __log_buf&lt;br /&gt;
&lt;br /&gt;
In the case of the OSK, this address maps to 0x10352d88.  So I reset the target board and use the following:&lt;br /&gt;
&lt;br /&gt;
 OMAP5912 OSK # md 10352d88&lt;br /&gt;
 10352d88: 4c3e353c 78756e69 72657620 6e6f6973    &amp;lt;5&amp;gt;Linux version&lt;br /&gt;
 10352d98: 362e3220 2e32322e 612d3631 6e5f706c     2.6.22.16-alp_n&lt;br /&gt;
 10352da8: 7428206c 64726962 6d697440 6b736564    l (tbird@timdesk&lt;br /&gt;
 10352db8: 2e6d612e 796e6f73 6d6f632e 67282029    .am.sony.com) (g&lt;br /&gt;
 10352dc8: 76206363 69737265 33206e6f 342e342e    cc version 3.4.4&lt;br /&gt;
 10352dd8: 34232029 45525020 54504d45 65755420    ) #4 PREEMPT Tue&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Grub also supports a dump command which you can invoke from the grub prompt.&lt;br /&gt;
 dump  [ -s offset ] [-n length] { FILE | (mem) }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using CONFIG_DEBUG_LL and printascii() (ARM only) ===&lt;br /&gt;
If the kernel fails before the serial console is enabled, you can use CONFIG_DEBUG_LL to add extra debug output routines to the kernel.  These are printascii, printch and printhex. These routines print directly to the serial port, bypassing the console code, and are available earlier in machine initialization.&lt;br /&gt;
&lt;br /&gt;
Here is an e-mail exchange seen on the linux-embedded mailing list (with answer by George Davis):[http://www.mail-archive.com/linux-embedded@vger.kernel.org/msg00223.html] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; When we try to boot a 2.6.21 kernel after uncompressing the kernel the boot process dies somehow.&lt;br /&gt;
&amp;gt; We've figured out so far that the kernel dies somewhere between the gunzip and start_kernel.&lt;br /&gt;
&lt;br /&gt;
Try enabling DEBUG_LL to see if it's an machine ID error.  If you see:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported processor variant.&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported machine ID...&lt;br /&gt;
&lt;br /&gt;
Then you either don't have proper processor support enabled for your target or your bootloader is passing in the wrong machine number.&lt;br /&gt;
&lt;br /&gt;
If you still don't see anything, try hacking printk.c to call printascii() (enabled for the DEBUG_LL case) to print directly to the serial port w/o a driver, etc.,.  You can find more details on these low-level debugging hacks via a little googling...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
You can also specify an argument on the kernel command line to enable this, or&lt;br /&gt;
you can enable it any time at runtime by doing the following:&lt;br /&gt;
&lt;br /&gt;
  $echo 1 &amp;gt;/sys/module/printk/parameters/time&lt;br /&gt;
&lt;br /&gt;
Also, there are tools available to use the information to show relative times&lt;br /&gt;
between printks (scripts/show_delta) and create graphs of durations in the&lt;br /&gt;
kernel (scripts/bootgraph.pl)&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more details&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Disabling printk messages at compile time ==&lt;br /&gt;
There is a configuration option which allows you to turn off all the printk messages in the&lt;br /&gt;
whole kernel (''CONFIG_PRINTK'').  This reduces the size the kernel, usually by at least 100k, &lt;br /&gt;
since all message strings are not compiled into the kernel binary image.  &lt;br /&gt;
&lt;br /&gt;
However, it also means you get absolutely no output from the kernel while it is running.  Disabling kernel&lt;br /&gt;
printk messages is usually the last thing you do when you are tuning your kernel for size.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [[Printk]]&lt;br /&gt;
* [http://lwn.net/Articles/487437/ LWN.net: The perils of pr_info()]&lt;br /&gt;
* [http://www.ibm.com/developerworks/linux/library/l-kernel-logging-apis/index.html Kernel logging: APIs and implementation, Tim Jones (for IBM)] (nice article)&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-04-03T21:08:07Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Most of the conversion specifiers supported by the user-space library routine printf() are also available in the kernel; there are some notable additions, including &amp;quot;%pf&amp;quot;, which will print the symbol name in place of the numeric pointer value, if available.&lt;br /&gt;
&lt;br /&gt;
The supported format strings are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CONT&lt;br /&gt;
|&amp;quot;&amp;lt;c&amp;gt;&amp;quot;&lt;br /&gt;
|&amp;quot;continued&amp;quot; line of log printout (only done after a line that had no enclosing \n) [http://lwn.net/Articles/252651/]&lt;br /&gt;
|pr_cont&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''KERN_CONT'' and ''pr_cont'' are special cases since they do not specify an urgency but rather indicate a 'continued message' e.g.:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;Doing something was &amp;quot;);&lt;br /&gt;
 /* &amp;lt;100 lines of whatever&amp;gt;*/&lt;br /&gt;
 if (success)&lt;br /&gt;
    printk(KERN_CONT &amp;quot;successful\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
    printk(KERN_CONT &amp;quot;NOT successful\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
 -&amp;gt; &amp;quot;Doing something was successful&amp;quot;&lt;br /&gt;
'''Important Note:''' ''KERN_CONT'' and ''pr_cont'' should only be used by core/arch code during early bootup (a continued line is not SMP-safe otherwise).[http://lwn.net/Articles/252651/]&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
=== Accessing the printk buffer after a silent hang on boot ===&lt;br /&gt;
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang.  However, there may still be messages in the printk buffer, which can give you an idea of where the problem is.&lt;br /&gt;
&lt;br /&gt;
The kernel starts putting messages into the printk buffer as soon as it starts.  They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices).  Even though these messages are not printed before the hang, it is still possible in some circumstances&lt;br /&gt;
to dump the printk buffer and see the messages.&lt;br /&gt;
&lt;br /&gt;
The tricky parts of doing this are:&lt;br /&gt;
&lt;br /&gt;
# using a warm reset (if possible) so the memory contents are not lost when transitioning from the stuck kernel to the bootloader.  You ''can'' do a cold boot, but if the memory is left unpowered for very long, you will start to see memory corruption.&lt;br /&gt;
# figuring out the address to use in the bootloader, based on the address of __log_buf in System.map.  You will probably need to subtract the value of CONFIG_PAGE_OFFSET from the __log_buf address.  However, there may be other offsets present as well (such as TEXT_OFFSET).  Sometimes you can find the buffer by dumping the memory in a suspected area and locating the kernel messages visually in the dump.  Note that the mapping offset between the kernel map of memory and the bootloader map of memory should not change.  So once you figure it out you are set.&lt;br /&gt;
&lt;br /&gt;
Quinn Jensen writes:&lt;br /&gt;
&lt;br /&gt;
Something I've found handy when the console is silent is to dump the printk buffer from the boot loader.  To do it you have to know how your boot loader maps memory compared to the kernel.&lt;br /&gt;
&lt;br /&gt;
==== Redboot example on a Freescale ADS board ====&lt;br /&gt;
Quinn says: Here's what I do with Redboot on i.MX31:&lt;br /&gt;
&lt;br /&gt;
 fgrep printk_buf System.map&lt;br /&gt;
&lt;br /&gt;
this shows the linked address of the printk_buf, e.g.:&lt;br /&gt;
&lt;br /&gt;
 c02338f0 b printk_buf.16194&lt;br /&gt;
&lt;br /&gt;
The address &amp;quot;c02338f0&amp;quot; is in kernel virtual, which, in the case of i.MX31 ADS, redboot will have mapped to 0x802338f0.  So, after resetting the target board, but without letting it try to boot again, at the redboot prompt:&lt;br /&gt;
&lt;br /&gt;
 dump -b 0x802338f0 -l 10000&lt;br /&gt;
&lt;br /&gt;
And you see the printk buffer that never got flushed to the UART.  Knowing what's there can be '''very''' useful in debugging your console.&lt;br /&gt;
&lt;br /&gt;
==== U-boot example on an OMAP OSK board ====&lt;br /&gt;
Tim Bird tried these steps and they worked:&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf System.map&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf /proc/kallsyms&lt;br /&gt;
&lt;br /&gt;
These show:&lt;br /&gt;
&lt;br /&gt;
 c0352d88 B __log_buf&lt;br /&gt;
&lt;br /&gt;
In the case of the OSK, this address maps to 0x10352d88.  So I reset the target board and use the following:&lt;br /&gt;
&lt;br /&gt;
 OMAP5912 OSK # md 10352d88&lt;br /&gt;
 10352d88: 4c3e353c 78756e69 72657620 6e6f6973    &amp;lt;5&amp;gt;Linux version&lt;br /&gt;
 10352d98: 362e3220 2e32322e 612d3631 6e5f706c     2.6.22.16-alp_n&lt;br /&gt;
 10352da8: 7428206c 64726962 6d697440 6b736564    l (tbird@timdesk&lt;br /&gt;
 10352db8: 2e6d612e 796e6f73 6d6f632e 67282029    .am.sony.com) (g&lt;br /&gt;
 10352dc8: 76206363 69737265 33206e6f 342e342e    cc version 3.4.4&lt;br /&gt;
 10352dd8: 34232029 45525020 54504d45 65755420    ) #4 PREEMPT Tue&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Grub also supports a dump command which you can invoke from the grub prompt.&lt;br /&gt;
 dump  [ -s offset ] [-n length] { FILE | (mem) }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using CONFIG_DEBUG_LL and printascii() (ARM only) ===&lt;br /&gt;
If the kernel fails before the serial console is enabled, you can use CONFIG_DEBUG_LL to add extra debug output routines to the kernel.  These are printascii, printch and printhex. These routines print directly to the serial port, bypassing the console code, and are available earlier in machine initialization.&lt;br /&gt;
&lt;br /&gt;
Here is an e-mail exchange seen on the linux-embedded mailing list (with answer by George Davis):[http://www.mail-archive.com/linux-embedded@vger.kernel.org/msg00223.html] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; When we try to boot a 2.6.21 kernel after uncompressing the kernel the boot process dies somehow.&lt;br /&gt;
&amp;gt; We've figured out so far that the kernel dies somewhere between the gunzip and start_kernel.&lt;br /&gt;
&lt;br /&gt;
Try enabling DEBUG_LL to see if it's an machine ID error.  If you see:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported processor variant.&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported machine ID...&lt;br /&gt;
&lt;br /&gt;
Then you either don't have proper processor support enabled for your target or your bootloader is passing in the wrong machine number.&lt;br /&gt;
&lt;br /&gt;
If you still don't see anything, try hacking printk.c to call printascii() (enabled for the DEBUG_LL case) to print directly to the serial port w/o a driver, etc.,.  You can find more details on these low-level debugging hacks via a little googling...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
You can also specify an argument on the kernel command line to enable this, or&lt;br /&gt;
you can enable it any time at runtime by doing the following:&lt;br /&gt;
&lt;br /&gt;
  $echo 1 &amp;gt;/sys/module/printk/parameters/time&lt;br /&gt;
&lt;br /&gt;
Also, there are tools available to use the information to show relative times&lt;br /&gt;
between printks (scripts/show_delta) and create graphs of durations in the&lt;br /&gt;
kernel (scripts/bootgraph.pl)&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more details&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [[Printk]]&lt;br /&gt;
* [http://lwn.net/Articles/487437/ LWN.net: The perils of pr_info()]&lt;br /&gt;
* [http://www.ibm.com/developerworks/linux/library/l-kernel-logging-apis/index.html Kernel logging: APIs and implementation, Tim Jones (for IBM)] (nice article)&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-04-03T21:07:47Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Added some stuff from [printk] here&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Most of the conversion specifiers supported by the user-space library routine printf() are also available in the kernel; there are some notable additions, including &amp;quot;%pf&amp;quot;, which will print the symbol name in place of the numeric pointer value, if available.&lt;br /&gt;
&lt;br /&gt;
The supported format strings are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CONT&lt;br /&gt;
|&amp;quot;&amp;lt;c&amp;gt;&amp;quot;&lt;br /&gt;
|&amp;quot;continued&amp;quot; line of log printout (only done after a line that had no enclosing \n) [http://lwn.net/Articles/252651/]&lt;br /&gt;
|pr_cont&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''KERN_CONT'' and ''pr_cont'' are special cases since they do not specify an urgency but rather indicate a 'continued message' e.g.:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;Doing something was &amp;quot;);&lt;br /&gt;
 /* &amp;lt;100 lines of whatever&amp;gt;*/&lt;br /&gt;
 if (success)&lt;br /&gt;
    printk(KERN_CONT &amp;quot;successful\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
    printk(KERN_CONT &amp;quot;NOT successful\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
 -&amp;gt; &amp;quot;Doing something was successful&amp;quot;&lt;br /&gt;
'''Important Note:''' ''KERN_CONT'' and ''pr_cont'' should only be used by core/arch code during early bootup (a continued line is not SMP-safe otherwise).[http://lwn.net/Articles/252651/]&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
=== Accessing the printk buffer after a silent hang on boot ===&lt;br /&gt;
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang.  However, there may still be messages in the printk buffer, which can give you an idea of where the problem is.&lt;br /&gt;
&lt;br /&gt;
The kernel starts putting messages into the printk buffer as soon as it starts.  They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices).  Even though these messages are not printed before the hang, it is still possible in some circumstances&lt;br /&gt;
to dump the printk buffer and see the messages.&lt;br /&gt;
&lt;br /&gt;
The tricky parts of doing this are:&lt;br /&gt;
&lt;br /&gt;
# using a warm reset (if possible) so the memory contents are not lost when transitioning from the stuck kernel to the bootloader.  You ''can'' do a cold boot, but if the memory is left unpowered for very long, you will start to see memory corruption.&lt;br /&gt;
# figuring out the address to use in the bootloader, based on the address of __log_buf in System.map.  You will probably need to subtract the value of CONFIG_PAGE_OFFSET from the __log_buf address.  However, there may be other offsets present as well (such as TEXT_OFFSET).  Sometimes you can find the buffer by dumping the memory in a suspected area and locating the kernel messages visually in the dump.  Note that the mapping offset between the kernel map of memory and the bootloader map of memory should not change.  So once you figure it out you are set.&lt;br /&gt;
&lt;br /&gt;
Quinn Jensen writes:&lt;br /&gt;
&lt;br /&gt;
Something I've found handy when the console is silent is to dump the printk buffer from the boot loader.  To do it you have to know how your boot loader maps memory compared to the kernel.&lt;br /&gt;
&lt;br /&gt;
==== Redboot example on a Freescale ADS board ====&lt;br /&gt;
Quinn says: Here's what I do with Redboot on i.MX31:&lt;br /&gt;
&lt;br /&gt;
 fgrep printk_buf System.map&lt;br /&gt;
&lt;br /&gt;
this shows the linked address of the printk_buf, e.g.:&lt;br /&gt;
&lt;br /&gt;
 c02338f0 b printk_buf.16194&lt;br /&gt;
&lt;br /&gt;
The address &amp;quot;c02338f0&amp;quot; is in kernel virtual, which, in the case of i.MX31 ADS, redboot will have mapped to 0x802338f0.  So, after resetting the target board, but without letting it try to boot again, at the redboot prompt:&lt;br /&gt;
&lt;br /&gt;
 dump -b 0x802338f0 -l 10000&lt;br /&gt;
&lt;br /&gt;
And you see the printk buffer that never got flushed to the UART.  Knowing what's there can be '''very''' useful in debugging your console.&lt;br /&gt;
&lt;br /&gt;
==== U-boot example on an OMAP OSK board ====&lt;br /&gt;
Tim Bird tried these steps and they worked:&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf System.map&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf /proc/kallsyms&lt;br /&gt;
&lt;br /&gt;
These show:&lt;br /&gt;
&lt;br /&gt;
 c0352d88 B __log_buf&lt;br /&gt;
&lt;br /&gt;
In the case of the OSK, this address maps to 0x10352d88.  So I reset the target board and use the following:&lt;br /&gt;
&lt;br /&gt;
 OMAP5912 OSK # md 10352d88&lt;br /&gt;
 10352d88: 4c3e353c 78756e69 72657620 6e6f6973    &amp;lt;5&amp;gt;Linux version&lt;br /&gt;
 10352d98: 362e3220 2e32322e 612d3631 6e5f706c     2.6.22.16-alp_n&lt;br /&gt;
 10352da8: 7428206c 64726962 6d697440 6b736564    l (tbird@timdesk&lt;br /&gt;
 10352db8: 2e6d612e 796e6f73 6d6f632e 67282029    .am.sony.com) (g&lt;br /&gt;
 10352dc8: 76206363 69737265 33206e6f 342e342e    cc version 3.4.4&lt;br /&gt;
 10352dd8: 34232029 45525020 54504d45 65755420    ) #4 PREEMPT Tue&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Grub also supports a dump command which you can invoke from the grub prompt.&lt;br /&gt;
 dump  [ -s offset ] [-n length] { FILE | (mem) }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using CONFIG_DEBUG_LL and printascii() (ARM only) ===&lt;br /&gt;
If the kernel fails before the serial console is enabled, you can use CONFIG_DEBUG_LL to add extra debug output routines to the kernel.  These are printascii, printch and printhex. These routines print directly to the serial port, bypassing the console code, and are available earlier in machine initialization.&lt;br /&gt;
&lt;br /&gt;
Here is an e-mail exchange seen on the linux-embedded mailing list (with answer by George Davis):[http://www.mail-archive.com/linux-embedded@vger.kernel.org/msg00223.html] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; When we try to boot a 2.6.21 kernel after uncompressing the kernel the boot process dies somehow.&lt;br /&gt;
&amp;gt; We've figured out so far that the kernel dies somewhere between the gunzip and start_kernel.&lt;br /&gt;
&lt;br /&gt;
Try enabling DEBUG_LL to see if it's an machine ID error.  If you see:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported processor variant.&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported machine ID...&lt;br /&gt;
&lt;br /&gt;
Then you either don't have proper processor support enabled for your target or your bootloader is passing in the wrong machine number.&lt;br /&gt;
&lt;br /&gt;
If you still don't see anything, try hacking printk.c to call printascii() (enabled for the DEBUG_LL case) to print directly to the serial port w/o a driver, etc.,.  You can find more details on these low-level debugging hacks via a little googling...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
You can also specify an argument on the kernel command line to enable this, or&lt;br /&gt;
you can enable it any time at runtime by doing the following:&lt;br /&gt;
&lt;br /&gt;
  $echo 1 &amp;gt;/sys/module/printk/parameters/time&lt;br /&gt;
&lt;br /&gt;
Also, there are tools available to use the information to show relative times&lt;br /&gt;
between printks (scripts/show_delta) and create graphs of durations in the&lt;br /&gt;
kernel (scripts/bootgraph.pl)&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more details&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [[Printk]]&lt;br /&gt;
* [http://lwn.net/Articles/487437/ LWN.net: The perils of pr_info()]&lt;br /&gt;
* [http://www.ibm.com/developerworks/linux/library/l-kernel-logging-apis/index.html Kernel logging: APIs and implementation, Tim Jones (for IBM)] (nice article)&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-04-03T21:02:52Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Added IBM Document&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported format strings are also quite similar to the standard ones&lt;br /&gt;
supported in printf and are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CONT&lt;br /&gt;
|&amp;quot;&amp;lt;c&amp;gt;&amp;quot;&lt;br /&gt;
|&amp;quot;continued&amp;quot; line of log printout (only done after a line that had no enclosing \n) [http://lwn.net/Articles/252651/]&lt;br /&gt;
|pr_cont&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''KERN_CONT'' and ''pr_cont'' are special cases since they do not specify an urgency but rather indicate a 'continued message' e.g.:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;Doing something was &amp;quot;);&lt;br /&gt;
 /* &amp;lt;100 lines of whatever&amp;gt;*/&lt;br /&gt;
 if (success)&lt;br /&gt;
    printk(KERN_CONT &amp;quot;successful\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
    printk(KERN_CONT &amp;quot;NOT successful\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
 -&amp;gt; &amp;quot;Doing something was successful&amp;quot;&lt;br /&gt;
'''Important Note:''' ''KERN_CONT'' and ''pr_cont'' should only be used by core/arch code during early bootup (a continued line is not SMP-safe otherwise).[http://lwn.net/Articles/252651/]&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
=== Accessing the printk buffer after a silent hang on boot ===&lt;br /&gt;
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang.  However, there may still be messages in the printk buffer, which can give you an idea of where the problem is.&lt;br /&gt;
&lt;br /&gt;
The kernel starts putting messages into the printk buffer as soon as it starts.  They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices).  Even though these messages are not printed before the hang, it is still possible in some circumstances&lt;br /&gt;
to dump the printk buffer and see the messages.&lt;br /&gt;
&lt;br /&gt;
The tricky parts of doing this are:&lt;br /&gt;
&lt;br /&gt;
# using a warm reset (if possible) so the memory contents are not lost when transitioning from the stuck kernel to the bootloader.  You ''can'' do a cold boot, but if the memory is left unpowered for very long, you will start to see memory corruption.&lt;br /&gt;
# figuring out the address to use in the bootloader, based on the address of __log_buf in System.map.  You will probably need to subtract the value of CONFIG_PAGE_OFFSET from the __log_buf address.  However, there may be other offsets present as well (such as TEXT_OFFSET).  Sometimes you can find the buffer by dumping the memory in a suspected area and locating the kernel messages visually in the dump.  Note that the mapping offset between the kernel map of memory and the bootloader map of memory should not change.  So once you figure it out you are set.&lt;br /&gt;
&lt;br /&gt;
Quinn Jensen writes:&lt;br /&gt;
&lt;br /&gt;
Something I've found handy when the console is silent is to dump the printk buffer from the boot loader.  To do it you have to know how your boot loader maps memory compared to the kernel.&lt;br /&gt;
&lt;br /&gt;
==== Redboot example on a Freescale ADS board ====&lt;br /&gt;
Quinn says: Here's what I do with Redboot on i.MX31:&lt;br /&gt;
&lt;br /&gt;
 fgrep printk_buf System.map&lt;br /&gt;
&lt;br /&gt;
this shows the linked address of the printk_buf, e.g.:&lt;br /&gt;
&lt;br /&gt;
 c02338f0 b printk_buf.16194&lt;br /&gt;
&lt;br /&gt;
The address &amp;quot;c02338f0&amp;quot; is in kernel virtual, which, in the case of i.MX31 ADS, redboot will have mapped to 0x802338f0.  So, after resetting the target board, but without letting it try to boot again, at the redboot prompt:&lt;br /&gt;
&lt;br /&gt;
 dump -b 0x802338f0 -l 10000&lt;br /&gt;
&lt;br /&gt;
And you see the printk buffer that never got flushed to the UART.  Knowing what's there can be '''very''' useful in debugging your console.&lt;br /&gt;
&lt;br /&gt;
==== U-boot example on an OMAP OSK board ====&lt;br /&gt;
Tim Bird tried these steps and they worked:&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf System.map&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf /proc/kallsyms&lt;br /&gt;
&lt;br /&gt;
These show:&lt;br /&gt;
&lt;br /&gt;
 c0352d88 B __log_buf&lt;br /&gt;
&lt;br /&gt;
In the case of the OSK, this address maps to 0x10352d88.  So I reset the target board and use the following:&lt;br /&gt;
&lt;br /&gt;
 OMAP5912 OSK # md 10352d88&lt;br /&gt;
 10352d88: 4c3e353c 78756e69 72657620 6e6f6973    &amp;lt;5&amp;gt;Linux version&lt;br /&gt;
 10352d98: 362e3220 2e32322e 612d3631 6e5f706c     2.6.22.16-alp_n&lt;br /&gt;
 10352da8: 7428206c 64726962 6d697440 6b736564    l (tbird@timdesk&lt;br /&gt;
 10352db8: 2e6d612e 796e6f73 6d6f632e 67282029    .am.sony.com) (g&lt;br /&gt;
 10352dc8: 76206363 69737265 33206e6f 342e342e    cc version 3.4.4&lt;br /&gt;
 10352dd8: 34232029 45525020 54504d45 65755420    ) #4 PREEMPT Tue&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Grub also supports a dump command which you can invoke from the grub prompt.&lt;br /&gt;
 dump  [ -s offset ] [-n length] { FILE | (mem) }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using CONFIG_DEBUG_LL and printascii() (ARM only) ===&lt;br /&gt;
If the kernel fails before the serial console is enabled, you can use CONFIG_DEBUG_LL to add extra debug output routines to the kernel.  These are printascii, printch and printhex. These routines print directly to the serial port, bypassing the console code, and are available earlier in machine initialization.&lt;br /&gt;
&lt;br /&gt;
Here is an e-mail exchange seen on the linux-embedded mailing list (with answer by George Davis):[http://www.mail-archive.com/linux-embedded@vger.kernel.org/msg00223.html] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; When we try to boot a 2.6.21 kernel after uncompressing the kernel the boot process dies somehow.&lt;br /&gt;
&amp;gt; We've figured out so far that the kernel dies somewhere between the gunzip and start_kernel.&lt;br /&gt;
&lt;br /&gt;
Try enabling DEBUG_LL to see if it's an machine ID error.  If you see:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported processor variant.&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported machine ID...&lt;br /&gt;
&lt;br /&gt;
Then you either don't have proper processor support enabled for your target or your bootloader is passing in the wrong machine number.&lt;br /&gt;
&lt;br /&gt;
If you still don't see anything, try hacking printk.c to call printascii() (enabled for the DEBUG_LL case) to print directly to the serial port w/o a driver, etc.,.  You can find more details on these low-level debugging hacks via a little googling...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
You can also specify an argument on the kernel command line to enable this, or&lt;br /&gt;
you can enable it any time at runtime by doing the following:&lt;br /&gt;
&lt;br /&gt;
  $echo 1 &amp;gt;/sys/module/printk/parameters/time&lt;br /&gt;
&lt;br /&gt;
Also, there are tools available to use the information to show relative times&lt;br /&gt;
between printks (scripts/show_delta) and create graphs of durations in the&lt;br /&gt;
kernel (scripts/bootgraph.pl)&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more details&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [[Printk]]&lt;br /&gt;
* [http://lwn.net/Articles/487437/ LWN.net: The perils of pr_info()]&lt;br /&gt;
* [http://www.ibm.com/developerworks/linux/library/l-kernel-logging-apis/index.html Kernel logging: APIs and implementation, Tim Jones (for IBM)] (nice article)&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-04-03T20:59:18Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: /* References and external links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported format strings are also quite similar to the standard ones&lt;br /&gt;
supported in printf and are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CONT&lt;br /&gt;
|&amp;quot;&amp;lt;c&amp;gt;&amp;quot;&lt;br /&gt;
|&amp;quot;continued&amp;quot; line of log printout (only done after a line that had no enclosing \n) [http://lwn.net/Articles/252651/]&lt;br /&gt;
|pr_cont&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''KERN_CONT'' and ''pr_cont'' are special cases since they do not specify an urgency but rather indicate a 'continued message' e.g.:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;Doing something was &amp;quot;);&lt;br /&gt;
 /* &amp;lt;100 lines of whatever&amp;gt;*/&lt;br /&gt;
 if (success)&lt;br /&gt;
    printk(KERN_CONT &amp;quot;successful\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
    printk(KERN_CONT &amp;quot;NOT successful\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
 -&amp;gt; &amp;quot;Doing something was successful&amp;quot;&lt;br /&gt;
'''Important Note:''' ''KERN_CONT'' and ''pr_cont'' should only be used by core/arch code during early bootup (a continued line is not SMP-safe otherwise).[http://lwn.net/Articles/252651/]&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
=== Accessing the printk buffer after a silent hang on boot ===&lt;br /&gt;
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang.  However, there may still be messages in the printk buffer, which can give you an idea of where the problem is.&lt;br /&gt;
&lt;br /&gt;
The kernel starts putting messages into the printk buffer as soon as it starts.  They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices).  Even though these messages are not printed before the hang, it is still possible in some circumstances&lt;br /&gt;
to dump the printk buffer and see the messages.&lt;br /&gt;
&lt;br /&gt;
The tricky parts of doing this are:&lt;br /&gt;
&lt;br /&gt;
# using a warm reset (if possible) so the memory contents are not lost when transitioning from the stuck kernel to the bootloader.  You ''can'' do a cold boot, but if the memory is left unpowered for very long, you will start to see memory corruption.&lt;br /&gt;
# figuring out the address to use in the bootloader, based on the address of __log_buf in System.map.  You will probably need to subtract the value of CONFIG_PAGE_OFFSET from the __log_buf address.  However, there may be other offsets present as well (such as TEXT_OFFSET).  Sometimes you can find the buffer by dumping the memory in a suspected area and locating the kernel messages visually in the dump.  Note that the mapping offset between the kernel map of memory and the bootloader map of memory should not change.  So once you figure it out you are set.&lt;br /&gt;
&lt;br /&gt;
Quinn Jensen writes:&lt;br /&gt;
&lt;br /&gt;
Something I've found handy when the console is silent is to dump the printk buffer from the boot loader.  To do it you have to know how your boot loader maps memory compared to the kernel.&lt;br /&gt;
&lt;br /&gt;
==== Redboot example on a Freescale ADS board ====&lt;br /&gt;
Quinn says: Here's what I do with Redboot on i.MX31:&lt;br /&gt;
&lt;br /&gt;
 fgrep printk_buf System.map&lt;br /&gt;
&lt;br /&gt;
this shows the linked address of the printk_buf, e.g.:&lt;br /&gt;
&lt;br /&gt;
 c02338f0 b printk_buf.16194&lt;br /&gt;
&lt;br /&gt;
The address &amp;quot;c02338f0&amp;quot; is in kernel virtual, which, in the case of i.MX31 ADS, redboot will have mapped to 0x802338f0.  So, after resetting the target board, but without letting it try to boot again, at the redboot prompt:&lt;br /&gt;
&lt;br /&gt;
 dump -b 0x802338f0 -l 10000&lt;br /&gt;
&lt;br /&gt;
And you see the printk buffer that never got flushed to the UART.  Knowing what's there can be '''very''' useful in debugging your console.&lt;br /&gt;
&lt;br /&gt;
==== U-boot example on an OMAP OSK board ====&lt;br /&gt;
Tim Bird tried these steps and they worked:&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf System.map&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf /proc/kallsyms&lt;br /&gt;
&lt;br /&gt;
These show:&lt;br /&gt;
&lt;br /&gt;
 c0352d88 B __log_buf&lt;br /&gt;
&lt;br /&gt;
In the case of the OSK, this address maps to 0x10352d88.  So I reset the target board and use the following:&lt;br /&gt;
&lt;br /&gt;
 OMAP5912 OSK # md 10352d88&lt;br /&gt;
 10352d88: 4c3e353c 78756e69 72657620 6e6f6973    &amp;lt;5&amp;gt;Linux version&lt;br /&gt;
 10352d98: 362e3220 2e32322e 612d3631 6e5f706c     2.6.22.16-alp_n&lt;br /&gt;
 10352da8: 7428206c 64726962 6d697440 6b736564    l (tbird@timdesk&lt;br /&gt;
 10352db8: 2e6d612e 796e6f73 6d6f632e 67282029    .am.sony.com) (g&lt;br /&gt;
 10352dc8: 76206363 69737265 33206e6f 342e342e    cc version 3.4.4&lt;br /&gt;
 10352dd8: 34232029 45525020 54504d45 65755420    ) #4 PREEMPT Tue&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Grub also supports a dump command which you can invoke from the grub prompt.&lt;br /&gt;
 dump  [ -s offset ] [-n length] { FILE | (mem) }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using CONFIG_DEBUG_LL and printascii() (ARM only) ===&lt;br /&gt;
If the kernel fails before the serial console is enabled, you can use CONFIG_DEBUG_LL to add extra debug output routines to the kernel.  These are printascii, printch and printhex. These routines print directly to the serial port, bypassing the console code, and are available earlier in machine initialization.&lt;br /&gt;
&lt;br /&gt;
Here is an e-mail exchange seen on the linux-embedded mailing list (with answer by George Davis):[http://www.mail-archive.com/linux-embedded@vger.kernel.org/msg00223.html] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; When we try to boot a 2.6.21 kernel after uncompressing the kernel the boot process dies somehow.&lt;br /&gt;
&amp;gt; We've figured out so far that the kernel dies somewhere between the gunzip and start_kernel.&lt;br /&gt;
&lt;br /&gt;
Try enabling DEBUG_LL to see if it's an machine ID error.  If you see:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported processor variant.&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported machine ID...&lt;br /&gt;
&lt;br /&gt;
Then you either don't have proper processor support enabled for your target or your bootloader is passing in the wrong machine number.&lt;br /&gt;
&lt;br /&gt;
If you still don't see anything, try hacking printk.c to call printascii() (enabled for the DEBUG_LL case) to print directly to the serial port w/o a driver, etc.,.  You can find more details on these low-level debugging hacks via a little googling...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
You can also specify an argument on the kernel command line to enable this, or&lt;br /&gt;
you can enable it any time at runtime by doing the following:&lt;br /&gt;
&lt;br /&gt;
  $echo 1 &amp;gt;/sys/module/printk/parameters/time&lt;br /&gt;
&lt;br /&gt;
Also, there are tools available to use the information to show relative times&lt;br /&gt;
between printks (scripts/show_delta) and create graphs of durations in the&lt;br /&gt;
kernel (scripts/bootgraph.pl)&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more details&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [[Printk]]&lt;br /&gt;
* [http://lwn.net/Articles/487437/ LWN.net: The perils of pr_info()]&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-04-03T20:58:16Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Added KERN_CONT&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported format strings are also quite similar to the standard ones&lt;br /&gt;
supported in printf and are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CONT&lt;br /&gt;
|&amp;quot;&amp;lt;c&amp;gt;&amp;quot;&lt;br /&gt;
|&amp;quot;continued&amp;quot; line of log printout (only done after a line that had no enclosing \n) [http://lwn.net/Articles/252651/]&lt;br /&gt;
|pr_cont&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
''KERN_CONT'' and ''pr_cont'' are special cases since they do not specify an urgency but rather indicate a 'continued message' e.g.:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;Doing something was &amp;quot;);&lt;br /&gt;
 /* &amp;lt;100 lines of whatever&amp;gt;*/&lt;br /&gt;
 if (success)&lt;br /&gt;
    printk(KERN_CONT &amp;quot;successful\n&amp;quot;);&lt;br /&gt;
 else&lt;br /&gt;
    printk(KERN_CONT &amp;quot;NOT successful\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
 -&amp;gt; &amp;quot;Doing something was successful&amp;quot;&lt;br /&gt;
'''Important Note:''' ''KERN_CONT'' and ''pr_cont'' should only be used by core/arch code during early bootup (a continued line is not SMP-safe otherwise).[http://lwn.net/Articles/252651/]&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
=== Accessing the printk buffer after a silent hang on boot ===&lt;br /&gt;
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang.  However, there may still be messages in the printk buffer, which can give you an idea of where the problem is.&lt;br /&gt;
&lt;br /&gt;
The kernel starts putting messages into the printk buffer as soon as it starts.  They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices).  Even though these messages are not printed before the hang, it is still possible in some circumstances&lt;br /&gt;
to dump the printk buffer and see the messages.&lt;br /&gt;
&lt;br /&gt;
The tricky parts of doing this are:&lt;br /&gt;
&lt;br /&gt;
# using a warm reset (if possible) so the memory contents are not lost when transitioning from the stuck kernel to the bootloader.  You ''can'' do a cold boot, but if the memory is left unpowered for very long, you will start to see memory corruption.&lt;br /&gt;
# figuring out the address to use in the bootloader, based on the address of __log_buf in System.map.  You will probably need to subtract the value of CONFIG_PAGE_OFFSET from the __log_buf address.  However, there may be other offsets present as well (such as TEXT_OFFSET).  Sometimes you can find the buffer by dumping the memory in a suspected area and locating the kernel messages visually in the dump.  Note that the mapping offset between the kernel map of memory and the bootloader map of memory should not change.  So once you figure it out you are set.&lt;br /&gt;
&lt;br /&gt;
Quinn Jensen writes:&lt;br /&gt;
&lt;br /&gt;
Something I've found handy when the console is silent is to dump the printk buffer from the boot loader.  To do it you have to know how your boot loader maps memory compared to the kernel.&lt;br /&gt;
&lt;br /&gt;
==== Redboot example on a Freescale ADS board ====&lt;br /&gt;
Quinn says: Here's what I do with Redboot on i.MX31:&lt;br /&gt;
&lt;br /&gt;
 fgrep printk_buf System.map&lt;br /&gt;
&lt;br /&gt;
this shows the linked address of the printk_buf, e.g.:&lt;br /&gt;
&lt;br /&gt;
 c02338f0 b printk_buf.16194&lt;br /&gt;
&lt;br /&gt;
The address &amp;quot;c02338f0&amp;quot; is in kernel virtual, which, in the case of i.MX31 ADS, redboot will have mapped to 0x802338f0.  So, after resetting the target board, but without letting it try to boot again, at the redboot prompt:&lt;br /&gt;
&lt;br /&gt;
 dump -b 0x802338f0 -l 10000&lt;br /&gt;
&lt;br /&gt;
And you see the printk buffer that never got flushed to the UART.  Knowing what's there can be '''very''' useful in debugging your console.&lt;br /&gt;
&lt;br /&gt;
==== U-boot example on an OMAP OSK board ====&lt;br /&gt;
Tim Bird tried these steps and they worked:&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf System.map&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf /proc/kallsyms&lt;br /&gt;
&lt;br /&gt;
These show:&lt;br /&gt;
&lt;br /&gt;
 c0352d88 B __log_buf&lt;br /&gt;
&lt;br /&gt;
In the case of the OSK, this address maps to 0x10352d88.  So I reset the target board and use the following:&lt;br /&gt;
&lt;br /&gt;
 OMAP5912 OSK # md 10352d88&lt;br /&gt;
 10352d88: 4c3e353c 78756e69 72657620 6e6f6973    &amp;lt;5&amp;gt;Linux version&lt;br /&gt;
 10352d98: 362e3220 2e32322e 612d3631 6e5f706c     2.6.22.16-alp_n&lt;br /&gt;
 10352da8: 7428206c 64726962 6d697440 6b736564    l (tbird@timdesk&lt;br /&gt;
 10352db8: 2e6d612e 796e6f73 6d6f632e 67282029    .am.sony.com) (g&lt;br /&gt;
 10352dc8: 76206363 69737265 33206e6f 342e342e    cc version 3.4.4&lt;br /&gt;
 10352dd8: 34232029 45525020 54504d45 65755420    ) #4 PREEMPT Tue&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Grub also supports a dump command which you can invoke from the grub prompt.&lt;br /&gt;
 dump  [ -s offset ] [-n length] { FILE | (mem) }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using CONFIG_DEBUG_LL and printascii() (ARM only) ===&lt;br /&gt;
If the kernel fails before the serial console is enabled, you can use CONFIG_DEBUG_LL to add extra debug output routines to the kernel.  These are printascii, printch and printhex. These routines print directly to the serial port, bypassing the console code, and are available earlier in machine initialization.&lt;br /&gt;
&lt;br /&gt;
Here is an e-mail exchange seen on the linux-embedded mailing list (with answer by George Davis):[http://www.mail-archive.com/linux-embedded@vger.kernel.org/msg00223.html] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; When we try to boot a 2.6.21 kernel after uncompressing the kernel the boot process dies somehow.&lt;br /&gt;
&amp;gt; We've figured out so far that the kernel dies somewhere between the gunzip and start_kernel.&lt;br /&gt;
&lt;br /&gt;
Try enabling DEBUG_LL to see if it's an machine ID error.  If you see:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported processor variant.&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported machine ID...&lt;br /&gt;
&lt;br /&gt;
Then you either don't have proper processor support enabled for your target or your bootloader is passing in the wrong machine number.&lt;br /&gt;
&lt;br /&gt;
If you still don't see anything, try hacking printk.c to call printascii() (enabled for the DEBUG_LL case) to print directly to the serial port w/o a driver, etc.,.  You can find more details on these low-level debugging hacks via a little googling...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
You can also specify an argument on the kernel command line to enable this, or&lt;br /&gt;
you can enable it any time at runtime by doing the following:&lt;br /&gt;
&lt;br /&gt;
  $echo 1 &amp;gt;/sys/module/printk/parameters/time&lt;br /&gt;
&lt;br /&gt;
Also, there are tools available to use the information to show relative times&lt;br /&gt;
between printks (scripts/show_delta) and create graphs of durations in the&lt;br /&gt;
kernel (scripts/bootgraph.pl)&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more details&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [[Printk]]&lt;br /&gt;
* []http://lwn.net/Articles/487437/ LWN.net: The perils of pr_info()]&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Kernel_Debugging_Tips</id>
		<title>Kernel Debugging Tips</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Kernel_Debugging_Tips"/>
				<updated>2012-04-03T20:45:24Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Moved to Debugging by Printing&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some miscellaneous tips for debugging a kernel:&lt;br /&gt;
&lt;br /&gt;
== Using printks ==&lt;br /&gt;
To add your own debug message to the kernel, you can place a &amp;quot;printk()&amp;quot; in the kernel code.&lt;br /&gt;
&lt;br /&gt;
These messages are logged to an internal buffer, and eventually displayed by the kernel, being emitted to whatever is the active console, at the time of display.  Since the console is not initialized until part-way through the boot sequence, several messages build up in the log until the console is initialize, at which point all buffered messages are displayed at once.&lt;br /&gt;
&lt;br /&gt;
After the messages are displayed on the kernel console, they are left in the log buffer (which is a ring buffer), and they can be (and usually are) retrieved later by various commands.&lt;br /&gt;
&lt;br /&gt;
printk is a variable-argument function, just like printf.  Note that there is no &amp;quot;printf()&amp;quot; function for the kernel.  &amp;quot;printk()&amp;quot; is used to specifically remind kernel developers that the environment is different.&lt;br /&gt;
&lt;br /&gt;
printk can use many standard C-style printf format characters, but not all of them.  See the kernel source for examples of what you can do.&lt;br /&gt;
&lt;br /&gt;
=== Log levels ===&lt;br /&gt;
Each kernel message can be pre-pended with a tag indicating the importance of the message. The message tags are shown in the file include/linux/kernel.h.  The available tags are:&lt;br /&gt;
 KERN_EMERG, KERN_ALERT, KERN_CRIT, KERN_WARNING, KERN_NOTICE, KERN_INFO, KERN_DEBUG.&lt;br /&gt;
&lt;br /&gt;
Note that these tags are defined as simple strings, with angle brackets and a number:&lt;br /&gt;
 #define      KERN_INFO       &amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
You could place the tag onto front of the string without using the #define, but that is considered very bad form, and is discouraged.&lt;br /&gt;
&lt;br /&gt;
The way the tag is placed on the string is with C string concatenation:&lt;br /&gt;
 printk(KERN_DEBUG &amp;quot;This is a debug message\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Note that there is no comma between the tag macro and the message string.&lt;br /&gt;
&lt;br /&gt;
=== Adding timing information ===&lt;br /&gt;
Sometimes, it is useful to add timing information to the printk values, so you can see when a particular event occurred.  The kernel includes an feature for doing&lt;br /&gt;
this called printk times.&lt;br /&gt;
&lt;br /&gt;
See the help for CONFIG_PRINTK_TIMES in the file lib/Kconfig.debug for more information on this feature.  This option is found on the &amp;quot;Kernel Hacking&amp;quot; menu when configuring the kernel.&lt;br /&gt;
&lt;br /&gt;
The timestamps which are inserted into the printk output consist of seconds and microseconds, as absolute values from the start of machine operation (or from the start of kernel timekeeping).&lt;br /&gt;
&lt;br /&gt;
There is also tool in the kernel source which will convert the timestamp values to relative values (so you can see the interval between events).  This tools is called show_delta and is located in the kernel 'scripts' directory.&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== Viewing log messages ===&lt;br /&gt;
The &amp;lt;tt&amp;gt;klogd&amp;lt;/tt&amp;gt; program will extract messages from the kernel log buffer, and send them to the system log (which winds up in /var/log/messages on most systems).  This command runs in the background on most desktop or server systems, and continually transfers messages from the kernel log buffer to the system log.&lt;br /&gt;
&lt;br /&gt;
You can view the contents of the log buffer directly, using the &amp;lt;tt&amp;gt;dmesg&amp;lt;/tt&amp;gt; command.  Note that by default &amp;lt;tt&amp;gt;dmesg&amp;lt;/tt&amp;gt; displays the messages from the buffer, but does not remove them.  So this command can be run multiple times to view the kernel printk messages.  See the dmesg man page for more things you can do with this tool.&lt;br /&gt;
&lt;br /&gt;
=== Controlling console output ===&lt;br /&gt;
In order to have the kernel boot be less &amp;quot;noisy&amp;quot;, or in order to boot more quickly, it is sometimes useful to control the amount of messages displayed to the console during boot.  You can do this by setting the kernel log level at boot time via a kernel command line option. See the &amp;quot;loglevel=&amp;quot; argument in &amp;lt;tt&amp;gt;Documentation/kernel-parameters.txt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You can turn off all messages using the kernel command line option &amp;quot;quiet&amp;quot;. See [[Disable Console]] for information on how much time this can save at boot up.&lt;br /&gt;
&lt;br /&gt;
Note that even if the log level is changed, or &amp;quot;quiet&amp;quot; is used, although the printk messages are not print to console, they are still entered into the log buffer, and they can still be extracted and displayed later using the &amp;lt;tt&amp;gt;dmesg&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
=== Changing the size of the printk buffer ===&lt;br /&gt;
The size of the buffer that printk writes to is referred to in the kernel source as the &amp;quot;log buffer&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
You can make the log buffer larger when you build the kernel. This is useful for when additional printk data (such as extra messages inserted for debugging) is produced by the kernel and it overflows the regular buffer. The log buffer is a ring buffer, so later messages will overwrite the earliest messages in the buffer if too much data is written before the log buffer is drained (by, e.g. klogd or dmesg)&lt;br /&gt;
&lt;br /&gt;
Step 1: Change the kernel log buffer size:&lt;br /&gt;
&lt;br /&gt;
On the General Setup menu, change &amp;quot;Kernel log buffer size&amp;quot; to a larger number. This corresponds to LOG_BUF_SHIFT, which is the power-of-two size of the log buffer.&lt;br /&gt;
By default, this is 14, which yeilds a log buffer size of 16KB.  Changing this to 17 will yield a log buffer size of 128KB.&lt;br /&gt;
&lt;br /&gt;
Set the option, then re-build and install the kernel for booting on the target board.&lt;br /&gt;
&lt;br /&gt;
Step 2: Tell dmesg to retrieve the larger buffer:&lt;br /&gt;
Even though the buffer is larger in the kernel, dmesg will still default to only reading 16K, unless told otherwise.  To read the full buffer, use the '-s' option&lt;br /&gt;
like so: &lt;br /&gt;
 $dmesg -s 128000&lt;br /&gt;
&lt;br /&gt;
== Using kernel symbols ==&lt;br /&gt;
You can look up the source code for a function address using your toolchain's addr2line program.&lt;br /&gt;
See [[Find a kernel function line]] or [[Addr2line for kernel debugging]].&lt;br /&gt;
&lt;br /&gt;
== Using a kernel debugger ==&lt;br /&gt;
You can use the in-kernel debugger: [[KDB]]&lt;br /&gt;
&lt;br /&gt;
Also, you can use QEMU and gdb (and a high-level IDE like eclipse).&lt;br /&gt;
&lt;br /&gt;
See [http://issaris.blogspot.com/2007/12/download-linux-kernel-sourcecode-from.html Debugging the Linux kernel using Eclipse/CDT and Qemu] for a great article on using Eclipse (with the CDT plugin) to debug the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
See [[Debugging_by_printing#Debugging_early_boot_problems]]&lt;br /&gt;
&lt;br /&gt;
== Triggering a kernel event ==&lt;br /&gt;
=== Overloading the sync system call ===&lt;br /&gt;
Sometimes, it is nice to trigger an event to happen in the kernel from user space. Instead of creating infrastructure to handle a /proc event, an ioctl() or making a new syscall, it can be quick and easy to just overload an existing function.  One function not used very often is sync.   (I have found that the sync system call is not normally called by user space programs (or during standard linux booting). &lt;br /&gt;
&lt;br /&gt;
It is quite easy to put a hook to your own kernel program in the sys_sync() routine (located in fs/sync.c) and cause it to execute by issuing 'sync' from the shell command line. This is handy as a temporary mechanism to test things that you have put in the kernel. &lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
&lt;br /&gt;
== Interpreting an Oops message ==&lt;br /&gt;
When the kernel encounters an internal fault, it will print an Oops message.&lt;br /&gt;
Here are some tips on using the Oops message to find the source of the problem.&lt;br /&gt;
* See [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob_plain;f=Documentation/oops-tracing.txt;hb=HEAD Documentation/oops-tracing.txt]&lt;br /&gt;
* See [http://vmlinux.org/jocke/linux/howto-find-oops-location.shtml HOWTO find oops location] by Denis Vlasenko&lt;br /&gt;
&lt;br /&gt;
== Compilation tricks for the kernel ==&lt;br /&gt;
Sometimes, you want to modify how the compiler builds an individual kernel file.  The following are tips for doing tasks related to this.&lt;br /&gt;
=== Build an individual file ===&lt;br /&gt;
You can build an individual output object file, with:&lt;br /&gt;
 make fs/buffer.o&lt;br /&gt;
&lt;br /&gt;
This will build JUST fs/buffer.o (if it needs rebuilding) and not the entire kernel.  To force it to need re-building, use 'touch' on the associated source file: &lt;br /&gt;
 touch fs/buffer.c&lt;br /&gt;
&lt;br /&gt;
=== Create the preprocessed file for an individual source file ===&lt;br /&gt;
Using the same technique, you can create the preprocessed file for a C source file.  This is useful if you're having trouble tracking down macro expansion or where defines/prototypes are coming from exactly.&lt;br /&gt;
 make fs/buffer.i&lt;br /&gt;
&lt;br /&gt;
=== Create the assembly file for an individual source file ===&lt;br /&gt;
Using the same technique, you can create the assembly file for a C source file.  This is useful to get an idea what actual machine instructions are generated from the C source code.&lt;br /&gt;
 make fs/buffer.s&lt;br /&gt;
&lt;br /&gt;
Another way to get the raw assembly, is to dump the object file using 'objdump'&lt;br /&gt;
 objdump -d fs/buffer.o &amp;gt; fs/buffer.disassem&lt;br /&gt;
&lt;br /&gt;
This will produce a disassembly of the object file, which should show how the assembly was translated into machine instructions.&lt;br /&gt;
&lt;br /&gt;
If the object has been compiled with debug symbols (using '-g'), then you might get more information using the '-S' option with objdump:&lt;br /&gt;
 objdump -S -d fs/buffer.o &amp;gt;fs/buffer.disassem&lt;br /&gt;
&lt;br /&gt;
You can also request that the toolchain show mixed source and assembly, by passing extra flags:&lt;br /&gt;
 make EXTRA_CFLAGS=&amp;quot;-g -Wa,-a,-ad -fverbose-asm&amp;quot; fs/buffer.o &amp;gt;fs/buffer.mixed&lt;br /&gt;
&lt;br /&gt;
=== Alter the flags for a compilation ===&lt;br /&gt;
Sometimes, you need to alter the compilation flags for an individual file.  There are two ways to do this. One is to add the extra flags on the make command line:&lt;br /&gt;
&lt;br /&gt;
 make EXTRA_CFLAGS=&amp;quot;-g -finstrument-functions&amp;quot; fs/buffer.o&lt;br /&gt;
&lt;br /&gt;
This will work if the flags can be appended to the regular set of C flags used for compiling the object.&lt;br /&gt;
&lt;br /&gt;
However, if you need to do something more complicated, like removing or modifying flags, then you can build your own command line by hand.  To do this, it is easiest to have 'make' produce the default compilation command (which will be several lines long), then copy, paste and edit it, to run on the command line directly.  To see the exact compile commands used to compile a particular object, use the V=1 option with the kernel build system:&lt;br /&gt;
&lt;br /&gt;
 make V=1 fs/buffer.o&lt;br /&gt;
&lt;br /&gt;
For me, this produced something like this:&lt;br /&gt;
&lt;br /&gt;
mipsel-linux-gcc -Wp,-MD,fs/.buffer.o.d -nostdinc -isystem /home/usr/local/mipsel-linux-glibc/bin/../lib/gcc/mipsisa32el-linux/3.4.3/include -D__KERNEL__ -Iinclude -Iinclude2 -I/home/tbird/work/linux/include -I/home/tbird/work/linux/fs -Ifs -Wall -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -ffreestanding -O2 -fomit-frame-pointer -g -I/home/tbird/work/linux/ -I /home/tbird/work/linux/include/asm/gcc -G 0 -mno-abicalls -fno-pic -pipe -finline-limit=100000 -mabi=32 -march=mips32r2 -Wa,-32 -Wa,-march=mips32r2 -Wa,-mips32r2 -Wa,--trap -I/home/tbird/work/linux/include/asm-mips/ati -Iinclude/asm-mips/ati -I/home/tbird/work/linux/include/asm-mips/mach-generic -Iinclude/asm-mips/mach-generic -Wdeclaration-after-statement  -DKBUILD_BASENAME=buffer -DKBUILD_MODNAME=buffer -c -o fs/buffer.o /home/tbird/work/linux/fs/buffer.c&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Kernel_Debugging_Tips</id>
		<title>Kernel Debugging Tips</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Kernel_Debugging_Tips"/>
				<updated>2012-04-03T20:44:35Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Undo revision 113000 by Peter Huewe (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some miscellaneous tips for debugging a kernel:&lt;br /&gt;
&lt;br /&gt;
== Using printks ==&lt;br /&gt;
To add your own debug message to the kernel, you can place a &amp;quot;printk()&amp;quot; in the kernel code.&lt;br /&gt;
&lt;br /&gt;
These messages are logged to an internal buffer, and eventually displayed by the kernel, being emitted to whatever is the active console, at the time of display.  Since the console is not initialized until part-way through the boot sequence, several messages build up in the log until the console is initialize, at which point all buffered messages are displayed at once.&lt;br /&gt;
&lt;br /&gt;
After the messages are displayed on the kernel console, they are left in the log buffer (which is a ring buffer), and they can be (and usually are) retrieved later by various commands.&lt;br /&gt;
&lt;br /&gt;
printk is a variable-argument function, just like printf.  Note that there is no &amp;quot;printf()&amp;quot; function for the kernel.  &amp;quot;printk()&amp;quot; is used to specifically remind kernel developers that the environment is different.&lt;br /&gt;
&lt;br /&gt;
printk can use many standard C-style printf format characters, but not all of them.  See the kernel source for examples of what you can do.&lt;br /&gt;
&lt;br /&gt;
=== Log levels ===&lt;br /&gt;
Each kernel message can be pre-pended with a tag indicating the importance of the message. The message tags are shown in the file include/linux/kernel.h.  The available tags are:&lt;br /&gt;
 KERN_EMERG, KERN_ALERT, KERN_CRIT, KERN_WARNING, KERN_NOTICE, KERN_INFO, KERN_DEBUG.&lt;br /&gt;
&lt;br /&gt;
Note that these tags are defined as simple strings, with angle brackets and a number:&lt;br /&gt;
 #define      KERN_INFO       &amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
You could place the tag onto front of the string without using the #define, but that is considered very bad form, and is discouraged.&lt;br /&gt;
&lt;br /&gt;
The way the tag is placed on the string is with C string concatenation:&lt;br /&gt;
 printk(KERN_DEBUG &amp;quot;This is a debug message\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Note that there is no comma between the tag macro and the message string.&lt;br /&gt;
&lt;br /&gt;
=== Adding timing information ===&lt;br /&gt;
Sometimes, it is useful to add timing information to the printk values, so you can see when a particular event occurred.  The kernel includes an feature for doing&lt;br /&gt;
this called printk times.&lt;br /&gt;
&lt;br /&gt;
See the help for CONFIG_PRINTK_TIMES in the file lib/Kconfig.debug for more information on this feature.  This option is found on the &amp;quot;Kernel Hacking&amp;quot; menu when configuring the kernel.&lt;br /&gt;
&lt;br /&gt;
The timestamps which are inserted into the printk output consist of seconds and microseconds, as absolute values from the start of machine operation (or from the start of kernel timekeeping).&lt;br /&gt;
&lt;br /&gt;
There is also tool in the kernel source which will convert the timestamp values to relative values (so you can see the interval between events).  This tools is called show_delta and is located in the kernel 'scripts' directory.&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== Viewing log messages ===&lt;br /&gt;
The &amp;lt;tt&amp;gt;klogd&amp;lt;/tt&amp;gt; program will extract messages from the kernel log buffer, and send them to the system log (which winds up in /var/log/messages on most systems).  This command runs in the background on most desktop or server systems, and continually transfers messages from the kernel log buffer to the system log.&lt;br /&gt;
&lt;br /&gt;
You can view the contents of the log buffer directly, using the &amp;lt;tt&amp;gt;dmesg&amp;lt;/tt&amp;gt; command.  Note that by default &amp;lt;tt&amp;gt;dmesg&amp;lt;/tt&amp;gt; displays the messages from the buffer, but does not remove them.  So this command can be run multiple times to view the kernel printk messages.  See the dmesg man page for more things you can do with this tool.&lt;br /&gt;
&lt;br /&gt;
=== Controlling console output ===&lt;br /&gt;
In order to have the kernel boot be less &amp;quot;noisy&amp;quot;, or in order to boot more quickly, it is sometimes useful to control the amount of messages displayed to the console during boot.  You can do this by setting the kernel log level at boot time via a kernel command line option. See the &amp;quot;loglevel=&amp;quot; argument in &amp;lt;tt&amp;gt;Documentation/kernel-parameters.txt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You can turn off all messages using the kernel command line option &amp;quot;quiet&amp;quot;. See [[Disable Console]] for information on how much time this can save at boot up.&lt;br /&gt;
&lt;br /&gt;
Note that even if the log level is changed, or &amp;quot;quiet&amp;quot; is used, although the printk messages are not print to console, they are still entered into the log buffer, and they can still be extracted and displayed later using the &amp;lt;tt&amp;gt;dmesg&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
=== Changing the size of the printk buffer ===&lt;br /&gt;
The size of the buffer that printk writes to is referred to in the kernel source as the &amp;quot;log buffer&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
You can make the log buffer larger when you build the kernel. This is useful for when additional printk data (such as extra messages inserted for debugging) is produced by the kernel and it overflows the regular buffer. The log buffer is a ring buffer, so later messages will overwrite the earliest messages in the buffer if too much data is written before the log buffer is drained (by, e.g. klogd or dmesg)&lt;br /&gt;
&lt;br /&gt;
Step 1: Change the kernel log buffer size:&lt;br /&gt;
&lt;br /&gt;
On the General Setup menu, change &amp;quot;Kernel log buffer size&amp;quot; to a larger number. This corresponds to LOG_BUF_SHIFT, which is the power-of-two size of the log buffer.&lt;br /&gt;
By default, this is 14, which yeilds a log buffer size of 16KB.  Changing this to 17 will yield a log buffer size of 128KB.&lt;br /&gt;
&lt;br /&gt;
Set the option, then re-build and install the kernel for booting on the target board.&lt;br /&gt;
&lt;br /&gt;
Step 2: Tell dmesg to retrieve the larger buffer:&lt;br /&gt;
Even though the buffer is larger in the kernel, dmesg will still default to only reading 16K, unless told otherwise.  To read the full buffer, use the '-s' option&lt;br /&gt;
like so: &lt;br /&gt;
 $dmesg -s 128000&lt;br /&gt;
&lt;br /&gt;
== Using kernel symbols ==&lt;br /&gt;
You can look up the source code for a function address using your toolchain's addr2line program.&lt;br /&gt;
See [[Find a kernel function line]] or [[Addr2line for kernel debugging]].&lt;br /&gt;
&lt;br /&gt;
== Using a kernel debugger ==&lt;br /&gt;
You can use the in-kernel debugger: [[KDB]]&lt;br /&gt;
&lt;br /&gt;
Also, you can use QEMU and gdb (and a high-level IDE like eclipse).&lt;br /&gt;
&lt;br /&gt;
See [http://issaris.blogspot.com/2007/12/download-linux-kernel-sourcecode-from.html Debugging the Linux kernel using Eclipse/CDT and Qemu] for a great article on using Eclipse (with the CDT plugin) to debug the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
=== Accessing the printk buffer after a silent hang on boot ===&lt;br /&gt;
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang.  However, there may still be messages in the printk buffer, which can give you an idea of where the problem is.&lt;br /&gt;
&lt;br /&gt;
The kernel starts putting messages into the printk buffer as soon as it starts.  They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices).  Even though these messages are not printed before the hang, it is still possible in some circumstances&lt;br /&gt;
to dump the printk buffer and see the messages.&lt;br /&gt;
&lt;br /&gt;
The tricky parts of doing this are:&lt;br /&gt;
&lt;br /&gt;
1) using a warm reset (if possible) so the memory contents are not lost when transitioning from the stuck kernel to the bootloader.  You ''can'' do a cold boot, but if the memory is left unpowered for very long, you will start to see memory corruption.&lt;br /&gt;
&lt;br /&gt;
2) figuring out the address to use in the bootloader, based on the address of __log_buf in System.map.  You will probably need to subtract the value of CONFIG_PAGE_OFFSET from the __log_buf address.  However, there may be other offsets present as well (such as TEXT_OFFSET).  Sometimes you can find the buffer by dumping the memory in a suspected area and locating the kernel messages visually in the dump.  Note that the mapping offset between the kernel map of memory and the bootloader map of memory should not change.  So once you figure it out you are set.&lt;br /&gt;
&lt;br /&gt;
Quinn Jensen writes:&lt;br /&gt;
&lt;br /&gt;
Something I've found handy when the console is silent is to dump the printk buffer from the boot loader.  To do it you have to know how your boot loader maps memory compared to the kernel.&lt;br /&gt;
&lt;br /&gt;
==== Redboot example on a Freescale ADS board ====&lt;br /&gt;
Quinn says: Here's what I do with Redboot on i.MX31:&lt;br /&gt;
&lt;br /&gt;
 fgrep printk_buf System.map&lt;br /&gt;
&lt;br /&gt;
this shows the linked address of the printk_buf, e.g.:&lt;br /&gt;
&lt;br /&gt;
 c02338f0 b printk_buf.16194&lt;br /&gt;
&lt;br /&gt;
The address &amp;quot;c02338f0&amp;quot; is in kernel virtual, which, in the case of i.MX31 ADS, redboot will have mapped to 0x802338f0.  So, after resetting the target board, but without letting it try to boot again, at the redboot prompt:&lt;br /&gt;
&lt;br /&gt;
 dump -b 0x802338f0 -l 10000&lt;br /&gt;
&lt;br /&gt;
And you see the printk buffer that never got flushed to the UART.  Knowing what's there can be '''very''' useful in debugging your console.&lt;br /&gt;
&lt;br /&gt;
==== U-boot example on an OMAP OSK board ====&lt;br /&gt;
Tim Bird tried these steps and they worked:&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf System.map&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf /proc/kallsyms&lt;br /&gt;
&lt;br /&gt;
These show:&lt;br /&gt;
&lt;br /&gt;
 c0352d88 B __log_buf&lt;br /&gt;
&lt;br /&gt;
In the case of the OSK, this address maps to 0x10352d88.  So I reset the target board and use the following:&lt;br /&gt;
&lt;br /&gt;
 OMAP5912 OSK # md 10352d88&lt;br /&gt;
 10352d88: 4c3e353c 78756e69 72657620 6e6f6973    &amp;lt;5&amp;gt;Linux version&lt;br /&gt;
 10352d98: 362e3220 2e32322e 612d3631 6e5f706c     2.6.22.16-alp_n&lt;br /&gt;
 10352da8: 7428206c 64726962 6d697440 6b736564    l (tbird@timdesk&lt;br /&gt;
 10352db8: 2e6d612e 796e6f73 6d6f632e 67282029    .am.sony.com) (g&lt;br /&gt;
 10352dc8: 76206363 69737265 33206e6f 342e342e    cc version 3.4.4&lt;br /&gt;
 10352dd8: 34232029 45525020 54504d45 65755420    ) #4 PREEMPT Tue&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Using CONFIG_DEBUG_LL and printascii() (ARM only) ===&lt;br /&gt;
If the kernel fails before the serial console is enabled, you can use CONFIG_DEBUG_LL to add extra debug output routines to the kernel.  These are printascii, printch and printhex. These routines print directly to the serial port, bypassing the console code, and are available earlier in machine initialization.&lt;br /&gt;
&lt;br /&gt;
Here is an e-mail exchange seen on the linux-embedded mailing list (with answer by George Davis):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; When we try to boot a 2.6.21 kernel after uncompressing the kernel the boot process dies somehow.&lt;br /&gt;
&amp;gt; We've figured out so far that the kernel dies somewhere between  the gunzip and start_kernel.&lt;br /&gt;
&lt;br /&gt;
Try enabling DEBUG_LL to see if it's an machine ID error.  If you see:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported processor variant.&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported machine ID...&lt;br /&gt;
&lt;br /&gt;
Then you either don't have proper processor support enabled for your target or your bootloader is passing in the wrong machine number.&lt;br /&gt;
&lt;br /&gt;
If you still don't see anything, try hacking printk.c to call printascii() (enabled for the DEBUG_LL case) to print directly to the serial port w/o a driver, etc.,.  You can find more details on these low-level debugging hacks via a little googling...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Triggering a kernel event ==&lt;br /&gt;
=== Overloading the sync system call ===&lt;br /&gt;
Sometimes, it is nice to trigger an event to happen in the kernel from user space. Instead of creating infrastructure to handle a /proc event, an ioctl() or making a new syscall, it can be quick and easy to just overload an existing function.  One function not used very often is sync.   (I have found that the sync system call is not normally called by user space programs (or during standard linux booting). &lt;br /&gt;
&lt;br /&gt;
It is quite easy to put a hook to your own kernel program in the sys_sync() routine (located in fs/sync.c) and cause it to execute by issuing 'sync' from the shell command line. This is handy as a temporary mechanism to test things that you have put in the kernel. &lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
&lt;br /&gt;
== Interpreting an Oops message ==&lt;br /&gt;
When the kernel encounters an internal fault, it will print an Oops message.&lt;br /&gt;
Here are some tips on using the Oops message to find the source of the problem.&lt;br /&gt;
* See [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob_plain;f=Documentation/oops-tracing.txt;hb=HEAD Documentation/oops-tracing.txt]&lt;br /&gt;
* See [http://vmlinux.org/jocke/linux/howto-find-oops-location.shtml HOWTO find oops location] by Denis Vlasenko&lt;br /&gt;
&lt;br /&gt;
== Compilation tricks for the kernel ==&lt;br /&gt;
Sometimes, you want to modify how the compiler builds an individual kernel file.  The following are tips for doing tasks related to this.&lt;br /&gt;
=== Build an individual file ===&lt;br /&gt;
You can build an individual output object file, with:&lt;br /&gt;
 make fs/buffer.o&lt;br /&gt;
&lt;br /&gt;
This will build JUST fs/buffer.o (if it needs rebuilding) and not the entire kernel.  To force it to need re-building, use 'touch' on the associated source file: &lt;br /&gt;
 touch fs/buffer.c&lt;br /&gt;
&lt;br /&gt;
=== Create the preprocessed file for an individual source file ===&lt;br /&gt;
Using the same technique, you can create the preprocessed file for a C source file.  This is useful if you're having trouble tracking down macro expansion or where defines/prototypes are coming from exactly.&lt;br /&gt;
 make fs/buffer.i&lt;br /&gt;
&lt;br /&gt;
=== Create the assembly file for an individual source file ===&lt;br /&gt;
Using the same technique, you can create the assembly file for a C source file.  This is useful to get an idea what actual machine instructions are generated from the C source code.&lt;br /&gt;
 make fs/buffer.s&lt;br /&gt;
&lt;br /&gt;
Another way to get the raw assembly, is to dump the object file using 'objdump'&lt;br /&gt;
 objdump -d fs/buffer.o &amp;gt; fs/buffer.disassem&lt;br /&gt;
&lt;br /&gt;
This will produce a disassembly of the object file, which should show how the assembly was translated into machine instructions.&lt;br /&gt;
&lt;br /&gt;
If the object has been compiled with debug symbols (using '-g'), then you might get more information using the '-S' option with objdump:&lt;br /&gt;
 objdump -S -d fs/buffer.o &amp;gt;fs/buffer.disassem&lt;br /&gt;
&lt;br /&gt;
You can also request that the toolchain show mixed source and assembly, by passing extra flags:&lt;br /&gt;
 make EXTRA_CFLAGS=&amp;quot;-g -Wa,-a,-ad -fverbose-asm&amp;quot; fs/buffer.o &amp;gt;fs/buffer.mixed&lt;br /&gt;
&lt;br /&gt;
=== Alter the flags for a compilation ===&lt;br /&gt;
Sometimes, you need to alter the compilation flags for an individual file.  There are two ways to do this. One is to add the extra flags on the make command line:&lt;br /&gt;
&lt;br /&gt;
 make EXTRA_CFLAGS=&amp;quot;-g -finstrument-functions&amp;quot; fs/buffer.o&lt;br /&gt;
&lt;br /&gt;
This will work if the flags can be appended to the regular set of C flags used for compiling the object.&lt;br /&gt;
&lt;br /&gt;
However, if you need to do something more complicated, like removing or modifying flags, then you can build your own command line by hand.  To do this, it is easiest to have 'make' produce the default compilation command (which will be several lines long), then copy, paste and edit it, to run on the command line directly.  To see the exact compile commands used to compile a particular object, use the V=1 option with the kernel build system:&lt;br /&gt;
&lt;br /&gt;
 make V=1 fs/buffer.o&lt;br /&gt;
&lt;br /&gt;
For me, this produced something like this:&lt;br /&gt;
&lt;br /&gt;
mipsel-linux-gcc -Wp,-MD,fs/.buffer.o.d -nostdinc -isystem /home/usr/local/mipsel-linux-glibc/bin/../lib/gcc/mipsisa32el-linux/3.4.3/include -D__KERNEL__ -Iinclude -Iinclude2 -I/home/tbird/work/linux/include -I/home/tbird/work/linux/fs -Ifs -Wall -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -ffreestanding -O2 -fomit-frame-pointer -g -I/home/tbird/work/linux/ -I /home/tbird/work/linux/include/asm/gcc -G 0 -mno-abicalls -fno-pic -pipe -finline-limit=100000 -mabi=32 -march=mips32r2 -Wa,-32 -Wa,-march=mips32r2 -Wa,-mips32r2 -Wa,--trap -I/home/tbird/work/linux/include/asm-mips/ati -Iinclude/asm-mips/ati -I/home/tbird/work/linux/include/asm-mips/mach-generic -Iinclude/asm-mips/mach-generic -Wdeclaration-after-statement  -DKBUILD_BASENAME=buffer -DKBUILD_MODNAME=buffer -c -o fs/buffer.o /home/tbird/work/linux/fs/buffer.c&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Kernel_Debugging_Tips</id>
		<title>Kernel Debugging Tips</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Kernel_Debugging_Tips"/>
				<updated>2012-04-03T20:43:50Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Moved to Debugging by Printing&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here are some miscellaneous tips for debugging a kernel:&lt;br /&gt;
&lt;br /&gt;
== Using printks ==&lt;br /&gt;
To add your own debug message to the kernel, you can place a &amp;quot;printk()&amp;quot; in the kernel code.&lt;br /&gt;
&lt;br /&gt;
These messages are logged to an internal buffer, and eventually displayed by the kernel, being emitted to whatever is the active console, at the time of display.  Since the console is not initialized until part-way through the boot sequence, several messages build up in the log until the console is initialize, at which point all buffered messages are displayed at once.&lt;br /&gt;
&lt;br /&gt;
After the messages are displayed on the kernel console, they are left in the log buffer (which is a ring buffer), and they can be (and usually are) retrieved later by various commands.&lt;br /&gt;
&lt;br /&gt;
printk is a variable-argument function, just like printf.  Note that there is no &amp;quot;printf()&amp;quot; function for the kernel.  &amp;quot;printk()&amp;quot; is used to specifically remind kernel developers that the environment is different.&lt;br /&gt;
&lt;br /&gt;
printk can use many standard C-style printf format characters, but not all of them.  See the kernel source for examples of what you can do.&lt;br /&gt;
&lt;br /&gt;
=== Log levels ===&lt;br /&gt;
Each kernel message can be pre-pended with a tag indicating the importance of the message. The message tags are shown in the file include/linux/kernel.h.  The available tags are:&lt;br /&gt;
 KERN_EMERG, KERN_ALERT, KERN_CRIT, KERN_WARNING, KERN_NOTICE, KERN_INFO, KERN_DEBUG.&lt;br /&gt;
&lt;br /&gt;
Note that these tags are defined as simple strings, with angle brackets and a number:&lt;br /&gt;
 #define      KERN_INFO       &amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
You could place the tag onto front of the string without using the #define, but that is considered very bad form, and is discouraged.&lt;br /&gt;
&lt;br /&gt;
The way the tag is placed on the string is with C string concatenation:&lt;br /&gt;
 printk(KERN_DEBUG &amp;quot;This is a debug message\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Note that there is no comma between the tag macro and the message string.&lt;br /&gt;
&lt;br /&gt;
=== Adding timing information ===&lt;br /&gt;
Sometimes, it is useful to add timing information to the printk values, so you can see when a particular event occurred.  The kernel includes an feature for doing&lt;br /&gt;
this called printk times.&lt;br /&gt;
&lt;br /&gt;
See the help for CONFIG_PRINTK_TIMES in the file lib/Kconfig.debug for more information on this feature.  This option is found on the &amp;quot;Kernel Hacking&amp;quot; menu when configuring the kernel.&lt;br /&gt;
&lt;br /&gt;
The timestamps which are inserted into the printk output consist of seconds and microseconds, as absolute values from the start of machine operation (or from the start of kernel timekeeping).&lt;br /&gt;
&lt;br /&gt;
There is also tool in the kernel source which will convert the timestamp values to relative values (so you can see the interval between events).  This tools is called show_delta and is located in the kernel 'scripts' directory.&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== Viewing log messages ===&lt;br /&gt;
The &amp;lt;tt&amp;gt;klogd&amp;lt;/tt&amp;gt; program will extract messages from the kernel log buffer, and send them to the system log (which winds up in /var/log/messages on most systems).  This command runs in the background on most desktop or server systems, and continually transfers messages from the kernel log buffer to the system log.&lt;br /&gt;
&lt;br /&gt;
You can view the contents of the log buffer directly, using the &amp;lt;tt&amp;gt;dmesg&amp;lt;/tt&amp;gt; command.  Note that by default &amp;lt;tt&amp;gt;dmesg&amp;lt;/tt&amp;gt; displays the messages from the buffer, but does not remove them.  So this command can be run multiple times to view the kernel printk messages.  See the dmesg man page for more things you can do with this tool.&lt;br /&gt;
&lt;br /&gt;
=== Controlling console output ===&lt;br /&gt;
In order to have the kernel boot be less &amp;quot;noisy&amp;quot;, or in order to boot more quickly, it is sometimes useful to control the amount of messages displayed to the console during boot.  You can do this by setting the kernel log level at boot time via a kernel command line option. See the &amp;quot;loglevel=&amp;quot; argument in &amp;lt;tt&amp;gt;Documentation/kernel-parameters.txt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You can turn off all messages using the kernel command line option &amp;quot;quiet&amp;quot;. See [[Disable Console]] for information on how much time this can save at boot up.&lt;br /&gt;
&lt;br /&gt;
Note that even if the log level is changed, or &amp;quot;quiet&amp;quot; is used, although the printk messages are not print to console, they are still entered into the log buffer, and they can still be extracted and displayed later using the &amp;lt;tt&amp;gt;dmesg&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
=== Changing the size of the printk buffer ===&lt;br /&gt;
The size of the buffer that printk writes to is referred to in the kernel source as the &amp;quot;log buffer&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
You can make the log buffer larger when you build the kernel. This is useful for when additional printk data (such as extra messages inserted for debugging) is produced by the kernel and it overflows the regular buffer. The log buffer is a ring buffer, so later messages will overwrite the earliest messages in the buffer if too much data is written before the log buffer is drained (by, e.g. klogd or dmesg)&lt;br /&gt;
&lt;br /&gt;
Step 1: Change the kernel log buffer size:&lt;br /&gt;
&lt;br /&gt;
On the General Setup menu, change &amp;quot;Kernel log buffer size&amp;quot; to a larger number. This corresponds to LOG_BUF_SHIFT, which is the power-of-two size of the log buffer.&lt;br /&gt;
By default, this is 14, which yeilds a log buffer size of 16KB.  Changing this to 17 will yield a log buffer size of 128KB.&lt;br /&gt;
&lt;br /&gt;
Set the option, then re-build and install the kernel for booting on the target board.&lt;br /&gt;
&lt;br /&gt;
Step 2: Tell dmesg to retrieve the larger buffer:&lt;br /&gt;
Even though the buffer is larger in the kernel, dmesg will still default to only reading 16K, unless told otherwise.  To read the full buffer, use the '-s' option&lt;br /&gt;
like so: &lt;br /&gt;
 $dmesg -s 128000&lt;br /&gt;
&lt;br /&gt;
== Using kernel symbols ==&lt;br /&gt;
You can look up the source code for a function address using your toolchain's addr2line program.&lt;br /&gt;
See [[Find a kernel function line]] or [[Addr2line for kernel debugging]].&lt;br /&gt;
&lt;br /&gt;
== Using a kernel debugger ==&lt;br /&gt;
You can use the in-kernel debugger: [[KDB]]&lt;br /&gt;
&lt;br /&gt;
Also, you can use QEMU and gdb (and a high-level IDE like eclipse).&lt;br /&gt;
&lt;br /&gt;
See [http://issaris.blogspot.com/2007/12/download-linux-kernel-sourcecode-from.html Debugging the Linux kernel using Eclipse/CDT and Qemu] for a great article on using Eclipse (with the CDT plugin) to debug the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Triggering a kernel event ==&lt;br /&gt;
=== Overloading the sync system call ===&lt;br /&gt;
Sometimes, it is nice to trigger an event to happen in the kernel from user space. Instead of creating infrastructure to handle a /proc event, an ioctl() or making a new syscall, it can be quick and easy to just overload an existing function.  One function not used very often is sync.   (I have found that the sync system call is not normally called by user space programs (or during standard linux booting). &lt;br /&gt;
&lt;br /&gt;
It is quite easy to put a hook to your own kernel program in the sys_sync() routine (located in fs/sync.c) and cause it to execute by issuing 'sync' from the shell command line. This is handy as a temporary mechanism to test things that you have put in the kernel. &lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
&lt;br /&gt;
== Interpreting an Oops message ==&lt;br /&gt;
When the kernel encounters an internal fault, it will print an Oops message.&lt;br /&gt;
Here are some tips on using the Oops message to find the source of the problem.&lt;br /&gt;
* See [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob_plain;f=Documentation/oops-tracing.txt;hb=HEAD Documentation/oops-tracing.txt]&lt;br /&gt;
* See [http://vmlinux.org/jocke/linux/howto-find-oops-location.shtml HOWTO find oops location] by Denis Vlasenko&lt;br /&gt;
&lt;br /&gt;
== Compilation tricks for the kernel ==&lt;br /&gt;
Sometimes, you want to modify how the compiler builds an individual kernel file.  The following are tips for doing tasks related to this.&lt;br /&gt;
=== Build an individual file ===&lt;br /&gt;
You can build an individual output object file, with:&lt;br /&gt;
 make fs/buffer.o&lt;br /&gt;
&lt;br /&gt;
This will build JUST fs/buffer.o (if it needs rebuilding) and not the entire kernel.  To force it to need re-building, use 'touch' on the associated source file: &lt;br /&gt;
 touch fs/buffer.c&lt;br /&gt;
&lt;br /&gt;
=== Create the preprocessed file for an individual source file ===&lt;br /&gt;
Using the same technique, you can create the preprocessed file for a C source file.  This is useful if you're having trouble tracking down macro expansion or where defines/prototypes are coming from exactly.&lt;br /&gt;
 make fs/buffer.i&lt;br /&gt;
&lt;br /&gt;
=== Create the assembly file for an individual source file ===&lt;br /&gt;
Using the same technique, you can create the assembly file for a C source file.  This is useful to get an idea what actual machine instructions are generated from the C source code.&lt;br /&gt;
 make fs/buffer.s&lt;br /&gt;
&lt;br /&gt;
Another way to get the raw assembly, is to dump the object file using 'objdump'&lt;br /&gt;
 objdump -d fs/buffer.o &amp;gt; fs/buffer.disassem&lt;br /&gt;
&lt;br /&gt;
This will produce a disassembly of the object file, which should show how the assembly was translated into machine instructions.&lt;br /&gt;
&lt;br /&gt;
If the object has been compiled with debug symbols (using '-g'), then you might get more information using the '-S' option with objdump:&lt;br /&gt;
 objdump -S -d fs/buffer.o &amp;gt;fs/buffer.disassem&lt;br /&gt;
&lt;br /&gt;
You can also request that the toolchain show mixed source and assembly, by passing extra flags:&lt;br /&gt;
 make EXTRA_CFLAGS=&amp;quot;-g -Wa,-a,-ad -fverbose-asm&amp;quot; fs/buffer.o &amp;gt;fs/buffer.mixed&lt;br /&gt;
&lt;br /&gt;
=== Alter the flags for a compilation ===&lt;br /&gt;
Sometimes, you need to alter the compilation flags for an individual file.  There are two ways to do this. One is to add the extra flags on the make command line:&lt;br /&gt;
&lt;br /&gt;
 make EXTRA_CFLAGS=&amp;quot;-g -finstrument-functions&amp;quot; fs/buffer.o&lt;br /&gt;
&lt;br /&gt;
This will work if the flags can be appended to the regular set of C flags used for compiling the object.&lt;br /&gt;
&lt;br /&gt;
However, if you need to do something more complicated, like removing or modifying flags, then you can build your own command line by hand.  To do this, it is easiest to have 'make' produce the default compilation command (which will be several lines long), then copy, paste and edit it, to run on the command line directly.  To see the exact compile commands used to compile a particular object, use the V=1 option with the kernel build system:&lt;br /&gt;
&lt;br /&gt;
 make V=1 fs/buffer.o&lt;br /&gt;
&lt;br /&gt;
For me, this produced something like this:&lt;br /&gt;
&lt;br /&gt;
mipsel-linux-gcc -Wp,-MD,fs/.buffer.o.d -nostdinc -isystem /home/usr/local/mipsel-linux-glibc/bin/../lib/gcc/mipsisa32el-linux/3.4.3/include -D__KERNEL__ -Iinclude -Iinclude2 -I/home/tbird/work/linux/include -I/home/tbird/work/linux/fs -Ifs -Wall -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -ffreestanding -O2 -fomit-frame-pointer -g -I/home/tbird/work/linux/ -I /home/tbird/work/linux/include/asm/gcc -G 0 -mno-abicalls -fno-pic -pipe -finline-limit=100000 -mabi=32 -march=mips32r2 -Wa,-32 -Wa,-march=mips32r2 -Wa,-mips32r2 -Wa,--trap -I/home/tbird/work/linux/include/asm-mips/ati -Iinclude/asm-mips/ati -I/home/tbird/work/linux/include/asm-mips/mach-generic -Iinclude/asm-mips/mach-generic -Wdeclaration-after-statement  -DKBUILD_BASENAME=buffer -DKBUILD_MODNAME=buffer -c -o fs/buffer.o /home/tbird/work/linux/fs/buffer.c&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-04-03T20:42:26Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Moved Debugging Early boot problems from Debugging tipps here.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported format strings are also quite similar to the standard ones&lt;br /&gt;
supported in printf and are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== Debugging early boot problems ==&lt;br /&gt;
=== Accessing the printk buffer after a silent hang on boot ===&lt;br /&gt;
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang.  However, there may still be messages in the printk buffer, which can give you an idea of where the problem is.&lt;br /&gt;
&lt;br /&gt;
The kernel starts putting messages into the printk buffer as soon as it starts.  They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices).  Even though these messages are not printed before the hang, it is still possible in some circumstances&lt;br /&gt;
to dump the printk buffer and see the messages.&lt;br /&gt;
&lt;br /&gt;
The tricky parts of doing this are:&lt;br /&gt;
&lt;br /&gt;
# using a warm reset (if possible) so the memory contents are not lost when transitioning from the stuck kernel to the bootloader.  You ''can'' do a cold boot, but if the memory is left unpowered for very long, you will start to see memory corruption.&lt;br /&gt;
# figuring out the address to use in the bootloader, based on the address of __log_buf in System.map.  You will probably need to subtract the value of CONFIG_PAGE_OFFSET from the __log_buf address.  However, there may be other offsets present as well (such as TEXT_OFFSET).  Sometimes you can find the buffer by dumping the memory in a suspected area and locating the kernel messages visually in the dump.  Note that the mapping offset between the kernel map of memory and the bootloader map of memory should not change.  So once you figure it out you are set.&lt;br /&gt;
&lt;br /&gt;
Quinn Jensen writes:&lt;br /&gt;
&lt;br /&gt;
Something I've found handy when the console is silent is to dump the printk buffer from the boot loader.  To do it you have to know how your boot loader maps memory compared to the kernel.&lt;br /&gt;
&lt;br /&gt;
==== Redboot example on a Freescale ADS board ====&lt;br /&gt;
Quinn says: Here's what I do with Redboot on i.MX31:&lt;br /&gt;
&lt;br /&gt;
 fgrep printk_buf System.map&lt;br /&gt;
&lt;br /&gt;
this shows the linked address of the printk_buf, e.g.:&lt;br /&gt;
&lt;br /&gt;
 c02338f0 b printk_buf.16194&lt;br /&gt;
&lt;br /&gt;
The address &amp;quot;c02338f0&amp;quot; is in kernel virtual, which, in the case of i.MX31 ADS, redboot will have mapped to 0x802338f0.  So, after resetting the target board, but without letting it try to boot again, at the redboot prompt:&lt;br /&gt;
&lt;br /&gt;
 dump -b 0x802338f0 -l 10000&lt;br /&gt;
&lt;br /&gt;
And you see the printk buffer that never got flushed to the UART.  Knowing what's there can be '''very''' useful in debugging your console.&lt;br /&gt;
&lt;br /&gt;
==== U-boot example on an OMAP OSK board ====&lt;br /&gt;
Tim Bird tried these steps and they worked:&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf System.map&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 grep __log_buf /proc/kallsyms&lt;br /&gt;
&lt;br /&gt;
These show:&lt;br /&gt;
&lt;br /&gt;
 c0352d88 B __log_buf&lt;br /&gt;
&lt;br /&gt;
In the case of the OSK, this address maps to 0x10352d88.  So I reset the target board and use the following:&lt;br /&gt;
&lt;br /&gt;
 OMAP5912 OSK # md 10352d88&lt;br /&gt;
 10352d88: 4c3e353c 78756e69 72657620 6e6f6973    &amp;lt;5&amp;gt;Linux version&lt;br /&gt;
 10352d98: 362e3220 2e32322e 612d3631 6e5f706c     2.6.22.16-alp_n&lt;br /&gt;
 10352da8: 7428206c 64726962 6d697440 6b736564    l (tbird@timdesk&lt;br /&gt;
 10352db8: 2e6d612e 796e6f73 6d6f632e 67282029    .am.sony.com) (g&lt;br /&gt;
 10352dc8: 76206363 69737265 33206e6f 342e342e    cc version 3.4.4&lt;br /&gt;
 10352dd8: 34232029 45525020 54504d45 65755420    ) #4 PREEMPT Tue&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Grub also supports a dump command which you can invoke from the grub prompt.&lt;br /&gt;
 dump  [ -s offset ] [-n length] { FILE | (mem) }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using CONFIG_DEBUG_LL and printascii() (ARM only) ===&lt;br /&gt;
If the kernel fails before the serial console is enabled, you can use CONFIG_DEBUG_LL to add extra debug output routines to the kernel.  These are printascii, printch and printhex. These routines print directly to the serial port, bypassing the console code, and are available earlier in machine initialization.&lt;br /&gt;
&lt;br /&gt;
Here is an e-mail exchange seen on the linux-embedded mailing list (with answer by George Davis):[http://www.mail-archive.com/linux-embedded@vger.kernel.org/msg00223.html] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; When we try to boot a 2.6.21 kernel after uncompressing the kernel the boot process dies somehow.&lt;br /&gt;
&amp;gt; We've figured out so far that the kernel dies somewhere between the gunzip and start_kernel.&lt;br /&gt;
&lt;br /&gt;
Try enabling DEBUG_LL to see if it's an machine ID error.  If you see:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported processor variant.&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
Error: unrecognized/unsupported machine ID...&lt;br /&gt;
&lt;br /&gt;
Then you either don't have proper processor support enabled for your target or your bootloader is passing in the wrong machine number.&lt;br /&gt;
&lt;br /&gt;
If you still don't see anything, try hacking printk.c to call printascii() (enabled for the DEBUG_LL case) to print directly to the serial port w/o a driver, etc.,.  You can find more details on these low-level debugging hacks via a little googling...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
You can also specify an argument on the kernel command line to enable this, or&lt;br /&gt;
you can enable it any time at runtime by doing the following:&lt;br /&gt;
&lt;br /&gt;
  $echo 1 &amp;gt;/sys/module/printk/parameters/time&lt;br /&gt;
&lt;br /&gt;
Also, there are tools available to use the information to show relative times&lt;br /&gt;
between printks (scripts/show_delta) and create graphs of durations in the&lt;br /&gt;
kernel (scripts/bootgraph.pl)&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more details&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [[Printk]]&lt;br /&gt;
* []http://lwn.net/Articles/487437/ LWN.net: The perils of pr_info()]&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-04-03T20:11:55Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: /* References and external links */  Added LWN Link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported format strings are also quite similar to the standard ones&lt;br /&gt;
supported in printf and are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
You can also specify an argument on the kernel command line to enable this, or&lt;br /&gt;
you can enable it any time at runtime by doing the following:&lt;br /&gt;
&lt;br /&gt;
  $echo 1 &amp;gt;/sys/module/printk/parameters/time&lt;br /&gt;
&lt;br /&gt;
Also, there are tools available to use the information to show relative times&lt;br /&gt;
between printks (scripts/show_delta) and create graphs of durations in the&lt;br /&gt;
kernel (scripts/bootgraph.pl)&lt;br /&gt;
&lt;br /&gt;
See [[Printk Times]] for more details&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [[Printk]]&lt;br /&gt;
* []http://lwn.net/Articles/487437/ LWN.net: The perils of pr_info()]&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/MagicSysRq</id>
		<title>MagicSysRq</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/MagicSysRq"/>
				<updated>2012-03-28T21:04:28Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;----&lt;br /&gt;
'''Note''': This article is currently only a draft and is a part of a series of articles I'm going to publish the next few months - if you want to contribute to it, please feel free to. However it would be nice if you could coordinate your efforts with [[User:Peter_Huewe|me]]&lt;br /&gt;
&lt;br /&gt;
This article is still work in progress and still needs a lot of effort.&lt;br /&gt;
----&lt;br /&gt;
== Introduction ==&lt;br /&gt;
MagicSysRq is a special key combination which lets the user perform certain&lt;br /&gt;
low level tasks of the kernel and is especially useful when the whole system&lt;br /&gt;
seems to be hung.&lt;br /&gt;
MagicSysRq e.g. makes it possible to, more or less, cleanly shutdown a system,&lt;br /&gt;
which doesn't even respond to CTRL+ALT+DEL any more.&lt;br /&gt;
&lt;br /&gt;
The MagicSysRq functions are invoked by pressing ALT+SysRq+Function Key where&lt;br /&gt;
function key describes one of the following.&lt;br /&gt;
&lt;br /&gt;
TODO:Insert table here&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The probably most used combination of MagicSysRq functions is the one RSEIUB,&lt;br /&gt;
which can be easyly remebered by the mnemonic trick ``Raising Elephants is so&lt;br /&gt;
utterly boring'' \footnote{``You can still find several references the&lt;br /&gt;
mnemonic ''Raising Skinny Elephants is utterly boring'' on the internet -&lt;br /&gt;
however it is probably better to do the sync after the tasks exited/were&lt;br /&gt;
killed}&lt;br /&gt;
- although we're dealing with penguins here ;)&lt;br /&gt;
According to the table above this performs, in order:&lt;br /&gt;
R Put Keyboard in Raw Mode&lt;br /&gt;
E terminate all tasks&lt;br /&gt;
I kill all tasks&lt;br /&gt;
S Sync&lt;br /&gt;
U remount all filesystems read-only&lt;br /&gt;
B Reboot&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
You can easily and safely check whether MagicSysRq works on your System by&lt;br /&gt;
pressing&lt;br /&gt;
Alt+SysRq+H - on a console you should now see a short help text of the&lt;br /&gt;
MagicSysRq Feature or at least print this to `dmesg`.&lt;br /&gt;
&lt;br /&gt;
If you don't see the help text, check whether CONFIG\_MAGIC\_SYSRQ=y is set in&lt;br /&gt;
your Kernel Config.&lt;br /&gt;
If it is set, please check the output of 'cat /proc/sys/kernel/sysrq' which&lt;br /&gt;
should report 1 if MagicSysRq is enabled. To enable it just do a simple echo 1&lt;br /&gt;
&amp;gt; /proc/sys/kernel/sysrq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Important Files ==&lt;br /&gt;
/proc/sys/kernel/sysrq - enable/disable MagicSysRq at runtime&lt;br /&gt;
/proc/sysrq-trigger - trigger MagicSysRq from the console (e.g. useful over&lt;br /&gt;
ssh)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TODO Content:&lt;br /&gt;
* Explanation of remaining keys&lt;br /&gt;
* using it over serial line -&amp;gt; BREAK+key, in kermit ctrl-\ b KEY&lt;br /&gt;
* Interaction with KDB &lt;br /&gt;
* Interaction with kexec / crashkernel&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_SysRq_key Wikipedia Article about Magic_SysRq_key]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/sysrq.txt;hb=HEAD  Kernel Documentation/sysrq.txt]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/MagicSysRq</id>
		<title>MagicSysRq</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/MagicSysRq"/>
				<updated>2012-03-28T21:03:41Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;----&lt;br /&gt;
'''Note''': This article is currently only a draft and is a part of a series of articles I'm going to publish the next few months - if you want to contribute to it, please feel free to. However it would be nice if you could coordinate your efforts with [[User:Peter_Huewe|me]&lt;br /&gt;
This article is still work in progress and still needs a lot of effort.&lt;br /&gt;
]&lt;br /&gt;
----&lt;br /&gt;
== Introduction ==&lt;br /&gt;
MagicSysRq is a special key combination which lets the user perform certain&lt;br /&gt;
low level tasks of the kernel and is especially useful when the whole system&lt;br /&gt;
seems to be hung.&lt;br /&gt;
MagicSysRq e.g. makes it possible to, more or less, cleanly shutdown a system,&lt;br /&gt;
which doesn't even respond to CTRL+ALT+DEL any more.&lt;br /&gt;
&lt;br /&gt;
The MagicSysRq functions are invoked by pressing ALT+SysRq+Function Key where&lt;br /&gt;
function key describes one of the following.&lt;br /&gt;
&lt;br /&gt;
TODO:Insert table here&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The probably most used combination of MagicSysRq functions is the one RSEIUB,&lt;br /&gt;
which can be easyly remebered by the mnemonic trick ``Raising Elephants is so&lt;br /&gt;
utterly boring'' \footnote{``You can still find several references the&lt;br /&gt;
mnemonic ''Raising Skinny Elephants is utterly boring'' on the internet -&lt;br /&gt;
however it is probably better to do the sync after the tasks exited/were&lt;br /&gt;
killed}&lt;br /&gt;
- although we're dealing with penguins here ;)&lt;br /&gt;
According to the table above this performs, in order:&lt;br /&gt;
R Put Keyboard in Raw Mode&lt;br /&gt;
E terminate all tasks&lt;br /&gt;
I kill all tasks&lt;br /&gt;
S Sync&lt;br /&gt;
U remount all filesystems read-only&lt;br /&gt;
B Reboot&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
You can easily and safely check whether MagicSysRq works on your System by&lt;br /&gt;
pressing&lt;br /&gt;
Alt+SysRq+H - on a console you should now see a short help text of the&lt;br /&gt;
MagicSysRq Feature or at least print this to `dmesg`.&lt;br /&gt;
&lt;br /&gt;
If you don't see the help text, check whether CONFIG\_MAGIC\_SYSRQ=y is set in&lt;br /&gt;
your Kernel Config.&lt;br /&gt;
If it is set, please check the output of 'cat /proc/sys/kernel/sysrq' which&lt;br /&gt;
should report 1 if MagicSysRq is enabled. To enable it just do a simple echo 1&lt;br /&gt;
&amp;gt; /proc/sys/kernel/sysrq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Important Files ==&lt;br /&gt;
/proc/sys/kernel/sysrq - enable/disable MagicSysRq at runtime&lt;br /&gt;
/proc/sysrq-trigger - trigger MagicSysRq from the console (e.g. useful over&lt;br /&gt;
ssh)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TODO Content:&lt;br /&gt;
* Explanation of remaining keys&lt;br /&gt;
* using it over serial line -&amp;gt; BREAK+key, in kermit ctrl-\ b KEY&lt;br /&gt;
* Interaction with KDB &lt;br /&gt;
* Interaction with kexec / crashkernel&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_SysRq_key Wikipedia Article about Magic_SysRq_key]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/sysrq.txt;hb=HEAD  Kernel Documentation/sysrq.txt]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/User:Peter_Huewe</id>
		<title>User:Peter Huewe</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/User:Peter_Huewe"/>
				<updated>2012-03-18T17:53:19Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Thanks for visiting my page.&lt;br /&gt;
&lt;br /&gt;
I'm a 26 year old Embedded Linux Software Developer from Germany.&lt;br /&gt;
&lt;br /&gt;
Don't hesitate to contact me if you have any questions.&lt;br /&gt;
I'm always open to new ideas and interesting projects.&lt;br /&gt;
&lt;br /&gt;
Contact:&lt;br /&gt;
Email: broeggle &amp;lt;at&amp;gt; scheissprovider &amp;lt;dot&amp;gt; de&lt;br /&gt;
PeterHuewe &amp;lt;at&amp;gt; linux &amp;lt;dot&amp;gt; com&lt;br /&gt;
&lt;br /&gt;
Jabber: broeggle &amp;lt;at&amp;gt; jabber &amp;lt;dot&amp;gt; ccc &amp;lt;dot&amp;gt; de&lt;br /&gt;
&lt;br /&gt;
ICQ : 137 1111 59&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of articles I'm currently working on / will be working on:&lt;br /&gt;
* [[Debugging by printing]]&lt;br /&gt;
* [[Debugging by querying]]&lt;br /&gt;
* [[Debugging OOPS]]&lt;br /&gt;
* [[JTAG]]&lt;br /&gt;
* [[MagicSysRq]]&lt;br /&gt;
* [[gcov]]&lt;br /&gt;
* [[profiling]]&lt;br /&gt;
* [[tracing]]&lt;br /&gt;
* [[Kernel Debug Support]]&lt;br /&gt;
* [[KGDB]]\[[KDB]]&lt;br /&gt;
* [[FTrace]] -&amp;gt; [[kernelshark]]&lt;br /&gt;
* [[LTTng]]&lt;br /&gt;
* [[oprofile]]&lt;br /&gt;
* [[System Tap]]&lt;br /&gt;
* [[Kprobes]]&lt;br /&gt;
* [[perf]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [[Debugging Portal]]&lt;br /&gt;
&lt;br /&gt;
Please feel free to help me ;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Currently missing articles on elinux.org&lt;br /&gt;
[[Coreboot]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/BeaconBoard</id>
		<title>BeaconBoard</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/BeaconBoard"/>
				<updated>2012-03-18T17:51:21Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: /* RGB LED */ Added RGB Led driver for Kernel 3.2 for Beagle and Pandaboard&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Description =&lt;br /&gt;
&lt;br /&gt;
Beacon Board is a small accessory board that is primarily intended for use with the [[PandaBoard]] or [[BeagleBoard]] however it can be wired into any development platform that supports GPIOs&lt;br /&gt;
&lt;br /&gt;
[[File:BeaconBoard.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
= Sponsors =&lt;br /&gt;
&lt;br /&gt;
The Beacon Board is sponsored by:&lt;br /&gt;
&lt;br /&gt;
* [http://tincantools.com TinCanTools]&lt;br /&gt;
* [http://boardzoo.com BoardZoo]&lt;br /&gt;
* Designed by [[User:Prpplague| David Anders]]&lt;br /&gt;
* Layout by Chris Auten&lt;br /&gt;
* Assembly by [http://www.circuitco.com/ CircuitCo]&lt;br /&gt;
&lt;br /&gt;
= Features =&lt;br /&gt;
&lt;br /&gt;
* Single tricolored RGB LED ([[media:rgb-led.pdf|datasheet]])&lt;br /&gt;
* WS2801 RGB LED PWM controller ([[media:ws2801.pdf|datasheet]])&lt;br /&gt;
* 74HC595 Serial Shift Register ([[media:74hc595.pdf|datasheet]])&lt;br /&gt;
* 7 Segment Display ([[media:7seg-display.pdf|datasheet]])&lt;br /&gt;
* 74AVC8T245 Level Shifter ([[media:74AVC8T245.pdf|datasheet]])&lt;br /&gt;
* I2C EEPROM ([[media:cat24aa01.pdf|datasheet]])&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&lt;br /&gt;
* [http://www.protostack.com/blog/2011/06/atmega168a-pulse-width-modulation-pwm/ PWM Tutorial]&lt;br /&gt;
* [http://conductiveresistance.com/interactive-595-shift-register-simulator/ 595 Tutorial]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Seven-segment_display_character_representations 7 Segment Display Character Mapping]&lt;br /&gt;
&lt;br /&gt;
= Projects =&lt;br /&gt;
* [http://youtu.be/jP0X9_z2pTQ 7 Segment Display Video]&lt;br /&gt;
&lt;br /&gt;
= Design =&lt;br /&gt;
&lt;br /&gt;
* [[media:beacon-revb1.pdf|Schematic]]&lt;br /&gt;
&lt;br /&gt;
= Interface =&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connectors ==&lt;br /&gt;
* Male Header Major Leage TSHS-114-D-06-A-T-LF&lt;br /&gt;
* Female Header Major League LSWSS-114-D-02-T-LF&lt;br /&gt;
* Digikey Part - http://search.digikey.com/us/en/products/1-534998-4/A26493-ND/352964 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 7 Segment Display ==&lt;br /&gt;
{|border=1&lt;br /&gt;
!Pin&lt;br /&gt;
!Function&lt;br /&gt;
!Beagle&lt;br /&gt;
!Panda&lt;br /&gt;
!Comment&lt;br /&gt;
|-&lt;br /&gt;
|14&lt;br /&gt;
|CLOCK&lt;br /&gt;
|GPIO161&lt;br /&gt;
|GPIO139&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|16&lt;br /&gt;
|LATCH&lt;br /&gt;
|GPIO162&lt;br /&gt;
|GPIO137&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
|DATA&lt;br /&gt;
|GPIO145&lt;br /&gt;
|GPIO138&lt;br /&gt;
|&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== RGB LED ==&lt;br /&gt;
{|border=1&lt;br /&gt;
!Pin&lt;br /&gt;
!Function&lt;br /&gt;
!Beagle&lt;br /&gt;
!Panda&lt;br /&gt;
!Comment&lt;br /&gt;
|-&lt;br /&gt;
|12&lt;br /&gt;
|DATA&lt;br /&gt;
|GPIO158&lt;br /&gt;
|GPIO136&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|18&lt;br /&gt;
|CLOCK&lt;br /&gt;
|GPIO159&lt;br /&gt;
|GPIO135&lt;br /&gt;
|&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Software =&lt;br /&gt;
== 7 Segment Display ==&lt;br /&gt;
* Driver for Linux Kernel 3.0&lt;br /&gt;
* Userspace Shell Script&lt;br /&gt;
** [[media:do7-panda.sh|PandaBoard for busybox ash]]&lt;br /&gt;
** [[media:do7-beagle.sh|BeagleBoard for bash]]&lt;br /&gt;
&lt;br /&gt;
== RGB LED ==&lt;br /&gt;
* [[media:kernel-ws2801-driver.patch| WS2801 Driver for Linux Kernel 3.0]]&lt;br /&gt;
* [[media:0001-LEDS-add-initial-support-for-WS2801-controller-Panda.patch‎| WS2801 Driver for Linux Kernel 3.2 (PandaBoard)]]&lt;br /&gt;
* [[media:0001-LEDS-add-initial-support-for-WS2801-controller-Beagl.patch‎| WS2801 Driver for Linux Kernel 3.2 (BeagleBoard)]]&lt;br /&gt;
* Userspace shell script&lt;br /&gt;
&lt;br /&gt;
== Angstrom ==&lt;br /&gt;
&lt;br /&gt;
* [http://git.angstrom-distribution.org/cgi-bin/cgit.cgi/meta-texasinstruments/commit/?id=7bab703f4ac28a1982eb9b16eea97330579404c6 Commit info]&lt;br /&gt;
&lt;br /&gt;
[[Category:BeagleBoard]]&lt;br /&gt;
[[Category:BeagleBoard Expansion Boards]]&lt;br /&gt;
[[Category:TinCanTools]]&lt;br /&gt;
&lt;br /&gt;
== Projects using BeaconBoard ==&lt;br /&gt;
&lt;br /&gt;
* [https://gitorious.org/av500/bacon-lunch Bacon Lunch] ([http://www.youtube.com/watch?v=OHhKzCKFINQ video])&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/File:0001-LEDS-add-initial-support-for-WS2801-controller-Panda.patch</id>
		<title>File:0001-LEDS-add-initial-support-for-WS2801-controller-Panda.patch</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/File:0001-LEDS-add-initial-support-for-WS2801-controller-Panda.patch"/>
				<updated>2012-03-18T17:47:35Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: LEDS: add initial support for WS2801 controller (PandaBoard)

This adds initial support for the WS2801 RGB LED controller on the
beaconboard for the Panda Board&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;LEDS: add initial support for WS2801 controller (PandaBoard)&lt;br /&gt;
&lt;br /&gt;
This adds initial support for the WS2801 RGB LED controller on the&lt;br /&gt;
beaconboard for the Panda Board&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/File:0001-LEDS-add-initial-support-for-WS2801-controller-Beagl.patch</id>
		<title>File:0001-LEDS-add-initial-support-for-WS2801-controller-Beagl.patch</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/File:0001-LEDS-add-initial-support-for-WS2801-controller-Beagl.patch"/>
				<updated>2012-03-18T17:46:51Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: This adds initial support for the WS2801 RGB LED controller on the
beaconboard for the BeagleBoard

v2:
- Make it compile on 3.2 and up&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This adds initial support for the WS2801 RGB LED controller on the&lt;br /&gt;
beaconboard for the BeagleBoard&lt;br /&gt;
&lt;br /&gt;
v2:&lt;br /&gt;
- Make it compile on 3.2 and up&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Main_Page</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Main_Page"/>
				<updated>2012-03-18T16:08:29Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Added Debugging Portal&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{|&lt;br /&gt;
| nowrap style=&amp;quot;vertical-align: top; font: bold xx-large sans-serif;&amp;quot; |&lt;br /&gt;
Embedded Linux Wiki&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin:0; margin-top:10px; margin-right:10px; border:1px solid #CCCC00; padding:0 1em 1em 1em; background-color:#ffffcc; align:right;&amp;quot;&amp;gt;&lt;br /&gt;
'''Site Maintenance Notification!'''&lt;br /&gt;
&lt;br /&gt;
The site will undergo maintenance on Monday, September 13, 2010 between the hours of 7:30pm PDT and 10:00pm PDT or earlier.  The site will be Read Only during this period.  Removal of this notice, a mailing list post, and IRC update will indicate that edit capability had been restored.  Thanks for your patience.&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;br/&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Welcome to the eLinux wiki!  The purpose of this wiki is to preserve and present information about the&lt;br /&gt;
development and use of Linux in embedded systems. To use this wiki, click on one of the portal links below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin:0; margin-top:10px; margin-right:10px; border:1px solid #dfdfdf; padding:0 1em 1em 1em; background-color:#ffffcc; align:right; &amp;quot;&amp;gt;&lt;br /&gt;
'''ELC2011 Presentations'''&lt;br /&gt;
&lt;br /&gt;
All presentations can be found on [[ELC_2011_Presentations]] eventually.  Presenters are encouraged to add their presentations asap.  NOTE:  If you add a wikilink to your presentation and attempt to upload it via the link, it may fail.  If it does, use the [[Special:Upload]] page to upload your file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Development Portals ==&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|style=&amp;quot;vertical-align:top&amp;quot; |&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0; margin-top:10px; margin-right:10px; padding: 0 1em 1em 1em; align:right;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin-left: 25px;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;width: 100%; margin:0; padding:0; border-collapse: collapse;&amp;quot;&lt;br /&gt;
| style=&amp;quot;width: 25%;&amp;quot; | [[image:Welly1.jpg|link=Boot Time]] [[Boot Time]]&lt;br /&gt;
| style=&amp;quot;width: 25%;&amp;quot; | [[image:cfcard.jpg|link=Memory Management]] [[Memory Management]]&lt;br /&gt;
| style=&amp;quot;width: 25%;&amp;quot; | [[image:Padlock2.jpg|link=Security]] [[Security]]&lt;br /&gt;
| style=&amp;quot;width: 25%;&amp;quot; | [[image:Event.jpg|link=Events]] [[Events]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:Multimedia.png|link=Multimedia]] [[Multimedia]]&lt;br /&gt;
| [[image:Power.png|link=Power Management]] [[Power Management]]&lt;br /&gt;
| [[image:Blimp.jpg|link=System Size]] [[System Size]]&lt;br /&gt;
| [[image:Skull.jpg|link=Hardware Hacking]] [[Hardware Hacking]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:Filecab.jpg|link=File Systems]] [[File Systems]]&lt;br /&gt;
| [[image:clockface.jpg|link=Real Time]] [[Real Time]]&lt;br /&gt;
| [[image:Board2.jpg|link=Resource Management]] [[Resource Management]]&lt;br /&gt;
| [[image:Board.jpg|link=Development Platforms]] [[Development Platforms]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:Icon-network.png|link=:Category:Networking]] [[:Category:Networking|Networking]]&lt;br /&gt;
| [[image:Processor.png|link=Firmware]] [[Firmware]]&lt;br /&gt;
| [[image:justice-scales.png|link=Legal Issues]] [[Legal Issues]]&lt;br /&gt;
| [[image:Toolbox.jpg|link=Toolbox]] [[Toolbox]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:Android.png|link=Android Portal]] [[Android Portal]]&lt;br /&gt;
| [[image:icon-inspector2.png|link=Debugging Portal]] [[Debugging Portal]]&lt;br /&gt;
| [[image:Category-box.png|link=:Category:Categories]] [[:Category:Categories]]&lt;br /&gt;
| &amp;lt;br /&amp;gt;&lt;br /&gt;
| &amp;lt;br /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin:0; margin-top:10px; margin-right:10px; border:1px solid #dfdfdf; padding:0 1em 1em 1em; background-color:#ffffcc; align:right; &amp;quot;&amp;gt;&lt;br /&gt;
'''ELC 2012 Presentations Page'''&lt;br /&gt;
&lt;br /&gt;
Presentations can be added to the [[ELC_2012_Presentations | ELC 2012 Presentations]] page.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin:0; margin-top:10px; margin-right:10px; border:1px solid #dfdfdf; padding:0 1em 1em 1em; background-color:#ccffff; align:right; &amp;quot;&amp;gt;&lt;br /&gt;
'''Highlight - Did you know...?'''&lt;br /&gt;
&lt;br /&gt;
[[Squash FS]] was accepted into the mainline kernel since 2.6.29.  &lt;br /&gt;
SquashFS is a compressed, read-only filesystem, commonly used in many existing embedded Linux systems.&lt;br /&gt;
Phillip Lougher, the Squash FS maintainer, was sponsored by CELF to push this code to mainline.&lt;br /&gt;
It had been used as patches outside of mainline for many years.&lt;br /&gt;
&lt;br /&gt;
See the [[Squash FS|elinux wiki SquashFS page]] or http://en.wikipedia.org/wiki/Squashfs for more information about this useful filesystem.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0; margin-top:10px; margin-right:10px; border: 1px solid #dfdfdf; padding: 0 1em 1em 1em; align:right;&amp;quot;&amp;gt;&lt;br /&gt;
'''Embedded Linux Information'''&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin-left: 25px;&amp;quot;&amp;gt;&lt;br /&gt;
{|style=&amp;quot;width: 100%; margin:0; padding:0; border-collapse: collapse;&amp;quot;&lt;br /&gt;
|style=&amp;quot;width: 20%;&amp;quot;|[[image:Productsico.jpg|link=Products]] [[Products]]&lt;br /&gt;
|style=&amp;quot;width: 20%;&amp;quot;|[[image:Companysico.jpg|link=Companies]] [[Companies]]&lt;br /&gt;
|style=&amp;quot;width: 20%;&amp;quot;|[[image:Vendorsico.jpg|link=Vendors]] [[Vendors]]&lt;br /&gt;
|style=&amp;quot;width: 20%;&amp;quot;|[[image:Processorsico.png|link=Processors]] [[Processors]]&lt;br /&gt;
|-&lt;br /&gt;
|[[image:communityico.jpg|link=Community]] [[Community]]&lt;br /&gt;
|[[image:communityico.jpg|link=Experts]] [[Experts]]&lt;br /&gt;
|[[image:at-work.jpg|link=Jobs]] [[Jobs]]&lt;br /&gt;
|[[image:Companysico.jpg|link=Board and Chip Vendors]] [[Board and Chip Vendors]]&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Technology Watch List ==&lt;br /&gt;
See the [[Technology Watch List]] for a list of interesting&lt;br /&gt;
projects and their current status in the Linux development&lt;br /&gt;
community.&lt;br /&gt;
&lt;br /&gt;
== eLinux.org Information and Usage tips ==&lt;br /&gt;
The main portals of the site take you to lists of resources or collections of&lt;br /&gt;
information, you can use to tackle problems in the particular area referred to.&lt;br /&gt;
For example, if you have a problem with boot up time of your embedded Linux system,&lt;br /&gt;
click on &amp;quot;Boot Time&amp;quot;.&lt;br /&gt;
You can also see a list of [[Special:Allpages|all the pages on this site]].&lt;br /&gt;
&lt;br /&gt;
Please read [[ELinuxWiki:Policies &amp;amp; Guidelines|Policies &amp;amp; Guidelines]] for a detail list of site policies.&lt;br /&gt;
&lt;br /&gt;
The following icons are for general information about this site, and related resources. &lt;br /&gt;
&amp;lt;div style=&amp;quot;margin-left: 50px;&amp;quot;&amp;gt;&lt;br /&gt;
{|style=&amp;quot;width: 100%; margin:0; padding:0; border-collapse: collapse;&amp;quot;&lt;br /&gt;
|style=&amp;quot;width: 25%;&amp;quot;|&lt;br /&gt;
[[image:mp_info.png|16px|link=Help:About]] [[Help:About|About]]&amp;lt;br/&amp;gt;&lt;br /&gt;
[[image:mp_help.png|16px|link=Help:Contents]] [[Help:Contents|Site Policy]]&lt;br /&gt;
|style=&amp;quot;width: 25%;&amp;quot;|&lt;br /&gt;
[[image:mp_man.png|16px|link=Help:Editing]] [[Help:Editing|Editing Help]]&amp;lt;br/&amp;gt;&lt;br /&gt;
[[image:mp_wanted.png|16px|link=Wanted]] [[Wanted|Wanted Pages]]&lt;br /&gt;
|style=&amp;quot;width: 25%;&amp;quot;|&lt;br /&gt;
[[image:mp_mail.png|16px|link=eLinuxWiki:Mailing List]] [[eLinuxWiki:Mailing List|Mailing Lists]]&amp;lt;br/&amp;gt;&lt;br /&gt;
[[image:mp_irc.png|16px|link=eLinuxWiki:Irc]] [[eLinuxWiki:Irc|IRC]]&lt;br /&gt;
|style=&amp;quot;width: 25%;&amp;quot;|&lt;br /&gt;
[[image:mp_admin.png|16px|link=eLinuxWiki:Glossary]] [[eLinuxWiki:Glossary|Glossary]]&amp;lt;br/&amp;gt;&lt;br /&gt;
[[image:mp_twitter.png|16px|link=http://twitter.com/elinux]] [http://twitter.com/elinux Twitter Follow]&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
We hope this information is helpful in your development tasks.&lt;br /&gt;
&lt;br /&gt;
If you see something wrong, please change it.  If you know something more about an issue, please&lt;br /&gt;
add it.  Please [[volunteer editor tasks|help to extend]] this wiki. Thank you!&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
To experiment with this wiki try [[Sandbox]]. See the [http://meta.wikipedia.org/wiki/MediaWiki_User's_Guide User's Guide] for usage and configuration help.&lt;br /&gt;
&lt;br /&gt;
[[Category:Community| ]]&lt;br /&gt;
[[Category:Categories| ]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/File:Icon-inspector2.png</id>
		<title>File:Icon-inspector2.png</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/File:Icon-inspector2.png"/>
				<updated>2012-03-18T16:07:56Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: uploaded a new version of &amp;amp;quot;File:Icon-inspector2.png&amp;amp;quot;: Icon created by Regional Computing Centre Erlangen (RRZE) and licenced under CC-BY-SA.
Retrieved from http://rrze-icon-set.berlios.de/gallery.html#I&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The image shows an Inspector with a magnifying glass.&lt;br /&gt;
Icon created by Regional Computing Centre Erlangen (RRZE) and licenced under CC-BY-SA.&lt;br /&gt;
Retrieved from http://rrze-icon-set.berlios.de/gallery.html#I&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/File:Icon-inspector2.png</id>
		<title>File:Icon-inspector2.png</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/File:Icon-inspector2.png"/>
				<updated>2012-03-18T16:05:40Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: uploaded a new version of &amp;amp;quot;File:Icon-inspector2.png&amp;amp;quot;: Icon created by Regional Computing Centre Erlangen (RRZE) and licenced under CC-BY-SA.
Retrieved from http://rrze-icon-set.berlios.de/gallery.html#I&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The image shows an Inspector with a magnifying glass.&lt;br /&gt;
Icon created by Regional Computing Centre Erlangen (RRZE) and licenced under CC-BY-SA.&lt;br /&gt;
Retrieved from http://rrze-icon-set.berlios.de/gallery.html#I&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/File:Icon-inspector2.png</id>
		<title>File:Icon-inspector2.png</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/File:Icon-inspector2.png"/>
				<updated>2012-03-18T16:00:51Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: The image shows an Inspector with a magnifying glass.
Icon created by Regional Computing Centre Erlangen (RRZE) and licenced under CC-BY-SA.
Retrieved from http://rrze-icon-set.berlios.de/gallery.html#I&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The image shows an Inspector with a magnifying glass.&lt;br /&gt;
Icon created by Regional Computing Centre Erlangen (RRZE) and licenced under CC-BY-SA.&lt;br /&gt;
Retrieved from http://rrze-icon-set.berlios.de/gallery.html#I&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_Portal</id>
		<title>Debugging Portal</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_Portal"/>
				<updated>2012-03-18T15:49:15Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: fixed tables&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is the new portal for all debugging related stuff.&lt;br /&gt;
It currently deals with Kernel topics, but feel free to add user space debugging too.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width=100%; background:#FFF;&amp;quot;&amp;gt;&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;5&amp;quot; cellpadding=&amp;quot;0&amp;quot; valign=&amp;quot;top&amp;quot; style=&amp;quot;background:inherit;&amp;quot;&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;margin: 0 0 0.5em 1em; border:1px solid #aaa; text-align:left; width: 50%;&amp;quot; cellpadding=&amp;quot;5&amp;quot;  |&lt;br /&gt;
&amp;lt;div style=&amp;quot;background: #eeeeee; border: 1px solid #2C547A; padding: 5px; margin: 3px; font-weight:bold;text-align:center;font-size:120%;&amp;quot;&amp;gt;Kernel Debugging&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0 0 1em;&amp;quot;&amp;gt;&lt;br /&gt;
;[[Debugging by printing]]&lt;br /&gt;
;[[Printk]]&lt;br /&gt;
;[[Kernel Debugging Tips]]&lt;br /&gt;
;[[Kgdb]]&lt;br /&gt;
;[[KDB]]&lt;br /&gt;
;[[Debugging The Linux Kernel Using Gdb]]&lt;br /&gt;
;[[MagicSysRq]]&lt;br /&gt;
;External Links:&lt;br /&gt;
*[http://tree.celinuxforum.org/CelfPubWiki/ELC2009Presentations?action=AttachFile&amp;amp;do=get&amp;amp;target=DebuggingWithJtagCelf2009.pdf Embedded Linux JTAG debugging (CELF presentation)]&lt;br /&gt;
*[http://issaris.blogspot.com/2007/12/download-linux-kernel-sourcecode-from.html Debugging the Linux kernel using Eclipse/CDT and Qemu]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;margin: 0 0 0.5em 1em; border:1px solid #aaa; text-align:left; width: 50%;&amp;quot; cellpadding=&amp;quot;5&amp;quot;|&lt;br /&gt;
&amp;lt;div style=&amp;quot;background: #eeeeee; border: 1px solid #2C547A; padding: 5px; margin: 3px; font-weight:bold;text-align:center;font-size:120%;&amp;quot;&amp;gt;Kernel Tracing and Profiling&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0 0 1em;&amp;quot;&amp;gt;&lt;br /&gt;
;[[System Tap]]&lt;br /&gt;
;[[Kernel Trace Systems]]&lt;br /&gt;
;[[Linux Trace Toolkit]]&lt;br /&gt;
;[[LTTng]]&lt;br /&gt;
;[[Ftrace]]&lt;br /&gt;
*[[Measuring Function Duration with FTrace]]&lt;br /&gt;
*[[Ftrace Function Graph ARM]]&lt;br /&gt;
;[[Using Kernel Function Trace]]&lt;br /&gt;
;[[Linux Kernel State Tracer]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_Portal</id>
		<title>Debugging Portal</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_Portal"/>
				<updated>2012-03-18T15:44:38Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Created page with &amp;quot;This page is the new portal for all debugging related stuff. It currently deals with Kernel topics, but feel free to add user space debugging too.  &amp;lt;div style=&amp;quot;width=100%; backgr...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is the new portal for all debugging related stuff.&lt;br /&gt;
It currently deals with Kernel topics, but feel free to add user space debugging too.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;width=100%; background:#FFF;&amp;quot;&amp;gt;&lt;br /&gt;
{| width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;5&amp;quot; cellpadding=&amp;quot;0&amp;quot; valign=&amp;quot;top&amp;quot; style=&amp;quot;background:inherit;&amp;quot;&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;margin: 0 0 0.5em 1em; border:1px solid #aaa; text-align:left; width: 33%;&amp;quot; cellpadding=&amp;quot;5&amp;quot;  |&lt;br /&gt;
&amp;lt;div style=&amp;quot;background: #eeeeee; border: 1px solid #2C547A; padding: 5px; margin: 3px; font-weight:bold;text-align:center;font-size:120%;&amp;quot;&amp;gt;Kernel Debugging&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0 0 1em;&amp;quot;&amp;gt;&lt;br /&gt;
;[[Debugging by printing]]&lt;br /&gt;
;[[Printk]]&lt;br /&gt;
;[[Kernel Debugging Tips]]&lt;br /&gt;
;[[Kgdb]]&lt;br /&gt;
;[[KDB]]&lt;br /&gt;
;[[Debugging The Linux Kernel Using Gdb]]&lt;br /&gt;
;[[MagicSysRq]]&lt;br /&gt;
;External Links:&lt;br /&gt;
*[http://tree.celinuxforum.org/CelfPubWiki/ELC2009Presentations?action=AttachFile&amp;amp;do=get&amp;amp;target=DebuggingWithJtagCelf2009.pdf Embedded Linux JTAG debugging (CELF presentation)]&lt;br /&gt;
*[http://issaris.blogspot.com/2007/12/download-linux-kernel-sourcecode-from.html Debugging the Linux kernel using Eclipse/CDT and Qemu]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; style=&amp;quot;margin: 0 0 0.5em 1em; border:1px solid #aaa; text-align:left; width: 33%;&amp;quot; cellpadding=&amp;quot;5&amp;quot;|&lt;br /&gt;
&amp;lt;div style=&amp;quot;background: #eeeeee; border: 1px solid #2C547A; padding: 5px; margin: 3px; font-weight:bold;text-align:center;font-size:120%;&amp;quot;&amp;gt;Kernel Tracing and Profiling&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin: 0 0 0 1em;&amp;quot;&amp;gt;&lt;br /&gt;
;[[System Tap]]&lt;br /&gt;
;[[Kernel Trace Systems]]&lt;br /&gt;
;[[Linux Trace Toolkit]]&lt;br /&gt;
;[[LTTng]]&lt;br /&gt;
;[[Ftrace]]&lt;br /&gt;
*[[Measuring Function Duration with FTrace]]&lt;br /&gt;
*[[Ftrace Function Graph ARM]]&lt;br /&gt;
;[[Using Kernel Function Trace]]&lt;br /&gt;
;[[Linux Kernel State Tracer]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/HP_t5325</id>
		<title>HP t5325</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/HP_t5325"/>
				<updated>2012-03-17T03:52:10Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Added short writeup of getting vanilla linux to work on hp t5325&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Vanilla Kernel on t5325 ==&lt;br /&gt;
In order to boot a vanilla kernel on the t5325 be sure to set these u-boot environment variables.&lt;br /&gt;
 setenv arcNumber 2846&lt;br /&gt;
 setenv mainlineLinux yes&lt;br /&gt;
 saveenv&lt;br /&gt;
 reset&lt;br /&gt;
&lt;br /&gt;
Otherwise the board will simply hang during boot.&lt;br /&gt;
Please be sure to verify that the ''Machine'' is reported like this&lt;br /&gt;
 [    0.000000] Machine: HP t5325 Thin Client&lt;br /&gt;
and '''not'''&lt;br /&gt;
 [    0.000000] Machine: Marvell DB-88F6281-BP Development Board&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	<entry>
		<id>http://www.elinux.org/Debugging_by_printing</id>
		<title>Debugging by printing</title>
		<link rel="alternate" type="text/html" href="http://www.elinux.org/Debugging_by_printing"/>
				<updated>2012-03-07T23:07:19Z</updated>
		
		<summary type="html">&lt;p&gt;Peter Huewe: Updated article about debugging by printing&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Probably the simplest way to get some debug information from your kernel code is by printing out various information with the kernel's equivalent of printf - the printk function and its derivatives.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
printk works more or less the same way as printf in userspace, so if you ever debugged your userspace program using printf, you are ready to do the same with your kernel code, e.g. by adding:&lt;br /&gt;
 printk(&amp;quot;My Debugger is Printk\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
This wasn't that difficult, was it?&lt;br /&gt;
&lt;br /&gt;
Usually you would print out some more interesting information like&lt;br /&gt;
 printk(&amp;quot;Var1 %d var2 %d\n&amp;quot;, var1, var2);&lt;br /&gt;
just like in userspace.&lt;br /&gt;
&lt;br /&gt;
In order to see the kernel messages, just use the&lt;br /&gt;
 $ dmesg&lt;br /&gt;
command in one of your shells - this one will print out the whole kernel log&lt;br /&gt;
buffer to you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported format strings are also quite similar to the standard ones&lt;br /&gt;
supported in printf and are quite extensively documented in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
&lt;br /&gt;
However please '''note''': always use ''%zu'', ''%zd'' or ''%zx'' for printing&lt;br /&gt;
''size_t'' and ''ssize_t'' values. ssize_t and size_t are quite common values in the kernel, so&lt;br /&gt;
please use the ''%z'' to avoid annoying compile warnings.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
If you want to debug an oops (e.g caused by releasing a resource twice) in your driver and you don't have a clue where the oops happens, simply add this line&lt;br /&gt;
 printk(KERN_ALERT &amp;quot;DEBUG: Passed %s %d \n&amp;quot;,__FUNCTION__,__LINE__);&lt;br /&gt;
after each possibly offending statement.&lt;br /&gt;
Recompile and (re-)load the module and trigger the error condition - your log now shows you the last line that was successfully executed before the oops happened.&lt;br /&gt;
&lt;br /&gt;
Of course you should '''remove''' these 'rude' statements before shipping your module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Log Levels ==&lt;br /&gt;
If you look into real kernel code you will always see something like:&lt;br /&gt;
 printk(KERN_ERR &amp;quot;something went wrong, return code: %d\n&amp;quot;,ret);&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;''KERN_ERR''&amp;quot; is one of the eight different log levels defined in&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] and specifes the severity of the error message.&lt;br /&gt;
&lt;br /&gt;
Note that there is '''NO''' comma between the ''KERN_ERR'' and the format string (as the preprocessor concatenates both strings)&lt;br /&gt;
&lt;br /&gt;
The log levels are:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!Name&lt;br /&gt;
!String&lt;br /&gt;
!Meaning&lt;br /&gt;
!alias function&lt;br /&gt;
|-&lt;br /&gt;
|KERN_EMERG&lt;br /&gt;
|&amp;quot;&amp;lt;0&amp;gt;&amp;quot;&lt;br /&gt;
|Emergency messages, system is about to crash or is unstable&lt;br /&gt;
|pr_emerg&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ALERT&lt;br /&gt;
|&amp;quot;&amp;lt;1&amp;gt;&amp;quot;&lt;br /&gt;
|Something bad happened and action must be taken immediately&lt;br /&gt;
|pr_alert&lt;br /&gt;
|-&lt;br /&gt;
|KERN_CRIT&lt;br /&gt;
|&amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
|A critical condition occurred like a serious hardware/software failure&lt;br /&gt;
|pr_crit&lt;br /&gt;
|-&lt;br /&gt;
|KERN_ERR&lt;br /&gt;
| &amp;quot;&amp;lt;3&amp;gt;&amp;quot;&lt;br /&gt;
|An error condition, often used by drivers to indicate difficulties with the hardware&lt;br /&gt;
|pr_err&lt;br /&gt;
|-&lt;br /&gt;
|KERN_WARNING&lt;br /&gt;
|&amp;quot;&amp;lt;4&amp;gt;&amp;quot;&lt;br /&gt;
|A warning, meaning nothing serious by itself but might indicate problems&lt;br /&gt;
|pr_warning&lt;br /&gt;
|-&lt;br /&gt;
|KERN_NOTICE&lt;br /&gt;
|&amp;quot;&amp;lt;5&amp;gt;&amp;quot;&lt;br /&gt;
|Nothing serious, but notably nevertheless. Often used to report security events.&lt;br /&gt;
|pr_notice&lt;br /&gt;
|-&lt;br /&gt;
|KERN_INFO&lt;br /&gt;
|&amp;quot;&amp;lt;6&amp;gt;&amp;quot;&lt;br /&gt;
|Informational message e.g. startup information at driver initialization&lt;br /&gt;
|pr_info&lt;br /&gt;
|-&lt;br /&gt;
|KERN_DEBUG&lt;br /&gt;
|&amp;quot;&amp;lt;7&amp;gt;&amp;quot;&lt;br /&gt;
|Debug messages&lt;br /&gt;
|pr_debug, pr_devel if DEBUG is defined&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The pr_* macros (with exception of pr_debug) are simple shorthand definitions&lt;br /&gt;
in ''include/linux/printk.h''&lt;br /&gt;
for their respective printk call and should probably be used in newer drivers.&lt;br /&gt;
&lt;br /&gt;
''pr_devel'' and ''pr_debug'' are replaced with ''printk(KERN_DEBUG ...'' if the kernel was&lt;br /&gt;
compiled with ''DEBUG'', otherwise replaced with an empty statement.&lt;br /&gt;
&lt;br /&gt;
For drivers the pr_debug should not be used anymore (use dev_dbg instead).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you don't specify a log level in your message it defaults to&lt;br /&gt;
''DEFAULT_MESSAGE_LOGLEVEL'' (usually ''&amp;quot;&amp;lt;4&amp;gt;&amp;quot;''=''KERN_WARNING'')&lt;br /&gt;
which can be set via the ''CONFIG_DEFAULT_MESSAGE_LOGLEVEL'' kernel config&lt;br /&gt;
option (''make menuconfig-&amp;gt; Kernel Hacking -&amp;gt; Default message log level'')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log level is used by the kernel to determine the importance of&lt;br /&gt;
a message and to decide whether it should be presented to the user&lt;br /&gt;
immediately, by printing it to the current console (where console could also&lt;br /&gt;
be a serial line or even a printer, not an xterm).&lt;br /&gt;
&lt;br /&gt;
For this the kernel compares the log level of the message to the&lt;br /&gt;
''console_loglevel'' (a kernel variable) and if the priority is higher (i.e. a&lt;br /&gt;
lower value) than the ''console_loglevel'' the message will be printed to the current console.&lt;br /&gt;
&lt;br /&gt;
To determine your current ''console_loglevel'' you simply enter:&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 	7       4       1       7&lt;br /&gt;
 	current	default	minimum	boot-time-default&lt;br /&gt;
&lt;br /&gt;
The first integer shows you your current console_loglevel; the second the&lt;br /&gt;
default log level that you have seen above.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To change your current console_loglevel simply write to this file, so in order&lt;br /&gt;
to get all messages printed to the console do a simple&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
and every kernel message will appear on your console.&lt;br /&gt;
&lt;br /&gt;
Another way to change the console log level is to use ''dmesg'' with the ''-n''&lt;br /&gt;
parameter&lt;br /&gt;
 # #set console_loglevel to print KERN_WARNING (4) or more severe messages&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
Only messages with a value lower ('''not''' lower equal) than the&lt;br /&gt;
console_loglevel will be printed.&lt;br /&gt;
&lt;br /&gt;
You can also specify the console_loglevel at boot time using the ''loglevel''&lt;br /&gt;
boot parameter. (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/kernel-parameters.txt;hb=HEAD#l1334 Documentation/kernel-parameters.txt] for more details)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Author's practical advice:'''&amp;lt;br&amp;gt;&lt;br /&gt;
Of course you should always specify an appropriate log level for your messages,&lt;br /&gt;
but for '''debugging''', I guess most developers leave the&lt;br /&gt;
console_loglevel unchanged and simply use KERN_ERR or KERN_CRIT to ensure the message reaches the console.&lt;br /&gt;
&lt;br /&gt;
 pr_err(&amp;quot;REMOVE ME: my debug statement that I swear to remove when I'm done\&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Please make sure to remove these 'inappropriately' tagged messages before&lt;br /&gt;
shipping the module ;)&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Rate limiting and one time messages ==&lt;br /&gt;
Occasionally you have to insert a message in a section which gets called&lt;br /&gt;
quite often. This not only might have a severe performance impact, it also&lt;br /&gt;
could overwrite and spam your kernel buffer so it should be avoided.&lt;br /&gt;
&lt;br /&gt;
As always the kernel already provides you with nice functions that solve your&lt;br /&gt;
problems:&lt;br /&gt;
 printk_ratelimited(...)&lt;br /&gt;
and&lt;br /&gt;
 printk_once(...)&lt;br /&gt;
&lt;br /&gt;
''printk_once'' is fairly trivial - no matter how often you call it, it prints once and never again.&lt;br /&gt;
&lt;br /&gt;
''printk_ratelimited'' is a little bit more complicated - it prints by default not more than 10&lt;br /&gt;
times in every 5 seconds (for each function it is called in).&lt;br /&gt;
&lt;br /&gt;
If you need other values for the maximum burst count and the timeout, you can&lt;br /&gt;
always setup your own ratelimit using the ''DEFINE_RATELIMIT_STATE'' macro and&lt;br /&gt;
the ''__ratelimit'' function - see the implementation of&lt;br /&gt;
''printk_ratelimited'' for an example.&lt;br /&gt;
&lt;br /&gt;
Be sure to ''#include &amp;lt;kernel/ratelimit.h&amp;gt;'' in order to use&lt;br /&gt;
''printk_ratelimited()''&lt;br /&gt;
&lt;br /&gt;
Both functions have also their ''pr_*'' equivalents like&lt;br /&gt;
''pr_info_ratelimited'' for ''printk_ratelimited(KERN_INFO...'' and&lt;br /&gt;
''pr_crit_once'' for ''printk_once(KERN_CRIT...''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note: both did not work as expected in my tests here, will probably investigate further'''&lt;br /&gt;
&lt;br /&gt;
== Printk from userspace ==&lt;br /&gt;
Sometimes, especially when doing automated testing, it is quite useful to&lt;br /&gt;
insert some messages in the kernel log buffer in order to annotate what's&lt;br /&gt;
going on.&lt;br /&gt;
&lt;br /&gt;
It is as simple as&lt;br /&gt;
 # echo &amp;quot;Hello Kernel-World&amp;quot; &amp;gt; /dev/kmsg&lt;br /&gt;
&lt;br /&gt;
Of course this messages gets the default log level assigned, if you want e.g.&lt;br /&gt;
to issue a KERN_CRIT message you have to use the string representation of the&lt;br /&gt;
log level - in this case &amp;quot;&amp;lt;2&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 # echo &amp;quot;&amp;lt;2&amp;gt;Writing critical printk messages from userspace&amp;quot; &amp;gt;/dev/kmsg&lt;br /&gt;
&lt;br /&gt;
The message will appear like any other '''kernel''' message - there is '''no way''' to distinguish them!&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Don't confuse this with printf - we are printing a kernel message&lt;br /&gt;
from userspace here.&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
Printk is implemented by using a ring buffer in the kernel with a size of&lt;br /&gt;
''__LOG_BUF_LEN'' bytes where ''__LOG_BUF_LEN'' equals ''(1 &amp;lt;&amp;lt;&lt;br /&gt;
CONFIG_LOG_BUF_SHIFT)'' (see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] for details).&lt;br /&gt;
&lt;br /&gt;
You can specify the size of the buffer in your kernel config by setting&lt;br /&gt;
''CONFIG_LOG_BUF_SHIFT'' to an appropriate value (e.g. 17 for 128Kb) (''make menuconfig -&amp;gt; General Setup -&amp;gt; Kernel log buffer size'').&lt;br /&gt;
&lt;br /&gt;
Using a ring buffer implies that older messages get overwritten once the&lt;br /&gt;
buffer fills up, but this is only a minor drawback compared to the robustness of this&lt;br /&gt;
solution (i.e. minimum memory footprint, callable from every context, not many&lt;br /&gt;
resources wasted if nobody reads the buffer, no filling up of disk space/ram when some kernel process goes&lt;br /&gt;
wild and spams the buffer, ...).&lt;br /&gt;
Using a reasonably large buffer size should give you enough time to read your&lt;br /&gt;
important messages before they are overwritten.&lt;br /&gt;
&lt;br /&gt;
The kernel log buffer is accessible for reading from userspace by ''/proc/kmsg''.&lt;br /&gt;
''/proc/kmsg'' behaves more or less like a FIFO and blocks until new messages&lt;br /&gt;
appear.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Please note''' - reading from ''/proc/kmsg'' consumes the messages in the&lt;br /&gt;
ring buffer so they may not be available for other programs. It is usually a&lt;br /&gt;
good idea to let ''klogd'' or ''syslog'' do this job and read the content&lt;br /&gt;
of the buffer via ''dmesg''.&lt;br /&gt;
&lt;br /&gt;
== Pros and Cons==&lt;br /&gt;
The main advantage of printk over other debugging solutions is that it requires no sophisticated setup and can be called anywhere from any time.&lt;br /&gt;
Printk can be called while holding a lock, from interrupt and process context, is SMP safe and does not need any special preparation. It is just there and just works.&lt;br /&gt;
The only precondition is that you have some kind of working console to display the messages.&lt;br /&gt;
&lt;br /&gt;
For the early stages in the boot process, where no console is available yet,&lt;br /&gt;
there is a special function named ''early_printk'', this function writes&lt;br /&gt;
directly to the VGA buffer or a serial line but otherwise works just like&lt;br /&gt;
printk -- you have to enable this function by setting ''CONFIG_EARLY_PRINTK''&lt;br /&gt;
in your kernel config (''make menuconfig -&amp;gt; Kernel Hacking -&amp;gt; Early printk'').&lt;br /&gt;
&lt;br /&gt;
The major drawback is that printk is quite static, so you have to figure out what you want to trace beforehand and if you want to trace something different you have to recompile your code - which can become quite cumbersome. (And of course printk is not interactive at all, so you can't modify any variables or the like.)&lt;br /&gt;
&lt;br /&gt;
The other drawback is that printing usually consumes quite some processing power and io time, so if you're trying to debug a timing critical section or a timing bug, you're probably out of luck.&lt;br /&gt;
&lt;br /&gt;
== NetConsole ==&lt;br /&gt;
Sometimes you are in the unlucky situation that the machine crashes or hangs and you have no way to access the console afterwards, e.g. the graphic driver hangs and and the kernel dies soon after.&lt;br /&gt;
In this case you could either hook up a serial line to your crashing target machine (if a serial port is available) or use the kernels netconsole feature to enable printk logging via UDP.&lt;br /&gt;
&lt;br /&gt;
In order to use it you have to enable the ''CONFIG_NETCONSOLE'' kernel config&lt;br /&gt;
option (''make menuconfig -&amp;gt; Device Drivers -&amp;gt; Network device support -&amp;gt; Network core driver support -&amp;gt; Network console logging support'') and&lt;br /&gt;
configure it appropriately by using the ''netconsole'' configuration parameter&lt;br /&gt;
&lt;br /&gt;
 netconsole=[src-port]@[src-ip]/[&amp;lt;dev&amp;gt;],[tgt-port]@&amp;lt;tgt-ip&amp;gt;/[tgt-macaddr]&lt;br /&gt;
 	where&lt;br /&gt;
 		src-port      source for UDP packets (defaults to 6665)&lt;br /&gt;
 		src-ip        source IP to use (interface address)&lt;br /&gt;
 		dev           network interface (eth0)&lt;br /&gt;
 		tgt-port      port for logging agent (6666)&lt;br /&gt;
 		tgt-ip        IP address for logging agent&lt;br /&gt;
 		tgt-macaddr   ethernet MAC address for logging agent (broadcast)&lt;br /&gt;
&lt;br /&gt;
e.g. specify at kernel commandline (in your bootloader)&lt;br /&gt;
 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc&lt;br /&gt;
to send messages from 10.0.0.1 port 4444 via eth1 to 10.0.0.2 port 9353 with the MAC 12:34:56:78:9a:bc&lt;br /&gt;
&lt;br /&gt;
or while loading the module e.g&lt;br /&gt;
 # insmod netconsole netconsole=@/,@10.0.0.2/&lt;br /&gt;
to send messages via broadcast to 10.0.0.2 port 6666&lt;br /&gt;
&lt;br /&gt;
On the other machine you can now simply fire up&lt;br /&gt;
 # netcat -u -l -p &amp;lt;port&amp;gt;&lt;br /&gt;
e.g.&lt;br /&gt;
 $ netcat -u -l -p 6666&lt;br /&gt;
and see the printk messages from your target dribbling in.&lt;br /&gt;
&lt;br /&gt;
If you don't see any messages you might have to set the console_loglevel to a&lt;br /&gt;
higher value (see above) or test the connection via telnet e.g. from the target type&lt;br /&gt;
 $ telnet 10.0.0.2 6666&lt;br /&gt;
&lt;br /&gt;
see&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
for more details.&lt;br /&gt;
&lt;br /&gt;
== Misc ==&lt;br /&gt;
=== Dmesg ===&lt;br /&gt;
 dmesg -c&lt;br /&gt;
clears the dmesg buffer.&lt;br /&gt;
Sometimes it is nice to start with a blank buffer, so you will only see new&lt;br /&gt;
messages when you invoke ''dmesg''&lt;br /&gt;
&lt;br /&gt;
=== Printk Timestamps ===&lt;br /&gt;
 CONFIG_PRINTK_TIMES&lt;br /&gt;
Setting this kernel config option prepends every printk statement with a&lt;br /&gt;
timestamp representing the time since boot. This is particularly useful to get&lt;br /&gt;
a general idea about the timings of your code.&lt;br /&gt;
&lt;br /&gt;
=== Printing buffers as hex ===&lt;br /&gt;
If you want to print a buffer as hex within the kernel, don't reinvent the&lt;br /&gt;
wheel use ''printk_hex_dump_bytes()'' instead.&lt;br /&gt;
&lt;br /&gt;
 print_hex_dump_bytes(const char *prefix_str, int prefix_type, const void *buf, size_t len)&lt;br /&gt;
this function prints a buffer as hex values to the kernel log buffer (with level KERN_DEBUG)&lt;br /&gt;
Example:&lt;br /&gt;
 Kernel Code:&lt;br /&gt;
 char mybuf[] = &amp;quot;abcdef&amp;quot;;&lt;br /&gt;
 print_hex_dump_bytes(&amp;quot;&amp;quot;, DUMP_PREFIX_NONE, mybuf, ARRAY_SIZE(mybuf));&lt;br /&gt;
&lt;br /&gt;
 dmesg output:&lt;br /&gt;
 61 62 63 64 65 66 00                             abcdef.&lt;br /&gt;
&lt;br /&gt;
If you need something more sophisticated and flexible maybe have a look at&lt;br /&gt;
''print_hex_dump()'' and ''hex_dump_to_buffer()''&lt;br /&gt;
&lt;br /&gt;
=== Dynamic Debugging ===&lt;br /&gt;
It is also possible to enable/disable debug information at runtime using the&lt;br /&gt;
dynamic debug functionality of the kernel.&lt;br /&gt;
For this the ''CONFIG_DYNAMIC_DEBUG'' kernel config option must be set.&lt;br /&gt;
See&lt;br /&gt;
[http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt] for more information.&lt;br /&gt;
&lt;br /&gt;
== References and external links ==&lt;br /&gt;
* [[Linux Kernel Development - by Robert Love|Linux Kernel Development]], Robert Love, 3rd Edition, Chapter 18 Debugging&lt;br /&gt;
* [[Linux Device Drivers]], Corbet, Rubini and Kroah-Hartmann, 3rd Edition, Chapter 4 Section 2&lt;br /&gt;
* [[Essential Linux Device Drivers]]&lt;br /&gt;
&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/printk-formats.txt;hb=HEAD Documentation/printk-formats.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/dynamic-debug-howto.txt;hb=HEAD Documentation/dynamic-debug-howto.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/networking/netconsole.txt;hb=HEAD Documentation/networking/netconsole.txt]&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/printk.c;hb=HEAD kernel/printk.c] Implementation of printk and others&lt;br /&gt;
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/printk.h;hb=HEAD include/linux/printk.h] printk header file&lt;br /&gt;
* [http://www.embedded-bits.co.uk/2010/printk-format-specifiers/ Blog Entry about the different %p format specifiers]&lt;br /&gt;
* [[Printk]]&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Development Tools]]&lt;br /&gt;
[[Category:Tips and Tricks]]&lt;br /&gt;
[[Category:Printk]]&lt;/div&gt;</summary>
		<author><name>Peter Huewe</name></author>	</entry>

	</feed>