power: introduce library for device-specific OPPs
Subsystems (4)
PATCH 1/1 power: introduce library for device-specific OPPs
SoCs have a standard set of tuples consisting of frequency and voltage pairs that the device will support per voltage domain. These are called Operating Performance Points or OPPs. The actual definitions of OPP varies over silicon versions. For a specific domain, we can have a set of {frequency, voltage} pairs. As the kernel boots and more information is available, a default set of these are activated based on the precise nature of device. Further on operation, based on conditions prevailing in the system (such as temperature), some OPP availability may be temporarily controlled by the SoC frameworks.
To implement an OPP, some sort of power management support is necessary hence this library depends on CONFIG_PM.
Contributions include:
Sanjeev Premi for the initial concept:
http://patchwork.kernel.org/patch/50998/
Kevin Hilman for converting original design to device-based Kevin Hilman and Paul Walmsey for cleaning up many of the function abstractions, improvements and data structure handling
Romit Dasgupta for using enums instead of opp pointers
Thara Gopinath, Eduardo Valentin and Vishwanath BS for fixes and cleanups.
Linus Walleij for recommending this layer be made generic for usage in other architectures beyond OMAP and ARM.
Mark Brown, Andrew Morton, Rafael J Wysocki, Paul E McKenney for valuable improvements.
Discussions and comments from:
http://marc.info/?l=linux-omap&m=126033945313269&w=2
http://marc.info/?l=linux-omap&m=125482970102327&w=2
http://marc.info/?t=125809247500002&r=1&w=2
http://marc.info/?l=linux-omap&m=126025973426007&w=2
http://marc.info/?t=128152609200064&r=1&w=2
http://marc.info/?t=128468723000002&r=1&w=2
incorporated.
---
V6:
mutexes reduced to a single one. dev_opp_list_lock now protects
both the devices and the opp lists, doc updated accordingly.
fixed opp_add removed an irrelevant find_device_opp, used IS_ERR to
check pointer
fixed updater routines to remove unnecessary reader operations. comments from v5 not included in v6:
- synchronize_rcu() is not needed after list_add_rcu as pointed by Paul in http://marc.info/?l=linux-omap&m=128535708720191&w=2
I have retained it's usage after list_replace_rcu as with v4.
- Temporary release of mutex in opp_add under if (IS_ERR(dev_opp)) { Rationale:
If two parallel calls to opp_add on the same device node which is not yet added in the list can cause data structure integrity issues. For example:
c1: holds mutex dev_opp_list_lock
c2: starts and is blocked on dev_opp_list_lock mutex here dev_opp = find_device_opp(dev); [c1 in progress here]
if (IS_ERR(dev_opp)) {
If c1 releases dev_opp_list_lock here, c2 can proceed to call find_device_opp which will return error and will cause following allocation to take place for same device node.
dev_opp = kzalloc(sizeof(struct device_opp), GFP_KERNEL);
This is undesirable as it will result in an additional node added for the same device (since the device is the same, c1 should have added the new node and c2 should have just added an opp). Since the actual addition of a device node by itself is rare, kzalloc is a tiny penalty to pay for integrity of the data structure. The other option being to move the kzalloc before the mutex locking, but, that will cause dev_opp allocation overhead for every opp addition.
All other comments have been incorporated.
Tested with cpufreq on SDP3630 (TI OMAP3630) with lockdep debugging to catch races.
V5: https://patchwork.kernel.org/patch/223272/
opp pointers were being passed to callers outside rcu locks, this
causes the pointers to be potentially invalid between calls if opp_enable/disable calls take place.
The solution for this cannot be reference counters either, as opp pointer without control of opp library and rcu locks are completely untrustworthy. The better approach is to enforce restrictions on callers of query and retrieval functions to wrap the relevant parts under rcu locks. This allows for tremendous flexibility in the way opp libraries can be used as the users can optimize their implementation based on the requirements.
NOTE: find_device_opp is implicitly wrapped as a result.
(ref, v4 comments)
One more side-effect has been that the opp_enable and disable
functions changed their prototypes to make it a little more easier for the users to use them without having to get the pointers before hand, as well as do the functionality that is being provided currently as well.
opp_init_cpufreq_table now returns int and result of operation for
callers to adequately handle their error conditions.
pr_fmt is being used instead of duplicating "%s" .. __func__ with
every pr_xxx call.
Documentation update to reflect these.
Sample usage:
http://pastebin.mozilla.org/802375: cleanups for omap pm layer
http://pastebin.mozilla.org/802374: omap opp initialization
V4: http://marc.info/?t=128533285000002&r=1&w=2
Cc list trimmed to just the MLs.
RCU implementation - thanks for the pointers Rafael re-tested on OMAP3630 with lock debugging enabled including cpufreq, idle paths and "exception cases - enable/disable". available_opp_count removed as it complicated the updates altogether
+ the usage latencies are not too high given small lists.
In removed list_reverse usage as rcu has no list reverse equivalents
+ searching either direction has no real difference when the list is ordered.
change in protos for get_{voltage,frequency} - const removed from parameter as rcu_dereference causes build warnings introduced opp_set_availability helper to wrap common code between
opp_{enable,disable} - leaving these as is as they are more readable from usage perspective + these are not meant to be used in hot paths anyways.
Header guard __ASM_OPP_H replaced with __LINUX_OPP_H__ for opp.h
V3: https://patchwork.kernel.org/patch/200382/
Bunch of documentation update based on feedback removed opp_def - opp_add enables the opp by default lock usage optimization
Sample usage:
http://pastebin.mozilla.org/794786 -> cleanups for OMAP power
http://pastebin.mozilla.org/794787 -> Sample OPP initialization for OMAP
V2: https://patchwork.kernel.org/patch/189532/
Incorporated review comments from v1. major changes being:
$subject change to reflect this is for power. Documentation revamp and including it in the patch :) OPP_DEF removed - lets introduce this if needed or leave it to SOC frameworks to organize code as needed.
Rename of enable to available to better reflect the intent few fixes and typos
Introduced mutex based locking for controlling access to list modification (note: query functions are still unsafe- rationale
in the patch below)
A new home for opp.c in drivers/base/power (moved from lib/) A few optimization in function flow and additional error checks added to exposed functions
offline aligned with Kevin for cleaning up the copyrights
V1: http://marc.info/?t=128468723000002&r=1&w=2
Documentation/power/00-INDEX | 2 + Documentation/power/opp.txt | 373 +++++++++++++++++++++++++ drivers/base/power/Makefile | 1 + drivers/base/power/opp.c | 620 ++++++++++++++++++++++++++++++++++++++++++ include/linux/opp.h | 105 +++++++ kernel/power/Kconfig | 14 + 6 files changed, 1115 insertions(+), 0 deletions(-) create mode 100644 Documentation/power/opp.txt create mode 100644 drivers/base/power/opp.c create mode 100644 include/linux/opp.h
Documentation/power/00-INDEX +2 -0
@@ -14,6 +14,8 @@ interface.txt - Power management user interface in /sys/power notifiers.txt - Registering suspend notifiers in device drivers +opp.txt + - Operating Performance Point library pci.txt - How the PCI Subsystem Does Power Management pm_qos_interface.txt
Documentation/power/opp.txt new file +373 -0
373 lines not on this page · raw message
drivers/base/power/Makefile +1 -0
@@ -3,6 +3,7 @@ obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o obj-$(CONFIG_PM_RUNTIME) += runtime.o obj-$(CONFIG_PM_OPS) += generic_ops.o obj-$(CONFIG_PM_TRACE_RTC) += trace.o +obj-$(CONFIG_PM_OPP) += opp.o ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG ccflags-$(CONFIG_PM_VERBOSE) += -DDEBUG
drivers/base/power/opp.c new file +620 -0
620 lines not on this page · raw message
include/linux/opp.h new file +105 -0
105 lines not on this page · raw message
kernel/power/Kconfig +14 -0
@@ -242,3 +242,17 @@ config PM_OPS bool depends on PM_SLEEP || PM_RUNTIME default y + +config PM_OPP + bool "Enable Operating Performance Point(OPP) Layer library" + depends on PM + ---help--- + SOCs have a standard set of tuples consisting of frequency and + voltage pairs that the device will support per voltage domain. This + is called Operating Performance Point or OPP. The actual definitions + of OPP varies over silicon within the same family of devices. + + OPP layer organizes the data internally using device pointers + representing individual voltage domains and provides SOC + implementations a ready to use framework to manage OPPs. + For more information, read <file:Documentation/power/opp.txt>
Signature · 1 line
1.6.3.3
Hi,
Quoted 10 lines · Nishanth Menon
SoCs have a standard set of tuples consisting of frequency and voltage pairs that the device will support per voltage domain. These are called Operating Performance Points or OPPs. The actual definitions of OPP varies over silicon versions. For a specific domain, we can have a set of {frequency, voltage} pairs. As the kernel boots and more information is available, a default set of these are activated based on the precise nature of device. Further on operation, based on conditions prevailing in the system (such as temperature), some OPP availability may be temporarily controlled by the SoC frameworks.
Quoted 2 lines
To implement an OPP, some sort of power management support is necessary hence this library depends on
CONFIG_PM.
The patch generally looks good to me, I only have a couple of cosmetic remarks (below).
...
drivers/base/power/opp.c line 457
Quoted 11 lines
drivers/base/power/opp.c new file +11
-0+static int opp_set_availability (struct device *dev,unsigned long freq, +bool availability_req) +{ +struct device_opp *tmp_dev_opp, *dev_opp =NULL ; +struct opp *new_opp, *tmp_opp, *opp =ERR_PTR (-ENODEV ); +int r =0 ; + +/* keep the node allocated */ + new_opp =kmalloc (sizeof (struct opp ),GFP_KERNEL ); +if (!new_opp) { +pr_warning ("Unable to allocate opp\n" );
Please add an identification string to the messages, something like "OPP: Unable to allocat object\n" (and similarly in the other messages). That would help to find the source of a message in case there's any problem.
Quoted 6 lines
drivers/base/power/opp.c new file +6
-0+return -ENOMEM ; + } + +mutex_lock (&dev_opp_list_lock); + +/* Find the device_opp */
drivers/base/power/opp.c line 473
Quoted 10 lines
drivers/base/power/opp.c new file +10
-0+list_for_each_entry (tmp_dev_opp, &dev_opp_list, node) { +if (dev == tmp_dev_opp->dev) { + dev_opp = tmp_dev_opp; +break ; + } + } +if (IS_ERR (dev_opp)) { + r =PTR_ERR (dev_opp); +pr_warning ("Unable to find device\n" ); + goto out1;
I'd prefer this lable to be called "unlock". It will be a bit more informative.
Quoted 22 lines
drivers/base/power/opp.c new file +22
-0+ } + +/* Do we have the frequency? */ +list_for_each_entry (tmp_opp, &dev_opp->opp_list, node) { +if (tmp_opp->rate == freq) { + opp = tmp_opp; +break ; + } + } +if (IS_ERR (opp)) { + r =PTR_ERR (opp); + goto out1; + } + +/* Is update really needed? */ +if (opp->available == availability_req) + goto out1; +/* copy the old data over */ + *new_opp = *opp; + +/* plug in new node */ + new_opp->available = availability_req;
drivers/base/power/opp.c line 505
Quoted 10 lines
drivers/base/power/opp.c new file +10
-0+ +list_replace_rcu (&opp->node, &new_opp->node); +mutex_unlock (&dev_opp_list_lock); +synchronize_rcu (); + +/* clean up old opp */ + new_opp = opp; + goto out; + +out1:
+unlock:
drivers/base/power/opp.c line 510
Quoted 5 lines
drivers/base/power/opp.c new file +5
-0+mutex_unlock (&dev_opp_list_lock); +out: +kfree (new_opp); +return r; +}
Thanks,
Rafael
Quoted 19 lines
-----Original Message-----
From: Rafael J. Wysocki [mailto:rjw at sisk.pl]
Sent: Thursday, October 07, 2010 4:55 PMHi,
Quoted 10 lines · Nishanth Menon
SoCs have a standard set of tuples consisting of frequency and voltage pairs that the device will support per voltage domain. These are called Operating Performance Points or OPPs. The actual definitions of OPP varies over silicon versions. For a specific domain, we can have a set of {frequency, voltage} pairs. As the kernel boots and more information is available, a default set of these are activated based on the precise nature of device. Further on operation, based on conditions prevailing in the system (such as temperature), some OPP availability may be temporarily controlled by the SoC frameworks.
Quoted 4 lines
Quoted 2 lines
To implement an OPP, some sort of power management support is necessary hence this library depends on
CONFIG_PM.The patch generally looks good to me, I only have a couple of cosmetic
Thanks for the great reviews.. It did bump up the resultant patch.
Quoted 4 lines
remarks
(below)....
Quoted 16 lines
drivers/base/power/opp.c line 457
Quoted 11 lines
drivers/base/power/opp.c new file +11
-0+static int opp_set_availability (struct device *dev,unsigned long freq, +bool availability_req) +{ +struct device_opp *tmp_dev_opp, *dev_opp =NULL ; +struct opp *new_opp, *tmp_opp, *opp =ERR_PTR (-ENODEV ); +int r =0 ; + +/* keep the node allocated */ + new_opp =kmalloc (sizeof (struct opp ),GFP_KERNEL ); +if (!new_opp) { +pr_warning ("Unable to allocate opp\n" );Please add an identification string to the messages, something like "OPP: Unable to allocat object\n" (and similarly in the other messages). That would help to find the source of a message in case there's any problem.
pr_fmt has been reformatted for this. The actual message which will appear is as follows:opp_set_availability: Unable to allocate opp
is'nt that good enough considering that all functions are opp_ prefixed? I can modify pr_fmt to add "OPP:" but I kinda think it is redundant. But I have no strong opinions on that and look forward to your recommendations.
Quoted 13 lines
Quoted 13 lines
drivers/base/power/opp.c new file +11
-0+return -ENOMEM ; + } + +mutex_lock (&dev_opp_list_lock); + +/* Find the device_opp */ +list_for_each_entry (tmp_dev_opp, &dev_opp_list, node) { +if (dev == tmp_dev_opp->dev) { + dev_opp = tmp_dev_opp; +break ; + }
Quoted 8 lines
drivers/base/power/opp.c line 473
Quoted 5 lines
drivers/base/power/opp.c new file +5
-0+ } +if (IS_ERR (dev_opp)) { + r =PTR_ERR (dev_opp); +pr_warning ("Unable to find device\n" ); + goto out1;I'd prefer this lable to be called "unlock". It will be a bit more informative.
Ack. Fixing in v6 if you are ok with the above.
Regards,
Nishanth Menon
Quoted 46 lines · Nishanth
Quoted 19 lines
-----Original Message-----
From: Rafael J. Wysocki [mailto:rjw at sisk.pl]
Sent: Thursday, October 07, 2010 4:55 PMHi,
Quoted 10 lines · Nishanth Menon
SoCs have a standard set of tuples consisting of frequency and voltage pairs that the device will support per voltage domain. These are called Operating Performance Points or OPPs. The actual definitions of OPP varies over silicon versions. For a specific domain, we can have a set of {frequency, voltage} pairs. As the kernel boots and more information is available, a default set of these are activated based on the precise nature of device. Further on operation, based on conditions prevailing in the system (such as temperature), some OPP availability may be temporarily controlled by the SoC frameworks.
Quoted 4 lines
Quoted 2 lines
To implement an OPP, some sort of power management support is necessary hence this library depends on
CONFIG_PM.The patch generally looks good to me, I only have a couple of cosmetic
Thanks for the great reviews.. It did bump up the resultant patch.
Quoted 4 lines
remarks
(below)....
Quoted 16 lines
drivers/base/power/opp.c line 457
Quoted 11 lines
drivers/base/power/opp.c new file +11
-0+static int opp_set_availability (struct device *dev,unsigned long freq, +bool availability_req) +{ +struct device_opp *tmp_dev_opp, *dev_opp =NULL ; +struct opp *new_opp, *tmp_opp, *opp =ERR_PTR (-ENODEV ); +int r =0 ; + +/* keep the node allocated */ + new_opp =kmalloc (sizeof (struct opp ),GFP_KERNEL ); +if (!new_opp) { +pr_warning ("Unable to allocate opp\n" );Please add an identification string to the messages, something like "OPP: Unable to allocat object\n" (and similarly in the other messages). That would help to find the source of a message in case there's any problem.
Quoted 7 lines
pr_fmthas been reformatted for this. The actual message which will appear is as follows:opp_set_availability: Unable to allocate oppis'nt that good enough considering that all functions are
opp_prefixed? I can modifypr_fmtto add "OPP:" but I kinda think it is redundant. But I have no strong opinions on that and look forward to your recommendations.
Even more informative would be to use dev_warn() and include the func. That way we'll even know which device has the problem.
Kevin
Quoted 7 lines
-----Original Message-----
From: Kevin Hilman [mailto:khilman at deeprootsystems.com]
Sent: Thursday, October 07, 2010 5:14 PM
To: Menon, Nishanth
Cc: Rafael J. Wysocki; linux-pm; lkml; l-o; l-a; Paul
Subject: Re: [PATCH] power: introduce library for device-specific OPPs
[...]
Quoted 23 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
+static int opp_set_availability(struct device *dev, unsigned long
freq,
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
drivers/base/power/opp.c new file +7
-0+ bool availability_req) +{ +struct device_opp *tmp_dev_opp, *dev_opp =NULL ; +struct opp *new_opp, *tmp_opp, *opp =ERR_PTR (-ENODEV ); +int r =0 ; + +/* keep the node allocated */ Quoted 8 lines
drivers/base/power/opp.c line 457
Quoted 3 lines
drivers/base/power/opp.c new file +3
-0+ new_opp =kmalloc (sizeof (struct opp ),GFP_KERNEL ); +if (!new_opp) { +pr_warning ("Unable to allocate opp\n" );Please add an identification string to the messages, something like "OPP: Unable to allocat object\n" (and similarly in the other messages). That would help to find the source of a message in case there's any problem.
Quoted 1 line
pr_fmthas been reformatted for this. The actual message which willappear
Quoted 3 lines
is as follows:
opp_set_availability: Unable to allocate opp
Quoted 7 lines
Quoted 2 lines
is'nt that good enough considering that all functions are
opp_prefixed? I can modifypr_fmtto add "OPP:" but I kinda think it is redundant. ButI
Quoted 1 line
have no strong opinions on that and look forward to your recommendations.
Even more informative would be to use
dev_warn()and include the func. That way we'll even know which device has the problem.
Ack. Thanks. Yeah, this is better.. will do the change.
Regards,
Nishanth Menon
Quoted 7 lines
-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Thursday, October 07, 2010 5:14 PM
To: Menon, Nishanth
Cc: Rafael J. Wysocki; linux-pm; lkml; l-o; l-a; Paul
Subject: Re: [PATCH] power: introduce library for device-specific OPPs
[...]
Quoted 23 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
+static int opp_set_availability(struct device *dev, unsigned long
freq,
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
drivers/base/power/opp.c new file +7
-0+ bool availability_req) +{ +struct device_opp *tmp_dev_opp, *dev_opp =NULL ; +struct opp *new_opp, *tmp_opp, *opp =ERR_PTR (-ENODEV ); +int r =0 ; + +/* keep the node allocated */ Quoted 8 lines
drivers/base/power/opp.c line 457
Quoted 3 lines
drivers/base/power/opp.c new file +3
-0+ new_opp =kmalloc (sizeof (struct opp ),GFP_KERNEL ); +if (!new_opp) { +pr_warning ("Unable to allocate opp\n" );Please add an identification string to the messages, something like "OPP: Unable to allocat object\n" (and similarly in the other messages). That would help to find the source of a message in case there's any problem.
Quoted 1 line
pr_fmthas been reformatted for this. The actual message which willappear
Quoted 3 lines
is as follows:
opp_set_availability: Unable to allocate opp
Quoted 7 lines
Quoted 2 lines
is'nt that good enough considering that all functions are
opp_prefixed? I can modifypr_fmtto add "OPP:" but I kinda think it is redundant. ButI
Quoted 1 line
have no strong opinions on that and look forward to your recommendations.
Even more informative would be to use
dev_warn()and include the func. That way we'll even know which device has the problem.
Ack. Thanks. Yeah, this is better.. will do the change.
Regards,
Nishanth Menon
Quoted 46 lines · Nishanth
Quoted 19 lines
-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: Thursday, October 07, 2010 4:55 PMHi,
Quoted 10 lines · Nishanth Menon
SoCs have a standard set of tuples consisting of frequency and voltage pairs that the device will support per voltage domain. These are called Operating Performance Points or OPPs. The actual definitions of OPP varies over silicon versions. For a specific domain, we can have a set of {frequency, voltage} pairs. As the kernel boots and more information is available, a default set of these are activated based on the precise nature of device. Further on operation, based on conditions prevailing in the system (such as temperature), some OPP availability may be temporarily controlled by the SoC frameworks.
Quoted 4 lines
Quoted 2 lines
To implement an OPP, some sort of power management support is necessary hence this library depends on
CONFIG_PM.The patch generally looks good to me, I only have a couple of cosmetic
Thanks for the great reviews.. It did bump up the resultant patch.
Quoted 4 lines
remarks
(below)....
Quoted 16 lines
drivers/base/power/opp.c line 457
Quoted 11 lines
drivers/base/power/opp.c new file +11
-0+static int opp_set_availability (struct device *dev,unsigned long freq, +bool availability_req) +{ +struct device_opp *tmp_dev_opp, *dev_opp =NULL ; +struct opp *new_opp, *tmp_opp, *opp =ERR_PTR (-ENODEV ); +int r =0 ; + +/* keep the node allocated */ + new_opp =kmalloc (sizeof (struct opp ),GFP_KERNEL ); +if (!new_opp) { +pr_warning ("Unable to allocate opp\n" );Please add an identification string to the messages, something like "OPP: Unable to allocat object\n" (and similarly in the other messages). That would help to find the source of a message in case there's any problem.
Quoted 7 lines
pr_fmthas been reformatted for this. The actual message which will appear is as follows:opp_set_availability: Unable to allocate oppis'nt that good enough considering that all functions are
opp_prefixed? I can modifypr_fmtto add "OPP:" but I kinda think it is redundant. But I have no strong opinions on that and look forward to your recommendations.
Even more informative would be to use dev_warn() and include the func. That way we'll even know which device has the problem.
Kevin
Quoted 19 lines
-----Original Message-----
From: Rafael J. Wysocki [mailto:[email protected]]
Sent: Thursday, October 07, 2010 4:55 PMHi,
Quoted 10 lines · Nishanth Menon
SoCs have a standard set of tuples consisting of frequency and voltage pairs that the device will support per voltage domain. These are called Operating Performance Points or OPPs. The actual definitions of OPP varies over silicon versions. For a specific domain, we can have a set of {frequency, voltage} pairs. As the kernel boots and more information is available, a default set of these are activated based on the precise nature of device. Further on operation, based on conditions prevailing in the system (such as temperature), some OPP availability may be temporarily controlled by the SoC frameworks.
Quoted 4 lines
Quoted 2 lines
To implement an OPP, some sort of power management support is necessary hence this library depends on
CONFIG_PM.The patch generally looks good to me, I only have a couple of cosmetic
Thanks for the great reviews.. It did bump up the resultant patch.
Quoted 4 lines
remarks
(below)....
Quoted 16 lines
drivers/base/power/opp.c line 457
Quoted 11 lines
drivers/base/power/opp.c new file +11
-0+static int opp_set_availability (struct device *dev,unsigned long freq, +bool availability_req) +{ +struct device_opp *tmp_dev_opp, *dev_opp =NULL ; +struct opp *new_opp, *tmp_opp, *opp =ERR_PTR (-ENODEV ); +int r =0 ; + +/* keep the node allocated */ + new_opp =kmalloc (sizeof (struct opp ),GFP_KERNEL ); +if (!new_opp) { +pr_warning ("Unable to allocate opp\n" );Please add an identification string to the messages, something like "OPP: Unable to allocat object\n" (and similarly in the other messages). That would help to find the source of a message in case there's any problem.
pr_fmt has been reformatted for this. The actual message which will appear is as follows:opp_set_availability: Unable to allocate opp
is'nt that good enough considering that all functions are opp_ prefixed? I can modify pr_fmt to add "OPP:" but I kinda think it is redundant. But I have no strong opinions on that and look forward to your recommendations.
Quoted 13 lines
Quoted 13 lines
drivers/base/power/opp.c new file +11
-0+return -ENOMEM ; + } + +mutex_lock (&dev_opp_list_lock); + +/* Find the device_opp */ +list_for_each_entry (tmp_dev_opp, &dev_opp_list, node) { +if (dev == tmp_dev_opp->dev) { + dev_opp = tmp_dev_opp; +break ; + }
Quoted 8 lines
drivers/base/power/opp.c line 473
Quoted 5 lines
drivers/base/power/opp.c new file +5
-0+ } +if (IS_ERR (dev_opp)) { + r =PTR_ERR (dev_opp); +pr_warning ("Unable to find device\n" ); + goto out1;I'd prefer this lable to be called "unlock". It will be a bit more informative.
Ack. Fixing in v6 if you are ok with the above.
Regards,
Nishanth Menon
Hi,
Quoted 10 lines · Nishanth Menon
SoCs have a standard set of tuples consisting of frequency and voltage pairs that the device will support per voltage domain. These are called Operating Performance Points or OPPs. The actual definitions of OPP varies over silicon versions. For a specific domain, we can have a set of {frequency, voltage} pairs. As the kernel boots and more information is available, a default set of these are activated based on the precise nature of device. Further on operation, based on conditions prevailing in the system (such as temperature), some OPP availability may be temporarily controlled by the SoC frameworks.
Quoted 2 lines
To implement an OPP, some sort of power management support is necessary hence this library depends on
CONFIG_PM.
The patch generally looks good to me, I only have a couple of cosmetic remarks (below).
...
drivers/base/power/opp.c line 457
Quoted 11 lines
drivers/base/power/opp.c new file +11
-0+static int opp_set_availability (struct device *dev,unsigned long freq, +bool availability_req) +{ +struct device_opp *tmp_dev_opp, *dev_opp =NULL ; +struct opp *new_opp, *tmp_opp, *opp =ERR_PTR (-ENODEV ); +int r =0 ; + +/* keep the node allocated */ + new_opp =kmalloc (sizeof (struct opp ),GFP_KERNEL ); +if (!new_opp) { +pr_warning ("Unable to allocate opp\n" );
Please add an identification string to the messages, something like "OPP: Unable to allocat object\n" (and similarly in the other messages). That would help to find the source of a message in case there's any problem.
Quoted 6 lines
drivers/base/power/opp.c new file +6
-0+return -ENOMEM ; + } + +mutex_lock (&dev_opp_list_lock); + +/* Find the device_opp */
drivers/base/power/opp.c line 473
Quoted 10 lines
drivers/base/power/opp.c new file +10
-0+list_for_each_entry (tmp_dev_opp, &dev_opp_list, node) { +if (dev == tmp_dev_opp->dev) { + dev_opp = tmp_dev_opp; +break ; + } + } +if (IS_ERR (dev_opp)) { + r =PTR_ERR (dev_opp); +pr_warning ("Unable to find device\n" ); + goto out1;
I'd prefer this lable to be called "unlock". It will be a bit more informative.
Quoted 22 lines
drivers/base/power/opp.c new file +22
-0+ } + +/* Do we have the frequency? */ +list_for_each_entry (tmp_opp, &dev_opp->opp_list, node) { +if (tmp_opp->rate == freq) { + opp = tmp_opp; +break ; + } + } +if (IS_ERR (opp)) { + r =PTR_ERR (opp); + goto out1; + } + +/* Is update really needed? */ +if (opp->available == availability_req) + goto out1; +/* copy the old data over */ + *new_opp = *opp; + +/* plug in new node */ + new_opp->available = availability_req;
drivers/base/power/opp.c line 505
Quoted 10 lines
drivers/base/power/opp.c new file +10
-0+ +list_replace_rcu (&opp->node, &new_opp->node); +mutex_unlock (&dev_opp_list_lock); +synchronize_rcu (); + +/* clean up old opp */ + new_opp = opp; + goto out; + +out1:
+unlock:
drivers/base/power/opp.c line 510
Quoted 5 lines
drivers/base/power/opp.c new file +5
-0+mutex_unlock (&dev_opp_list_lock); +out: +kfree (new_opp); +return r; +}
Thanks,
Rafael