linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] powernv:cpufreq: Export nominal and current frequency via sysfs
@ 2014-03-03  8:33 Gautham R. Shenoy
  2014-03-03  8:33 ` [PATCH 1/4] powernv:cpufreq: Create pstate_id_to_freq() helper Gautham R. Shenoy
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Gautham R. Shenoy @ 2014-03-03  8:33 UTC (permalink / raw)
  To: linuxppc-dev, Ben Herrenschmidt, Paul Mackerras,
	Vaidyanathan Srinivasan, Srivatsa S . Bhat
  Cc: Gautham R. Shenoy

From: "Gautham R. Shenoy" <ego@linux.vnet.ibm.com>

Hi,

On IBM POWERNV platforms[1], presently we do not report the current
operating frequency of the processor through the sysfs interface
"cpuinfo_cur_freq" since the cpu frequency driver[1] has not
implemented the ->get(unsigned int cpu) method. Fix this by
implementing the ->get(unsigned int cpu) method which will report the
frequency corresponding to the pstate_id on PMSR on "cpu".

Also, export the nominal frequency of the processor through the sysfs
interface "cpuinfo_nominal_freq" by defining it as a driver attribute.

The patch series depends on the cpu-frequency driver patch-series[1].

[1] http://comments.gmane.org/gmane.linux.ports.ppc.embedded/67905

Thanks and Regards
gautham.

Summary:
==========================
Gautham R. Shenoy (4):
  powernv:cpufreq: Create pstate_id_to_freq() helper
  powernv:cpufreq: Export nominal frequency via sysfs.
  powernv:cpufreq: Create a powernv_cpu_to_core_mask() helper.
  powernv:cpufreq: Implement the driver->get() method

 drivers/cpufreq/powernv-cpufreq.c | 115 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 110 insertions(+), 5 deletions(-)

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] powernv:cpufreq: Create pstate_id_to_freq() helper
  2014-03-03  8:33 [PATCH 0/4] powernv:cpufreq: Export nominal and current frequency via sysfs Gautham R. Shenoy
@ 2014-03-03  8:33 ` Gautham R. Shenoy
  2014-03-03  8:33 ` [PATCH 2/4] powernv:cpufreq: Export nominal frequency via sysfs Gautham R. Shenoy
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Gautham R. Shenoy @ 2014-03-03  8:33 UTC (permalink / raw)
  To: linuxppc-dev, Ben Herrenschmidt, Paul Mackerras,
	Vaidyanathan Srinivasan, Srivatsa S . Bhat
  Cc: Gautham R. Shenoy

From: "Gautham R. Shenoy" <ego@linux.vnet.ibm.com>

Create a helper routine that can return the cpu-frequency for the
corresponding pstate_id.

Also, cache the values of the pstate_max, pstate_min and
pstate_nominal and nr_pstates in a static structure so that they can
be reused in the future to perform any validations.

Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
---
 drivers/cpufreq/powernv-cpufreq.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index 345501e..d0a8dee 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -37,6 +37,15 @@ static DEFINE_PER_CPU(struct mutex, freq_switch_lock);
 #define POWERNV_MAX_PSTATES	256
 
 static struct cpufreq_frequency_table powernv_freqs[POWERNV_MAX_PSTATES+1];
+struct powernv_pstate_info {
+	int pstate_min_id;
+	int pstate_max_id;
+	int pstate_nominal_id;
+	int nr_pstates;
+};
+
+static struct powernv_pstate_info powernv_pstate_info;
+
 
 /*
  * Initialize the freq table based on data obtained
@@ -106,9 +115,28 @@ static int init_powernv_pstates(void)
 	powernv_freqs[i].driver_data = 0;
 	powernv_freqs[i].frequency = CPUFREQ_TABLE_END;
 
+	powernv_pstate_info.pstate_min_id = pstate_min;
+	powernv_pstate_info.pstate_max_id = pstate_max;
+	powernv_pstate_info.pstate_nominal_id = pstate_nominal;
+	powernv_pstate_info.nr_pstates = nr_pstates;
+
 	return 0;
 }
 
+/**
+ * Returns the cpu frequency corresponding to the pstate_id.
+ */
+static unsigned int pstate_id_to_freq(int pstate_id)
+{
+	int i;
+
+	i = powernv_pstate_info.pstate_max_id - pstate_id;
+
+	BUG_ON(i >= powernv_pstate_info.nr_pstates || i < 0);
+	WARN_ON(powernv_freqs[i].driver_data != pstate_id);
+	return powernv_freqs[i].frequency;
+}
+
 static struct freq_attr *powernv_cpu_freq_attr[] = {
 	&cpufreq_freq_attr_scaling_available_freqs,
 	NULL,
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] powernv:cpufreq: Export nominal frequency via sysfs.
  2014-03-03  8:33 [PATCH 0/4] powernv:cpufreq: Export nominal and current frequency via sysfs Gautham R. Shenoy
  2014-03-03  8:33 ` [PATCH 1/4] powernv:cpufreq: Create pstate_id_to_freq() helper Gautham R. Shenoy
