linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cpufreq: acpi_cpufreq: base frequency attribute support
@ 2015-10-01 22:25 Srinivas Pandruvada
  2015-10-07 17:23 ` Viresh Kumar
  0 siblings, 1 reply; 20+ messages in thread
From: Srinivas Pandruvada @ 2015-10-01 22:25 UTC (permalink / raw)
  To: rafael.j.wysocki, viresh.kumar; +Cc: linux-pm, Srinivas Pandruvada

Currently scaling_available_frequencies displays list of available
frequencies which can be used to set max/min or current scaling frequency.

>cat scaling_available_frequencies
2301000 2300000 2200000 2000000 1900000 1800000 1700000 1500000 1400000
1300000 1100000 1000000 900000 800000 600000 500000

Here traditionally it is assumed that only 2301000 is a turbo frequency,
which is purely opportunistic, anything else user can request and may
get it.
But because of configurable thermal design power implementation in several
Intel CPUs, the opportunistic frequency start can be any frequency in this
range. For example it can be 2300000 or any lower value.
This change adds an optional new attribute called "base_frequency",
which displays the max non-turbo frequency (base frequency). For example:
>cat base_frequency
2200000
This will allow user to choose a certain frequency which is not
opportunistic.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/cpufreq/acpi-cpufreq.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index cec1ee2..4433f6b 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -70,6 +70,7 @@ struct acpi_cpufreq_data {
 	unsigned int cpu_feature;
 	unsigned int acpi_perf_cpu;
 	cpumask_var_t freqdomain_cpus;
+	bool base_freq_attr_present;
 };
 
 /* acpi_perf_data is a pointer to percpu data. */
@@ -651,6 +652,21 @@ static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c)
 }
 #endif
 
+static ssize_t base_frequency_show(struct cpufreq_policy *policy, char *buf)
+{
+	u64 tar;
+	int err;
+
+	err = rdmsrl_safe(MSR_TURBO_ACTIVATION_RATIO, &tar);
+	if (!err)
+		/* Refer to IA64, IA32 SDM table 35-20, unit = 100 MHz */
+		return sprintf(buf, "%llu\n", tar * 100000);
+
+	return err;
+}
+
+static struct freq_attr cpufreq_attr_base_frequency = __ATTR_RO(base_frequency);
+
 static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
 {
 	unsigned int i;
@@ -827,6 +843,21 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
 		break;
 	}
 
+	if (data->cpu_feature == SYSTEM_INTEL_MSR_CAPABLE) {
+		u64 tar;
+		int err;
+
+		err = rdmsrl_safe(MSR_TURBO_ACTIVATION_RATIO, &tar);
+		if (!err) {
+			result = sysfs_create_file(&policy->kobj,
+					&(cpufreq_attr_base_frequency.attr));
+			if (result)
+				goto err_freqfree;
+
+			data->base_freq_attr_present = true;
+		}
+	}
+
 	/* notify BIOS that we exist */
 	acpi_processor_notify_smm(THIS_MODULE);
 
@@ -866,6 +897,9 @@ static int acpi_cpufreq_cpu_exit(struct cpufreq_policy *policy)
 	pr_debug("acpi_cpufreq_cpu_exit\n");
 
 	if (data) {
+		if (data->base_freq_attr_present)
+			sysfs_remove_file(&policy->kobj,
+					  &(cpufreq_attr_base_frequency.attr));
 		policy->driver_data = NULL;
 		acpi_processor_unregister_performance(data->acpi_perf_cpu);
 		free_cpumask_var(data->freqdomain_cpus);
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 20+ messages in thread
* [PATCH] cpufreq: acpi_cpufreq: base frequency attribute support
@ 2016-02-29 20:36 Srinivas Pandruvada
  2016-03-01  2:28 ` Viresh Kumar
  0 siblings, 1 reply; 20+ messages in thread
From: Srinivas Pandruvada @ 2016-02-29 20:36 UTC (permalink / raw)
  To: rjw, viresh.kumar; +Cc: linux-pm, Srinivas Pandruvada

Currently scaling_available_frequencies displays list of available
frequencies which can be used to set max/min or current scaling frequency.

