【问题标题】:Could someone explain what is nice time in cpu stat?有人可以解释一下 cpu stat 的美好时光吗?
【发布时间】:2013-11-12 11:06:54
【问题描述】:

我知道用户时间和系统时间之间的区别。但是,我不太确定美好的时光。我以前知道nice time是nice pr中使用的时间,但是当我做一个实验的时候,我发现nice time在我renic一个100%-CPU-using program(infinite loop doing add in)后并没有长大Java)到 19。所以,我很困惑......

顺便说一句,我要编写一个 C++ 程序来监控 CPU 使用率。我现在所能做的就是阅读 /proc/stat 两次并获得差异。但是,我不知道如何计算总时间。

total = user + sys + idle

total = user + sys + nice + idle 甚至

total = user + sys + nice + idle + iowait + ...(整行)。

哪个是对的?

【问题讨论】:

  • 我认为这回答了你的问题:serverfault.com/a/527945
  • @davek 我很困惑用户时间中是否包含美好时光?

标签: linux system


【解决方案1】:

Mpstat(1) 读取 /proc/stat。深入内核源代码树,我发现了一个文件 kernel/sched/cputime.c,取自 Linux 3.11.7 源代码,其中似乎包含更新 /proc/stat 中反映的内容的相关位:

/*
 * 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);
}

这暗示运行 niced 任务所花费的时间通常不包含在显示运行用户模式任务所花费时间的列中(index= 行似乎与此相关)。

【讨论】:

  • 是啊,我翻到内核源码,终于把cat /proc/stat打印出来的10列的意思全部找出来了……谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-22
  • 2016-12-12
  • 2021-04-01
  • 2011-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多