![/proc/stat - ゲストはユーザー時間にカウントされますか?](https://rvso.com/image/36002/%2Fproc%2Fstat%20-%20%E3%82%B2%E3%82%B9%E3%83%88%E3%81%AF%E3%83%A6%E3%83%BC%E3%82%B6%E3%83%BC%E6%99%82%E9%96%93%E3%81%AB%E3%82%AB%E3%82%A6%E3%83%B3%E3%83%88%E3%81%95%E3%82%8C%E3%81%BE%E3%81%99%E3%81%8B%3F.png)
ちょっと質問があります。/proc/stat のマニュアル ページで、次のことがよくわかりません。guest 時間と guest_nice 時間は、/proc/stat のユーザー時間に含まれているのでしょうか?
詳しくは、man5.5 を参照してください。 マニュアルには/proc/[pid]/statについてのヒントしかありません
https://lkml.org/lkml/2008/6/23/65 ここでは、私の理解する限り、/proc/statと/proc/[pid]/statの両方について話している。
誰か説明してくれませんか?できればこの情報の出典を示してもらえませんか?
答え1
man ページから:
This includes guest time,
guest_time (time spent running a virtual CPU, see
below), so that applications that are not aware of
the guest time field do not lose that time from
their calculations.
カーネルソースから(.../kernel/sched/cputime.c
) ゲスト時間が考慮されると、すべてのゲスト時間もユーザー時間に追加されることがわかります (nice についても同様です)。
/*
* Account guest cpu time to a process.
* @p: the process that the cpu time gets accounted to
* @cputime: the cpu time spent in virtual machine since the last update
* @cputime_scaled: cputime scaled by cpu frequency
*/
static void account_guest_time(struct task_struct *p, cputime_t cputime,
cputime_t cputime_scaled)
{
u64 *cpustat = kcpustat_this_cpu->cpustat;
/* Add guest time to process. */
p->utime += cputime;
p->utimescaled += cputime_scaled;
account_group_user_time(p, cputime);
p->gtime += cputime;
/* Add guest time to cpustat. */
if (task_nice(p) > 0) {
cpustat[CPUTIME_NICE] += (__force u64) cputime;
cpustat[CPUTIME_GUEST_NICE] += (__force u64) cputime;
} else {
cpustat[CPUTIME_USER] += (__force u64) cputime;
cpustat[CPUTIME_GUEST] += (__force u64) cputime;
}
}
表示されるユーザー時間とゲスト時間は/proc/[pid]/stat
、.../fs/proc/array.c
では、 とdo_task_stat()
を呼び出し、それぞれ とのフィールドを返しますが、gtime は調整される可能性があります。task_cputime_adjusted()
task_gtime()
utime
gtime
struct task_struct
cputime_t task_gtime(struct task_struct *t)
{
unsigned int seq;
cputime_t gtime;
if (!vtime_accounting_enabled())
return t->gtime;
do {
seq = read_seqcount_begin(&t->vtime_seqcount);
gtime = t->gtime;
if (t->vtime_snap_whence == VTIME_SYS && t->flags & PF_VCPU)
gtime += vtime_delta(t);
} while (read_seqcount_retry(&t->vtime_seqcount, seq));
return gtime;
}
[この投稿で引用されているコードはコミットからのものです29b4817 2016-08-07 Linus Torvalds Linux 4.8-rc1
]