![/proc/stat – wird der Gast zur Benutzerzeit gezählt?](https://rvso.com/image/36002/%2Fproc%2Fstat%20%E2%80%93%20wird%20der%20Gast%20zur%20Benutzerzeit%20gez%C3%A4hlt%3F.png)
Ich habe eine kurze Frage. In der Manpage für /proc/stat ist mir Folgendes nicht klar: Ist die Zeit von guest und guest_nice in der Benutzerzeit in /proc/stat enthalten?
http://man7.org/linux/man-pages/man5/proc.5.html im Handbuch gibt es nur einen Hinweis zu /proc/[pid]/stat
https://lkml.org/lkml/2008/6/23/65 hier, soweit ich weiß, sprechen sie sowohl über /proc/stat als auch über /proc/[pid]/stat
Kann das jemand erklären? Und hoffentlich auf eine Quelle dieser Informationen verweisen?
Antwort1
Aus der Manpage:
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.
Aus den Kernelquellen (.../kernel/sched/cputime.c
) sehen wir, dass bei Berücksichtigung der Gastzeit die gesamte Gastzeit auch zur Benutzerzeit hinzugerechnet wird (und das Gleiche gilt für „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;
}
}
Die Benutzerzeit und die Gastzeit, die angezeigt werden, /proc/[pid]/stat
werden abgerufen in.../fs/proc/array.c
in do_task_stat()
mit Aufrufen von task_cputime_adjusted()
und , die die bzw. Felder von task_gtime()
zurückgeben , obwohl gtime möglicherweise optimiert wird: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;
}
[der in diesem Beitrag zitierte Code stammt aus dem Commit 29b4817 2016-08-07 Linus Torvalds Linux 4.8-rc1
]