Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8001487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:06:15+00:00 2026-06-04T16:06:15+00:00

There are a number of posts and references on how to get CPU Utilization

  • 0

There are a number of posts and references on how to get CPU Utilization using statistics in /proc/stat. However, most of them use only four of the 7+ CPU stats (user, nice, system, and idle), ignoring the remaining jiffie CPU counts present in Linux 2.6 (iowait, irq, softirq).

As an example, see Determining CPU utilization.

My question is this: Are the iowait/irq/softirq numbers also counted in one of the first four numbers (user/nice/system/idle)? In other words, does the total jiffie count equal the sum of the first four stats? Or, is the total jiffie count equal to the sum of all 7 stats? If the latter is true, then a CPU utilization formula should take all of the numbers into account, like this:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  long double a[7],b[7],loadavg;
  FILE *fp;

  for(;;)
  {
    fp = fopen("/proc/stat","r");
    fscanf(fp,"%*s %Lf %Lf %Lf %Lf",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6]);
    fclose(fp);
    sleep(1);
    fp = fopen("/proc/stat","r");
    fscanf(fp,"%*s %Lf %Lf %Lf %Lf",&b[0],&b[1],&b[2],&b[3],&b[4],&b[5],&b[6]);
    fclose(fp);

    loadavg = ((b[0]+b[1]+b[2]+b[4]+b[5]+b[6]) - (a[0]+a[1]+a[2]+a[4]+a[5]+a[6]))
         / ((b[0]+b[1]+b[2]+b[3]+b[4]+b[5]+b[6]) - (a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]));
    printf("The current CPU utilization is : %Lf\n",loadavg);

  }

  return(0);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:06:18+00:00Added an answer on June 4, 2026 at 4:06 pm

    I think iowait/irq/softirq are not counted in one of the first 4 numbers. You can see the comment of irqtime_account_process_tick in kernel code for more detail:

    (for Linux kernel 4.1.1)

    2815  * Tick demultiplexing follows the order
    2816  * - pending hardirq update    <-- this is irq
    2817  * - pending softirq update    <-- this is softirq
    2818  * - user_time
    2819  * - idle_time         <-- iowait is included in here, discuss below
    2820  * - system time
    2821  *   - check for guest_time
    2822  *   - else account as system_time
    

    For the idle time handling, see account_idle_time function:

    2772 /*
    2773  * Account for idle time.
    2774  * @cputime: the cpu time spent in idle wait
    2775  */
    2776 void account_idle_time(cputime_t cputime)
    2777 {
    2778         u64 *cpustat = kcpustat_this_cpu->cpustat;
    2779         struct rq *rq = this_rq();
    2780
    2781         if (atomic_read(&rq->nr_iowait) > 0)
    2782                 cpustat[CPUTIME_IOWAIT] += (__force u64) cputime;
    2783         else
    2784                 cpustat[CPUTIME_IDLE] += (__force u64) cputime;
    2785 }
    

    If the cpu is idle AND there is some IO pending, it will count the time in CPUTIME_IOWAIT. Otherwise, it is count in CPUTIME_IDLE.

    To conclude, I think the jiffies in irq/softirq should be counted as “busy” for cpu because it was actually handling some IRQ or soft IRQ. On the other hand, the jiffies in “iowait” should be counted as “idle” for cpu because it was not doing something but waiting for a pending IO to happen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the vxWorks shell, there are a number of routines you can use to
I realize there have already been a number of posts on n-tier design and
There's a number of posts here on hashing of passwords and numerous recommendations on
I have an images array in which there are number of images. Not fixed,
Here is the jsfiddle for what I was testing http://jsfiddle.net/5hhRF/ there is number 1
There are a number of JSON libraries available for Erlang, and it's not clear
Is there a maximum number of email addresses that can be included in a
Is there a maximum number of trace sources for app.config, and by definition listeners
There is a canvas element with 10 children (polygons). There is a number in
Say I have two files where there is one number per line File 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.