1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Chapter&#160;6.&#160;Common Routines</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Unreliable Guide To Hacking The Linux Kernel"><link rel="up" href="index.html" title="Unreliable Guide To Hacking The Linux Kernel"><link rel="prev" href="deadlock-recipes.html" title="Chapter&#160;5.&#160;Recipes for Deadlock"><link rel="next" href="routines-copy.html" title="copy_[to/from]_user() / get_user() / put_user() include/asm/uaccess.h"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&#160;6.&#160;Common Routines</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="deadlock-recipes.html">Prev</a>&#160;</td><th width="60%" align="center">&#160;</th><td width="20%" align="right">&#160;<a accesskey="n" href="routines-copy.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="common-routines"></a>Chapter&#160;6.&#160;Common Routines</h1></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="sect1"><a href="common-routines.html#routines-printk">
2    <code class="function">printk()</code>
3    <code class="filename">include/linux/kernel.h</code>
4   </a></span></dt><dt><span class="sect1"><a href="routines-copy.html">
5    <code class="function">copy_[to/from]_user()</code>
6    /
7    <code class="function">get_user()</code>
8    /
9    <code class="function">put_user()</code>
10    <code class="filename">include/asm/uaccess.h</code>
11   </a></span></dt><dt><span class="sect1"><a href="routines-kmalloc.html"><code class="function">kmalloc()</code>/<code class="function">kfree()</code>
12    <code class="filename">include/linux/slab.h</code></a></span></dt><dt><span class="sect1"><a href="routines-current.html"><code class="function">current</code>
13    <code class="filename">include/asm/current.h</code></a></span></dt><dt><span class="sect1"><a href="routines-udelay.html"><code class="function">mdelay()</code>/<code class="function">udelay()</code>
14     <code class="filename">include/asm/delay.h</code>
15     <code class="filename">include/linux/delay.h</code>
16   </a></span></dt><dt><span class="sect1"><a href="routines-endian.html"><code class="function">cpu_to_be32()</code>/<code class="function">be32_to_cpu()</code>/<code class="function">cpu_to_le32()</code>/<code class="function">le32_to_cpu()</code>
17     <code class="filename">include/asm/byteorder.h</code>
18   </a></span></dt><dt><span class="sect1"><a href="routines-local-irqs.html"><code class="function">local_irq_save()</code>/<code class="function">local_irq_restore()</code>
19    <code class="filename">include/linux/irqflags.h</code>
20   </a></span></dt><dt><span class="sect1"><a href="routines-softirqs.html"><code class="function">local_bh_disable()</code>/<code class="function">local_bh_enable()</code>
21    <code class="filename">include/linux/interrupt.h</code></a></span></dt><dt><span class="sect1"><a href="routines-processorids.html"><code class="function">smp_processor_id</code>()
22    <code class="filename">include/asm/smp.h</code></a></span></dt><dt><span class="sect1"><a href="routines-init.html"><span class="type">__init</span>/<span class="type">__exit</span>/<span class="type">__initdata</span>
23    <code class="filename">include/linux/init.h</code></a></span></dt><dt><span class="sect1"><a href="routines-init-again.html"><code class="function">__initcall()</code>/<code class="function">module_init()</code>
24    <code class="filename">include/linux/init.h</code></a></span></dt><dt><span class="sect1"><a href="routines-moduleexit.html"> <code class="function">module_exit()</code>
25    <code class="filename">include/linux/init.h</code> </a></span></dt><dt><span class="sect1"><a href="routines-module-use-counters.html"> <code class="function">try_module_get()</code>/<code class="function">module_put()</code>
26    <code class="filename">include/linux/module.h</code></a></span></dt></dl></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="routines-printk"></a>
27    <code class="function">printk()</code>
28    <code class="filename">include/linux/kernel.h</code>
29   </h2></div></div></div><p>
30    <code class="function">printk()</code> feeds kernel messages to the
31    console, dmesg, and the syslog daemon.  It is useful for debugging
32    and reporting errors, and can be used inside interrupt context,
33    but use with caution: a machine which has its console flooded with
34    printk messages is unusable.  It uses a format string mostly
35    compatible with ANSI C printf, and C string concatenation to give
36    it a first "priority" argument:
37   </p><pre class="programlisting">
38printk(KERN_INFO "i = %u\n", i);
39   </pre><p>
40    See <code class="filename">include/linux/kernel.h</code>;
41    for other KERN_ values; these are interpreted by syslog as the
42    level.  Special case: for printing an IP address use
43   </p><pre class="programlisting">
44__be32 ipaddress;
45printk(KERN_INFO "my ip: %pI4\n", &amp;ipaddress);
46   </pre><p>
47    <code class="function">printk()</code> internally uses a 1K buffer and does
48    not catch overruns.  Make sure that will be enough.
49   </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
50     You will know when you are a real kernel hacker
51     when you start typoing printf as printk in your user programs :)
52    </p></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
53     Another sidenote: the original Unix Version 6 sources had a
54     comment on top of its printf function: "Printf should not be
55     used for chit-chat".  You should follow that advice.
56    </p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="deadlock-recipes.html">Prev</a>&#160;</td><td width="20%" align="center">&#160;</td><td width="40%" align="right">&#160;<a accesskey="n" href="routines-copy.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&#160;5.&#160;Recipes for Deadlock&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;
57    <code class="function">copy_[to/from]_user()</code>
58    /
59    <code class="function">get_user()</code>
60    /
61    <code class="function">put_user()</code>
62    <code class="filename">include/asm/uaccess.h</code>
63   </td></tr></table></div></body></html>
64