/proc/stat: ¿se cuenta el invitado en el tiempo del usuario?

/proc/stat: ¿se cuenta el invitado en el tiempo del usuario?

Tengo una pregunta rápida. En la página de manual de /proc/stat, esto no me queda claro: ¿el tiempo de invitado y de invitado_nice está incluido en el tiempo del usuario en /proc/stat?

http://man7.org/linux/man-pages/man5/proc.5.html en el manual sólo hay una pista sobre /proc/[pid]/stat

https://lkml.org/lkml/2008/6/23/65 aquí, hasta donde tengo entendido, están hablando tanto de /proc/stat como de /proc/[pid]/stat

¿Alguien puede explicarlo? ¿Y con suerte señalar alguna fuente de esta información?

Respuesta1

Desde la página de manual:

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.

De la fuente del núcleo (.../kernel/sched/cputime.c) vemos que cuando se contabiliza el tiempo de los invitados, todo el tiempo de los invitados también se agrega al tiempo del usuario (y de manera similar en el caso de 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;
        }
}

La hora del usuario y la hora del huésped que se mostrarán a través de /proc/[pid]/statse recuperan en.../fs/proc/array.ccon do_task_stat()llamadas a task_cputime_adjusted()y task_gtime()que devuelven los campos utimey gtimede struct task_struct, respectivamente, aunque gtime puede modificarse:

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;
}

[el código citado en esta publicación es de confirmación 29b4817 2016-08-07 Linus Torvalds Linux 4.8-rc1]

información relacionada