summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2013-12-18 02:20:39 +0000
committerHisham Muhammad <hisham@gobolinux.org>2013-12-18 02:20:39 +0000
commitaf285d1d3bb182c3f09c70110f4305cb19437245 (patch)
tree994689fcc2f1840a742d40c36ef63a79389feeeb
parent6cfa9e0bf2ded1add3f018986268d9b1c3b119b6 (diff)
Fixes in accounting of guest time when using virtualization
(thanks to Patrick Marlier)
-rw-r--r--ChangeLog2
-rw-r--r--ProcessList.c23
2 files changed, 15 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 2ddc2b36..5efc3e52 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
What's new in version 1.0.3
+* Fixes in accounting of guest time when using virtualization
+ (thanks to Patrick Marlier)
* Performance improvements
(thanks to Jann Horn)
* Further performance improvements due to conditional parsing
diff --git a/ProcessList.c b/ProcessList.c
index ce1319a3..88ccae44 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -886,24 +886,27 @@ void ProcessList_scan(ProcessList* this) {
for (int i = 0; i <= cpus; i++) {
char buffer[256];
int cpuid;
- unsigned long long int ioWait, irq, softIrq, steal, guest;
- ioWait = irq = softIrq = steal = guest = 0;
+ unsigned long long int ioWait, irq, softIrq, steal, guest, guestnice;
+ ioWait = irq = softIrq = steal = guest = guestnice = 0;
// Dependending on your kernel version,
- // 5, 7 or 8 of these fields will be set.
+ // 5, 7, 8 or 9 of these fields will be set.
// The rest will remain at zero.
fgets(buffer, 255, file);
if (i == 0)
- sscanf(buffer, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest);
+ sscanf(buffer, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
else {
- sscanf(buffer, "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest);
+ sscanf(buffer, "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
assert(cpuid == i - 1);
}
+ // Guest time is already accounted in usertime
+ usertime = usertime - guest;
+ nicetime = nicetime - guestnice;
// Fields existing on kernels >= 2.6
// (and RHEL's patched kernel 2.4...)
idlealltime = idletime + ioWait;
systemalltime = systemtime + irq + softIrq;
- virtalltime = steal + guest;
- totaltime = usertime + nicetime + systemalltime + idlealltime + virtalltime;
+ virtalltime = guest + guestnice;
+ totaltime = usertime + nicetime + systemalltime + idlealltime + steal + virtalltime;
CPUData* cpuData = &(this->cpus[i]);
assert (usertime >= cpuData->userTime);
assert (nicetime >= cpuData->niceTime);
@@ -916,7 +919,7 @@ void ProcessList_scan(ProcessList* this) {
assert (irq >= cpuData->irqTime);
assert (softIrq >= cpuData->softIrqTime);
assert (steal >= cpuData->stealTime);
- assert (guest >= cpuData->guestTime);
+ assert (virtalltime >= cpuData->guestTime);
cpuData->userPeriod = usertime - cpuData->userTime;
cpuData->nicePeriod = nicetime - cpuData->niceTime;
cpuData->systemPeriod = systemtime - cpuData->systemTime;
@@ -927,7 +930,7 @@ void ProcessList_scan(ProcessList* this) {
cpuData->irqPeriod = irq - cpuData->irqTime;
cpuData->softIrqPeriod = softIrq - cpuData->softIrqTime;
cpuData->stealPeriod = steal - cpuData->stealTime;
- cpuData->guestPeriod = guest - cpuData->guestTime;
+ cpuData->guestPeriod = virtalltime - cpuData->guestTime;
cpuData->totalPeriod = totaltime - cpuData->totalTime;
cpuData->userTime = usertime;
cpuData->niceTime = nicetime;
@@ -939,7 +942,7 @@ void ProcessList_scan(ProcessList* this) {
cpuData->irqTime = irq;
cpuData->softIrqTime = softIrq;
cpuData->stealTime = steal;
- cpuData->guestTime = guest;
+ cpuData->guestTime = virtalltime;
cpuData->totalTime = totaltime;
}
double period = (double)this->cpus[0].totalPeriod / cpus; fclose(file);

© 2014-2024 Faster IT GmbH | imprint | privacy policy