![/proc/stat - 게스트가 사용자 시간에 포함되나요?](https://rvso.com/image/36002/%2Fproc%2Fstat%20-%20%EA%B2%8C%EC%8A%A4%ED%8A%B8%EA%B0%80%20%EC%82%AC%EC%9A%A9%EC%9E%90%20%EC%8B%9C%EA%B0%84%EC%97%90%20%ED%8F%AC%ED%95%A8%EB%90%98%EB%82%98%EC%9A%94%3F.png)
빠른 질문이 있습니다. /proc/stat에 대한 매뉴얼 페이지에서는 이것이 명확하지 않습니다. /proc/stat의 사용자 시간에 guest 및 guest_nice 시간이 포함되어 있습니까?
http://man7.org/linux/man-pages/man5/proc.5.html 매뉴얼에는 /proc/[pid]/stat에 대한 힌트만 있습니다.
https://lkml.org/lkml/2008/6/23/65 여기서는 내가 이해하는 한 그들은 /proc/stat 및 /proc/[pid]/stat 둘 다에 대해 이야기하고 있습니다.
누군가 그것을 설명할 수 있나요? 그리고 이 정보의 출처를 알려주시기 바랍니다.
답변1
매뉴얼 페이지에서:
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
gtime이 조정될 수 있지만 각각 의 및 필드를 반환하는 및 do_task_stat()
호출을 사용하여 다음 을 수행합니다.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
.]