I write a kernel module which has initialize and end function. I want one more function and want to call it from the user space process at any time i want.

Is it applicable ? If so, how ?

I am working on CentOS 5.2 and custom kernel, patched from linux 2.6.18.

EDIT: To make clear, I want to write a function into kernel module and call this function from the regular source.c file.

  • 2
    To call some function in your module you would have to create a custom system call, that is the only way of directly calling into the kernel. What exactly are you trying to do?
    – vonbrand
    Mar 12, 2013 at 17:14
  • I try to use WBINVD instruction, and i want to trigger it from the userspace. This instruction is the only one that is need for our benchmark research.
    – ykulah
    Mar 12, 2013 at 19:31
  • What does that instruction do? Is it privileged in some way that you need to run it in the kernel? What exactly are you benchmarking, isn't there a much less invasive way of doing that?
    – vonbrand
    Mar 12, 2013 at 19:43
  • It writes the dirty cache lines to the memory and invalidate all cpu cache. My aim is to count the cache miss/hits. Yeap, this is a privileged instruction, thats why i am trying to write a piece of kernel code.
    – ykulah
    Mar 12, 2013 at 19:48
  • Isn't it enough to run some random stuff before your benchmark, or make it sizeable enough that "leftover cache" effects aren't an issue?
    – vonbrand
    Mar 12, 2013 at 19:53

2 Answers 2


Doing a kernel module that can use the /proc filesystem sounds like it might work for you. IBM developerWorks has an article on that topic. I worked through the code a few years ago, and it worked back then. The article is dated 2006, and seems to apply to Linux 2.6 kernels.

The problem I can foresee with using "files" in the /proc filesystem to get your module to do its work is that an open/read/close style API probably doesn't match what you want to do. You might have to use an open() on a /proc file to mean "execute WBINVD" or something unobvious like that.

  • I read the article but my patched kernel prompts some warnings about the vmlinux - Section mismatch. what can be the reason ?
    – ykulah
    Mar 19, 2013 at 9:22
  • I do not use /proc file system for the solution because of the timing problem. But I read the article and i am sure that /proc did the job unless you have a timing restriction.
    – ykulah
    Mar 23, 2013 at 22:38

simplest thing to do is to have a character device, and write to that device, then the driver's read gets called and do the processing in the read callback of the character device in kernel.

  • Could you give an example which would help the user asking the question as well as people who have the same problem?
    – n0pe
    Mar 14, 2013 at 12:00
  • here's one: tldp.org/LDP/lkmpg/2.6/html/x569.html. but can be changed to work on the latest kernels (3.5 e.t.c) Mar 14, 2013 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.