PM / OPP: move cpufreq specific OPP functions out of generic OPP library
Subsystems (9)
Nishanth Menon
maintainerRFC PATCH 1/1 PM / OPP: move cpufreq specific OPP functions out of generic OPP library
CPUFREQ specific functions for OPP (Operating Performance Points) can be isolated to just cpufreq. This allows for independent modifications as needed. The functionality desired by cpufreq can easily be provided by existing functions and any future "special handling" needed for cpufreq drivers can similarly be handled.
With this change the internal storage order of OPP entries are no longer a limiting factor for how we need cpufreq table to look like.
---
patch based on v3.15-rc1 tag.
Test log: OMAP5uEVM: http://slexy.org/view/s20WzLXI7K
drivers/base/power/opp.c | 91 ---------------------------- drivers/cpufreq/Kconfig | 5 ++ drivers/cpufreq/Makefile | 2 + drivers/cpufreq/arm_big_little.c | 2 +- drivers/cpufreq/arm_big_little_dt.c | 2 +- drivers/cpufreq/cpufreq-cpu0.c | 3 +- drivers/cpufreq/cpufreq_opp.c | 102 ++++++++++++++++++++++++++++++++ drivers/cpufreq/cpufreq_opp.h | 39 ++++++++++++ drivers/cpufreq/exynos5440-cpufreq.c | 3 +- drivers/cpufreq/imx6q-cpufreq.c | 3 +- drivers/cpufreq/omap-cpufreq.c | 3 +- drivers/cpufreq/vexpress-spc-cpufreq.c | 2 +- include/linux/pm_opp.h | 20 ------- 13 files changed, 159 insertions(+), 118 deletions(-) create mode 100644 drivers/cpufreq/cpufreq_opp.c create mode 100644 drivers/cpufreq/cpufreq_opp.h
drivers/base/power/opp.c +0 -91
@@ -15,7 +15,6 @@#include <linux/errno.h> #include <linux/err.h> #include <linux/slab.h> -#include <linux/cpufreq.h> #include <linux/device.h> #include <linux/list.h> #include <linux/rculist.h>
@@ -596,96 +595,6 @@ int dev_pm_opp_disable(struct device *dev, unsigned long freq) }EXPORT_SYMBOL_GPL (dev_pm_opp_disable); -#ifdef CONFIG_CPU_FREQ -/** -* dev_pm_opp_init_cpufreq_table() - create a cpufreq table for a device -* @dev: device for which we do this operation -* @table: Cpufreq table returned back to caller -* -* Generate a cpufreq table for a provided device- this assumes that the -* opp list is already initialized and ready for usage. -* -* This function allocates required memory for the cpufreq table. It is -* expected that the caller does the required maintenance such as freeing -* the table as required. -* -* Returns -EINVAL for bad pointers, -ENODEV if the device is not found, -ENOMEM -* if no memory available for the operation (table is not populated), returns 0 -* if successful and table is populated. -* -* WARNING: It is important for the callers to ensure refreshing their copy of -* the table if any of the mentioned functions have been invoked in the interim. -* -* Locking: The internal device_opp and opp structures are RCU protected. -* To simplify the logic, we pretend we are updater and hold relevant mutex here -* Callers should ensure that this function is *NOT* called under RCU protection -* or in contexts where mutex locking cannot be used. -*/ -int dev_pm_opp_init_cpufreq_table (struct device *dev, -struct cpufreq_frequency_table **table) -{ -struct device_opp *dev_opp; -struct dev_pm_opp *opp; -struct cpufreq_frequency_table *freq_table; -int i =0 ; - -/* Pretend as if I am an updater */ -mutex_lock (&dev_opp_list_lock); - - dev_opp =find_device_opp (dev); -if (IS_ERR (dev_opp)) { -int r =PTR_ERR (dev_opp); -mutex_unlock (&dev_opp_list_lock); -dev_err (dev,"%s: Device OPP not found (%d)\n" , __func__, r); -return r; - } - - freq_table =kzalloc (sizeof (struct cpufreq_frequency_table ) * - (dev_pm_opp_get_opp_count (dev) +1 ),GFP_KERNEL ); -if (!freq_table) { -mutex_unlock (&dev_opp_list_lock); -dev_warn (dev,"%s: Unable to allocate frequency table\n" , - __func__); -return -ENOMEM ; - } - -list_for_each_entry (opp, &dev_opp->opp_list, node) { -if (opp->available) { - freq_table[i].driver_data = i; - freq_table[i].frequency = opp->rate /1000 ; - i++; - } - } -mutex_unlock (&dev_opp_list_lock); - - freq_table[i].driver_data = i; - freq_table[i].frequency =CPUFREQ_TABLE_END ; - - *table = &freq_table[0 ]; - -return 0 ; -} -EXPORT_SYMBOL_GPL (dev_pm_opp_init_cpufreq_table); - -/** -* dev_pm_opp_free_cpufreq_table() - free the cpufreq table -* @dev: device for which we do this operation -* @table: table to free -* -* Free up the table allocated by dev_pm_opp_init_cpufreq_table -*/ -void dev_pm_opp_free_cpufreq_table (struct device *dev, -struct cpufreq_frequency_table **table) -{ -if (!table) -return ; - -kfree (*table); - *table =NULL ; -} -EXPORT_SYMBOL_GPL (dev_pm_opp_free_cpufreq_table); -#endif /* CONFIG_CPU_FREQ */ -/** * dev_pm_opp_get_notifier() - find notifier_head of the device with opp * @dev: device pointer used to lookup device OPPs.
drivers/cpufreq/Kconfig +5 -0
@@ -17,6 +17,11 @@ config CPU_FREQ if CPU_FREQ +config CPU_FREQ_PM_OPP + bool + depends on PM_OPP + default y + config CPU_FREQ_GOV_COMMON bool
drivers/cpufreq/Makefile +2 -0
@@ -1,5 +1,7 @@ # CPUfreq core obj-$(CONFIG_CPU_FREQ) += cpufreq.o freq_table.o +obj-$(CONFIG_CPU_FREQ_PM_OPP) += cpufreq_opp.o + # CPUfreq stats obj-$(CONFIG_CPU_FREQ_STAT) += cpufreq_stats.o
drivers/cpufreq/arm_big_little.c +1 -1
@@ -26,13 +26,13 @@#include <linux/export.h> #include <linux/mutex.h> #include <linux/of_platform.h> -#include <linux/pm_opp.h> #include <linux/slab.h> #include <linux/topology.h> #include <linux/types.h> #include <asm/bL_switcher.h> #include "arm_big_little.h" +#include "cpufreq_opp.h" /* Currently we support only two clusters */ #define A15_CLUSTER 0
drivers/cpufreq/arm_big_little_dt.c +1 -1
@@ -24,11 +24,11 @@#include <linux/export.h> #include <linux/module.h> #include <linux/of_device.h> -#include <linux/pm_opp.h> #include <linux/platform_device.h> #include <linux/slab.h> #include <linux/types.h> #include "arm_big_little.h" +#include "cpufreq_opp.h" /* get cpu node with valid operating-points */ static struct device_node *get_cpu_node_with_valid_op (int cpu)
drivers/cpufreq/cpufreq-cpu0.c +2 -1
@@ -19,12 +19,13 @@#include <linux/err.h> #include <linux/module.h> #include <linux/of.h> -#include <linux/pm_opp.h> #include <linux/platform_device.h> #include <linux/regulator/consumer.h> #include <linux/slab.h> #include <linux/thermal.h> +#include "cpufreq_opp.h" +static unsigned int transition_latency;static unsigned int voltage_tolerance;/* in percentage */
drivers/cpufreq/cpufreq_opp.c new file +102 -0
102 lines not on this page · raw message
drivers/cpufreq/cpufreq_opp.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Generic OPP Interface for CPUFREQ drivers +* +* Copyright (C) 2009-2014 Texas Instruments Incorporated. +* Nishanth Menon +* Romit Dasgupta +* Kevin Hilman +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ +#ifndef __CPUFREQ_OPP_H__ +#define __CPUFREQ_OPP_H__ + +#include <linux/cpufreq.h> +#include <linux/pm_opp.h> + +#if defined(CONFIG_CPU_FREQ ) && defined(CONFIG_PM_OPP ) +int dev_pm_opp_init_cpufreq_table (struct device *dev, +struct cpufreq_frequency_table **table); +void dev_pm_opp_free_cpufreq_table (struct device *dev, +struct cpufreq_frequency_table **table); +#else +static inline int dev_pm_opp_init_cpufreq_table (struct device *dev, +struct cpufreq_frequency_table + **table) +{ +return -EINVAL ; +} + +static inline void dev_pm_opp_free_cpufreq_table (struct device *dev, +struct cpufreq_frequency_table + **table) +{ +} +#endif /* CONFIG_CPU_FREQ */ + +#endif /* __CPUFREQ_OPP_H__ */
drivers/cpufreq/exynos5440-cpufreq.c +2 -1
@@ -20,10 +20,11 @@#include <linux/module.h> #include <linux/of_address.h> #include <linux/of_irq.h> -#include <linux/pm_opp.h> #include <linux/platform_device.h> #include <linux/slab.h> +#include "cpufreq_opp.h" +/* Register definitions */ #define XMU_DVFS_CTRL 0x0060#define XMU_PMU_P0_7 0x0064
drivers/cpufreq/imx6q-cpufreq.c +2 -1
@@ -13,10 +13,11 @@#include <linux/err.h> #include <linux/module.h> #include <linux/of.h> -#include <linux/pm_opp.h> #include <linux/platform_device.h> #include <linux/regulator/consumer.h> +#include "cpufreq_opp.h" +#define PU_SOC_VOLTAGE_NORMAL 1250000#define PU_SOC_VOLTAGE_HIGH 1275000#define FREQ_1P2_GHZ 1200000000
drivers/cpufreq/omap-cpufreq.c +2 -1
@@ -22,7 +22,6 @@#include <linux/err.h> #include <linux/clk.h> #include <linux/io.h> -#include <linux/pm_opp.h> #include <linux/cpu.h> #include <linux/module.h> #include <linux/platform_device.h>
@@ -31,6 +30,8 @@#include <asm/smp_plat.h> #include <asm/cpu.h> +#include "cpufreq_opp.h" +/* OPP tolerance in percentage */ #define OPP_TOLERANCE 4
drivers/cpufreq/vexpress-spc-cpufreq.c +1 -1
@@ -21,10 +21,10 @@#include <linux/cpufreq.h> #include <linux/module.h> #include <linux/platform_device.h> -#include <linux/pm_opp.h> #include <linux/types.h> #include "arm_big_little.h" +#include "cpufreq_opp.h" static int ve_spc_init_opp_table (struct device *cpu_dev) {
include/linux/pm_opp.h +0 -20
@@ -15,7 +15,6 @@#define __LINUX_OPP_H__#include <linux/err.h> -#include <linux/cpufreq.h> #include <linux/notifier.h> struct dev_pm_opp ;
@@ -117,23 +116,4 @@ static inline int of_init_opp_table(struct device *dev) }#endif -#if defined(CONFIG_CPU_FREQ ) && defined(CONFIG_PM_OPP ) -int dev_pm_opp_init_cpufreq_table (struct device *dev, -struct cpufreq_frequency_table **table); -void dev_pm_opp_free_cpufreq_table (struct device *dev, -struct cpufreq_frequency_table **table); -#else -static inline int dev_pm_opp_init_cpufreq_table (struct device *dev, -struct cpufreq_frequency_table **table) -{ -return -EINVAL ; -} - -static inline -void dev_pm_opp_free_cpufreq_table (struct device *dev, -struct cpufreq_frequency_table **table) -{ -} -#endif /* CONFIG_CPU_FREQ */ -#endif /* __LINUX_OPP_H__ */
Signature · 1 line
1.7.9.5
Viresh Kumar
maintainerdrivers/cpufreq/Kconfig config CPU_FREQ · line 24
Quoted 13 lines · Nishanth Menon
drivers/cpufreq/Kconfig +5
-0@@ -17,6 +17,11 @@ config CPU_FREQ if CPU_FREQ +config CPU_FREQ_PM_OPP + bool + depends on PM_OPP + default y +
Don't need this
drivers/cpufreq/Makefile line 3
Quoted 11 lines
drivers/cpufreq/Kconfig +0
-0config CPU_FREQ_GOV_COMMON booldrivers/cpufreq/Makefile +1
-0@@ -1,5 +1,7 @@ # CPUfreq core obj-$(CONFIG_CPU_FREQ) += cpufreq.o freq_table.o +obj-$(CONFIG_CPU_FREQ_PM_OPP) += cpufreq_opp.o
Just use: obj-$(CONFIG_PM_OPP)
Quoted 13 lines
drivers/cpufreq/Makefile +1
-0+ # CPUfreq stats obj-$(CONFIG_CPU_FREQ_STAT) += cpufreq_stats.odrivers/cpufreq/cpufreq_opp.c new file +2
-0@@ -0,0 +1,102 @@ +/* +* Generic OPP Interface for CPUFREQ drivers
drivers/cpufreq/cpufreq_opp.c line 12
Quoted 10 lines
drivers/cpufreq/cpufreq_opp.c new file +10
-0+* +* Copyright (C) 2009-2014 Texas Instruments Incorporated. +* Nishanth Menon +* Romit Dasgupta +* Kevin Hilman +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/
I hope you have just copy pasted routines to this file, and haven't done even the most minor modification in those, as its hard to review it.
drivers/cpufreq/cpufreq_opp.c line 14
Quoted 1 line
drivers/cpufreq/cpufreq_opp.c new file +1
-0+#include <linux/slab.h>
Sure? That's it, nothing else required to compile this file independently? As a rule include all the files directly which might be required for compilation of this file and don't expect them to be included by some other header files indirectly.
drivers/cpufreq/cpufreq_opp.h
Quoted 1 line
drivers/cpufreq/cpufreq_opp.h +0
-0
Two problems, driver may lie in arch/ as well, though we don't recommend them, secondly move these in cpufreq.h, don't need a header here for sure.
Nishanth Menon
maintainerQuoted 9 lines · Viresh Kumar
Quoted 8 lines · Nishanth Menon
drivers/cpufreq/Kconfig +0
-0@@ -17,6 +17,11 @@ config CPU_FREQ if CPU_FREQ
Quoted 7 lines
drivers/cpufreq/Kconfig config CPU_FREQ · line 24
Quoted 5 lines
drivers/cpufreq/Kconfig +5
-0+config CPU_FREQ_PM_OPP + bool + depends on PM_OPP + default y +Don't need this
ok.
Quoted 4 lines
Quoted 4 lines
drivers/cpufreq/Kconfig +0
-0config CPU_FREQ_GOV_COMMON bool
Quoted 10 lines
drivers/cpufreq/Makefile line 3
Quoted 8 lines
drivers/cpufreq/Makefile +1
-0@@ -1,5 +1,7 @@ # CPUfreq core obj-$(CONFIG_CPU_FREQ) += cpufreq.o freq_table.o +obj-$(CONFIG_CPU_FREQ_PM_OPP) += cpufreq_opp.oJust use: obj-$(CONFIG_PM_OPP)
ok.
Quoted 19 lines
Quoted 19 lines
drivers/cpufreq/Makefile +1
-0+ # CPUfreq stats obj-$(CONFIG_CPU_FREQ_STAT) += cpufreq_stats.odrivers/cpufreq/cpufreq_opp.c new file +7
-0@@ -0,0 +1,102 @@ +/* +* Generic OPP Interface for CPUFREQ drivers +* +* Copyright (C) 2009-2014 Texas Instruments Incorporated. +* Nishanth Menon +* Romit Dasgupta +* Kevin Hilman
Quoted 8 lines
drivers/cpufreq/cpufreq_opp.c line 12
Quoted 5 lines
drivers/cpufreq/cpufreq_opp.c new file +5
-0+* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ I hope you have just copy pasted routines to this file, and haven't done even the most minor modification in those, as its hard to review it.
there is code replacement ofcourse ->
* the logic of walking down the list holding a mutex has been replaced with rcu locks,
* instead of reading internal data structure and generating the list, use the existing search API that does exactly the same.
* Documentation update for the same.
Both are needed if you have to move the code out. functionally, both are equivalent
Quoted 7 lines
drivers/cpufreq/cpufreq_opp.c line 14
Quoted 2 lines
drivers/cpufreq/cpufreq_opp.c new file +1
-0+#include <linux/slab.h> Sure? That's it, nothing else required to compile this file independently? As a rule include all the files directly which might be required for compilation of this file and don't expect them to be included by some other header files indirectly.
Alrite. will do, I try to trim the headers down to bare minimum, but will take care of it in the formal post.
Quoted 5 lines
drivers/cpufreq/cpufreq_opp.h
Quoted 2 lines
drivers/cpufreq/cpufreq_opp.h +0
-0Two problems, driver may lie in
arch/as well, though we don't recommend them, secondly move these incpufreq.h, don't need a header here for sure.
There are none at the moment. ideally, we'd like to discourage folks putting cpufreq drivers in arch/ given the amount of effort you have undertaken in bringing them all here. but I have personally no strong objection to getting rid of the private header and using the generic cpufreq header.
Otherwise, I assume you are ok with this approach and will post a formal patch by monday.
Regards,
Nishanth Menon
Viresh Kumar
maintainerQuoted 23 lines · Nishanth Menon
Quoted 13 lines · Viresh Kumar
Quoted 13 lines
drivers/cpufreq/cpufreq_opp.c new file +7
-0@@ -0,0 +1,102 @@ +/* +* Generic OPP Interface for CPUFREQ drivers +* +* Copyright (C) 2009-2014 Texas Instruments Incorporated. +* Nishanth Menon +* Romit Dasgupta +* Kevin Hilman Quoted 8 lines
drivers/cpufreq/cpufreq_opp.c line 12
Quoted 5 lines
drivers/cpufreq/cpufreq_opp.c new file +5
-0+* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ I hope you have just copy pasted routines to this file, and haven't done even the most minor modification in those, as its hard to review it.
Quoted 6 lines
there is code replacement ofcourse ->
* the logic of walking down the list holding a mutex has been replaced with rcu locks,
* instead of reading internal data structure and generating the list, use the existing search API that does exactly the same.
* Documentation update for the same.
Hmm, actually if I would have written this patch, then probably I would have done the same thing, but looking from the reviewers perspective, it would be much more easy if we can separate things into patches.
So, maybe do these changes first in opp.c only and then finally a patch that just moves things around.
Quoted 2 lines
Both are needed if you have to move the code out. functionally, both are equivalent
That's an assumption and we never know when we might have screwed the code :) .. And so more careful review of those parts is required :)
Quoted 6 lines
Quoted 4 lines
drivers/cpufreq/cpufreq_opp.h
Quoted 1 line
drivers/cpufreq/cpufreq_opp.h +0
-0Two problems, driver may lie in
arch/as well, though we don't recommend them, secondly move these incpufreq.h, don't need a header here for sure.There are none at the moment. ideally, we'd like to discourage folks
Yes, we do. :)
Quoted 7 lines
putting cpufreq drivers in
arch/given the amount of effort you have undertaken in bringing them all here. but I have personally no strong objection to getting rid of the private header and using the generic cpufreq header.Otherwise, I assume you are ok with this approach and will post a formal patch by monday.
Yep.
Nishanth Menon
maintainerQuoted 35 lines · Viresh Kumar
Quoted 23 lines · Nishanth Menon
Quoted 13 lines · Viresh Kumar
Quoted 13 lines
drivers/cpufreq/cpufreq_opp.c new file +7
-0@@ -0,0 +1,102 @@ +/* +* Generic OPP Interface for CPUFREQ drivers +* +* Copyright (C) 2009-2014 Texas Instruments Incorporated. +* Nishanth Menon +* Romit Dasgupta +* Kevin Hilman Quoted 8 lines
drivers/cpufreq/cpufreq_opp.c line 12
Quoted 5 lines
drivers/cpufreq/cpufreq_opp.c new file +5
-0+* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ I hope you have just copy pasted routines to this file, and haven't done even the most minor modification in those, as its hard to review it.
Quoted 6 lines
there is code replacement ofcourse ->
* the logic of walking down the list holding a mutex has been replaced with rcu locks,
* instead of reading internal data structure and generating the list, use the existing search API that does exactly the same.
* Documentation update for the same.Hmm, actually if I would have written this patch, then probably I would have done the same thing, but looking from the reviewers perspective, it would be much more easy if we can separate things into patches.
Quoted 8 lines
So, maybe do these changes first in
opp.conly and then finally a patch that just moves things around.Quoted 2 lines
Both are needed if you have to move the code out. functionally, both are equivalent
That's an assumption and we never know when we might have screwed the code :) .. And so more careful review of those parts is required :)
True. Will do the same as suggested for the formal series. Thanks for your feedback and review.
Regards,
Nishanth Menon