Over the years, we tend to collect little snippets of code and routines that we use, like, refine and reuse.
I’ve done so, for (mostly) user-space and kernel programming on the 2.6 / 3.x Linux kernel. Feel free to use it. Please do get back with any bugs you find, suggestions, etc.
License: GPL / LGPL
Click here to view the code!
There are macros / functions to:
- make debug prints along with function name and line# info (via the usual printk() or trace_printk()) – (only if DEBUG mode is On)
- [EDIT] : rate-limiting turned Off by default (else we risk missing some prints)
-will preferably use rate-limited printk’s
- [EDIT] : rate-limiting turned Off by default (else we risk missing some prints)
- dump the kernel-mode stack
- print the current context (process or interrupt along with flags in the form that ftrace uses)
- a simple assert() macro (!)
- a cpu-intensive DELAY_LOOP (useful for test rigs that must spin on the processor)
- an equivalent to usermode sleep functionality (DELAY_SEC()).
Whew 🙂
<<
Edit: removed the header listing inline here; it’s far more convenient to just view it online here.
>>
Added a link (see post above) to conveniently download convenient.h – for your convenience 😉
Hi All, I’ve updated the post:
– we’re not supposed to use printk_ratelimit() any longer; replaced with printk_ratelimited() .
– have stripped out the code inline in the blog post; pl download from the link provided.
If you’re facing indentation issues (because of imprecise html render probably), pl install the ‘indent’ tool on Linux and:
indent -linux convenient.h
Minor Update: added comment on the simple assert() macro, mentioning the BUG*() and WARN*() macros available in the kernel.
Update: The source is on a code-snippet-sharing site now: ideone.com. Added the link.
Turned rate-limiting Off by default