Debugging by Querying
The previous section described how printk works and how it can be used. What it didn’t talk about are its disadvantages.
A massive use of printk can slow down the system noticeably,
because syslogd keeps syncing its output files, so every line that
is printed causes a disk operation. This is correct from syslogd’s
perspective. It tries to write everything to disk in case the
system crashes right after printing the message; however, you don’t
want to slow down your system just for the sake of debugging messages.
This problem can be solved by prefixing with a dash the name of your logfile
as it appears in /etc/syslogd.conf, but sometimes you don’t
want to change your config files. Otherwise, you can run a program other than
klogd (like cat /proc/kmesg, as suggested above)
but this may not provide a suitable environment for normal system
operation.
More often than not, the best way to get relevant information is to query the system when you need the information, instead of continually producing data. In fact, every Unix system provides many tools for obtaining system information: ps, netstat, vmstat, and so on.
There are two techniques available to driver developers for
querying the system, namely, creating a file in the
/proc filesystem and using the ioctl driver method.
Using the /proc Filesystem
The /proc filesystem in Linux is not associated with any
device--the files living in /proc are generated by the kernel when they are read. These files are usually ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access