Skip to contentSkip to conversation

cpufreq: Move ->get callback check outside of __cpufreq_get()

PATCH In review Yue Hu 3 participants 5 messages Apr 19, 2019 – May 1, 2019 CPU frequency scaling framework

lore
Share & tools
lore

Yue Hu

author
#0 lore raw

PATCH 1/1 cpufreq: Move ->get callback check outside of __cpufreq_get()

From: Yue Hu <[email protected]>

Currenly, __cpufreq_get() called by show_cpuinfo_cur_freq() will check ->get callback. That is needless since cpuinfo_cur_freq attribute will not be created if ->get is not set. So let's drop it in __cpufreq_get(). Also keep this check in cpufreq_get().

---
 drivers/cpufreq/cpufreq.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/cpufreq/cpufreq.c +3 -2
index 047662b..c6187f1 100644
@@ -1548,7 +1548,7 @@ static unsigned int __cpufreq_get(struct cpufreq_policy *policy)
 {
 	unsigned int ret_freq = 0;
 
-	if (unlikely(policy_is_inactive(policy)) || !cpufreq_driver->get)
+	if (unlikely(policy_is_inactive(policy)))
 		return ret_freq;
 
 	ret_freq = cpufreq_driver->get(policy->cpu);
@@ -1586,7 +1586,8 @@ unsigned int cpufreq_get(unsigned int cpu)
 
 	if (policy) {
 		down_read(&policy->rwsem);
-		ret_freq = __cpufreq_get(policy);
+		if (cpufreq_driver->get)
+			ret_freq = __cpufreq_get(policy);
 		up_read(&policy->rwsem);
 
 		cpufreq_cpu_put(policy);
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 1/1 cpufreq: Expose real_cpus out to userspace

From: Yue Hu <[email protected]>

Currently, there are 3 CPU masks, let's expose real_cpus just like the others if user want to know related CPUs that are actually present.

---
 drivers/cpufreq/cpufreq.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/cpufreq/cpufreq.c +7 -0
index c6187f1..0322cce 100644
@@ -824,6 +824,11 @@ static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
 	return cpufreq_show_cpus(policy->cpus, buf);
 }
 
+static ssize_t show_real_cpus(struct cpufreq_policy *policy, char *buf)
+{
+	return cpufreq_show_cpus(policy->real_cpus, buf);
+}
+
 static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
 					const char *buf, size_t count)
 {
@@ -873,6 +878,7 @@ static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
 cpufreq_freq_attr_ro(bios_limit);
 cpufreq_freq_attr_ro(related_cpus);
 cpufreq_freq_attr_ro(affected_cpus);
+cpufreq_freq_attr_ro(real_cpus);
 cpufreq_freq_attr_rw(scaling_min_freq);
 cpufreq_freq_attr_rw(scaling_max_freq);
 cpufreq_freq_attr_rw(scaling_governor);
@@ -886,6 +892,7 @@ static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
 	&scaling_max_freq.attr,
 	&affected_cpus.attr,
 	&related_cpus.attr,
+	&real_cpus.attr,
 	&scaling_governor.attr,
 	&scaling_driver.attr,
 	&scaling_available_governors.attr,
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [PATCH] cpufreq: Expose real_cpus out to userspace

Quoted 35 lines · Yue Hu

From: Yue Hu <[email protected]>

Currently, there are 3 CPU masks, let's expose real_cpus just like the others if user want to know related CPUs that are actually present.

---
 drivers/cpufreq/cpufreq.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/cpufreq/cpufreq.c +6 -0
index c6187f1..0322cce 100644
@@ -824,6 +824,11 @@ static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
 	return cpufreq_show_cpus(policy->cpus, buf);
 }
 
+static ssize_t show_real_cpus(struct cpufreq_policy *policy, char *buf)
+{
+	return cpufreq_show_cpus(policy->real_cpus, buf);
+}
+
 static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
 					const char *buf, size_t count)
 {
@@ -873,6 +878,7 @@ static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
 cpufreq_freq_attr_ro(bios_limit);
 cpufreq_freq_attr_ro(related_cpus);
 cpufreq_freq_attr_ro(affected_cpus);
+cpufreq_freq_attr_ro(real_cpus);
 cpufreq_freq_attr_rw(scaling_min_freq);
 cpufreq_freq_attr_rw(scaling_max_freq);
 cpufreq_freq_attr_rw(scaling_governor);

drivers/cpufreq/cpufreq.c static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf) · line 898

