Find the answer to your Linux question:
Results 1 to 7 of 7
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    get CPU utilization in a kernel module


    I have a kernel module, which is monitoring CPU load for overload detection..
    But i am not getting an exact api or way to calculate CPU load from kernel module.

    /proc/loadavg and /proc/stat ae 2 options.. But not a good way if open this file from my module.

    Which is the best option or way to calculate CPU load, so as my overload module will function correctly..

    Thank you in advance...

  2. #2
    I think you can use top command to do that. You can call thise with system("top").

  3. #3
    I need to get the CPU usage from a kernel module. top is a user space program.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    12,498
    You can get that from /proc files, such as /proc/stat, etc.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #5
    I think profiling tools like oprofile can also give usage by modules. Am I right?

  7. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    12,498
    Quote Originally Posted by charlie_arya View Post
    I think profiling tools like oprofile can also give usage by modules. Am I right?
    Perhaps - I'm not sure about from inside the kernel. However, you need to instrument the code being executed first. I think the poster wants something that can check system CPU utilization from within a kernel module at runtime, without needing to instrument anything, only needing to load the kernel module. I'm not sure what benefits that gives them, but that's another issue.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  8. #7
    Using /proc/stat can give cpu usage from userspace. For that I need to use netlink sockets to hook with userspace. This may be slow.

    by the way, my intention is to have some mechanism to detect cpu load in kernel. So based on that, overload situation can be detected.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •