/proc/stat - ゲストはユーザー時間に含まれますか?

/proc/stat - ゲストはユーザー時間に含まれますか?

速い質問があります。 /proc/stat のマニュアルページでは明確ではありません。 Is guest および guest_nice 時間は /proc/stat のユーザー時間に含まれていますか?

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.cgtimeは調整できますが、それぞれとフィールドをdo_task_stat()呼び出して返します。task_cputime_adjusted()task_gtime()utimegtimestruct 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;
}

[この記事に引用されているコードは commit から取られました29b4817 2016-08-07 Linus Torvalds Linux 4.8-rc1。]

おすすめ記事