Linux top命令输出一般如下

和CPU相关的内容如下:

  • load average:当前系统任务调度繁忙程度
  • %CPU:cpu使用率
    • us:用户态CPU占用率

    • sy:kernel态CPU占用率

    • ni:那些调整过进程nice值(-20 ~ 19之间,越小优先级越高),且nice大于0的进程的CPU占用率。此值越大,说明有一些进程被调低了优先级,但是其实是CPU繁忙类型的进程,这样做是不当的。

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      
      /*
           * Account user cpu time to a process.
           * @p: the process that the cpu time gets accounted to
           * @cputime: the cpu time spent in user space since the last update
           * @cputime_scaled: cputime scaled by cpu frequency
           */
          void account_user_time(struct task_struct *p, cputime_t cputime,
                                 cputime_t cputime_scaled)
          {
                  int index;
            
                  /* Add user time to process. */
                  p->utime += cputime;
                  p->utimescaled += cputime_scaled;
                  account_group_user_time(p, cputime);
            
                  index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
            
                  /* Add user time to cpustat. */
                  task_group_account_field(p, index, (__force u64) cputime);
            
                  /* Account for user time used */
                  acct_account_cputime(p);
          }
      
    • id:CPU空闲

    • wa:CPU等待I/O的时间比例

    • hi:硬件中断的时间比例

    • si:软件终端的时间比例

    • st:虚拟机偷用时间