@ 2014-03-03  8:33 ` Gautham R. Shenoy
  2014-03-03  8:33 ` [PATCH 3/4] powernv:cpufreq: Create a powernv_cpu_to_core_mask() helper Gautham R. Shenoy
  2014-03-03  8:33 ` [PATCH 4/4] powernv:cpufreq: Implement the driver->get() method Gautham R. Shenoy
  3 siblings, 0 replies; 5+ messages in thread
From: Gautham R. Shenoy @ 2014-03-03  8:33 UTC (permalink / raw)
  To: linuxppc-dev, Ben Herrenschmidt, Paul Mackerras,
	Vaidyanathan Srinivasan, Srivatsa S . Bhat
  Cc: Gautham R. Shenoy

From: "Gautham R. Shenoy" <ego@linux.vnet.ibm.com>

Create a driver attribute named cpuinfo_nominal_frequency which
creates a sysfs read-only file named cpuinfo_nominal_frequency. Export
the frequency corresponding to the nominal_pstate through this
interface.

Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
---
 drivers/cpufreq/powernv-cpufreq.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index d0a8dee..c59eb26 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -137,8 +137,30 @@ static unsigned int pstate_id_to_freq(int pstate_id)
 	return powernv_freqs[i].frequency;
 }
 
+/**
+ * show_cpuinfo_nominal_freq - Show the nominal CPU frequency as indicated by
+ * the firmware
+ */
+static ssize_t show_cpuinfo_nominal_freq(struct cpufreq_policy *policy,
+					char *buf)
+{
+	int nominal_freq;
+	nominal_freq = pstate_id_to_freq(powernv_pstate_info.pstate_nominal_id);
+	return sprintf(buf, "%u\n", nominal_freq);
+}
+
+
+struct freq_attr cpufreq_freq_attr_cpuinfo_nominal_freq = {
+	.attr = { .name = "cpuinfo_nominal_freq",
+		  .mode = 0444,
+		},
+	.show = show_cpuinfo_nominal_freq,
+};
+
+
 static struct freq_attr *powernv_cpu_freq_attr[] = {
 	&cpufreq_freq_attr_scaling_available_freqs,
+	&cpufreq_freq_attr_cpuinfo_nominal_freq,
 	NULL,
 };
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] powernv:cpufreq: Create a powernv_cpu_to_core_mask() helper.
  2014-03-03  8:33 [PATCH 0/4] powernv:cpufreq: Export nominal and current frequency via sysfs Gautham R. Shenoy
  2014-03-03  8:33 ` [PATCH 1/4] powernv:cpufreq: Create pstate_id_to_freq() helper Gautham R. Shenoy
  2014-03-03  8:33 ` [PATCH 2/4] powernv:cpufreq: Export nominal frequency via sysfs Gautham R. Shenoy
@ 2014-03-03  8:33 ` Gautham R. Shenoy
  2014-03-03  8:33 ` [PATCH 4/4] powernv:cpufreq: Implement the driver->get() method Gautham R. Shenoy
  3 siblings, 0 replies; 5+ messages in thread
From: Gautham R. Shenoy @ 2014-03-03  8:33 UTC (permalink / raw)
  To: linuxppc-dev, Ben Herrenschmidt, Paul Mackerras,
	Vaidyanathan Srinivasan, Srivatsa S . Bhat
  Cc: Gautham R. Shenoy

From: "Gautham R. Shenoy" <ego@linux.vnet.ibm.com>

Move the code that computes the cpumask corresponding to the
thread-siblings of a cpu to a new method named
powernv_cpu_to_core_mask() so that it can be used by other places in
the code.

Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
---
 drivers/cpufreq/powernv-cpufreq.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index c59eb26..f0dae6f 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -166,6 +166,23 @@ static struct freq_attr *powernv_cpu_freq_attr[] = {
 
 /* Helper routines */
 
+/**
+ * Sets the bits corresponding to the thread-siblings of cpu in its core
+ * in 'cpus'.
+ */
+static void powernv_cpu_to_core_mask(unsigned int cpu, cpumask_var_t cpus)
+{
+	int base, i;
+
+	base = cpu_first_thread_sibling(cpu);
+
+	for (i = 0; i < threads_per_core; i++) {
+		cpumask_set_cpu(base + i, cpus);
+	}
+
+	return;
+}
+
 /* Access helpers to power mgt SPR */
 
 static inline unsigned long get_pmspr(unsigned long sprn)
@@ -231,13 +248,10 @@ static int powernv_set_freq(cpumask_var_t cpus, unsigned int new_index)
 
 static int powernv_cpufreq_cpu_init(struct cpufreq_policy *policy)
 {
-	int base, i;
+	int i;
 
 #ifdef CONFIG_SMP
-	base = cpu_first_thread_sibling(policy->cpu);
-
-	for (i = 0; i < threads_per_core; i++)
-		cpumask_set_cpu(base + i, policy->cpus);
+	powernv_cpu_to_core_mask(policy->cpu, policy->cpus);
 #endif
 	policy->cpuinfo.transition_latency = 25000;
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] powernv:cpufreq: Implement the driver->get() method
  2014-03-03  8:33 [PATCH 0/4] powernv:cpufreq: Export nominal and current frequency via sysfs Gautham R. Shenoy
                   ` (2 preceding siblings ...)
  2014-03-03  8:33 ` [PATCH 3/4] powernv:cpufreq: Create a powernv_cpu_to_core_mask() helper Gautham R. Shenoy
@ 2014-03-03  8:33 ` Gautham R. Shenoy
  3 siblings, 0 replies; 5+ messages in thread
