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=
似乎与此相关)。