Skip to contentSkip to conversation

fix stolen time for SMT without LPAR

PATCH In review Michael Neuling 2 participants 4 messages May 24, 2007 – Jun 8, 2007 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix stolen time for SMT without LPAR

For POWERPC, stolen time accounts for cycles lost to the hypervisor or PURR cycles attributed to the other SMT thread. Hence, when a PURR is available, we should still calculate stolen time, irrespective of being virtualised.

---
Kudos to sfr for realizing the problem here.

 arch/powerpc/kernel/time.c |    6 ++++--
 include/asm-powerpc/time.h |    2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)
arch/powerpc/kernel/time.c +4 -2
Index: linux-2.6-ozlabs/arch/powerpc/kernel/time.c
===================================================================
@@ -244,7 +244,8 @@ void snapshot_timebases(void)
 {
 	int cpu;
 
-	if (!cpu_has_feature(CPU_FTR_PURR))
+	if (!cpu_has_feature(CPU_FTR_PURR) &&
+	    !firmware_has_feature(FW_FEATURE_SPLPAR))
 		return;
 	for_each_possible_cpu(cpu)
 		spin_lock_init(&per_cpu(cpu_purr_data, cpu).lock);
@@ -257,7 +258,8 @@ void calculate_steal_time(void)
 	s64 stolen;
 	struct cpu_purr_data *pme;
 
-	if (!cpu_has_feature(CPU_FTR_PURR))
+	if (!cpu_has_feature(CPU_FTR_PURR) &&
+	    !firmware_has_feature(FW_FEATURE_SPLPAR))
 		return;
 	pme = &per_cpu(cpu_purr_data, smp_processor_id());
 	if (!pme->initialized)
include/asm-powerpc/time.h +1 -1
Index: linux-2.6-ozlabs/include/asm-powerpc/time.h
===================================================================
@@ -232,7 +232,7 @@ extern void account_process_vtime(struct
 #define account_process_vtime(tsk)		do { } while (0)
 #endif
 
-#if defined(CONFIG_VIRT_CPU_ACCOUNTING) && defined(CONFIG_PPC_SPLPAR)
+#if defined(CONFIG_VIRT_CPU_ACCOUNTING)
 extern void calculate_steal_time(void);
 extern void snapshot_timebases(void);
 #else
#1 lore raw

For POWERPC, stolen time accounts for cycles lost to the hypervisor or PURR cycles attributed to the other SMT thread. Hence, when a PURR is available, we should still calculate stolen time, irrespective of being virtualised.

---
Updated to fix link error when CONFIG_PPC_SPLPAR is off.

 arch/powerpc/kernel/time.c |    8 +++++---
 include/asm-powerpc/time.h |    2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)
arch/powerpc/kernel/time.c +5 -3
Index: linux-2.6-ozlabs/arch/powerpc/kernel/time.c
===================================================================
@@ -214,7 +214,6 @@ static void account_process_time(struct 
  	run_posix_cpu_timers(current);
 }
 
-#ifdef CONFIG_PPC_SPLPAR
 /*
  * Stuff for accounting stolen time.
  */
@@ -244,7 +243,8 @@ void snapshot_timebases(void)
 {
 	int cpu;
 
-	if (!cpu_has_feature(CPU_FTR_PURR))
+	if (!cpu_has_feature(CPU_FTR_PURR) &&
+	    !firmware_has_feature(FW_FEATURE_SPLPAR))
 		return;
 	for_each_possible_cpu(cpu)
 		spin_lock_init(&per_cpu(cpu_purr_data, cpu).lock);
@@ -257,7 +257,8 @@ void calculate_steal_time(void)
 	s64 stolen;
 	struct cpu_purr_data *pme;
 
-	if (!cpu_has_feature(CPU_FTR_PURR))
+	if (!cpu_has_feature(CPU_FTR_PURR) &&
+	    !firmware_has_feature(FW_FEATURE_SPLPAR))
 		return;
 	pme = &per_cpu(cpu_purr_data, smp_processor_id());
 	if (!pme->initialized)
@@ -273,6 +274,7 @@ void calculate_steal_time(void)
 	spin_unlock(&pme->lock);
 }
 
+#ifdef CONFIG_PPC_SPLPAR
 /*
  * Must be called before the cpu is added to the online map when
  * a cpu is being brought up at runtime.
include/asm-powerpc/time.h +1 -1
Index: linux-2.6-ozlabs/include/asm-powerpc/time.h
===================================================================
@@ -232,7 +232,7 @@ extern void account_process_vtime(struct
 #define account_process_vtime(tsk)		do { } while (0)
 #endif
 
-#if defined(CONFIG_VIRT_CPU_ACCOUNTING) && defined(CONFIG_PPC_SPLPAR)
+#if defined(CONFIG_VIRT_CPU_ACCOUNTING)
 extern void calculate_steal_time(void);
 extern void snapshot_timebases(void);
 #else
#2 lore raw

arch/powerpc/kernel/time.c void snapshot_timebases(void) · line 250

Quoted 6 lines · Michael Neuling
arch/powerpc/kernel/time.c +2 -1
-	if (!cpu_has_feature(CPU_FTR_PURR))
+	if (!cpu_has_feature(CPU_FTR_PURR) &&
+	    !firmware_has_feature(FW_FEATURE_SPLPAR))
 		return;
 	for_each_possible_cpu(cpu)
 		spin_lock_init(&per_cpu(cpu_purr_data, cpu).lock);

This means that on a machine with SPLPAR but not a PURR, e.g. a JS21, we'll try to read the PURR register and do the stolen time calculation with whatever value was in the register before the mfspr from the PURR. If we're going to make this change then we also need to add code to do the H_PURR hcall instead of reading the PURR directly on such machines.

Paul.

#3 lore raw

PATCH 1/1 fix stolen time for SMT without LPAR

For POWERPC, stolen time accounts for cycles lost to the hypervisor or PURR cycles attributed to the other SMT thread. Hence, when a PURR is available, we should still calculate stolen time, irrespective of being virtualised.

---

Quoted 6 lines

This means that on a machine with SPLPAR but not a PURR, e.g. a JS21, we'll try to read the PURR register and do the stolen time calculation with whatever value was in the register before the mfspr from the PURR. If we're going to make this change then we also need to add code to do the H_PURR hcall instead of reading the PURR directly on such machines.

This version bails on reading the PURR if it doesn't exist, so it doesn't make JS21 any worse. We still need to fix JS21, but our initial patches using H_PURR showed some lmbench crappy-ness.

Tested on JS21 and BML. Like you said offline, this can be 2.6.23.

 arch/powerpc/kernel/time.c |    2 +-
 include/asm-powerpc/time.h |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kernel/time.c +1 -1
Index: linux-2.6-ozlabs/arch/powerpc/kernel/time.c
===================================================================
@@ -214,7 +214,6 @@ static void account_process_time(struct 
  	run_posix_cpu_timers(current);
 }
 
-#ifdef CONFIG_PPC_SPLPAR
 /*
  * Stuff for accounting stolen time.
  */
@@ -273,6 +272,7 @@ void calculate_steal_time(void)
 	spin_unlock(&pme->lock);
 }
 
+#ifdef CONFIG_PPC_SPLPAR
 /*
  * Must be called before the cpu is added to the online map when
  * a cpu is being brought up at runtime.
include/asm-powerpc/time.h +1 -1
Index: linux-2.6-ozlabs/include/asm-powerpc/time.h
===================================================================
@@ -232,7 +232,7 @@ extern void account_process_vtime(struct
 #define account_process_vtime(tsk)		do { } while (0)
 #endif
 
-#if defined(CONFIG_VIRT_CPU_ACCOUNTING) && defined(CONFIG_PPC_SPLPAR)
+#if defined(CONFIG_VIRT_CPU_ACCOUNTING)
 extern void calculate_steal_time(void);
 extern void snapshot_timebases(void);
 #else