Re: [PATCH 0/4] Virtual Machine Time Accounting

Peter Zijlstra
2009-08-04T17:33:51Z

On Tue, 2009-08-04 at 19:29 +0200, Martin Schwidefsky wrote:

> > So its going to split user time into user and guest. Does that really
> > make sense? For the host kernel it really is just another user process,
> > no?
>
> The code (at least in parts) is already upstream. Look at the
> account_guest_time function:
>
> static void account_guest_time(struct task_struct *p, cputime_t cputime,
> cputime_t cputime_scaled)
> {
> cputime64_t tmp;
> struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
>
> tmp = cputime_to_cputime64(cputime);
>
> /* Add guest time to process. */
> p->utime = cputime_add(p->utime, cputime);
> p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
> account_group_user_time(p, cputime);
> p->gtime = cputime_add(p->gtime, cputime);
>
> /* Add guest time to cpustat. */
> cpustat->user = cputime64_add(cpustat->user, tmp);
> cpustat->guest = cputime64_add(cpustat->guest, tmp);
> }
>
> The cpu time for a guest is added to p->utime AND p->gtime. That is
> done not to break existing tools that know nothing about guest time.
> A guest time aware tool can subtract the p->gtime from p->utime to
> get the time spent by the process outside of the guest context.

But why? How a vcpu anything other than yet another userspace process?