Skip to contentSkip to conversation

powerpc/cpufreq: Add pr_warn() on OPAL firmware failures

PATCH In review Vaidyanathan Srinivasan 2 participants 2 messages Aug 3, 2014 – Aug 4, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/cpufreq: Add pr_warn() on OPAL firmware failures

Cpufreq depends on platform firmware to implement PStates. In case of platform firmware failure, cpufreq should not panic host kernel with BUG_ON(). Less severe pr_warn() will suffice.

Add firmware_has_feature(FW_FEATURE_OPALv3) check to skip probing for device-tree on non-powernv platforms.

---
Tested on powernv and pseries platforms with v3.16-rc7 kernel.

 drivers/cpufreq/powernv-cpufreq.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/cpufreq/powernv-cpufreq.c +16 -2
index bb1d08d..379c083 100644
@@ -28,6 +28,7 @@
 #include <linux/of.h>
 
 #include <asm/cputhreads.h>
+#include <asm/firmware.h>
 #include <asm/reg.h>
 #include <asm/smp.h> /* Required for cpu_sibling_mask() in UP configs */
 
@@ -98,7 +99,11 @@ static int init_powernv_pstates(void)
 		return -ENODEV;
 	}
 
-	WARN_ON(len_ids != len_freqs);
+	if (len_ids != len_freqs) {
+		pr_warn("Entries in ibm,pstate-ids and "
+			"ibm,pstate-frequencies-mhz does not match\n");
+	}
+
 	nr_pstates = min(len_ids, len_freqs) / sizeof(u32);
 	if (!nr_pstates) {
 		pr_warn("No PStates found\n");
@@ -131,7 +136,12 @@ static unsigned int pstate_id_to_freq(int pstate_id)
 	int i;
 
 	i = powernv_pstate_info.max - pstate_id;
-	BUG_ON(i >= powernv_pstate_info.nr_pstates || i < 0);
+	if (i >= powernv_pstate_info.nr_pstates || i < 0) {
+		pr_warn("PState id %d outside of PState table, "
+			"reporting nominal id %d instead\n",
+			pstate_id, powernv_pstate_info.nominal);
+		i = powernv_pstate_info.max - powernv_pstate_info.nominal;
+	}
 
 	return powernv_freqs[i].frequency;
 }
@@ -321,6 +331,10 @@ static int __init powernv_cpufreq_init(void)
 {
 	int rc = 0;
 
+	/* Don't probe on pseries (guest) platforms */
+	if (!firmware_has_feature(FW_FEATURE_OPALv3))
+		return -ENODEV;
+
 	/* Discover pstates from device tree and init */
 	rc = init_powernv_pstates();
 	if (rc) {
Acked-by on v1 1/1
#1 lore raw

drivers/cpufreq/powernv-cpufreq.c static unsigned int pstate_id_to_freq(int pstate_id) · line 143

Quoted 10 lines · Vaidyanathan Srinivasan
drivers/cpufreq/powernv-cpufreq.c +5 -1
@@ -131,7 +136,12 @@ static unsigned int pstate_id_to_freq(int pstate_id)
 	int i;
 
 	i = powernv_pstate_info.max - pstate_id;
-	BUG_ON(i >= powernv_pstate_info.nr_pstates || i < 0);
+	if (i >= powernv_pstate_info.nr_pstates || i < 0) {
+		pr_warn("PState id %d outside of PState table, "
+			"reporting nominal id %d instead\n",
+			pstate_id, powernv_pstate_info.nominal);
+		i = powernv_pstate_info.max - powernv_pstate_info.nominal;

As of now the default loglevel corresponds to KERN_WARNING so this warning should get printed anyway. However, don't you think it would be better if we make it a pr_err( ) since it's a platform error that's causing the pstate_id to go out of bounds ?

Otherwise it looks ok.

drivers/cpufreq/powernv-cpufreq.c static unsigned int pstate_id_to_freq(int pstate_id) · line 147

Quoted 4 lines
drivers/cpufreq/powernv-cpufreq.c +1 -0
+	}
 
 	return powernv_freqs[i].frequency;
 }

--
Thanks and Regards
gautham.