>cat scaling_available_frequencies
2301000 2300000 2200000 2000000 1900000 1800000 1700000 1500000 1400000
1300000 1100000 1000000 900000 800000 600000 500000

Here traditionally it is assumed that only 2301000 is a turbo frequency,
which is purely opportunistic, anything else user can request and may
get it.
But because of configurable thermal design power implementation in several
Intel CPUs, the opportunistic frequency start can be any frequency in this
range. For example it can be 2300000 or any lower value.
This change adds an optional new attribute called "base_frequency",
which displays the max non-turbo frequency (base frequency). For example:
>cat base_frequency
2200000
This will allow user to choose a certain frequency which is not
opportunistic.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/cpufreq/acpi-cpufreq.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index 51eef87..76edd28 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -646,6 +646,21 @@ static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c)
 }
 #endif
 
+static ssize_t show_base_frequency(struct cpufreq_policy *policy, char *buf)
+{
+	u64 tar;
+	int err;
+
+	err = rdmsrl_safe_on_cpu(policy->cpu, MSR_TURBO_ACTIVATION_RATIO, &tar);
+	if (!err)
+		/* Refer to IA64, IA32 SDM table 35-20, unit = 100 MHz */
+		return sprintf(buf, "%llu\n", tar * 100000);
+
+	return err;
+}
+
+cpufreq_freq_attr_ro(base_frequency);
+
 static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
 {
 	unsigned int i;
@@ -889,6 +904,7 @@ static struct freq_attr *acpi_cpufreq_attr[] = {
 	&cpb,
 #endif
 	NULL,
+	NULL,
 };
 
 static struct cpufreq_driver acpi_cpufreq_driver = {
@@ -971,6 +987,26 @@ static int __init acpi_cpufreq_init(void)
 			}
 	}
 #endif
+
+	if (boot_cpu_has(X86_FEATURE_IDA)) {
+		u64 plat_info, tar;
+		int err;
+
+		err = rdmsrl_safe_on_cpu(0, MSR_PLATFORM_INFO, &plat_info);
+		/* Check number of config TDP levels > 0 */
+		if (!err && ((plat_info >> 33) & 0x03) > 0) {
+			err = rdmsrl_safe_on_cpu(0, MSR_TURBO_ACTIVATION_RATIO,
+						 &tar);
+			if (!err) {
+				struct freq_attr **attr;
+
+				for (attr = acpi_cpufreq_attr; *attr; attr++)
+				;
+				*attr = &base_frequency;
+			}
+		}
+	}
+
 	acpi_cpufreq_boost_init();
 
 	ret = cpufreq_register_driver(&acpi_cpufreq_driver);
-- 
2.4.3


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

end of thread, other threads:[~2016-03-02  2:38 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-01 22:25 [PATCH] cpufreq: acpi_cpufreq: base frequency attribute support Srinivas Pandruvada
2015-10-07 17:23 ` Viresh Kumar
2015-10-09 15:34   ` Srinivas Pandruvada
2015-10-15 22:45   ` Rafael J. Wysocki
2015-10-16  5:42     ` Viresh Kumar
2016-02-24 20:00       ` Srinivas Pandruvada
2016-02-24 20:05         ` Rafael J. Wysocki
2016-02-24 23:37           ` Srinivas Pandruvada
2016-02-25  3:27             ` Viresh Kumar
2016-02-25 18:07               ` Srinivas Pandruvada
2016-02-26  1:10                 ` Pandruvada, Srinivas
2016-02-26  1:57                 ` Viresh Kumar
2016-02-26 20:21                   ` Srinivas Pandruvada
2016-02-29  3:16                     ` Viresh Kumar
2016-02-29 17:11                       ` Srinivas Pandruvada
2016-03-01  2:16                         ` Viresh Kumar
  -- strict thread matches above, loose matches on Subject: below --
2016-02-29 20:36 Srinivas Pandruvada
2016-03-01  2:28 ` Viresh Kumar
2016-03-01 18:10   ` Srinivas Pandruvada
2016-03-02  2:38     ` Viresh Kumar

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).