From: Gautham R. Shenoy @ 2014-03-03  8:33 UTC (permalink / raw)
  To: linuxppc-dev, Ben Herrenschmidt, Paul Mackerras,
	Vaidyanathan Srinivasan, Srivatsa S . Bhat
  Cc: Gautham R. Shenoy

From: "Gautham R. Shenoy" <ego@linux.vnet.ibm.com>

The current frequency of a cpu is reported through the sysfs file
cpuinfo_cur_freq. This requires the driver to implement a
"->get(unsigned int cpu)" method which will return the current
operating frequency.

Implement a function named powernv_cpufreq_get() which corresponds to
the required ->get() method.

Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
---
 drivers/cpufreq/powernv-cpufreq.c | 41 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index f0dae6f..5f43e4f 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -218,6 +218,46 @@ static inline void set_pmspr(unsigned long sprn, unsigned long val)
 	BUG();
 }
 
+/**
+ * Computes the current frequency on this cpu
+ * and stores the result in *ret_freq.
+ */
+static void powernv_get_cpu_freq(void *ret_freq)
+{
+	unsigned long pmspr_val;
+	long pstate_id;
+	int *cur_freq, freq;
+
+	cur_freq = (int *)ret_freq;
+	pmspr_val = get_pmspr(SPRN_PMSR);
+	pstate_id = pmspr_val;
+	pstate_id = pstate_id >> 56;
+	WARN_ON(pstate_id > 0);
+	freq = pstate_id_to_freq(pstate_id);
+	pr_debug("cpu %d pmsr %lx pstate_id %ld frequency %d \n",
+		smp_processor_id(), pmspr_val, pstate_id, freq);
+	*cur_freq = freq;
+}
+
+/**
+ * Returns the cpu frequency as reported by the firmware for 'cpu'.
+ * This value is reported through the sysfs file cpuinfo_cur_freq.
+ */
+unsigned int powernv_cpufreq_get(unsigned int cpu)
+{
+	int ret_freq;
+	cpumask_var_t sibling_mask;
+
+	if (!zalloc_cpumask_var(&sibling_mask, GFP_KERNEL))
+		return -ENOMEM;
+
+	powernv_cpu_to_core_mask(cpu, sibling_mask);
+	smp_call_function_any(sibling_mask, powernv_get_cpu_freq, &ret_freq, 1);
+
+	free_cpumask_var(sibling_mask);
+	return ret_freq;
+}
+
 static void set_pstate(void *pstate)
 {
 	unsigned long val;
@@ -310,6 +350,7 @@ static int powernv_cpufreq_target(struct cpufreq_policy *policy,
 static struct cpufreq_driver powernv_cpufreq_driver = {
 	.verify		= powernv_cpufreq_verify,
 	.target		= powernv_cpufreq_target,
+	.get		= powernv_cpufreq_get,
 	.init		= powernv_cpufreq_cpu_init,
 	.exit		= powernv_cpufreq_cpu_exit,
 	.name		= "powernv-cpufreq",
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-03-03  8:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-03  8:33 [PATCH 0/4] powernv:cpufreq: Export nominal and current frequency via sysfs Gautham R. Shenoy
2014-03-03  8:33 ` [PATCH 1/4] powernv:cpufreq: Create pstate_id_to_freq() helper Gautham R. Shenoy
2014-03-03  8:33 ` [PATCH 2/4] powernv:cpufreq: Export nominal frequency via sysfs Gautham R. Shenoy
2014-03-03  8:33 ` [PATCH 3/4] powernv:cpufreq: Create a powernv_cpu_to_core_mask() helper Gautham R. Shenoy
2014-03-03  8:33 ` [PATCH 4/4] powernv:cpufreq: Implement the driver->get() method Gautham R. Shenoy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).