Quoted 7 lines
drivers/cpufreq/cpufreq.c +1 -0
@@ -886,6 +892,7 @@ static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
 	&scaling_max_freq.attr,
 	&affected_cpus.attr,
 	&related_cpus.attr,
+	&real_cpus.attr,
 	&scaling_governor.attr,
 	&scaling_driver.attr,
 	&scaling_available_governors.attr,

The same information can be looked into (indirectly though) by looking at related_cpus and online_cpus isn't it ? Why expose it then ? I am a bit against it as it is only used for internal reasons right now.

Signature · 1 line
viresh
maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Yue Hu
Quoted 26 lines · Yue Hu

From: Yue Hu <[email protected]>

Currenly, __cpufreq_get() called by show_cpuinfo_cur_freq() will check ->get callback. That is needless since cpuinfo_cur_freq attribute will not be created if ->get is not set. So let's drop it in __cpufreq_get(). Also keep this check in cpufreq_get().

---
 drivers/cpufreq/cpufreq.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/cpufreq/cpufreq.c +1 -1
index 047662b..c6187f1 100644
@@ -1548,7 +1548,7 @@ static unsigned int __cpufreq_get(struct cpufreq_policy *policy)
 {
 	unsigned int ret_freq = 0;
 
-	if (unlikely(policy_is_inactive(policy)) || !cpufreq_driver->get)
+	if (unlikely(policy_is_inactive(policy)))
 		return ret_freq;
 
 	ret_freq = cpufreq_driver->get(policy->cpu);

drivers/cpufreq/cpufreq.c unsigned int cpufreq_get(unsigned int cpu) · line 1593

Quoted 9 lines
drivers/cpufreq/cpufreq.c +2 -1
@@ -1586,7 +1586,8 @@ unsigned int cpufreq_get(unsigned int cpu)
 
 	if (policy) {
 		down_read(&policy->rwsem);
-		ret_freq = __cpufreq_get(policy);
+		if (cpufreq_driver->get)
+			ret_freq = __cpufreq_get(policy);
 		up_read(&policy->rwsem);
 
 		cpufreq_cpu_put(policy);
Signature · 1 line
viresh
#4 lore raw
Quoted 35 lines · CEST Viresh Kumar
Quoted 34 lines · Yue Hu

From: Yue Hu <[email protected]>

Currenly, __cpufreq_get() called by show_cpuinfo_cur_freq() will check ->get callback. That is needless since cpuinfo_cur_freq attribute will not be created if ->get is not set. So let's drop it in __cpufreq_get(). Also keep this check in cpufreq_get().

---
 drivers/cpufreq/cpufreq.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/cpufreq/cpufreq.c +3 -2
index 047662b..c6187f1 100644
@@ -1548,7 +1548,7 @@ static unsigned int __cpufreq_get(struct cpufreq_policy *policy)
 {
 	unsigned int ret_freq = 0;
 
-	if (unlikely(policy_is_inactive(policy)) || !cpufreq_driver->get)
+	if (unlikely(policy_is_inactive(policy)))
 		return ret_freq;
 
 	ret_freq = cpufreq_driver->get(policy->cpu);
@@ -1586,7 +1586,8 @@ unsigned int cpufreq_get(unsigned int cpu)
 
 	if (policy) {
 		down_read(&policy->rwsem);
-		ret_freq = __cpufreq_get(policy);
+		if (cpufreq_driver->get)
+			ret_freq = __cpufreq_get(policy);
 		up_read(&policy->rwsem);
 
Quoted 3 lines

drivers/cpufreq/cpufreq.c unsigned int cpufreq_get(unsigned int cpu) · line 1593

Quoted 1 line
drivers/cpufreq/cpufreq.c +0 -0
 		cpufreq_cpu_put(policy);

Patch applied, thanks!