CPUFreq: Initialize CPU's OPP tables from core
Subsystems (6)
Viresh Kumar
maintainerPATCH 1/5 driver/core: cpu: initialize opp table
In reply to Viresh KumarAll drivers expecting CPU's OPPs from device tree initialize OPP table using of_init_opp_table() and there is nothing driver specific in that. They all do it in the same way adding to code redundancy.
It would be better if we can get rid of code redundancy by initializing CPU OPPs from core code for all CPUs that have a "operating-points" property defined in their node.
This patch initializes OPPs as soon as CPU device is registered in register_cpu().
--- drivers/base/cpu.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/base/cpu.c +12 -2
@@ -16,6 +16,7 @@#include <linux/acpi.h> #include <linux/of.h> #include <linux/cpufeature.h> +#include <linux/pm_opp.h> #include "base.h"
@@ -349,11 +350,20 @@ int register_cpu(struct cpu *cpu, int num)if (cpu->hotpluggable) cpu->dev.groups = hotplugable_cpu_attr_groups; error =device_register (&cpu->dev); -if (!error) +if (!error) {per_cpu (cpu_sys_devices, num) = &cpu->dev; -if (!error)register_cpu_under_node (num,cpu_to_node (num)); +/* Initialize CPUs OPP table */ +if (of_node_get (cpu->dev.of_node)) { + error =of_init_opp_table (&cpu->dev); +if (error && error != -ENODEV ) +pr_err ("****%s: failed to init OPP table for cpu%d, err: %d\n" , + __func__, num, error); +of_node_put (cpu->dev.of_node); + } + } +return error; }
Signature · 1 line
2.0.0.rc2
Viresh Kumar
maintainerPATCH 2/5 cpufreq: arm_big_little: don't initialize opp table
In reply to Viresh KumarOPP tables are already initialized for all CPUs by cpufreq core and so we don't need to reinitialize them from arm_big_little_dt driver.
Also, as the arm_big_little_dt driver doesn't have a .init_opp_table() callback anymore, make it optional in arm_big_little driver.
--- drivers/cpufreq/arm_big_little.c | 12 +++++++----- drivers/cpufreq/arm_big_little_dt.c | 18 ------------------ 2 files changed, 7 insertions(+), 23 deletions(-)
drivers/cpufreq/arm_big_little.c +7 -5
@@ -325,11 +325,13 @@ static int _get_cluster_clk_and_freq_table(struct device *cpu_dev)if (freq_table[cluster])return 0 ; - ret = arm_bL_ops->init_opp_table (cpu_dev); -if (ret) { -dev_err (cpu_dev,"%s: init_opp_table failed, cpu: %d, err: %d\n" , +if (arm_bL_ops->init_opp_table) { + ret = arm_bL_ops->init_opp_table (cpu_dev); +if (ret) { +dev_err (cpu_dev,"%s: init_opp_table failed, cpu: %d, err: %d\n" , __func__, cpu_dev->id, ret); - goto out; + goto out; + } } ret =dev_pm_opp_init_cpufreq_table (cpu_dev, &freq_table[cluster]);
@@ -542,7 +544,7 @@ int bL_cpufreq_register(struct cpufreq_arm_bL_ops *ops)return -EBUSY ; } -if (!ops || !strlen (ops->name) || !ops->init_opp_table) { +if (!ops || !strlen (ops->name)) {pr_err ("%s: Invalid arm_bL_ops, exiting\n" , __func__);return -ENODEV ; }
drivers/cpufreq/arm_big_little_dt.c +0 -18
@@ -43,23 +43,6 @@ static struct device_node *get_cpu_node_with_valid_op(int cpu)return np; } -static int dt_init_opp_table (struct device *cpu_dev) -{ -struct device_node *np; -int ret; - - np =of_node_get (cpu_dev->of_node); -if (!np) { -pr_err ("failed to find cpu%d node\n" , cpu_dev->id); -return -ENOENT ; - } - - ret =of_init_opp_table (cpu_dev); -of_node_put (np); - -return ret; -} -static int dt_get_transition_latency (struct device *cpu_dev) {struct device_node *np;
@@ -81,7 +64,6 @@ static int dt_get_transition_latency(struct device *cpu_dev)static struct cpufreq_arm_bL_ops dt_bL_ops = { .name ="dt-bl" , .get_transition_latency = dt_get_transition_latency, - .init_opp_table = dt_init_opp_table, };static int generic_bL_probe (struct platform_device *pdev)
Signature · 1 line
2.0.0.rc2
Viresh Kumar
maintainerPATCH 3/5 cpufreq: imx6q: don't initialize opp table
In reply to Viresh KumarOPP tables are already initialized for CPU0 by cpufreq core and so we don't need to reinitialize them from imx6q specific code.
--- arch/arm/mach-imx/mach-imx6q.c | 36 ++++++++---------------------------- drivers/cpufreq/imx6q-cpufreq.c | 20 +------------------- 2 files changed, 9 insertions(+), 47 deletions(-)
arch/arm/mach-imx/mach-imx6q.c +8 -28
@@ -290,12 +290,18 @@ static void __init imx6q_init_machine(void)#define OCOTP_CFG3_SPEED_996MHZ 0x2#define OCOTP_CFG3_SPEED_852MHZ 0x1 -static void __init imx6q_opp_check_speed_grading (struct device *cpu_dev) +static void __init imx6q_opp_check_speed_grading (void ) { +struct device *cpu_dev =get_cpu_device (0 );struct device_node *np;void __iomem *base;u32 val; +if (!cpu_dev) { +pr_warn ("failed to get cpu0 device\n" ); +return ; + } + np =of_find_compatible_node (NULL ,NULL ,"fsl,imx6q-ocotp" );if (!np) {pr_warn ("failed to find ocotp node\n" );
@@ -336,32 +342,6 @@ put_node:of_node_put (np); } -static void __init imx6q_opp_init (void ) -{ -struct device_node *np; -struct device *cpu_dev =get_cpu_device (0 ); - -if (!cpu_dev) { -pr_warn ("failed to get cpu0 device\n" ); -return ; - } - np =of_node_get (cpu_dev->of_node); -if (!np) { -pr_warn ("failed to find cpu0 node\n" ); -return ; - } - -if (of_init_opp_table (cpu_dev)) { -pr_warn ("failed to init OPP table\n" ); - goto put_node; - } - -imx6q_opp_check_speed_grading (cpu_dev); - -put_node: -of_node_put (np); -} -static struct platform_device imx6q_cpufreq_pdev = { .name ="imx6q-cpufreq" , };
@@ -376,7 +356,7 @@ static void __init imx6q_init_late(void)imx6q_cpuidle_init ();if (IS_ENABLED (CONFIG_ARM_IMX6Q_CPUFREQ )) { -imx6q_opp_init (); +imx6q_opp_check_speed_grading ();platform_device_register (&imx6q_cpufreq_pdev); } }
drivers/cpufreq/imx6q-cpufreq.c +1 -19
@@ -191,26 +191,8 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev) goto put_node; } -/* -* We expect an OPP table supplied by platform. -* Just, incase the platform did not supply the OPP -* table, it will try to get it. -*/ num =dev_pm_opp_get_opp_count (cpu_dev); -if (num <0 ) { - ret =of_init_opp_table (cpu_dev); -if (ret <0 ) { -dev_err (cpu_dev,"failed to init OPP table: %d\n" , ret); - goto put_node; - } - - num =dev_pm_opp_get_opp_count (cpu_dev); -if (num <0 ) { - ret = num; -dev_err (cpu_dev,"no OPP table is found: %d\n" , ret); - goto put_node; - } - } +WARN_ON (num <0 ); ret =dev_pm_opp_init_cpufreq_table (cpu_dev, &freq_table);if (ret) {
Signature · 1 line
2.0.0.rc2
Viresh Kumar
maintainerPATCH 4/5 cpufreq: cpufreq-cpu0: don't initialize opp table
In reply to Viresh KumarOPP tables are already initialized for CPU0 by cpufreq core and so we don't need to reinitialize them from cpufreq-cpu0 driver.
--- drivers/cpufreq/cpufreq-cpu0.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/cpufreq/cpufreq-cpu0.c +0 -6
@@ -152,12 +152,6 @@ static int cpu0_cpufreq_probe(struct platform_device *pdev) goto out_put_node; } - ret =of_init_opp_table (cpu_dev); -if (ret) { -pr_err ("failed to init OPP table: %d\n" , ret); - goto out_put_node; - } - ret =dev_pm_opp_init_cpufreq_table (cpu_dev, &freq_table);if (ret) {pr_err ("failed to init cpufreq table: %d\n" , ret);
Signature · 1 line
2.0.0.rc2
Viresh Kumar
maintainerPATCH 5/5 cpufreq: exynos5440: don't initialize opp table
In reply to Viresh KumarOPP tables are already initialized for CPU0 by cpufreq core and so we don't need to reinitialize them from exynos5440's driver.
--- drivers/cpufreq/exynos5440-cpufreq.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/cpufreq/exynos5440-cpufreq.c +0 -6
@@ -360,12 +360,6 @@ static int exynos_cpufreq_probe(struct platform_device *pdev) goto err_put_node; } - ret =of_init_opp_table (dvfs_info->dev); -if (ret) { -dev_err (dvfs_info->dev,"failed to init OPP table: %d\n" , ret); - goto err_put_node; - } - ret =dev_pm_opp_init_cpufreq_table (dvfs_info->dev, &dvfs_info->freq_table);if (ret) {
Signature · 1 line
2.0.0.rc2
Viresh Kumar
maintainercover CPUFreq: Initialize CPU's OPP tables from core
All drivers expecting CPU's OPPs from device tree initialize OPP table using of_init_opp_table() and there is nothing driver specific in that. They all do it in the same way adding to code redundancy.
It would be better if we can get rid of code redundancy by initializing CPU OPPs from core code for all CPUs that have a "operating-points" property defined in their node.
First patch initializes OPPs as soon as CPU device is registered in register_cpu(). Following patches get rid of these calls from individual drivers which are currently initializing OPPs.
The idea was initially discussed here: https://lkml.org/lkml/2014/5/17/123
Viresh Kumar (5):
driver/core: cpu: initialize opp table
cpufreq: arm_big_little: don't initialize opp table
cpufreq: imx6q: don't initialize opp table
cpufreq: cpufreq-cpu0: don't initialize opp table
cpufreq: exynos5440: don't initialize opp table
arch/arm/mach-imx/mach-imx6q.c | 36 ++++++++---------------------------- drivers/base/cpu.c | 14 ++++++++++++-- drivers/cpufreq/arm_big_little.c | 12 +++++++----- drivers/cpufreq/arm_big_little_dt.c | 18 ------------------ drivers/cpufreq/cpufreq-cpu0.c | 6 ------ drivers/cpufreq/exynos5440-cpufreq.c | 6 ------ drivers/cpufreq/imx6q-cpufreq.c | 20 +------------------- 7 files changed, 28 insertions(+), 84 deletions(-)
Signature · 1 line
2.0.0.rc2
Viresh Kumar
maintainerPATCH RESEND 1/1 driver/core: cpu: initialize opp table
In reply to Viresh KumarAll drivers expecting CPU's OPPs from device tree initialize OPP table using of_init_opp_table() and there is nothing driver specific in that. They all do it in the same way adding to code redundancy.
It would be better if we can get rid of code redundancy by initializing CPU OPPs from core code for all CPUs that have a "operating-points" property defined in their node.
This patch initializes OPPs as soon as CPU device is registered in register_cpu().
---
V1-V2:
A colleague spotted some extra debug prints in my first mail :(
Replace
+ pr_err("****%s: failed to init OPP table for cpu%d, err: %d\n", with
+ pr_err("%s: failed to init OPP table for cpu%d, err: %d\n",
drivers/base/cpu.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/base/cpu.c +12 -2
@@ -16,6 +16,7 @@#include <linux/acpi.h> #include <linux/of.h> #include <linux/cpufeature.h> +#include <linux/pm_opp.h> #include "base.h"
@@ -349,11 +350,20 @@ int register_cpu(struct cpu *cpu, int num)if (cpu->hotpluggable) cpu->dev.groups = hotplugable_cpu_attr_groups; error =device_register (&cpu->dev); -if (!error) +if (!error) {per_cpu (cpu_sys_devices, num) = &cpu->dev; -if (!error)register_cpu_under_node (num,cpu_to_node (num)); +/* Initialize CPUs OPP table */ +if (of_node_get (cpu->dev.of_node)) { + error =of_init_opp_table (&cpu->dev); +if (error && error != -ENODEV ) +pr_err ("%s: failed to init OPP table for cpu%d, err: %d\n" , + __func__, num, error); +of_node_put (cpu->dev.of_node); + } + } +return error; }
Signature · 1 line
2.0.0.rc2
Re: [PATCH Resend] driver/core: cpu: initialize opp table
Quoted 42 lines · Viresh Kumar
All drivers expecting CPU's OPPs from device tree initialize OPP table using
of_init_opp_table()and there is nothing driver specific in that. They all do it in the same way adding to code redundancy.It would be better if we can get rid of code redundancy by initializing CPU OPPs from core code for all CPUs that have a "operating-points" property defined in their node.
This patch initializes OPPs as soon as CPU device is registered in
register_cpu().Cc Greg Kroah-Hartman <[email protected]>Cc Amit Daniel Kachhap <[email protected]>Cc Kukjin Kim <[email protected]>Cc Shawn Guo <[email protected]>Cc Sudeep Holla <[email protected]>Signed-off-by Viresh Kumar <[email protected]>---
V1-V2:
A colleague spotted some extra debug prints in my first mail :(Replace
+ pr_err("****%s: failed to init OPP table for cpu%d, err: %d\n", with
+ pr_err("%s: failed to init OPP table for cpu%d, err: %d\n",drivers/base/cpu.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/base/cpu.c +1
-0@@ -16,6 +16,7 @@#include <linux/acpi.h> #include <linux/of.h> #include <linux/cpufeature.h> +#include <linux/pm_opp.h> #include "base.h"
drivers/base/cpu.c int register_cpu(struct cpu *cpu, int num) · line 352
Quoted 4 lines
drivers/base/cpu.c +0
-1@@ -349,11 +350,20 @@ int register_cpu(struct cpu *cpu, int num)if (cpu->hotpluggable) cpu->dev.groups = hotplugable_cpu_attr_groups; error =device_register (&cpu->dev); -if (!error)
What about
if (error) return error;
and then you'd save an indentation level?
Anyway, I find adding of_node* stuff directly to the driver core this way kind of disgusting as there still are platforms that don't use it.
Can we have a call to a function that will change into an empty stub on such platforms here, please?
Quoted 19 lines
drivers/base/cpu.c +11
-1+if (!error) {per_cpu (cpu_sys_devices, num) = &cpu->dev; -if (!error)register_cpu_under_node (num,cpu_to_node (num)); +/* Initialize CPUs OPP table */ +if (of_node_get (cpu->dev.of_node)) { + error =of_init_opp_table (&cpu->dev); +if (error && error != -ENODEV ) +pr_err ("%s: failed to init OPP table for cpu%d, err: %d\n" , + __func__, num, error); +of_node_put (cpu->dev.of_node); + } + } +return error; }
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: [PATCH Resend] driver/core: cpu: initialize opp table
Quoted 12 lines · Rafael J. Wysocki
Quoted 11 lines · Viresh Kumar
All drivers expecting CPU's OPPs from device tree initialize OPP table using
of_init_opp_table()and there is nothing driver specific in that. They all do it in the same way adding to code redundancy.It would be better if we can get rid of code redundancy by initializing CPU OPPs from core code for all CPUs that have a "operating-points" property defined in their node.
This patch initializes OPPs as soon as CPU device is registered in
register_cpu().
Quoted 6 lines
Quoted 6 lines
Cc Greg Kroah-Hartman <[email protected]>Cc Amit Daniel Kachhap <[email protected]>Cc Kukjin Kim <[email protected]>Cc Shawn Guo <[email protected]>Cc Sudeep Holla <[email protected]>Signed-off-by Viresh Kumar <[email protected]>
Do patches [2-5/5] depend on this one BTW?
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Viresh Kumar
maintainerRe: [PATCH Resend] driver/core: cpu: initialize opp table
In reply to Rafael J. WysockiQuoted 6 lines · Rafael J. Wysocki
What about
if (error) return error;and then you'd save an indentation level?
Yes.
Quoted 5 lines
Anyway, I find adding of_node* stuff directly to the driver core this way kind of disgusting as there still are platforms that don't use it.
Can we have a call to a function that will change into an empty stub on such platforms here, please?
Okay. But can you explain a bit more about how and where those stubs would be implemented?
Viresh Kumar
maintainerRe: [PATCH Resend] driver/core: cpu: initialize opp table
In reply to Rafael J. WysockiQuoted 1 line · Rafael J. Wysocki
Do patches [2-5/5] depend on this one BTW?
Yes.
Quoted 1 line · Viresh Kumar
Viresh Kumar (5):
...
Quoted 2 lines
cpufreq: imx6q: don't initialize opp table
cpufreq: cpufreq-cpu0: don't initialize opp table
Re: [PATCH Resend] driver/core: cpu: initialize opp table
In reply to Viresh KumarQuoted 11 lines · Viresh Kumar
All drivers expecting CPU's OPPs from device tree initialize OPP table using
of_init_opp_table()and there is nothing driver specific in that. They all do it in the same way adding to code redundancy.It would be better if we can get rid of code redundancy by initializing CPU OPPs from core code for all CPUs that have a "operating-points" property defined in their node.
This patch initializes OPPs as soon as CPU device is registered in
register_cpu().
This is really nice getting rid of all duplicate code.
Quoted 34 lines
Cc Greg Kroah-Hartman <[email protected]>Cc Amit Daniel Kachhap <[email protected]>Cc Kukjin Kim <[email protected]>Cc Shawn Guo <[email protected]>Cc Sudeep Holla <[email protected]>Signed-off-by Viresh Kumar <[email protected]>---
V1-V2:
A colleague spotted some extra debug prints in my first mail :(Replace
+ pr_err("****%s: failed to init OPP table for cpu%d, err: %d\n", with
+ pr_err("%s: failed to init OPP table for cpu%d, err: %d\n",drivers/base/cpu.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/base/cpu.c +1
-0@@ -16,6 +16,7 @@#include <linux/acpi.h> #include <linux/of.h> #include <linux/cpufeature.h> +#include <linux/pm_opp.h> #include "base.h" @@ -349,11 +350,20 @@ int register_cpu(struct cpu *cpu, int num)if (cpu->hotpluggable) cpu->dev.groups = hotplugable_cpu_attr_groups; error =device_register (&cpu->dev);
drivers/base/cpu.c int register_cpu(struct cpu *cpu, int num) · line 360
Quoted 10 lines
drivers/base/cpu.c +5
-2-if (!error) +if (!error) {per_cpu (cpu_sys_devices, num) = &cpu->dev; -if (!error)register_cpu_under_node (num,cpu_to_node (num)); +/* Initialize CPUs OPP table */ +if (of_node_get (cpu->dev.of_node)) { + error =of_init_opp_table (&cpu->dev); +if (error && error != -ENODEV )
As Rafael mentioned it's better to have a wrapper function to hide these details. You should consider the fact that of_init_opp_table returns -EINVAL if CONFIG_PM_OPP not defined as well as when the list is invalid in the DT. IMO we can return -ENOSYS if not implemented(i.e. !CONFIG_PM_OPP)
drivers/base/cpu.c int register_cpu(struct cpu *cpu, int num) · line 369
Quoted 9 lines
drivers/base/cpu.c +6
-0+pr_err ("%s: failed to init OPP table for cpu%d, err: %d\n" , + __func__, num, error); +of_node_put (cpu->dev.of_node); + } + } +return error; }
Regards,
Sudeep
Viresh Kumar
maintainerRe: [PATCH Resend] driver/core: cpu: initialize opp table
Quoted 5 lines · Sudeep Holla
As Rafael mentioned it's better to have a wrapper function to hide these details. You should consider the fact that
of_init_opp_tablereturns-EINVALifCONFIG_PM_OPPnot defined as well as when the list is invalid in the DT. IMO we can return-ENOSYSif not implemented(i.e. !CONFIG_PM_OPP)
I didn't understood Rafael's comment as I couldn't figure out if he is just pointing to CONFIG_** or some arch specific thing..
But it looks more obvious that he asked me something similar to what you are saying :)
Why do we need to return anything? Let that function have return type 'void'? Also would it make sense to move this into it as well?
cpu->dev.of_node = of_get_cpu_node(num, NULL);
Re: [PATCH Resend] driver/core: cpu: initialize opp table
Quoted 7 lines · Viresh Kumar
Quoted 5 lines · Sudeep Holla
As Rafael mentioned it's better to have a wrapper function to hide these details. You should consider the fact that
of_init_opp_tablereturns-EINVALifCONFIG_PM_OPPnot defined as well as when the list is invalid in the DT. IMO we can return-ENOSYSif not implemented(i.e. !CONFIG_PM_OPP)
Quoted 6 lines
I didn't understood Rafael's comment as I couldn't figure out if he is just pointing to CONFIG_** or some arch specific thing..
But it looks more obvious that he asked me something similar to what you are saying :)
I believe so, mainly the non-DT case, since you are checking for error, it will end up with spurious messages as the return value is -EINVAL. Hence I was suggesting return -ENOSYS(which means Function not implemented)
Quoted 1 line
Why do we need to return anything? Let that function have return type 'void'?
Hmm, don't we still need to throw error if DT has invalid OPP ? It doesn't may sense to me if no errors is returned and still CPUFreq fails later.
Quoted 4 lines
Also would it make sense to move this into it as well?
cpu->dev.of_node=of_get_cpu_node(num, NULL);
I don't quite understand what you mean here ?
Regards,
Sudeep
Viresh Kumar
maintainerRe: [PATCH Resend] driver/core: cpu: initialize opp table
Quoted 7 lines · Sudeep Holla
Quoted 2 lines
Why do we need to return anything? Let that function have return type 'void'?
Hmm, don't we still need to throw error if DT has invalid OPP ? It doesn't may sense to me if no errors is returned and still CPUFreq fails later.
I wasn't sure if we should fail CPU's registration if it had bad OPPs. Maybe just print a good message and go ahead. CPU is usable atleast :)
Quoted 6 lines
Quoted 4 lines
Also would it make sense to move this into it as well?
cpu->dev.of_node=of_get_cpu_node(num, NULL);I don't quite understand what you mean here ?
This piece of code was added by you earlier to register_cpu(). As this was also DT specific, should I move this as well to the new routine we are creating?
Re: [PATCH Resend] driver/core: cpu: initialize opp table
In reply to Viresh KumarQuoted 10 lines · Viresh Kumar
Quoted 6 lines · Rafael J. Wysocki
What about
if (error) return error;and then you'd save an indentation level?
Yes.
Quoted 8 lines
Quoted 5 lines
Anyway, I find adding of_node* stuff directly to the driver core this way kind of disgusting as there still are platforms that don't use it.
Can we have a call to a function that will change into an empty stub on such platforms here, please?
Okay. But can you explain a bit more about how and where those stubs would be implemented?
In a header file included by cpu.c. Something like
#if defined(CONFIG_OF) && defined(CONFIG_PM_OPP)
<function header>
#else
static inline <stub>
#endif
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Viresh Kumar
maintainerRe: [PATCH Resend] driver/core: cpu: initialize opp table
Quoted 7 lines · Rafael J. Wysocki
In a header file included by
cpu.c. Something like#if
defined(CONFIG_OF)&&defined(CONFIG_PM_OPP)
<function header>
#else
static inline <stub>
#endif
Thanks, Sudeep already helped me in understanding that :) .. Already implemented that in cpu.c only ..