A Header of Convenience

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 
  • 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.
>>

8 thoughts on “A Header of Convenience”

  1. 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.

  2. If you’re facing indentation issues (because of imprecise html render probably), pl install the ‘indent’ tool on Linux and:
    indent -linux convenient.h

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.