arch_topology: Minor cleanups
Subsystems (3)
v2 cover arch_topology: Minor cleanups
Hi Greg,
You weren't included in the first [1] version of this series, as it was targeting arch/arm*/ directories then.
Here are some cleanups for the arch_topology core.
Tested on ARM64 Hikey board by setting following in cpu nodes in DT:
capacity-dmips-mhz = <1000>;
V1->V2:
- based over linux-next/master (to get Juri's recent changes)
- More cleanups included. V1 only had the first patch.
- Rename of cap_parsing_failed isn't required anymore (as it is localized to a single routine now).
--
viresh
[1] https://marc.info/?l=linux-arm-kernel&m=149795553024005
Viresh Kumar (5):
arch_topology: Get rid of "cap_parsing_done"
arch_topology: Don't break lines unnecessarily
arch_topology: Covert switch block to if block
arch_topology: Return 0 or -ve errors from
topology_parse_cpu_capacity()
arch_topology: Localize cap_parsing_failed to
topology_parse_cpu_capacity()
arch/arm/kernel/topology.c | 2 +- drivers/base/arch_topology.c | 78 ++++++++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 40 deletions(-)
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
PATCH v2 1/5 arch_topology: Get rid of "cap_parsing_done"
We can reuse "cap_parsing_failed" instead of keeping an additional variable here.
--- drivers/base/arch_topology.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/base/arch_topology.c +2 -3
@@ -161,7 +161,6 @@ int __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)#ifdef CONFIG_CPU_FREQ static cpumask_var_t cpus_to_visit; -static bool cap_parsing_done;static void parsing_done_workfn (struct work_struct *work); static DECLARE_WORK(parsing_done_work, parsing_done_workfn);
@@ -173,7 +172,7 @@ init_cpu_capacity_callback(struct notifier_block *nb,struct cpufreq_policy *policy = data;int cpu; -if (cap_parsing_failed || cap_parsing_done) +if (cap_parsing_failed)return 0 ;switch (val) {
@@ -193,7 +192,7 @@ init_cpu_capacity_callback(struct notifier_block *nb,topology_normalize_cpu_scale ();kfree (raw_capacity);pr_debug ("cpu_capacity: parsing done\n" ); - cap_parsing_done = true; + cap_parsing_failed = true;schedule_work (&parsing_done_work); } }
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
PATCH v2 2/5 arch_topology: Don't break lines unnecessarily
In reply to Viresh KumarThere is no need of line break at few places, avoid them.
--- drivers/base/arch_topology.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/base/arch_topology.c +3 -6
@@ -41,8 +41,7 @@ static ssize_t cpu_capacity_show(struct device *dev, { struct cpu *cpu = container_of(dev, struct cpu, dev); -return sprintf (buf,"%lu\n" , -topology_get_cpu_scale (NULL , cpu->dev.id)); +return sprintf (buf,"%lu\n" ,topology_get_cpu_scale (NULL , cpu->dev.id)); } static ssize_t cpu_capacity_store(struct device *dev,
@@ -128,8 +127,7 @@ int __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)if (cap_parsing_failed)return !ret; - ret =of_property_read_u32 (cpu_node, -"capacity-dmips-mhz" , + ret =of_property_read_u32 (cpu_node,"capacity-dmips-mhz" , &cpu_capacity);if (!ret) {if (!raw_capacity) {
@@ -180,8 +178,7 @@ init_cpu_capacity_callback(struct notifier_block *nb,pr_debug ("cpu_capacity: init cpu capacity for CPUs [%*pbl] (to_visit=%*pbl)\n" ,cpumask_pr_args (policy->related_cpus),cpumask_pr_args (cpus_to_visit)); -cpumask_andnot (cpus_to_visit, - cpus_to_visit, +cpumask_andnot (cpus_to_visit, cpus_to_visit, policy->related_cpus);for_each_cpu (cpu, policy->related_cpus) { raw_capacity[cpu] = topology_get_cpu_scale(NULL, cpu) *
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
PATCH v2 3/5 arch_topology: Covert switch block to if block
In reply to Viresh KumarWe only need to take care of one case here (CPUFREQ_NOTIFY) and there is no need to add an extra level of indentation to the case specific code by using a switch block. Use an if block instead.
Also add some blank lines to make the code look better.
--- drivers/base/arch_topology.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-)
drivers/base/arch_topology.c +22 -19
@@ -173,26 +173,29 @@ init_cpu_capacity_callback(struct notifier_block *nb,if (cap_parsing_failed)return 0 ; -switch (val) { -case CPUFREQ_NOTIFY : -pr_debug ("cpu_capacity: init cpu capacity for CPUs [%*pbl] (to_visit=%*pbl)\n" , -cpumask_pr_args (policy->related_cpus), -cpumask_pr_args (cpus_to_visit)); -cpumask_andnot (cpus_to_visit, cpus_to_visit, - policy->related_cpus); -for_each_cpu (cpu, policy->related_cpus) { - raw_capacity[cpu] =topology_get_cpu_scale (NULL , cpu) * - policy->cpuinfo.max_freq /1000UL ; - capacity_scale =max (raw_capacity[cpu], capacity_scale); - } -if (cpumask_empty (cpus_to_visit)) { -topology_normalize_cpu_scale (); -kfree (raw_capacity); -pr_debug ("cpu_capacity: parsing done\n" ); - cap_parsing_failed = true; -schedule_work (&parsing_done_work); - } +if (val !=CPUFREQ_NOTIFY ) +return 0 ; + +pr_debug ("cpu_capacity: init cpu capacity for CPUs [%*pbl] (to_visit=%*pbl)\n" , +cpumask_pr_args (policy->related_cpus), +cpumask_pr_args (cpus_to_visit)); + +cpumask_andnot (cpus_to_visit, cpus_to_visit, policy->related_cpus); + +for_each_cpu (cpu, policy->related_cpus) { + raw_capacity[cpu] =topology_get_cpu_scale (NULL , cpu) * + policy->cpuinfo.max_freq /1000UL ; + capacity_scale =max (raw_capacity[cpu], capacity_scale); } + +if (cpumask_empty (cpus_to_visit)) { +topology_normalize_cpu_scale (); +kfree (raw_capacity); +pr_debug ("cpu_capacity: parsing done\n" ); + cap_parsing_failed = true; +schedule_work (&parsing_done_work); + } +return 0 ; }
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
PATCH v2 4/5 arch_topology: Return 0 or -ve errors from topology_parse_cpu_capacity()
In reply to Viresh KumarUse the standard way of returning errors instead of returning 0(failure) OR 1(success) and making it hard to read.
--- arch/arm/kernel/topology.c | 2 +- drivers/base/arch_topology.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
arch/arm/kernel/topology.c +1 -1
@@ -111,7 +111,7 @@ static void __init parse_dt_topology(void)continue ; } -if (topology_parse_cpu_capacity (cn, cpu)) { +if (!topology_parse_cpu_capacity (cn, cpu)) {of_node_put (cn);continue ; }
drivers/base/arch_topology.c +4 -4
@@ -121,11 +121,11 @@ void topology_normalize_cpu_scale(void)int __init topology_parse_cpu_capacity (struct device_node *cpu_node,int cpu) { -int ret =1 ; +int ret;u32 cpu_capacity;if (cap_parsing_failed) -return !ret; +return -EINVAL ; ret =of_property_read_u32 (cpu_node,"capacity-dmips-mhz" , &cpu_capacity);
@@ -137,7 +137,7 @@ int __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)if (!raw_capacity) {pr_err ("cpu_capacity: failed to allocate memory for raw capacities\n" ); cap_parsing_failed = true; -return 0 ; +return -ENOMEM ; } } capacity_scale =max (cpu_capacity, capacity_scale);
@@ -154,7 +154,7 @@ int __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)kfree (raw_capacity); } -return !ret; +return ret; }#ifdef CONFIG_CPU_FREQ
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
PATCH v2 5/5 arch_topology: Localize cap_parsing_failed to topology_parse_cpu_capacity()
In reply to Viresh Kumarcap_parsing_failed is only required in topology_parse_cpu_capacity() to know if we have already tried to allocate raw_capacity and failed, or if at least one of the cpu_node didn't had the required "capacity-dmips-mhz" property.
All other users can use raw_capacity instead of cap_parsing_failed.
Make sure we set raw_capacity to NULL after we free it.
--- drivers/base/arch_topology.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
drivers/base/arch_topology.c +13 -12
@@ -95,14 +95,21 @@ subsys_initcall(register_cpu_capacity_sysctl);static u32 capacity_scale;static u32 *raw_capacity; -static bool cap_parsing_failed; + +static int __init free_raw_capacity (void ) +{ +kfree (raw_capacity); + raw_capacity =NULL ; + +return 0 ; +}void topology_normalize_cpu_scale (void ) {u64 capacity;int cpu; -if (!raw_capacity || cap_parsing_failed) +if (!raw_capacity)return ;pr_debug ("cpu_capacity: capacity_scale=%u\n" , capacity_scale);
@@ -121,6 +128,7 @@ void topology_normalize_cpu_scale(void)int __init topology_parse_cpu_capacity (struct device_node *cpu_node,int cpu) { +static bool cap_parsing_failed;int ret;u32 cpu_capacity;
@@ -151,7 +159,7 @@ int __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)pr_err ("cpu_capacity: partial information: fallback to 1024 for all CPUs\n" ); } cap_parsing_failed = true; -kfree (raw_capacity); +free_raw_capacity (); }return ret;
@@ -170,7 +178,7 @@ init_cpu_capacity_callback(struct notifier_block *nb,struct cpufreq_policy *policy = data;int cpu; -if (cap_parsing_failed) +if (!raw_capacity)return 0 ;if (val !=CPUFREQ_NOTIFY )
@@ -190,9 +198,8 @@ init_cpu_capacity_callback(struct notifier_block *nb,if (cpumask_empty (cpus_to_visit)) {topology_normalize_cpu_scale (); -kfree (raw_capacity); +free_raw_capacity ();pr_debug ("cpu_capacity: parsing done\n" ); - cap_parsing_failed = true;schedule_work (&parsing_done_work); }
@@ -232,11 +239,5 @@ static void parsing_done_workfn(struct work_struct *work) }#else -static int __init free_raw_capacity (void ) -{ -kfree (raw_capacity); - -return 0 ; -}core_initcall (free_raw_capacity);#endif
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
Re: [PATCH V2 4/5] arch_topology: Return 0 or -ve errors from topology_parse_cpu_capacity()
In reply to Viresh KumarHi,
Quoted 14 lines · Viresh Kumar
Use the standard way of returning errors instead of returning 0(failure) OR 1(success) and making it hard to read.
Signed-off-by Viresh Kumar <[email protected]>--- arch/arm/kernel/topology.c | 2 +- drivers/base/arch_topology.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)arch/arm/kernel/topology.c +0
-0
arch/arm/kernel/topology.c static void __init parse_dt_topology(void) · line 114
Quoted 5 lines
arch/arm/kernel/topology.c +1
-1@@ -111,7 +111,7 @@ static void __init parse_dt_topology(void)continue ; } -if (topology_parse_cpu_capacity (cn, cpu)) { +if (!topology_parse_cpu_capacity (cn, cpu)) {
Not sure why you want to change this.
I currently read it as "if cpu_capacity parsing succedeed" continue with next CPU, otherwise we set cap_from_dt to false and fall back to using efficiencies.
Thanks,
- Juri
Re: [PATCH V2 1/5] arch_topology: Get rid of "cap_parsing_done"
In reply to Viresh KumarHi,
Quoted 30 lines · Viresh Kumar
We can reuse "
cap_parsing_failed" instead of keeping an additional variable here.Signed-off-by Viresh Kumar <[email protected]>--- drivers/base/arch_topology.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/base/arch_topology.c +1
-2@@ -161,7 +161,6 @@ int __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)#ifdef CONFIG_CPU_FREQ static cpumask_var_t cpus_to_visit; -static bool cap_parsing_done;static void parsing_done_workfn (struct work_struct *work); static DECLARE_WORK(parsing_done_work, parsing_done_workfn);@@ -173,7 +172,7 @@ init_cpu_capacity_callback(struct notifier_block *nb,struct cpufreq_policy *policy = data;int cpu; -if (cap_parsing_failed || cap_parsing_done) +if (cap_parsing_failed)return 0 ;switch (val) {
drivers/base/arch_topology.c init_cpu_capacity_callback(struct notifier_block *nb, · line 195
Quoted 5 lines
drivers/base/arch_topology.c +1
-1@@ -193,7 +192,7 @@ init_cpu_capacity_callback(struct notifier_block *nb,topology_normalize_cpu_scale ();kfree (raw_capacity);pr_debug ("cpu_capacity: parsing done\n" ); - cap_parsing_done = true; + cap_parsing_failed = true;
But we didn't actually failed here, right?
Thanks,
- Juri
Re: [PATCH V2 4/5] arch_topology: Return 0 or -ve errors from topology_parse_cpu_capacity()
In reply to Juri LelliQuoted 20 lines · Juri Lelli
Hi,
Quoted 17 lines · Viresh Kumar
Use the standard way of returning errors instead of returning 0(failure) OR 1(success) and making it hard to read.
Signed-off-by Viresh Kumar <[email protected]>--- arch/arm/kernel/topology.c | 2 +- drivers/base/arch_topology.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)arch/arm/kernel/topology.c +0
-0@@ -111,7 +111,7 @@ static void __init parse_dt_topology(void)continue ; }
Quoted 4 lines
arch/arm/kernel/topology.c static void __init parse_dt_topology(void) · line 114
Quoted 2 lines
arch/arm/kernel/topology.c +1
-1-if (topology_parse_cpu_capacity (cn, cpu)) { +if (!topology_parse_cpu_capacity (cn, cpu)) {Not sure why you want to change this.
I just didn't find it straight forward to read.
Quoted 3 lines
I currently read it as "if
cpu_capacityparsing succedeed" continue with next CPU, otherwise we setcap_from_dtto false and fall back to using efficiencies.
Actually, I can just make the return type bool and that should solve the issues I was seeing and keep the code as it is.
Will that be fine ?
Signature · 1 line
viresh
Re: [PATCH V2 1/5] arch_topology: Get rid of "cap_parsing_done"
In reply to Juri LelliQuoted 31 lines · Juri Lelli
Hi,
Quoted 28 lines · Viresh Kumar
We can reuse "
cap_parsing_failed" instead of keeping an additional variable here.Signed-off-by Viresh Kumar <[email protected]>--- drivers/base/arch_topology.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/base/arch_topology.c +1
-2@@ -161,7 +161,6 @@ int __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)#ifdef CONFIG_CPU_FREQ static cpumask_var_t cpus_to_visit; -static bool cap_parsing_done;static void parsing_done_workfn (struct work_struct *work); static DECLARE_WORK(parsing_done_work, parsing_done_workfn);@@ -173,7 +172,7 @@ init_cpu_capacity_callback(struct notifier_block *nb,struct cpufreq_policy *policy = data;int cpu; -if (cap_parsing_failed || cap_parsing_done) +if (cap_parsing_failed)return 0 ;
Quoted 9 lines
drivers/base/arch_topology.c init_cpu_capacity_callback(struct notifier_block *nb, · line 195
Quoted 7 lines
drivers/base/arch_topology.c +1
-1switch (val) {@@ -193,7 +192,7 @@ init_cpu_capacity_callback(struct notifier_block *nb,topology_normalize_cpu_scale ();kfree (raw_capacity);pr_debug ("cpu_capacity: parsing done\n" ); - cap_parsing_done = true; + cap_parsing_failed = true;But we didn't actually failed here, right?
Yeah. So I can actually move this patch to the end of the series and cap_parsing_done can be dropped then as we will end up using !raw_capacity instead. And the end result will stay the same.
Signature · 1 line
viresh
Re: [PATCH V2 4/5] arch_topology: Return 0 or -ve errors from topology_parse_cpu_capacity()
In reply to Viresh KumarQuoted 28 lines · Viresh Kumar
Quoted 20 lines · Juri Lelli
Hi,
Quoted 17 lines · Viresh Kumar
Use the standard way of returning errors instead of returning 0(failure) OR 1(success) and making it hard to read.
Signed-off-by Viresh Kumar <[email protected]>--- arch/arm/kernel/topology.c | 2 +- drivers/base/arch_topology.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)arch/arm/kernel/topology.c +0
-0@@ -111,7 +111,7 @@ static void __init parse_dt_topology(void)continue ; }Quoted 4 lines
arch/arm/kernel/topology.c static void __init parse_dt_topology(void) · line 114
Quoted 2 lines
arch/arm/kernel/topology.c +1
-1-if (topology_parse_cpu_capacity (cn, cpu)) { +if (!topology_parse_cpu_capacity (cn, cpu)) {Not sure why you want to change this.
I just didn't find it straight forward to read.
Quoted 9 lines
Quoted 3 lines
I currently read it as "if
cpu_capacityparsing succedeed" continue with next CPU, otherwise we setcap_from_dtto false and fall back to using efficiencies.Actually, I can just make the return type bool and that should solve the issues I was seeing and keep the code as it is.
Will that be fine ?
Think so.
Re: [PATCH V2 1/5] arch_topology: Get rid of "cap_parsing_done"
In reply to Viresh KumarQuoted 42 lines · Viresh Kumar
Quoted 31 lines · Juri Lelli
Hi,
Quoted 28 lines · Viresh Kumar
We can reuse "
cap_parsing_failed" instead of keeping an additional variable here.Signed-off-by Viresh Kumar <[email protected]>--- drivers/base/arch_topology.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/base/arch_topology.c +1
-2@@ -161,7 +161,6 @@ int __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)#ifdef CONFIG_CPU_FREQ static cpumask_var_t cpus_to_visit; -static bool cap_parsing_done;static void parsing_done_workfn (struct work_struct *work); static DECLARE_WORK(parsing_done_work, parsing_done_workfn);@@ -173,7 +172,7 @@ init_cpu_capacity_callback(struct notifier_block *nb,struct cpufreq_policy *policy = data;int cpu; -if (cap_parsing_failed || cap_parsing_done) +if (cap_parsing_failed)return 0 ;Quoted 9 lines
drivers/base/arch_topology.c init_cpu_capacity_callback(struct notifier_block *nb, · line 195
Quoted 7 lines
drivers/base/arch_topology.c +1
-1switch (val) {@@ -193,7 +192,7 @@ init_cpu_capacity_callback(struct notifier_block *nb,topology_normalize_cpu_scale ();kfree (raw_capacity);pr_debug ("cpu_capacity: parsing done\n" ); - cap_parsing_done = true; + cap_parsing_failed = true;But we didn't actually failed here, right?
Quoted 4 lines
Yeah. So I can actually move this patch to the end of the series and
cap_parsing_donecan be dropped then as we will end up using !raw_capacity instead. And the end result will stay the same.
OK.