Skip to contentSkip to conversation

Fix energy calcultation in RAPL MSR

PATCH In review Anthony Harivel 2 participants 3 messages Aug 7, 2024 – Aug 9, 2024

lore
Share & tools
lore
#0 lore raw

cover Fix energy calcultation in RAPL MSR

Hi Paolo,

The value reported by the calculation was looking very wrong to me.

This should fix it for good.

Calculated value appears now way more accurate from what is expected from the feature:

with "-smp 4":

[...]

# modprobe intel_rapl_msr.ko
intel_rapl_common: Found RAPL domain package
intel_rapl_common: found 1 domains on package-0
intel_rapl_common: Core CPU package-0:package energy=61035pJ, time=976us, power=125000uW
intel_rapl_common: update package-0 domain package data
# 
# 
# 
# cat /sys/class/powercap/intel-rapl:0/energy_uj 
303160
# cat /sys/class/powercap/intel-rapl:0/energy_uj 
325621
# cat /sys/class/powercap/intel-rapl:0/energy_uj 
325621
# cat /sys/class/powercap/intel-rapl:0/energy_uj 
357237
# cat /sys/class/powercap/intel-rapl:0/energy_uj 
357237
# cat /sys/class/powercap/intel-rapl:0/energy_uj 
388792
[...]

Tested with several SMP architecture.
(i.e -smp 4 / -smp 8,sockets=2,dies=1 / -smp 8,sockets=4,dies=2 )

Anthony Harivel (1):
target/i386: Fix arguments for vmsr_read_thread_stat()

 target/i386/kvm/kvm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/1 target/i386: Fix arguments for vmsr_read_thread_stat()

Snapshot of the stat utime and stime for each thread, taken before and after the pause, must be stored in separate locations

---
 target/i386/kvm/kvm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
target/i386/kvm/kvm.c +4 -4
index 31f149c9902c..2fa88ef1e373 100644
@@ -2712,8 +2712,8 @@ static void *kvm_msr_energy_thread(void *data)
             thd_stat[i].thread_id = thread_ids[i];
             vmsr_read_thread_stat(vmsr->pid,
                                   thd_stat[i].thread_id,
-                                  thd_stat[i].utime,
-                                  thd_stat[i].stime,
+                                  &thd_stat[i].utime[0],
+                                  &thd_stat[i].stime[0],
                                   &thd_stat[i].cpu_id);
             thd_stat[i].pkg_id =
                 vmsr_get_physical_package_id(thd_stat[i].cpu_id);
@@ -2777,8 +2777,8 @@ static void *kvm_msr_energy_thread(void *data)
         for (int i = 0; i < num_threads; i++) {
             vmsr_read_thread_stat(vmsr->pid,
                                   thd_stat[i].thread_id,
-                                  thd_stat[i].utime,
-                                  thd_stat[i].stime,
+                                  &thd_stat[i].utime[1],
+                                  &thd_stat[i].stime[1],
                                   &thd_stat[i].cpu_id);
 
             if (vmsr->pid < 0) {
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#2 lore raw

Re: [PATCH 1/1] target/i386: Fix arguments for vmsr_read_thread_stat()

Quoted 11 lines · Anthony Harivel

Date: Wed, 7 Aug 2024 14:43:20 +0200
From: Anthony Harivel <[email protected]>
Subject: [PATCH 1/1] target/i386: Fix arguments for vmsr_read_thread_stat()

Snapshot of the stat utime and stime for each thread, taken before and after the pause, must be stored in separate locations

---
 target/i386/kvm/kvm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)