The aim of these four patches is to introduce Virtual Machine time accounting. _Ingo_, as these patches modify files of the scheduler, could you have a look to them, please ? [PATCH 1/4] as recent CPUs introduce a third running state, after "user" and "system", we need a new field, "guest", in cpustat to store the time used by the CPU to run virtual CPU. Modify /proc/stat to display this new field. [PATCH 2/4] like for cpustat, introduce the "gtime" (guest time of the task) and "cgtime" (guest time of the task children) fields for the tasks. Modify signal_struct and task_struct. Modify /proc/<pid>/stat to display these new fields. [PATCH 3/4] modify account_system_time() to add cputime to cpustat->guest if we are running a VCPU. We add this cputime to cpustat->user instead of cpustat->system because this part of KVM code is in fact user code although it is executed in the kernel. We duplicate VCPU time between guest and user to allow an unmodified "top(1)" to display correct value. A modified "top(1)" is able to display good cpu user time and cpu guest time by subtracting cpu guest time from cpu user time. Update "gtime" and "cgtime" in signal_struct and task_struct accordingly. [PATCH 4/4] Modify KVM to update guest time accounting. Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net> -- ------------- Laurent.Vivier@bull.net -------------- "Software is hard" - Donald Knuth
Laurent Vivier wrote:> The aim of these four patches is to introduce Virtual Machine time accounting. >1-3 look good to me. 4 needs minor edits... -- error compiling committee.c: too many arguments to function
Laurent> The aim of these four patches is to introduce Virtual Machine Laurent> time accounting. So what does this buy us? What increased functionality? Laurent> [PATCH 1/4] as recent CPUs introduce a third running state, Laurent> after "user" and "system", we need a new field, "guest", in Laurent> cpustat to store the time used by the CPU to run virtual Laurent> CPU. Modify /proc/stat to display this new field. What happens when you have multiple guests, is this state cummulative? I've glanced over these patches and the #ifdefs are ugly..., esp since the overhead seems to exist even if you don't run any Guest CPUs. Or whatever you're doing here. Please justify this patch more in terms of what it provides and why it's a good thing to have. Thanks, John
These patches never seem to have made it onto LKML?! On Mon, 2007-08-20 at 15:13 +0200, Laurent Vivier wrote:> The aim of these four patches is to introduce Virtual Machine time accounting. > > _Ingo_, as these patches modify files of the scheduler, could you have a look to > them, please ? > > [PATCH 1/4] as recent CPUs introduce a third running state, after "user" and > "system", we need a new field, "guest", in cpustat to store the time used by > the CPU to run virtual CPU. Modify /proc/stat to display this new field. > > [PATCH 2/4] like for cpustat, introduce the "gtime" (guest time of the task) and > "cgtime" (guest time of the task children) fields for the > tasks. Modify signal_struct and task_struct. Modify /proc/<pid>/stat to display > these new fields. > > [PATCH 3/4] modify account_system_time() to add cputime to cpustat->guest if we > are running a VCPU. We add this cputime to cpustat->user instead of > cpustat->system because this part of KVM code is in fact user code although it > is executed in the kernel. We duplicate VCPU time between guest and user to > allow an unmodified "top(1)" to display correct value. A modified "top(1)" is > able to display good cpu user time and cpu guest time by subtracting cpu guest > time from cpu user time. Update "gtime" and "cgtime" in signal_struct and > task_struct accordingly. > > [PATCH 4/4] Modify KVM to update guest time accounting.Isn't this exactly what CONFIG_VIRT_CPU_ACCOUNTING is about?
On Tue, 04 Aug 2009 19:33:14 +0200 Peter Zijlstra <peterz at infradead.org> wrote:> 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?Because you have two different contexts where you spent time, the "normal" process context and the "guest" process context. To know how much of your cpu time is spent on virtualization overhead is an interesting number. -- blue skies, Martin. "Reality continues to ruin my life." - Calvin.
Apparently Analagous Threads
- [PATCH 0/4] Virtual Machine Time Accounting
- [PATCH 2/4] Introduce a new fields "gtime" and "cgtime" in task_struct and signal_struct
- [PATCH 2/4] Introduce a new fields "gtime" and "cgtime" in task_struct and signal_struct
- [PATCH/RFC 2/4]Introduce a new field "guest" in task_struct
- [PATCH/RFC 2/4]Introduce a new field "guest" in task_struct