Skip to contentSkip to conversation

powerpc/vtime: Initialize starttime at boot for native accounting

PATCH Applied Shrikanth Hegde 2 participants 2 messages Jun 5 – Jul 21 PowerPC

lore
Share & tools
lore

Shrikanth Hegde

author reviewer
#0 lore raw

PATCH v2 1/1 powerpc/vtime: Initialize starttime at boot for native accounting

It was observed that /proc/stat had very large value for one ore more CPUs. It was more visible after recent code simplifications around cpustats.

System has 240 CPUs.

cat /proc/uptime;
194.18 46500.55
cat /proc/stat
cpu 5966 39 837032887 4650070 164 185 100 0 0 0
cpu0 108 0 837030890 19109 24 4 23 0 0 0

Since uptime is 194s, system time of each CPU can't be more than 19400. Sum of system time of all CPUs can't be more than 19400*240 4656000. In fact huge value is close to mftb(). Note mftb doesn't reset on powerVM when the LPAR restart. It only resets when whole system resets. The same issue exists for kexec too.

This happens since starttime is not setup at init time. Once it is set then subsequent vtime_delta will return the right delta.

Fix it by initializing the starttime during CPU initialization. This fixes the large times seen.

cat /proc/uptime; cat /proc/stat
15.78 3694.63
cpu 6035 35 1347 369479 23 144 49 0 0 0
cpu0 19 0 38 1508 0 1 14 0 0 0

Now, system time is reported as expected.

Fixes cf9efce0ce31 ("powerpc: Account time using timebase rather than PURR")

---
Applies on top of tip/timers/nohz
at 6199f9999a9b ("sched/cputime: Handle dyntick-idle steal time correctly")

Discussion thread:
https://lore.kernel.org/all/[email protected]/

Note: Backporting to earlier tags may need manual addition of vtime_reset where needed!

v1->v2:
- Addeds tags and Fixes. (Thanks to Christophe Leroy)
v1: https://lore.kernel.org/all/[email protected]/

 arch/powerpc/kernel/time.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/kernel/time.c +3 -1
index 3460d1a5a97c..11145c40183d 100644
@@ -377,7 +377,6 @@ void vtime_task_switch(struct task_struct *prev)
 	}
 }
 
-#ifdef CONFIG_NO_HZ_COMMON
 /**
  * vtime_reset - Fast forward vtime entry clocks
  *
@@ -394,6 +393,7 @@ void vtime_reset(void)
 #endif
 }
 
+#ifdef CONFIG_NO_HZ_COMMON
 /**
  * vtime_dyntick_start - Inform vtime about entry to idle-dynticks
  *
@@ -933,6 +933,7 @@ static void __init set_decrementer_max(void)
 static void __init init_decrementer_clockevent(void)
 {
 	register_decrementer_clockevent(smp_processor_id());
+	vtime_reset();
 }
 
 void secondary_cpu_time_init(void)
@@ -948,6 +949,7 @@ void secondary_cpu_time_init(void)
 	/* FIME: Should make unrelated change to move snapshot_timebase
 	 * call here ! */
 	register_decrementer_clockevent(smp_processor_id());
+	vtime_reset();
 }
 
 /*
Signature · 1 line
2.47.3
maintainer Applied
#1 lore raw
Quoted 6 lines · Shrikanth Hegde

It was observed that /proc/stat had very large value for one ore more CPUs. It was more visible after recent code simplifications around cpustats.

System has 240 CPUs.

Quoted 7 lines

cat /proc/uptime;
194.18 46500.55
cat /proc/stat
cpu 5966 39 837032887 4650070 164 185 100 0 0 0
cpu0 108 0 837030890 19109 24 4 23 0 0 0

[...]

Applied to powerpc/fixes.

[1/1] powerpc/vtime: Initialize starttime at boot for native accounting

      https://git.kernel.org/powerpc/c/c1c1ffa490fc33591e90852ed0d38804dd20bc36

cheers