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)
    • 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
  • a function to calculate the time delta given two timestamps (timeval structs)
  • convert decimal to binary, and
  • a few more.

Whew :-)

<<
Edit: removed the header listing inline here; it’s far more convenient to just view it online here (on ideone.com)  -or-
download it here (dropbox).
>>

About these ads

6 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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s