driver core / pmdomain: Add support for fined grained sync_state
v3 cover driver core / pmdomain: Add support for fined grained sync_state
Changes in v3:
- Dropped tested-by tags from Geert, due to changes in patch2.
- Addressed the comments from Danilo and Geert, more information in the changelog for each patch.
Assuming this is accepted, the best merge strategy would be for Danilo to pick up the driver core patches (1 to 4) and host a branch that I can pull into my pmdomain tree so I can take the rest of the series. Danilo, please let me know what you prefer.
Since the introduction [1] of the common sync_state support for pmdomains (genpd), we have encountered a lot of various interesting problems. In most cases the new behaviour of genpd triggered some weird platform specific bugs.
That said, in LPC in Tokyo me and Saravana hosted a session to walk through the remaining limitations that we have found for genpd's sync state support. In particular, we discussed the problems we have for the so-called onecell power domain providers, where a single provider typically provides multiple independent power domains, all with their own set of consumers.
Note that, onecell power domain providers are very common. It's being used by many SoCs/platforms/technologies. To name a few:
SCMI, Qualcomm, NXP, Mediatek, Renesas, TI, etc.
Anyway, in these cases, the generic sync_state mechanism with fw_devlink isn't fine grained enough, as we end up waiting for all consumers for all power domains before the ->sync_callback gets called for the supplier/provider. In other words, we may end up keeping unused power domains powered-on, for no good reasons.
The series intends to fix this problem. Please have a look at the commit messages for more details and help review/test!
Kind regards
Ulf Hansson
[1]
https://lore.kernel.org/all/[email protected]/
Ulf Hansson (13):
Revert "driver core: move dev_has_sync_state() to drivers/base/base.h" driver core: Enable suppliers to implement fine grained sync_state
support
driver core: Add documentation for dev_set_drv_sync_state() driver core: Add dev_set_drv_queue_sync_state()
pmdomain: core: Move genpd_get_from_provider()
pmdomain: core: Add initial fine grained sync_state support
pmdomain: core: Extend fine grained sync_state to more onecell
providers
pmdomain: core: Export a common function for ->queue_sync_state()
pmdomain: renesas: rcar-gen4-sysc: Drop GENPD_FLAG_NO_STAY_ON
pmdomain: renesas: rcar-sysc: Drop GENPD_FLAG_NO_STAY_ON
pmdomain: renesas: rmobile-sysc: Drop GENPD_FLAG_NO_STAY_ON
pmdomain: core: Avoid an unnecessary power off at sync_state
pmdomain: core: Add a couple of debug prints for sync_state
drivers/base/base.h | 22 ++- drivers/base/core.c | 77 ++++++-- drivers/base/driver.c | 7 + drivers/pmdomain/core.c | 227 ++++++++++++++++++---- drivers/pmdomain/renesas/rcar-gen4-sysc.c | 1 - drivers/pmdomain/renesas/rcar-sysc.c | 1 - drivers/pmdomain/renesas/rmobile-sysc.c | 3 +- include/linux/device.h | 44 +++++ include/linux/device/driver.h | 7 + include/linux/pm_domain.h | 3 + 10 files changed, 318 insertions(+), 74 deletions(-)
Signature · 1 line
2.43.0
PATCH v3 1/13 Revert "driver core: move dev_has_sync_state() to drivers/base/base.h"
It turns out that the dev_has_sync_state() is needed outside the driver core. A subsequent change to the pmdomain subsystem starts making use of it.
---
Changes in v3:
- New patch.
--- drivers/base/base.h | 14 -------------- include/linux/device.h | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-)
drivers/base/base.h +0 -14
@@ -188,20 +188,6 @@ static inline int driver_match_device(const struct device_driver *drv,return drv->bus->match ? drv->bus->match (dev, drv) :1 ; } -static inline bool dev_has_sync_state (struct device *dev) -{ -struct device_driver *drv; - -if (!dev) -return false; - drv =READ_ONCE (dev->driver); -if (drv && drv->sync_state) -return true; -if (dev->bus && dev->bus->sync_state) -return true; -return false; -} -static inline void dev_sync_state (struct device *dev) {if (dev->bus->sync_state)
include/linux/device.h +14 -0
@@ -1061,6 +1061,20 @@ static inline void device_lock_assert(struct device *dev)lockdep_assert_held (&dev->mutex); } +static inline bool dev_has_sync_state (struct device *dev) +{ +struct device_driver *drv; + +if (!dev) +return false; + drv =READ_ONCE (dev->driver); +if (drv && drv->sync_state) +return true; +if (dev->bus && dev->bus->sync_state) +return true; +return false; +} +static inline int dev_set_drv_sync_state (struct device *dev,void (*fn)(struct device *dev)) {
Signature · 1 line
2.43.0
Danilo Krummrich
maintainerRe: [PATCH v3 01/13] Revert "driver core: move dev_has_sync_state() to drivers/base/base.h"
Quoted 5 lines · Ulf Hansson
It turns out that the
dev_has_sync_state()is needed outside the driver core. A subsequent change to the pmdomain subsystem starts making use of it.Fixes 9db268212e0d ("driver core: move dev_has_sync_state() to drivers/base/base.h")
Hm...the commit was correct, it's just that you now want to use it outside of the driver-core code, so I'd drop this tag.
Quoted 1 line
Signed-off-by Ulf Hansson <[email protected]>
PATCH v3 2/13 driver core: Enable suppliers to implement fine grained sync_state support
In reply to Ulf HanssonThe common sync_state support isn't fine grained enough for some types of suppliers, like power domains for example. Especially when a supplier provides multiple independent power domains, each with their own set of consumers. In these cases we need to wait for all consumers for all the provided power domains before invoking the supplier's ->sync_state().
To allow a more fine grained sync_state support to be implemented on per supplier's driver basis, let's add a new optional callback. As soon as there is an update worth to consider in regards to managing sync_state for a supplier device, __device_links_queue_sync_state() queues the device in a list, allowing the new callback to be invoked when flushing the list in device_links_flush_sync_list().
---
Changes in v3:
- Re-worked the approach to use a list to queue/flush devices for ->queue_sync_state(). This should make sure the device lock is being held when it's needed, as pointed out by Danilo.
--- drivers/base/base.h | 18 ++++++++ drivers/base/core.c | 77 ++++++++++++++++++++++++++--------- drivers/base/driver.c | 7 ++++ include/linux/device.h | 2 + include/linux/device/driver.h | 7 ++++ 5 files changed, 91 insertions(+), 20 deletions(-)
drivers/base/base.h +18 -0
@@ -196,6 +196,24 @@ static inline void dev_sync_state(struct device *dev) dev->driver->sync_state (dev); } +static inline bool dev_has_queue_sync_state (struct device *dev) +{ +struct device_driver *drv; + +if (!dev) +return false; + drv =READ_ONCE (dev->driver); +if (drv && drv->queue_sync_state) +return true; +return false; +} + +static inline void dev_queue_sync_state (struct device *dev) +{ +if (dev->driver && dev->driver->queue_sync_state) + dev->driver->queue_sync_state (dev); +} +int driver_add_groups (const struct device_driver *drv,const struct attribute_group **groups);void driver_remove_groups (const struct device_driver *drv,const struct attribute_group **groups);void device_driver_detach (struct device *dev);
drivers/base/core.c +57 -20
182 lines not on this page · raw message
drivers/base/driver.c +7 -0
@@ -239,6 +239,13 @@ int driver_register(struct device_driver *drv)pr_warn ("Driver '%s' needs updating - please use " "bus_type methods\n" , drv->name); +if (drv->queue_sync_state && !drv->sync_state && + !drv->bus->sync_state) { +pr_err ("Driver '%s' or its bus_type needs ->sync_state()" , + drv->name); +return -EINVAL ; + } + other =driver_find (drv->name, drv->bus);if (other) { pr_err("Error: Driver '%s' is already registered, "
include/linux/device.h +2 -0
@@ -414,12 +414,14 @@ enum device_removable {* @suppliers: List of links to supplier devices. * @consumers: List of links to consumer devices. * @defer_sync: Hook to global list of devices that have deferred sync_state. +* @defer_sync: Hook to global list of devices scheduled for queue_sync_state. * @status: Driver status information. */ struct dev_links_info {struct list_head suppliers;struct list_head consumers;struct list_head defer_sync; +struct list_head queue_sync;enum dl_dev_state status; };
include/linux/device/driver.h +7 -0
@@ -68,6 +68,12 @@ enum probe_type {* be called at late_initcall_sync level. If the device has * consumers that are never bound to a driver, this function * will never get called until they do. +* @queue_sync_state: Similar to the ->sync_state() callback, but called to +* allow syncing device state to software state in a more fine +* grained way. It is called when there is an updated state that +* may be worth to consider for any of the consumers linked to +* this device. If implemented, the ->sync_state() callback is +* required too. * @remove: Called when the device is removed from the system to * unbind a device from this driver. * @shutdown: Called at shut-down time to quiesce the device.
@@ -110,6 +116,7 @@ struct device_driver {int (*probe) (struct device *dev);void (*sync_state)(struct device *dev); +void (*queue_sync_state)(struct device *dev);int (*remove) (struct device *dev);void (*shutdown) (struct device *dev);int (*suspend) (struct device *dev,pm_message_t state);
Signature · 1 line
2.43.0
Danilo Krummrich
maintainerRe: [PATCH v3 02/13] driver core: Enable suppliers to implement fine grained sync_state support
Quoted 12 lines · Ulf Hansson
drivers/base/base.h +4
-0@@ -196,6 +196,24 @@ static inline void dev_sync_state(struct device *dev) dev->driver->sync_state (dev); } +static inline bool dev_has_queue_sync_state (struct device *dev) +{ +struct device_driver *drv; +
drivers/base/base.h static inline void dev_sync_state(struct device *dev) · line 212
Quoted 10 lines
drivers/base/base.h +10
-0+if (!dev) +return false; + drv =READ_ONCE (dev->driver); +if (drv && drv->queue_sync_state) +return true; +return false; +} + +static inline void dev_queue_sync_state (struct device *dev) +{
Let's add device_lock_assert(dev), as this function requires it to be held.
Quoted 3 lines
drivers/base/base.h +3
-0+if (dev->driver && dev->driver->queue_sync_state) + dev->driver->queue_sync_state (dev); +}
<snip>
drivers/base/base.h static void device_links_flush_sync_list(struct list_head *list, · line 1196
Quoted 10 lines
drivers/base/base.h +6
-0@@ -1175,6 +1188,25 @@ static void device_links_flush_sync_list(struct list_head *list,put_device (dev); } + +if (!q_list) +return ; + +list_for_each_entry_safe (dev, tmp, q_list, links.queue_sync) { +list_del_init (&dev->links.queue_sync);
Hm...this is called without the device_links_write_lock() held, so this looks like this could this race with the list_del_init() from device_links_driver_cleanup() and create an infinite loop.
(The other list iterator above might have the same issue.)
drivers/base/base.h static void device_links_flush_sync_list(struct list_head *list, · line 1198
Quoted 2 lines
drivers/base/base.h +2
-0+ +if (dev != dont_lock_dev)
This is pre-existing, but I think it would be good to add a device_lock_assert() call for this as well.
Quoted 12 lines
drivers/base/base.h +11
-0+device_lock (dev); + +device_links_write_lock (); +dev_queue_sync_state (dev); +device_links_write_unlock (); + +if (dev != dont_lock_dev) +device_unlock (dev); + +put_device (dev); + } }
Re: [PATCH v3 02/13] driver core: Enable suppliers to implement fine grained sync_state support
Quoted 48 lines · Danilo Krummrich
Quoted 12 lines · Ulf Hansson
drivers/base/base.h +4
-0@@ -196,6 +196,24 @@ static inline void dev_sync_state(struct device *dev) dev->driver->sync_state (dev); } +static inline bool dev_has_queue_sync_state (struct device *dev) +{ +struct device_driver *drv; +drivers/base/base.h static inline void dev_sync_state(struct device *dev) · line 212
Quoted 10 lines
drivers/base/base.h +10
-0+if (!dev) +return false; + drv =READ_ONCE (dev->driver); +if (drv && drv->queue_sync_state) +return true; +return false; +} + +static inline void dev_queue_sync_state (struct device *dev) +{Let's add
device_lock_assert(dev), as this function requires it to be held.Quoted 3 lines
drivers/base/base.h +3
-0+if (dev->driver && dev->driver->queue_sync_state) + dev->driver->queue_sync_state (dev); +}<snip>
drivers/base/base.h static void device_links_flush_sync_list(struct list_head *list, · line 1196
Quoted 10 lines
drivers/base/base.h +6
-0@@ -1175,6 +1188,25 @@ static void device_links_flush_sync_list(struct list_head *list,put_device (dev); } + +if (!q_list) +return ; + +list_for_each_entry_safe (dev, tmp, q_list, links.queue_sync) { +list_del_init (&dev->links.queue_sync);Hm...this is called without the
device_links_write_lock()held, so this looks like this could this race with thelist_del_init()fromdevice_links_driver_cleanup()and create an infinite loop.
Quoted 1 line
(The other list iterator above might have the same issue.)
Yes, you are right!
I was trying to follow the existing implementation for the regular sync_state, but it certainly looks like we need a separate lock to protect the lists.
Let me fold in a patch that fixes this for the regular ->sync_state() code first.
Quoted 6 lines
drivers/base/base.h static void device_links_flush_sync_list(struct list_head *list, · line 1198
Quoted 3 lines
drivers/base/base.h +2
-0+ +if (dev != dont_lock_dev)This is pre-existing, but I think it would be good to add a
device_lock_assert()call for this as well.
Makes perfect sense.
Again, I will fold in a patch that start by adding this for the regular ->sync_state().
Quoted 13 lines
drivers/base/base.h static void device_links_flush_sync_list(struct list_head *list, · line 1210
Quoted 13 lines
drivers/base/base.h +11
-0+device_lock (dev); + +device_links_write_lock (); +dev_queue_sync_state (dev); +device_links_write_unlock (); + +if (dev != dont_lock_dev) +device_unlock (dev); + +put_device (dev); + } }
Thanks for reviewing!
Kind regards
Uffe
Re: [PATCH v3 02/13] driver core: Enable suppliers to implement fine grained sync_state support
In reply to Ulf HanssonQuoted 14 lines · Ulf Hansson
The common
sync_statesupport isn't fine grained enough for some types of suppliers, like power domains for example. Especially when a supplier provides multiple independent power domains, each with their own set of consumers. In these cases we need to wait for all consumers for all the provided power domains before invoking the supplier's ->sync_state().To allow a more fine grained
sync_statesupport to be implemented on per supplier's driver basis, let's add a new optional callback. As soon as there is an update worth to consider in regards to managingsync_statefor a supplier device,__device_links_queue_sync_state()queues the device in a list, allowing the new callback to be invoked when flushing the list indevice_links_flush_sync_list().
Quoted 8 lines
Signed-off-by Ulf Hansson <[email protected]>---
Changes in v3:
- Re-worked the approach to use a list to queue/flush devices for ->queue_sync_state(). This should make sure the device lock is being held when it's needed, as pointed out by Danilo.
Hi Ulf,
Thanks for working on this!
And please bear with my slow replies.
Quoted 13 lines
--- drivers/base/base.h | 18 ++++++++ drivers/base/core.c | 77 ++++++++++++++++++++++++++--------- drivers/base/driver.c | 7 ++++ include/linux/device.h | 2 + include/linux/device/driver.h | 7 ++++ 5 files changed, 91 insertions(+), 20 deletions(-)drivers/base/base.h +0
-0
drivers/base/base.h static inline void dev_sync_state(struct device *dev) · line 199
Quoted 4 lines
drivers/base/base.h +1
-0@@ -196,6 +196,24 @@ static inline void dev_sync_state(struct device *dev) dev->driver->sync_state (dev); } +static inline bool dev_has_queue_sync_state (struct device *dev)
Let's please pick a better name. This is too similar to the actual queue function you call __device_links_queue_sync_state() and is very confusing. Maybe something that has a meaning along the lines of "another consumer probed". So, maybe:
* consumer_probed()
* change_of_active_consumers()
I'm going to refer to this new callback as "consumer_probed()" in the rest of my replies so I can keep it straight in my head.
Quoted 29 lines
drivers/base/base.h +17
-0+{ +struct device_driver *drv; + +if (!dev) +return false; + drv =READ_ONCE (dev->driver); +if (drv && drv->queue_sync_state) +return true; +return false; +} + +static inline void dev_queue_sync_state (struct device *dev) +{ +if (dev->driver && dev->driver->queue_sync_state) + dev->driver->queue_sync_state (dev); +} +int driver_add_groups (const struct device_driver *drv,const struct attribute_group **groups);void driver_remove_groups (const struct device_driver *drv,const struct attribute_group **groups);void device_driver_detach (struct device *dev);drivers/base/core.c +0
-1@@ -1101,15 +1101,18 @@ int device_links_check_suppliers(struct device *dev)/** * __device_links_queue_sync_state - Queue a device for sync_state() callback * @dev: Device to call sync_state() on -* @list: List head to queue the @dev on
drivers/base/core.c int device_links_check_suppliers(struct device *dev) · line 1112
Quoted 10 lines
drivers/base/core.c +5
-1+* @s_list: List head for the sync_state to queue the @dev on +* @q_list: List head for the queue_sync_state to queue the @dev on * * Queues a device for a sync_state() callback when the device links write lock * isn't held. This allows the sync_state() execution flow to use device links * APIs. The caller must ensure this function is called with -* device_links_write_lock() held. +* device_links_write_lock() held. Note, if the optional queue_sync_state() +* callback has been assigned too, the device is queued for that list to allow a +* more fine grained support to be implemented on per supplier basis.
Why not keep this in the same format as the existing doc? Something like:
If option list xxx is provided, queues the device for the consumer_probed() callback.
Quoted 129 lines
drivers/base/core.c +45
-14* * This function does a get_device() to make sure the device is not freed while -* on this list. +* on the corresponding list. * * So the caller must also ensure that device_links_flush_sync_list() is called * as soon as the caller releases device_links_write_lock(). This is necessary @@ -1117,7 +1120,8 @@ int device_links_check_suppliers(struct device *dev)* put_device() is called on this device. */ static void __device_links_queue_sync_state (struct device *dev, -struct list_head *list) +struct list_head *s_list, +struct list_head *q_list) {struct device_link *link;@@ -1129,8 +1133,14 @@ static void __device_links_queue_sync_state(struct device *dev,list_for_each_entry (link, &dev->links.consumers, s_node) {if (!device_link_test (link,DL_FLAG_MANAGED ))continue ; -if (link->status !=DL_STATE_ACTIVE ) +if (link->status !=DL_STATE_ACTIVE ) { +if (dev_has_queue_sync_state (dev) && +list_empty (&dev->links.queue_sync)) { +get_device (dev); +list_add_tail (&dev->links.queue_sync, q_list); + }return ; + } }/* @@ -1144,25 +1154,28 @@ static void __device_links_queue_sync_state(struct device *dev,return ;get_device (dev); -list_add_tail (&dev->links.defer_sync, list); +list_add_tail (&dev->links.defer_sync, s_list); }/** -* device_links_flush_sync_list - Call sync_state() on a list of devices -* @list: List of devices to call sync_state() on +* device_links_flush_sync_list - Call sync_state callbacks for the devices +* @s_list: List of devices to call sync_state() on +* @q_list: List of devices to call queue_sync_state() on * @dont_lock_dev: Device for which lock is already held by the caller * -* Calls sync_state() on all the devices that have been queued for it. This -* function is used in conjunction with __device_links_queue_sync_state(). The -* @dont_lock_dev parameter is useful when this function is called from a -* context where a device lock is already held. +* Calls sync_state() and queue_sync_state() on all the devices that have been +* queued for it. This function is used in conjunction with +* __device_links_queue_sync_state(). The @dont_lock_dev parameter is useful +* when this function is called from a context where a device lock is already +* held. */ -static void device_links_flush_sync_list (struct list_head *list, +static void device_links_flush_sync_list (struct list_head *s_list, +struct list_head *q_list,struct device *dont_lock_dev) {struct device *dev, *tmp; -list_for_each_entry_safe (dev, tmp, list, links.defer_sync) { +list_for_each_entry_safe (dev, tmp, s_list, links.defer_sync) {list_del_init (&dev->links.defer_sync);if (dev != dont_lock_dev)@@ -1175,6 +1188,25 @@ static void device_links_flush_sync_list(struct list_head *list,put_device (dev); } + +if (!q_list) +return ; + +list_for_each_entry_safe (dev, tmp, q_list, links.queue_sync) { +list_del_init (&dev->links.queue_sync); + +if (dev != dont_lock_dev) +device_lock (dev); + +device_links_write_lock (); +dev_queue_sync_state (dev); +device_links_write_unlock (); + +if (dev != dont_lock_dev) +device_unlock (dev); + +put_device (dev); + } }void device_links_supplier_sync_state_pause (void )@@ -1188,6 +1220,7 @@ void device_links_supplier_sync_state_resume(void) {struct device *dev, *tmp;LIST_HEAD (sync_list); +LIST_HEAD (queue_list);device_links_write_lock ();if (!defer_sync_state_count) {@@ -1204,12 +1237,12 @@ void device_links_supplier_sync_state_resume(void)* sync_list because defer_sync is used for both lists. */ list_del_init (&dev->links.defer_sync); -__device_links_queue_sync_state (dev, &sync_list); +__device_links_queue_sync_state (dev, &sync_list, &queue_list); } out:device_links_write_unlock (); -device_links_flush_sync_list (&sync_list,NULL ); +device_links_flush_sync_list (&sync_list, &queue_list,NULL ); }static int sync_state_resume_initcall (void )@@ -1296,6 +1329,7 @@ void device_links_driver_bound(struct device *dev) {struct device_link *link, *ln;LIST_HEAD (sync_list); +LIST_HEAD (queue_list);/* * If a device binds successfully, it's expected to have created all
drivers/base/core.c void device_links_driver_bound(struct device *dev) · line 1388
Quoted 5 lines
drivers/base/core.c +1
-1@@ -1351,7 +1385,7 @@ void device_links_driver_bound(struct device *dev)if (defer_sync_state_count)__device_links_supplier_defer_sync (dev);else -__device_links_queue_sync_state (dev, &sync_list); +__device_links_queue_sync_state (dev, &sync_list, &queue_list);
This path is really meant only for situations when the device has no consumers. So, I don't think fine grained control is relevant.
Quoted 88 lines
drivers/base/core.c +6
-3list_for_each_entry_safe (link, ln, &dev->links.suppliers, c_node) {struct device *supplier;@@ -1393,14 +1427,15 @@ void device_links_driver_bound(struct device *dev)if (defer_sync_state_count)__device_links_supplier_defer_sync (supplier);else -__device_links_queue_sync_state (supplier, &sync_list); +__device_links_queue_sync_state (supplier, &sync_list, + &queue_list); } dev->links.status =DL_DEV_DRIVER_BOUND ;device_links_write_unlock (); -device_links_flush_sync_list (&sync_list, dev); +device_links_flush_sync_list (&sync_list, &queue_list, dev); }/** @@ -1516,6 +1551,7 @@ void device_links_driver_cleanup(struct device *dev) }list_del_init (&dev->links.defer_sync); +list_del_init (&dev->links.queue_sync);__device_links_no_driver (dev);device_links_write_unlock ();@@ -1808,7 +1844,7 @@ void fw_devlink_probing_done(void)class_for_each_device (&devlink_class,NULL , &sync_list, fw_devlink_dev_sync_state);device_links_write_unlock (); -device_links_flush_sync_list (&sync_list,NULL ); +device_links_flush_sync_list (&sync_list,NULL ,NULL ); }/** @@ -3169,6 +3205,7 @@ void device_initialize(struct device *dev)INIT_LIST_HEAD (&dev->links.consumers);INIT_LIST_HEAD (&dev->links.suppliers);INIT_LIST_HEAD (&dev->links.defer_sync); +INIT_LIST_HEAD (&dev->links.queue_sync); dev->links.status =DL_DEV_NO_DRIVER ;dev_assign_dma_coherent (dev, dma_default_coherent);swiotlb_dev_init (dev);drivers/base/driver.c +7
-0@@ -239,6 +239,13 @@ int driver_register(struct device_driver *drv)pr_warn ("Driver '%s' needs updating - please use " "bus_type methods\n" , drv->name); +if (drv->queue_sync_state && !drv->sync_state && + !drv->bus->sync_state) { +pr_err ("Driver '%s' or its bus_type needs ->sync_state()" , + drv->name); +return -EINVAL ; + } + other =driver_find (drv->name, drv->bus);if (other) { pr_err("Error: Driver '%s' is already registered, "include/linux/device.h +2
-0@@ -414,12 +414,14 @@ enum device_removable {* @suppliers: List of links to supplier devices. * @consumers: List of links to consumer devices. * @defer_sync: Hook to global list of devices that have deferred sync_state. +* @defer_sync: Hook to global list of devices scheduled for queue_sync_state. * @status: Driver status information. */ struct dev_links_info {struct list_head suppliers;struct list_head consumers;struct list_head defer_sync; +struct list_head queue_sync;enum dl_dev_state status; };include/linux/device/driver.h +0
-0
include/linux/device/driver.h enum probe_type { · line 76
Quoted 9 lines
include/linux/device/driver.h +6
-0@@ -68,6 +68,12 @@ enum probe_type {* be called at late_initcall_sync level. If the device has * consumers that are never bound to a driver, this function * will never get called until they do. +* @queue_sync_state: Similar to the ->sync_state() callback, but called to +* allow syncing device state to software state in a more fine +* grained way. It is called when there is an updated state that +* may be worth to consider for any of the consumers linked to +* this device. If implemented, the ->sync_state() callback is +* required too.
Let's make it clear that if a device gets sync_state() callback, it needs to sync the state independent of whether it has received any/all "consumer_probed()".
Thanks,
Saravana
Quoted 14 lines
include/linux/device/driver.h +1
-1* @remove: Called when the device is removed from the system to * unbind a device from this driver. * @shutdown: Called at shut-down time to quiesce the device. @@ -110,6 +116,7 @@ struct device_driver {int (*probe) (struct device *dev);void (*sync_state)(struct device *dev); +void (*queue_sync_state)(struct device *dev);int (*remove) (struct device *dev);void (*shutdown) (struct device *dev);int (*suspend) (struct device *dev,pm_message_t state); --2.43.0
Re: [PATCH v3 02/13] driver core: Enable suppliers to implement fine grained sync_state support
Quoted 25 lines · Saravana Kannan
Quoted 14 lines · Ulf Hansson
The common
sync_statesupport isn't fine grained enough for some types of suppliers, like power domains for example. Especially when a supplier provides multiple independent power domains, each with their own set of consumers. In these cases we need to wait for all consumers for all the provided power domains before invoking the supplier's ->sync_state().To allow a more fine grained
sync_statesupport to be implemented on per supplier's driver basis, let's add a new optional callback. As soon as there is an update worth to consider in regards to managingsync_statefor a supplier device,__device_links_queue_sync_state()queues the device in a list, allowing the new callback to be invoked when flushing the list indevice_links_flush_sync_list().Quoted 8 lines
Signed-off-by Ulf Hansson <[email protected]>---
Changes in v3:
- Re-worked the approach to use a list to queue/flush devices for ->queue_sync_state(). This should make sure the device lock is being held when it's needed, as pointed out by Danilo.
Quoted 5 lines
Hi Ulf,
Thanks for working on this!
And please bear with my slow replies.
I will try, but taking more than 2 months to reply isn't sustainable, I think. Let's hope you can get some more bandwidth for reviews when moving forward.
Quoted 17 lines
Quoted 17 lines
--- drivers/base/base.h | 18 ++++++++ drivers/base/core.c | 77 ++++++++++++++++++++++++++--------- drivers/base/driver.c | 7 ++++ include/linux/device.h | 2 + include/linux/device/driver.h | 7 ++++ 5 files changed, 91 insertions(+), 20 deletions(-)drivers/base/base.h +0
-0@@ -196,6 +196,24 @@ static inline void dev_sync_state(struct device *dev) dev->driver->sync_state (dev); }
Quoted 8 lines
drivers/base/base.h static inline void dev_sync_state(struct device *dev) · line 199
Quoted 1 line
drivers/base/base.h +1
-0+static inline bool dev_has_queue_sync_state (struct device *dev)Let's please pick a better name. This is too similar to the actual queue function you call
__device_links_queue_sync_state()and is very confusing. Maybe something that has a meaning along the lines of "another consumer probed". So, maybe:
*consumer_probed()
*change_of_active_consumers()
The whole point of naming it "queue_sync_state" was exactly to refer to __device_links_queue_sync_state(). The point is, the callback can't be invoked unless __device_links_queue_sync_state() has been called for the device first.
Not sure why you think that is confusing? To me, that is rather the opposite. :-)
Before deciding on another name, note also that __device_links_queue_sync_state() is called when resuming sync_state from device_links_supplier_sync_state_resume() and from device_links_driver_bound(). I am not sure "consumer_probed" a good name that covers both of these cases; what do you think?
Quoted 39 lines
I'm going to refer to this new callback as "
consumer_probed()" in the rest of my replies so I can keep it straight in my head.Quoted 35 lines
drivers/base/base.h +17
-0+{ +struct device_driver *drv; + +if (!dev) +return false; + drv =READ_ONCE (dev->driver); +if (drv && drv->queue_sync_state) +return true; +return false; +} + +static inline void dev_queue_sync_state (struct device *dev) +{ +if (dev->driver && dev->driver->queue_sync_state) + dev->driver->queue_sync_state (dev); +} +int driver_add_groups (const struct device_driver *drv,const struct attribute_group **groups);void driver_remove_groups (const struct device_driver *drv,const struct attribute_group **groups);void device_driver_detach (struct device *dev);drivers/base/core.c +2
-1@@ -1101,15 +1101,18 @@ int device_links_check_suppliers(struct device *dev)/** * __device_links_queue_sync_state - Queue a device for sync_state() callback * @dev: Device to call sync_state() on -* @list: List head to queue the @dev on +* @s_list: List head for the sync_state to queue the @dev on +* @q_list: List head for the queue_sync_state to queue the @dev on * * Queues a device for a sync_state() callback when the device links write lock * isn't held. This allows the sync_state() execution flow to use device links * APIs. The caller must ensure this function is called with
Quoted 8 lines
drivers/base/core.c int device_links_check_suppliers(struct device *dev) · line 1112
Quoted 4 lines
drivers/base/core.c +3
-1-* device_links_write_lock() held. +* device_links_write_lock() held. Note, if the optional queue_sync_state() +* callback has been assigned too, the device is queued for that list to allow a +* more fine grained support to be implemented on per supplier basis. Why not keep this in the same format as the existing doc? Something like:
If option list xxx is provided, queues the device for theconsumer_probed()callback.
Okay, let me clarify this.
Quoted 127 lines
Quoted 127 lines
drivers/base/core.c +45
-14* * This function does a get_device() to make sure the device is not freed while -* on this list. +* on the corresponding list. * * So the caller must also ensure that device_links_flush_sync_list() is called * as soon as the caller releases device_links_write_lock(). This is necessary @@ -1117,7 +1120,8 @@ int device_links_check_suppliers(struct device *dev)* put_device() is called on this device. */ static void __device_links_queue_sync_state (struct device *dev, -struct list_head *list) +struct list_head *s_list, +struct list_head *q_list) {struct device_link *link;@@ -1129,8 +1133,14 @@ static void __device_links_queue_sync_state(struct device *dev,list_for_each_entry (link, &dev->links.consumers, s_node) {if (!device_link_test (link,DL_FLAG_MANAGED ))continue ; -if (link->status !=DL_STATE_ACTIVE ) +if (link->status !=DL_STATE_ACTIVE ) { +if (dev_has_queue_sync_state (dev) && +list_empty (&dev->links.queue_sync)) { +get_device (dev); +list_add_tail (&dev->links.queue_sync, q_list); + }return ; + } }/* @@ -1144,25 +1154,28 @@ static void __device_links_queue_sync_state(struct device *dev,return ;get_device (dev); -list_add_tail (&dev->links.defer_sync, list); +list_add_tail (&dev->links.defer_sync, s_list); }/** -* device_links_flush_sync_list - Call sync_state() on a list of devices -* @list: List of devices to call sync_state() on +* device_links_flush_sync_list - Call sync_state callbacks for the devices +* @s_list: List of devices to call sync_state() on +* @q_list: List of devices to call queue_sync_state() on * @dont_lock_dev: Device for which lock is already held by the caller * -* Calls sync_state() on all the devices that have been queued for it. This -* function is used in conjunction with __device_links_queue_sync_state(). The -* @dont_lock_dev parameter is useful when this function is called from a -* context where a device lock is already held. +* Calls sync_state() and queue_sync_state() on all the devices that have been +* queued for it. This function is used in conjunction with +* __device_links_queue_sync_state(). The @dont_lock_dev parameter is useful +* when this function is called from a context where a device lock is already +* held. */ -static void device_links_flush_sync_list (struct list_head *list, +static void device_links_flush_sync_list (struct list_head *s_list, +struct list_head *q_list,struct device *dont_lock_dev) {struct device *dev, *tmp; -list_for_each_entry_safe (dev, tmp, list, links.defer_sync) { +list_for_each_entry_safe (dev, tmp, s_list, links.defer_sync) {list_del_init (&dev->links.defer_sync);if (dev != dont_lock_dev)@@ -1175,6 +1188,25 @@ static void device_links_flush_sync_list(struct list_head *list,put_device (dev); } + +if (!q_list) +return ; + +list_for_each_entry_safe (dev, tmp, q_list, links.queue_sync) { +list_del_init (&dev->links.queue_sync); + +if (dev != dont_lock_dev) +device_lock (dev); + +device_links_write_lock (); +dev_queue_sync_state (dev); +device_links_write_unlock (); + +if (dev != dont_lock_dev) +device_unlock (dev); + +put_device (dev); + } }void device_links_supplier_sync_state_pause (void )@@ -1188,6 +1220,7 @@ void device_links_supplier_sync_state_resume(void) {struct device *dev, *tmp;LIST_HEAD (sync_list); +LIST_HEAD (queue_list);device_links_write_lock ();if (!defer_sync_state_count) {@@ -1204,12 +1237,12 @@ void device_links_supplier_sync_state_resume(void)* sync_list because defer_sync is used for both lists. */ list_del_init (&dev->links.defer_sync); -__device_links_queue_sync_state (dev, &sync_list); +__device_links_queue_sync_state (dev, &sync_list, &queue_list); } out:device_links_write_unlock (); -device_links_flush_sync_list (&sync_list,NULL ); +device_links_flush_sync_list (&sync_list, &queue_list,NULL ); }static int sync_state_resume_initcall (void )@@ -1296,6 +1329,7 @@ void device_links_driver_bound(struct device *dev) {struct device_link *link, *ln;LIST_HEAD (sync_list); +LIST_HEAD (queue_list);
Quoted 11 lines
drivers/base/core.c void device_links_driver_bound(struct device *dev) · line 1388
Quoted 8 lines
drivers/base/core.c +1
-1/* * If a device binds successfully, it's expected to have created all @@ -1351,7 +1385,7 @@ void device_links_driver_bound(struct device *dev)if (defer_sync_state_count)__device_links_supplier_defer_sync (dev);else -__device_links_queue_sync_state (dev, &sync_list); +__device_links_queue_sync_state (dev, &sync_list, &queue_list);This path is really meant only for situations when the device has no consumers. So, I don't think fine grained control is relevant.
Okay, makes sense!
Quoted 94 lines
Quoted 94 lines
drivers/base/core.c +6
-3list_for_each_entry_safe (link, ln, &dev->links.suppliers, c_node) {struct device *supplier;@@ -1393,14 +1427,15 @@ void device_links_driver_bound(struct device *dev)if (defer_sync_state_count)__device_links_supplier_defer_sync (supplier);else -__device_links_queue_sync_state (supplier, &sync_list); +__device_links_queue_sync_state (supplier, &sync_list, + &queue_list); } dev->links.status =DL_DEV_DRIVER_BOUND ;device_links_write_unlock (); -device_links_flush_sync_list (&sync_list, dev); +device_links_flush_sync_list (&sync_list, &queue_list, dev); }/** @@ -1516,6 +1551,7 @@ void device_links_driver_cleanup(struct device *dev) }list_del_init (&dev->links.defer_sync); +list_del_init (&dev->links.queue_sync);__device_links_no_driver (dev);device_links_write_unlock ();@@ -1808,7 +1844,7 @@ void fw_devlink_probing_done(void)class_for_each_device (&devlink_class,NULL , &sync_list, fw_devlink_dev_sync_state);device_links_write_unlock (); -device_links_flush_sync_list (&sync_list,NULL ); +device_links_flush_sync_list (&sync_list,NULL ,NULL ); }/** @@ -3169,6 +3205,7 @@ void device_initialize(struct device *dev)INIT_LIST_HEAD (&dev->links.consumers);INIT_LIST_HEAD (&dev->links.suppliers);INIT_LIST_HEAD (&dev->links.defer_sync); +INIT_LIST_HEAD (&dev->links.queue_sync); dev->links.status =DL_DEV_NO_DRIVER ;dev_assign_dma_coherent (dev, dma_default_coherent);swiotlb_dev_init (dev);drivers/base/driver.c +7
-0@@ -239,6 +239,13 @@ int driver_register(struct device_driver *drv)pr_warn ("Driver '%s' needs updating - please use " "bus_type methods\n" , drv->name); +if (drv->queue_sync_state && !drv->sync_state && + !drv->bus->sync_state) { +pr_err ("Driver '%s' or its bus_type needs ->sync_state()" , + drv->name); +return -EINVAL ; + } + other =driver_find (drv->name, drv->bus);if (other) { pr_err("Error: Driver '%s' is already registered, "include/linux/device.h +2
-0@@ -414,12 +414,14 @@ enum device_removable {* @suppliers: List of links to supplier devices. * @consumers: List of links to consumer devices. * @defer_sync: Hook to global list of devices that have deferred sync_state. +* @defer_sync: Hook to global list of devices scheduled for queue_sync_state. * @status: Driver status information. */ struct dev_links_info {struct list_head suppliers;struct list_head consumers;struct list_head defer_sync; +struct list_head queue_sync;enum dl_dev_state status; };include/linux/device/driver.h +2
-0@@ -68,6 +68,12 @@ enum probe_type {* be called at late_initcall_sync level. If the device has * consumers that are never bound to a driver, this function * will never get called until they do. +* @queue_sync_state: Similar to the ->sync_state() callback, but called to +* allow syncing device state to software state in a more fine
Quoted 8 lines
include/linux/device/driver.h enum probe_type { · line 76
Quoted 4 lines
include/linux/device/driver.h +4
-0+* grained way. It is called when there is an updated state that +* may be worth to consider for any of the consumers linked to +* this device. If implemented, the ->sync_state() callback is +* required too. Let's make it clear that if a device gets
sync_state()callback, it needs to sync the state independent of whether it has received any/all "consumer_probed()".
Right, good point! Let me clarify that!
Quoted 10 lines
Thanks,
SaravanaQuoted 5 lines
include/linux/device/driver.h +0
-0* @remove: Called when the device is removed from the system to * unbind a device from this driver. * @shutdown: Called at shut-down time to quiesce the device. @@ -110,6 +116,7 @@ struct device_driver {
Quoted 9 lines
Quoted 9 lines
include/linux/device/driver.h +1
-1int (*probe) (struct device *dev);void (*sync_state)(struct device *dev); +void (*queue_sync_state)(struct device *dev);int (*remove) (struct device *dev);void (*shutdown) (struct device *dev);int (*suspend) (struct device *dev,pm_message_t state); --2.43.0
Kind regards
Uffe
Re: [PATCH v3 02/13] driver core: Enable suppliers to implement fine grained sync_state support
Quoted 63 lines · Ulf Hansson
Quoted 25 lines · Saravana Kannan
Quoted 14 lines · Ulf Hansson
The common
sync_statesupport isn't fine grained enough for some types of suppliers, like power domains for example. Especially when a supplier provides multiple independent power domains, each with their own set of consumers. In these cases we need to wait for all consumers for all the provided power domains before invoking the supplier's ->sync_state().To allow a more fine grained
sync_statesupport to be implemented on per supplier's driver basis, let's add a new optional callback. As soon as there is an update worth to consider in regards to managingsync_statefor a supplier device,__device_links_queue_sync_state()queues the device in a list, allowing the new callback to be invoked when flushing the list indevice_links_flush_sync_list().Quoted 8 lines
Signed-off-by Ulf Hansson <[email protected]>---
Changes in v3:
- Re-worked the approach to use a list to queue/flush devices for ->queue_sync_state(). This should make sure the device lock is being held when it's needed, as pointed out by Danilo.Quoted 5 lines
Hi Ulf,
Thanks for working on this!
And please bear with my slow replies.
I will try, but taking more than 2 months to reply isn't sustainable, I think. Let's hope you can get some more bandwidth for reviews when moving forward.
Quoted 17 lines
Quoted 17 lines
--- drivers/base/base.h | 18 ++++++++ drivers/base/core.c | 77 ++++++++++++++++++++++++++--------- drivers/base/driver.c | 7 ++++ include/linux/device.h | 2 + include/linux/device/driver.h | 7 ++++ 5 files changed, 91 insertions(+), 20 deletions(-)drivers/base/base.h +0
-0@@ -196,6 +196,24 @@ static inline void dev_sync_state(struct device *dev) dev->driver->sync_state (dev); }Quoted 8 lines
drivers/base/base.h static inline void dev_sync_state(struct device *dev) · line 199
Quoted 1 line
drivers/base/base.h +1
-0+static inline bool dev_has_queue_sync_state (struct device *dev)Let's please pick a better name. This is too similar to the actual queue function you call
__device_links_queue_sync_state()and is very confusing. Maybe something that has a meaning along the lines of "another consumer probed". So, maybe:
*consumer_probed()
*change_of_active_consumers()
Quoted 7 lines
The whole point of naming it "
queue_sync_state" was exactly to refer to__device_links_queue_sync_state(). The point is, the callback can't be invoked unless__device_links_queue_sync_state()has been called for the device first.Not sure why you think that is confusing? To me, that is rather the opposite. :-)
sync_state() is a callback telling the driver that it's okay to sync the state of the hardware with the software.
queue_sync_state() means nothing to the driver. It's just leaking an internal implementation detail (name of the internal function) to the driver that's not really relevant. What you are really telling the driver is that some additional consumers have probed.
Quoted 5 lines
Before deciding on another name, note also that
__device_links_queue_sync_state()is called when resumingsync_statefromdevice_links_supplier_sync_state_resume()and fromdevice_links_driver_bound(). I am not sure "consumer_probed" a good name that covers both of these cases; what do you think?
Yes, I'm well aware of that :) The contract of sync_state() is that it'll come after a point where it's safe to sync the state. Not "as soon as it's safe" -- meaning no timing guarantee. Really, this is just to make sure sync_state() doesn't come before late initcalls (because a lot of frameworks make assumptions around it) are done and before all the top level devices are added.
So, even today, sync_state() can come a bit late. In general, the driver framework doesn't guarantee immediate action. There is no guarantee that a drive probe will be called as soon as it's registered (if there is a device) and vice versa. The same will be true for a "consumer_probed()" callback too.
Also, your implementation is literally trying to check which consumers have probed and which ones haven't. So something like "consumer_probed()" or "consumer_change()" should work well and is actually meaningful for a driver developer.
Quoted 49 lines
Quoted 40 lines
I'm going to refer to this new callback as "
consumer_probed()" in the rest of my replies so I can keep it straight in my head.Quoted 35 lines
drivers/base/base.h +17
-0+{ +struct device_driver *drv; + +if (!dev) +return false; + drv =READ_ONCE (dev->driver); +if (drv && drv->queue_sync_state) +return true; +return false; +} + +static inline void dev_queue_sync_state (struct device *dev) +{ +if (dev->driver && dev->driver->queue_sync_state) + dev->driver->queue_sync_state (dev); +} +int driver_add_groups (const struct device_driver *drv,const struct attribute_group **groups);void driver_remove_groups (const struct device_driver *drv,const struct attribute_group **groups);void device_driver_detach (struct device *dev);drivers/base/core.c +2
-1@@ -1101,15 +1101,18 @@ int device_links_check_suppliers(struct device *dev)/** * __device_links_queue_sync_state - Queue a device for sync_state() callback * @dev: Device to call sync_state() on -* @list: List head to queue the @dev on +* @s_list: List head for the sync_state to queue the @dev on +* @q_list: List head for the queue_sync_state to queue the @dev on * * Queues a device for a sync_state() callback when the device links write lock * isn't held. This allows the sync_state() execution flow to use device links * APIs. The caller must ensure this function is called with Quoted 8 lines
drivers/base/core.c int device_links_check_suppliers(struct device *dev) · line 1112
Quoted 4 lines
drivers/base/core.c +3
-1-* device_links_write_lock() held. +* device_links_write_lock() held. Note, if the optional queue_sync_state() +* callback has been assigned too, the device is queued for that list to allow a +* more fine grained support to be implemented on per supplier basis. Why not keep this in the same format as the existing doc? Something like:
If option list xxx is provided, queues the device for theconsumer_probed()callback.
Quoted 1 line
Okay, let me clarify this.
Thanks
Quoted 245 lines
Quoted 128 lines
Quoted 128 lines
drivers/base/core.c +45
-14* * This function does a get_device() to make sure the device is not freed while -* on this list. +* on the corresponding list. * * So the caller must also ensure that device_links_flush_sync_list() is called * as soon as the caller releases device_links_write_lock(). This is necessary @@ -1117,7 +1120,8 @@ int device_links_check_suppliers(struct device *dev)* put_device() is called on this device. */ static void __device_links_queue_sync_state (struct device *dev, -struct list_head *list) +struct list_head *s_list, +struct list_head *q_list) {struct device_link *link;@@ -1129,8 +1133,14 @@ static void __device_links_queue_sync_state(struct device *dev,list_for_each_entry (link, &dev->links.consumers, s_node) {if (!device_link_test (link,DL_FLAG_MANAGED ))continue ; -if (link->status !=DL_STATE_ACTIVE ) +if (link->status !=DL_STATE_ACTIVE ) { +if (dev_has_queue_sync_state (dev) && +list_empty (&dev->links.queue_sync)) { +get_device (dev); +list_add_tail (&dev->links.queue_sync, q_list); + }return ; + } }/* @@ -1144,25 +1154,28 @@ static void __device_links_queue_sync_state(struct device *dev,return ;get_device (dev); -list_add_tail (&dev->links.defer_sync, list); +list_add_tail (&dev->links.defer_sync, s_list); }/** -* device_links_flush_sync_list - Call sync_state() on a list of devices -* @list: List of devices to call sync_state() on +* device_links_flush_sync_list - Call sync_state callbacks for the devices +* @s_list: List of devices to call sync_state() on +* @q_list: List of devices to call queue_sync_state() on * @dont_lock_dev: Device for which lock is already held by the caller * -* Calls sync_state() on all the devices that have been queued for it. This -* function is used in conjunction with __device_links_queue_sync_state(). The -* @dont_lock_dev parameter is useful when this function is called from a -* context where a device lock is already held. +* Calls sync_state() and queue_sync_state() on all the devices that have been +* queued for it. This function is used in conjunction with +* __device_links_queue_sync_state(). The @dont_lock_dev parameter is useful +* when this function is called from a context where a device lock is already +* held. */ -static void device_links_flush_sync_list (struct list_head *list, +static void device_links_flush_sync_list (struct list_head *s_list, +struct list_head *q_list,struct device *dont_lock_dev) {struct device *dev, *tmp; -list_for_each_entry_safe (dev, tmp, list, links.defer_sync) { +list_for_each_entry_safe (dev, tmp, s_list, links.defer_sync) {list_del_init (&dev->links.defer_sync);if (dev != dont_lock_dev)@@ -1175,6 +1188,25 @@ static void device_links_flush_sync_list(struct list_head *list,put_device (dev); } + +if (!q_list) +return ; + +list_for_each_entry_safe (dev, tmp, q_list, links.queue_sync) { +list_del_init (&dev->links.queue_sync); + +if (dev != dont_lock_dev) +device_lock (dev); + +device_links_write_lock (); +dev_queue_sync_state (dev); +device_links_write_unlock (); + +if (dev != dont_lock_dev) +device_unlock (dev); + +put_device (dev); + } }void device_links_supplier_sync_state_pause (void )@@ -1188,6 +1220,7 @@ void device_links_supplier_sync_state_resume(void) {struct device *dev, *tmp;LIST_HEAD (sync_list); +LIST_HEAD (queue_list);device_links_write_lock ();if (!defer_sync_state_count) {@@ -1204,12 +1237,12 @@ void device_links_supplier_sync_state_resume(void)* sync_list because defer_sync is used for both lists. */ list_del_init (&dev->links.defer_sync); -__device_links_queue_sync_state (dev, &sync_list); +__device_links_queue_sync_state (dev, &sync_list, &queue_list); } out:device_links_write_unlock (); -device_links_flush_sync_list (&sync_list,NULL ); +device_links_flush_sync_list (&sync_list, &queue_list,NULL ); }static int sync_state_resume_initcall (void )@@ -1296,6 +1329,7 @@ void device_links_driver_bound(struct device *dev) {struct device_link *link, *ln;LIST_HEAD (sync_list); +LIST_HEAD (queue_list);Quoted 11 lines
drivers/base/core.c void device_links_driver_bound(struct device *dev) · line 1388
Quoted 8 lines
drivers/base/core.c +1
-1/* * If a device binds successfully, it's expected to have created all @@ -1351,7 +1385,7 @@ void device_links_driver_bound(struct device *dev)if (defer_sync_state_count)__device_links_supplier_defer_sync (dev);else -__device_links_queue_sync_state (dev, &sync_list); +__device_links_queue_sync_state (dev, &sync_list, &queue_list);This path is really meant only for situations when the device has no consumers. So, I don't think fine grained control is relevant.
Okay, makes sense!
Quoted 94 lines
Quoted 94 lines
drivers/base/core.c +6
-3list_for_each_entry_safe (link, ln, &dev->links.suppliers, c_node) {struct device *supplier;@@ -1393,14 +1427,15 @@ void device_links_driver_bound(struct device *dev)if (defer_sync_state_count)__device_links_supplier_defer_sync (supplier);else -__device_links_queue_sync_state (supplier, &sync_list); +__device_links_queue_sync_state (supplier, &sync_list, + &queue_list); } dev->links.status =DL_DEV_DRIVER_BOUND ;device_links_write_unlock (); -device_links_flush_sync_list (&sync_list, dev); +device_links_flush_sync_list (&sync_list, &queue_list, dev); }/** @@ -1516,6 +1551,7 @@ void device_links_driver_cleanup(struct device *dev) }list_del_init (&dev->links.defer_sync); +list_del_init (&dev->links.queue_sync);__device_links_no_driver (dev);device_links_write_unlock ();@@ -1808,7 +1844,7 @@ void fw_devlink_probing_done(void)class_for_each_device (&devlink_class,NULL , &sync_list, fw_devlink_dev_sync_state);device_links_write_unlock (); -device_links_flush_sync_list (&sync_list,NULL ); +device_links_flush_sync_list (&sync_list,NULL ,NULL ); }/** @@ -3169,6 +3205,7 @@ void device_initialize(struct device *dev)INIT_LIST_HEAD (&dev->links.consumers);INIT_LIST_HEAD (&dev->links.suppliers);INIT_LIST_HEAD (&dev->links.defer_sync); +INIT_LIST_HEAD (&dev->links.queue_sync); dev->links.status =DL_DEV_NO_DRIVER ;dev_assign_dma_coherent (dev, dma_default_coherent);swiotlb_dev_init (dev);drivers/base/driver.c +7
-0@@ -239,6 +239,13 @@ int driver_register(struct device_driver *drv)pr_warn ("Driver '%s' needs updating - please use " "bus_type methods\n" , drv->name); +if (drv->queue_sync_state && !drv->sync_state && + !drv->bus->sync_state) { +pr_err ("Driver '%s' or its bus_type needs ->sync_state()" , + drv->name); +return -EINVAL ; + } + other =driver_find (drv->name, drv->bus);if (other) { pr_err("Error: Driver '%s' is already registered, "include/linux/device.h +2
-0@@ -414,12 +414,14 @@ enum device_removable {* @suppliers: List of links to supplier devices. * @consumers: List of links to consumer devices. * @defer_sync: Hook to global list of devices that have deferred sync_state. +* @defer_sync: Hook to global list of devices scheduled for queue_sync_state. * @status: Driver status information. */ struct dev_links_info {struct list_head suppliers;struct list_head consumers;struct list_head defer_sync; +struct list_head queue_sync;enum dl_dev_state status; };include/linux/device/driver.h +2
-0@@ -68,6 +68,12 @@ enum probe_type {* be called at late_initcall_sync level. If the device has * consumers that are never bound to a driver, this function * will never get called until they do. +* @queue_sync_state: Similar to the ->sync_state() callback, but called to +* allow syncing device state to software state in a more fine Quoted 8 lines
include/linux/device/driver.h enum probe_type { · line 76
Quoted 4 lines
include/linux/device/driver.h +4
-0+* grained way. It is called when there is an updated state that +* may be worth to consider for any of the consumers linked to +* this device. If implemented, the ->sync_state() callback is +* required too. Let's make it clear that if a device gets
sync_state()callback, it needs to sync the state independent of whether it has received any/all "consumer_probed()".
Quoted 2 lines
Right, good point! Let me clarify that!
Thanks,
Saravana
Quoted 22 lines
Quoted 10 lines
Thanks,
SaravanaQuoted 5 lines
include/linux/device/driver.h +0
-0* @remove: Called when the device is removed from the system to * unbind a device from this driver. * @shutdown: Called at shut-down time to quiesce the device. @@ -110,6 +116,7 @@ struct device_driver {Quoted 9 lines
Quoted 9 lines
include/linux/device/driver.h +1
-1int (*probe) (struct device *dev);void (*sync_state)(struct device *dev); +void (*queue_sync_state)(struct device *dev);int (*remove) (struct device *dev);void (*shutdown) (struct device *dev);int (*suspend) (struct device *dev,pm_message_t state); --2.43.0
Kind regards
Uffe
Re: [PATCH v3 02/13] driver core: Enable suppliers to implement fine grained sync_state support
Quoted 101 lines · Saravana Kannan
Quoted 63 lines · Ulf Hansson
Quoted 25 lines · Saravana Kannan
Quoted 14 lines · Ulf Hansson
The common
sync_statesupport isn't fine grained enough for some types of suppliers, like power domains for example. Especially when a supplier provides multiple independent power domains, each with their own set of consumers. In these cases we need to wait for all consumers for all the provided power domains before invoking the supplier's ->sync_state().To allow a more fine grained
sync_statesupport to be implemented on per supplier's driver basis, let's add a new optional callback. As soon as there is an update worth to consider in regards to managingsync_statefor a supplier device,__device_links_queue_sync_state()queues the device in a list, allowing the new callback to be invoked when flushing the list indevice_links_flush_sync_list().Quoted 8 lines
Signed-off-by Ulf Hansson <[email protected]>---
Changes in v3:
- Re-worked the approach to use a list to queue/flush devices for ->queue_sync_state(). This should make sure the device lock is being held when it's needed, as pointed out by Danilo.Quoted 5 lines
Hi Ulf,
Thanks for working on this!
And please bear with my slow replies.
I will try, but taking more than 2 months to reply isn't sustainable, I think. Let's hope you can get some more bandwidth for reviews when moving forward.
Quoted 17 lines
Quoted 17 lines
--- drivers/base/base.h | 18 ++++++++ drivers/base/core.c | 77 ++++++++++++++++++++++++++--------- drivers/base/driver.c | 7 ++++ include/linux/device.h | 2 + include/linux/device/driver.h | 7 ++++ 5 files changed, 91 insertions(+), 20 deletions(-)drivers/base/base.h +0
-0@@ -196,6 +196,24 @@ static inline void dev_sync_state(struct device *dev) dev->driver->sync_state (dev); }Quoted 8 lines
drivers/base/base.h static inline void dev_sync_state(struct device *dev) · line 199
Quoted 1 line
drivers/base/base.h +1
-0+static inline bool dev_has_queue_sync_state (struct device *dev)Let's please pick a better name. This is too similar to the actual queue function you call
__device_links_queue_sync_state()and is very confusing. Maybe something that has a meaning along the lines of "another consumer probed". So, maybe:
*consumer_probed()
*change_of_active_consumers()Quoted 7 lines
The whole point of naming it "
queue_sync_state" was exactly to refer to__device_links_queue_sync_state(). The point is, the callback can't be invoked unless__device_links_queue_sync_state()has been called for the device first.Not sure why you think that is confusing? To me, that is rather the opposite. :-)
sync_state()is a callback telling the driver that it's okay to sync the state of the hardware with the software.
queue_sync_state()means nothing to the driver. It's just leaking an internal implementation detail (name of the internal function) to the driver that's not really relevant. What you are really telling the driver is that some additional consumers have probed.Quoted 5 lines
Before deciding on another name, note also that
__device_links_queue_sync_state()is called when resumingsync_statefromdevice_links_supplier_sync_state_resume()and fromdevice_links_driver_bound(). I am not sure "consumer_probed" a good name that covers both of these cases; what do you think?Yes, I'm well aware of that :) The contract of
sync_state()is that it'll come after a point where it's safe to sync the state. Not "as soon as it's safe" -- meaning no timing guarantee. Really, this is just to make suresync_state()doesn't come before late initcalls (because a lot of frameworks make assumptions around it) are done and before all the top level devices are added.So, even today,
sync_state()can come a bit late. In general, the driver framework doesn't guarantee immediate action. There is no guarantee that a drive probe will be called as soon as it's registered (if there is a device) and vice versa. The same will be true for a "consumer_probed()" callback too.
Quoted 4 lines
Also, your implementation is literally trying to check which consumers have probed and which ones haven't. So something like "
consumer_probed()" or "consumer_change()" should work well and is actually meaningful for a driver developer.
I have no strong opinion on the name, so if you prefer "consumer_probed|changed", let me just pick one of them then.
[...]
Kind regards
Uffe
Re: [PATCH v3 02/13] driver core: Enable suppliers to implement fine grained sync_state support
Quoted 103 lines · Ulf Hansson
Quoted 101 lines · Saravana Kannan
Quoted 63 lines · Ulf Hansson
Quoted 25 lines · Saravana Kannan
Quoted 14 lines · Ulf Hansson
The common
sync_statesupport isn't fine grained enough for some types of suppliers, like power domains for example. Especially when a supplier provides multiple independent power domains, each with their own set of consumers. In these cases we need to wait for all consumers for all the provided power domains before invoking the supplier's ->sync_state().To allow a more fine grained
sync_statesupport to be implemented on per supplier's driver basis, let's add a new optional callback. As soon as there is an update worth to consider in regards to managingsync_statefor a supplier device,__device_links_queue_sync_state()queues the device in a list, allowing the new callback to be invoked when flushing the list indevice_links_flush_sync_list().Quoted 8 lines
Signed-off-by Ulf Hansson <[email protected]>---
Changes in v3:
- Re-worked the approach to use a list to queue/flush devices for ->queue_sync_state(). This should make sure the device lock is being held when it's needed, as pointed out by Danilo.Quoted 5 lines
Hi Ulf,
Thanks for working on this!
And please bear with my slow replies.
I will try, but taking more than 2 months to reply isn't sustainable, I think. Let's hope you can get some more bandwidth for reviews when moving forward.
Quoted 17 lines
Quoted 17 lines
--- drivers/base/base.h | 18 ++++++++ drivers/base/core.c | 77 ++++++++++++++++++++++++++--------- drivers/base/driver.c | 7 ++++ include/linux/device.h | 2 + include/linux/device/driver.h | 7 ++++ 5 files changed, 91 insertions(+), 20 deletions(-)drivers/base/base.h +0
-0@@ -196,6 +196,24 @@ static inline void dev_sync_state(struct device *dev) dev->driver->sync_state (dev); }Quoted 8 lines
drivers/base/base.h static inline void dev_sync_state(struct device *dev) · line 199
Quoted 1 line
drivers/base/base.h +1
-0+static inline bool dev_has_queue_sync_state (struct device *dev)Let's please pick a better name. This is too similar to the actual queue function you call
__device_links_queue_sync_state()and is very confusing. Maybe something that has a meaning along the lines of "another consumer probed". So, maybe:
*consumer_probed()
*change_of_active_consumers()Quoted 7 lines
The whole point of naming it "
queue_sync_state" was exactly to refer to__device_links_queue_sync_state(). The point is, the callback can't be invoked unless__device_links_queue_sync_state()has been called for the device first.Not sure why you think that is confusing? To me, that is rather the opposite. :-)
sync_state()is a callback telling the driver that it's okay to sync the state of the hardware with the software.
queue_sync_state()means nothing to the driver. It's just leaking an internal implementation detail (name of the internal function) to the driver that's not really relevant. What you are really telling the driver is that some additional consumers have probed.Quoted 5 lines
Before deciding on another name, note also that
__device_links_queue_sync_state()is called when resumingsync_statefromdevice_links_supplier_sync_state_resume()and fromdevice_links_driver_bound(). I am not sure "consumer_probed" a good name that covers both of these cases; what do you think?Yes, I'm well aware of that :) The contract of
sync_state()is that it'll come after a point where it's safe to sync the state. Not "as soon as it's safe" -- meaning no timing guarantee. Really, this is just to make suresync_state()doesn't come before late initcalls (because a lot of frameworks make assumptions around it) are done and before all the top level devices are added.So, even today,
sync_state()can come a bit late. In general, the driver framework doesn't guarantee immediate action. There is no guarantee that a drive probe will be called as soon as it's registered (if there is a device) and vice versa. The same will be true for a "consumer_probed()" callback too.
Quoted 7 lines
Quoted 4 lines
Also, your implementation is literally trying to check which consumers have probed and which ones haven't. So something like "
consumer_probed()" or "consumer_change()" should work well and is actually meaningful for a driver developer.I have no strong opinion on the name, so if you prefer "consumer_probed|changed", let me just pick one of them then.
Thanks for taking my input.
I'm thinking "consumer_state_changed()" would be good because:
1. Not using "probed" because we might need to send this in the future when a consumer gets deleted.
2. Adding "state" because "consumer_changed()" could be mistaken to mean the actual consumer(s) changed.
With that said, I don't have a strong preference between consumer_probed(), consumer_changed() or consumer_state_changed().
Thanks,
Saravana
PATCH v3 3/13 driver core: Add documentation for dev_set_drv_sync_state()
In reply to Ulf HanssonAs dev_set_drv_sync_state() is an exported function, let's add some documentation of it.
---
Changes in v3:
- New patch.
--- include/linux/device.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/linux/device.h +8 -0
@@ -1077,6 +1077,14 @@ static inline bool dev_has_sync_state(struct device *dev)return false; } +/** +* dev_set_drv_sync_state - Assign the ->sync_state callback for a device. +* @dev: The device. +* @fn: The callback. +* +* This function dynamically tries to assign the driver's ->sync_state() +* callback for the corresponding @dev. +*/ static inline int dev_set_drv_sync_state (struct device *dev,void (*fn)(struct device *dev)) {
Signature · 1 line
2.43.0
PATCH v3 4/13 driver core: Add dev_set_drv_queue_sync_state()
In reply to Ulf HanssonSimilar to the dev_set_drv_sync_state() helper, let's add another one to allow subsystem level code to set the ->queue_sync_state() callback for a driver that has not already set it.
---
Changes in v3:
- Added documentation.
--- include/linux/device.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
include/linux/device.h +20 -0
@@ -1097,6 +1097,26 @@ static inline int dev_set_drv_sync_state(struct device *dev,return 0 ; } +/** +* dev_set_drv_sync_state - Assign the ->queue_sync_state callback for a device. +* @dev: The device. +* @fn: The callback. +* +* This function dynamically tries to assign the driver's ->queue_sync_state() +* callback for the corresponding @dev. +*/ +static inline int dev_set_drv_queue_sync_state (struct device *dev, +void (*fn)(struct device *dev)) +{ +if (!dev || !dev->driver) +return 0 ; +if (dev->driver->queue_sync_state && dev->driver->queue_sync_state != fn) +return -EBUSY ; +if (!dev->driver->queue_sync_state) + dev->driver->queue_sync_state = fn; +return 0 ; +} +static inline void dev_set_removable (struct device *dev,enum device_removable removable) {
Signature · 1 line
2.43.0
PATCH v3 5/13 pmdomain: core: Move genpd_get_from_provider()
In reply to Ulf HanssonTo prepare for subsequent changes and to avoid an unnecessary function declaration, let's move genpd_get_from_provider() a bit earlier in the code.
---
Changes in v3:
- No change.
--- drivers/pmdomain/core.c | 70 ++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 35 deletions(-)
drivers/pmdomain/core.c +35 -35
@@ -2664,6 +2664,41 @@ static bool genpd_present(const struct generic_pm_domain *genpd)return ret; } +/** +* genpd_get_from_provider() - Look-up PM domain +* @genpdspec: OF phandle args to use for look-up +* +* Looks for a PM domain provider under the node specified by @genpdspec and if +* found, uses xlate function of the provider to map phandle args to a PM +* domain. +* +* Returns a valid pointer to struct generic_pm_domain on success or ERR_PTR() +* on failure. +*/ +static struct generic_pm_domain *genpd_get_from_provider ( +const struct of_phandle_args *genpdspec) +{ +struct generic_pm_domain *genpd =ERR_PTR (-ENOENT ); +struct of_genpd_provider *provider; + +if (!genpdspec) +return ERR_PTR (-EINVAL ); + +mutex_lock (&of_genpd_mutex); + +/* Check if we have such a provider in our array */ +list_for_each_entry (provider, &of_genpd_providers, link) { +if (provider->node == genpdspec->np) + genpd = provider->xlate (genpdspec, provider->data); +if (!IS_ERR (genpd)) +break ; + } + +mutex_unlock (&of_genpd_mutex); + +return genpd; +} +static void genpd_sync_state (struct device *dev) {return of_genpd_sync_state (dev->of_node);
@@ -2889,41 +2924,6 @@ void of_genpd_del_provider(struct device_node *np) }EXPORT_SYMBOL_GPL (of_genpd_del_provider); -/** -* genpd_get_from_provider() - Look-up PM domain -* @genpdspec: OF phandle args to use for look-up -* -* Looks for a PM domain provider under the node specified by @genpdspec and if -* found, uses xlate function of the provider to map phandle args to a PM -* domain. -* -* Returns a valid pointer to struct generic_pm_domain on success or ERR_PTR() -* on failure. -*/ -static struct generic_pm_domain *genpd_get_from_provider ( -const struct of_phandle_args *genpdspec) -{ -struct generic_pm_domain *genpd =ERR_PTR (-ENOENT ); -struct of_genpd_provider *provider; - -if (!genpdspec) -return ERR_PTR (-EINVAL ); - -mutex_lock (&of_genpd_mutex); - -/* Check if we have such a provider in our array */ -list_for_each_entry (provider, &of_genpd_providers, link) { -if (provider->node == genpdspec->np) - genpd = provider->xlate (genpdspec, provider->data); -if (!IS_ERR (genpd)) -break ; - } - -mutex_unlock (&of_genpd_mutex); - -return genpd; -} -/** * of_genpd_add_device() - Add a device to an I/O PM domain * @genpdspec: OF phandle args to use for look-up PM domain
Signature · 1 line
2.43.0
PATCH v3 6/13 pmdomain: core: Add initial fine grained sync_state support
In reply to Ulf HanssonA onecell (#power-domain-cells = <1 or 2>; in DT) power domain provider typically provides multiple independent power domains, each with their own corresponding consumers. In these cases we have to wait for all consumers for all the provided power domains before the ->sync_state() callback gets called for the supplier.
In a first step to improve this, let's implement support for fine grained sync_state support a per genpd basis by using the ->queue_sync_state() callback. To take step by step, let's initially limit the improvement to the internal genpd provider driver and to its corresponding genpd devices for onecell providers.
---
Changes in v3:
- Addressed some cosmetic comments from Geert.
--- drivers/pmdomain/core.c | 124 ++++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 1 + 2 files changed, 125 insertions(+)
drivers/pmdomain/core.c +124 -0
@@ -2699,6 +2699,119 @@ static struct generic_pm_domain *genpd_get_from_provider(return genpd; } +static bool genpd_should_wait_for_consumer (struct device_node *np) +{ +struct generic_pm_domain *genpd; +bool should_wait = false; + +mutex_lock (&gpd_list_lock); +list_for_each_entry (genpd, &gpd_list, gpd_list_node) { +if (genpd->provider ==of_fwnode_handle (np)) { +genpd_lock (genpd); + +/* Clear the previous state before reevaluating. */ + genpd->wait_for_consumer = false; + +/* +* Unless there is at least one genpd for the provider +* that is being kept powered-on, we don't have to care +* about waiting for consumers. +*/ +if (genpd->stay_on) + should_wait = true; + +genpd_unlock (genpd); + } + } +mutex_unlock (&gpd_list_lock); + +return should_wait; +} + +static void genpd_parse_for_consumer (struct device_node *sup, +struct device_node *con) +{ +struct generic_pm_domain *genpd; + +for (unsigned int i =0 ; ; i++) { +struct of_phandle_args pd_args; + +if (of_parse_phandle_with_args (con,"power-domains" , +"#power-domain-cells" , + i, &pd_args)) +break ; + +/* +* The phandle must correspond to the supplier's genpd provider +* to be relevant else let's move to the next index. +*/ +if (sup != pd_args.np) { +of_node_put (pd_args.np); +continue ; + } + +mutex_lock (&gpd_list_lock); + genpd =genpd_get_from_provider (&pd_args); +if (!IS_ERR (genpd)) { +genpd_lock (genpd); + genpd->wait_for_consumer = true; +genpd_unlock (genpd); + } +mutex_unlock (&gpd_list_lock); + +of_node_put (pd_args.np); + } +} + +static void _genpd_queue_sync_state (struct device_node *np) +{ +struct generic_pm_domain *genpd; + +mutex_lock (&gpd_list_lock); +list_for_each_entry (genpd, &gpd_list, gpd_list_node) { +if (genpd->provider ==of_fwnode_handle (np)) { +genpd_lock (genpd); +if (genpd->stay_on && !genpd->wait_for_consumer) { + genpd->stay_on = false; +genpd_queue_power_off_work (genpd); + } +genpd_unlock (genpd); + } + } +mutex_unlock (&gpd_list_lock); +} + +static void genpd_queue_sync_state (struct device *dev) +{ +struct device_node *np = dev->of_node; +struct device_link *link; + +if (!genpd_should_wait_for_consumer (np)) +return ; + +list_for_each_entry (link, &dev->links.consumers, s_node) { +struct device *consumer = link->consumer; + +if (!device_link_test (link,DL_FLAG_MANAGED )) +continue ; + +if (link->status ==DL_STATE_ACTIVE ) +continue ; + +if (!consumer->of_node) +continue ; + +/* +* A consumer device has not been probed yet. Let's parse its +* device node for the power-domains property, to find out the +* genpds it may belong to and then prevent sync state for them. +*/ +genpd_parse_for_consumer (np, consumer->of_node); + } + +_genpd_queue_sync_state (np); +} +static void genpd_sync_state (struct device *dev) {return of_genpd_sync_state (dev->of_node);
@@ -3531,6 +3644,16 @@ static int genpd_provider_probe(struct device *dev)return 0 ; } +static void genpd_provider_queue_sync_state (struct device *dev) +{ + struct generic_pm_domain *genpd = container_of(dev, struct generic_pm_domain, dev); + +if (genpd->sync_state !=GENPD_SYNC_STATE_ONECELL ) +return ; + +genpd_queue_sync_state (dev); +} +static void genpd_provider_sync_state (struct device *dev) { struct generic_pm_domain *genpd = container_of(dev, struct generic_pm_domain, dev);
@@ -3559,6 +3682,7 @@ static struct device_driver genpd_provider_drv = { .name = "genpd_provider", .bus = &genpd_provider_bus_type, .probe = genpd_provider_probe, + .queue_sync_state = genpd_provider_queue_sync_state, .sync_state = genpd_provider_sync_state, .suppress_bind_attrs = true, };
include/linux/pm_domain.h +1 -0
@@ -215,6 +215,7 @@ struct generic_pm_domain {cpumask_var_t cpus;/* A cpumask of the attached CPUs */ bool synced_poweroff;/* A consumer needs a synced poweroff */ bool stay_on;/* Stay powered-on during boot. */ +bool wait_for_consumer;/* Consumers awaits to be probed. */ enum genpd_sync_state sync_state;/* How sync_state is managed. */ int (*power_off)(struct generic_pm_domain *domain);int (*power_on)(struct generic_pm_domain *domain);
Signature · 1 line
2.43.0
Re: [PATCH v3 06/13] pmdomain: core: Add initial fine grained sync_state support
Quoted 47 lines · Ulf Hansson
A onecell (#power-domain-cells = <1 or 2>; in DT) power domain provider typically provides multiple independent power domains, each with their own corresponding consumers. In these cases we have to wait for all consumers for all the provided power domains before the ->sync_state() callback gets called for the supplier.
In a first step to improve this, let's implement support for fine grained
sync_statesupport a per genpd basis by using the ->queue_sync_state() callback. To take step by step, let's initially limit the improvement to the internal genpd provider driver and to its corresponding genpd devices for onecell providers.Signed-off-by Ulf Hansson <[email protected]>---
Changes in v3:
- Addressed some cosmetic comments from Geert.--- drivers/pmdomain/core.c | 124 ++++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 1 + 2 files changed, 125 insertions(+)drivers/pmdomain/core.c +15
-0@@ -2699,6 +2699,119 @@ static struct generic_pm_domain *genpd_get_from_provider(return genpd; } +static bool genpd_should_wait_for_consumer (struct device_node *np) +{ +struct generic_pm_domain *genpd; +bool should_wait = false; + +mutex_lock (&gpd_list_lock); +list_for_each_entry (genpd, &gpd_list, gpd_list_node) { +if (genpd->provider ==of_fwnode_handle (np)) { +genpd_lock (genpd); + +/* Clear the previous state before reevaluating. */ + genpd->wait_for_consumer = false; + +/* +* Unless there is at least one genpd for the provider
drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2726
Quoted 10 lines
drivers/pmdomain/core.c +10
-0+* that is being kept powered-on, we don't have to care +* about waiting for consumers. +*/ +if (genpd->stay_on) + should_wait = true; + +genpd_unlock (genpd); + } + } +mutex_unlock (&gpd_list_lock);
I think I understand the intent of this function, but haven't dug into genpd code enough to comment on this yet. I'll come back to this later.
Quoted 6 lines
drivers/pmdomain/core.c +6
-0+ +return should_wait; +} + +static void genpd_parse_for_consumer (struct device_node *sup, +struct device_node *con)
drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2742
Quoted 10 lines
drivers/pmdomain/core.c +10
-0+{ +struct generic_pm_domain *genpd; + +for (unsigned int i =0 ; ; i++) { +struct of_phandle_args pd_args; + +if (of_parse_phandle_with_args (con,"power-domains" , +"#power-domain-cells" , + i, &pd_args)) +break ;
Why not use a while or a do while() instead of this infinite for loop with a break?
Quoted 40 lines
drivers/pmdomain/core.c +40
-0+ +/* +* The phandle must correspond to the supplier's genpd provider +* to be relevant else let's move to the next index. +*/ +if (sup != pd_args.np) { +of_node_put (pd_args.np); +continue ; + } + +mutex_lock (&gpd_list_lock); + genpd =genpd_get_from_provider (&pd_args); +if (!IS_ERR (genpd)) { +genpd_lock (genpd); + genpd->wait_for_consumer = true; +genpd_unlock (genpd); + } +mutex_unlock (&gpd_list_lock); + +of_node_put (pd_args.np); + } +} + +static void _genpd_queue_sync_state (struct device_node *np) +{ +struct generic_pm_domain *genpd; + +mutex_lock (&gpd_list_lock); +list_for_each_entry (genpd, &gpd_list, gpd_list_node) { +if (genpd->provider ==of_fwnode_handle (np)) { +genpd_lock (genpd); +if (genpd->stay_on && !genpd->wait_for_consumer) { + genpd->stay_on = false; +genpd_queue_power_off_work (genpd); + } +genpd_unlock (genpd); + } + } +mutex_unlock (&gpd_list_lock); +}
drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2792
Quoted 10 lines
drivers/pmdomain/core.c +10
-0+ +static void genpd_queue_sync_state (struct device *dev) +{ +struct device_node *np = dev->of_node; +struct device_link *link; + +if (!genpd_should_wait_for_consumer (np)) +return ; + +list_for_each_entry (link, &dev->links.consumers, s_node) {
Couple of issues:
1. I don't want the frameworks to be so deeply aware of driver core internals. I want the driver core maintainers to be able to change the devlink implementation without having to worry about going and fixing all the frameworks. So, please add a for_each_consumer_dev(supplier, callback) and for_each_supplier_dev(consumer, callback) helper functions.
2. This doesn't ignore "SYNC_STATE_ONLY" links and that's going to confuse the consumer count/check you might do or at the least waste parsing those.
3. **Device** links are not the complete list of consumers because they can only link consumer **devices** once the consumer **device** is created.
4. What you really need is a for_each_consumer_fwnode(supplier, callback) that first loops through all the consumer device links and calls the callback() on their fwnode and then the same function needs to loop through all the fwnode links and then pass those consumer fwnodes to the callback. And inside that callback you can do whatever you want.
5. You might want to add a for_each_inactive_consumer(supplier, callback) too to simplify your need for checking if a fwnode has a device and then checking if it's probed.
Thanks,
Saravana
Quoted 65 lines
drivers/pmdomain/core.c +33
-0+struct device *consumer = link->consumer; + +if (!device_link_test (link,DL_FLAG_MANAGED )) +continue ; + +if (link->status ==DL_STATE_ACTIVE ) +continue ; + +if (!consumer->of_node) +continue ; + +/* +* A consumer device has not been probed yet. Let's parse its +* device node for the power-domains property, to find out the +* genpds it may belong to and then prevent sync state for them. +*/ +genpd_parse_for_consumer (np, consumer->of_node); + } + +_genpd_queue_sync_state (np); +} +static void genpd_sync_state (struct device *dev) {return of_genpd_sync_state (dev->of_node);@@ -3531,6 +3644,16 @@ static int genpd_provider_probe(struct device *dev)return 0 ; } +static void genpd_provider_queue_sync_state (struct device *dev) +{ + struct generic_pm_domain *genpd = container_of(dev, struct generic_pm_domain, dev); + +if (genpd->sync_state !=GENPD_SYNC_STATE_ONECELL ) +return ; + +genpd_queue_sync_state (dev); +} +static void genpd_provider_sync_state (struct device *dev) { struct generic_pm_domain *genpd = container_of(dev, struct generic_pm_domain, dev);@@ -3559,6 +3682,7 @@ static struct device_driver genpd_provider_drv = { .name = "genpd_provider", .bus = &genpd_provider_bus_type, .probe = genpd_provider_probe, + .queue_sync_state = genpd_provider_queue_sync_state, .sync_state = genpd_provider_sync_state, .suppress_bind_attrs = true, };include/linux/pm_domain.h +1
-1@@ -215,6 +215,7 @@ struct generic_pm_domain {cpumask_var_t cpus;/* A cpumask of the attached CPUs */ bool synced_poweroff;/* A consumer needs a synced poweroff */ bool stay_on;/* Stay powered-on during boot. */ +bool wait_for_consumer;/* Consumers awaits to be probed. */ enum genpd_sync_state sync_state;/* How sync_state is managed. */ int (*power_off)(struct generic_pm_domain *domain);int (*power_on)(struct generic_pm_domain *domain); --2.43.0
Re: [PATCH v3 06/13] pmdomain: core: Add initial fine grained sync_state support
Quoted 75 lines · Saravana Kannan
Quoted 47 lines · Ulf Hansson
A onecell (#power-domain-cells = <1 or 2>; in DT) power domain provider typically provides multiple independent power domains, each with their own corresponding consumers. In these cases we have to wait for all consumers for all the provided power domains before the ->sync_state() callback gets called for the supplier.
In a first step to improve this, let's implement support for fine grained
sync_statesupport a per genpd basis by using the ->queue_sync_state() callback. To take step by step, let's initially limit the improvement to the internal genpd provider driver and to its corresponding genpd devices for onecell providers.Signed-off-by Ulf Hansson <[email protected]>---
Changes in v3:
- Addressed some cosmetic comments from Geert.--- drivers/pmdomain/core.c | 124 ++++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 1 + 2 files changed, 125 insertions(+)drivers/pmdomain/core.c +15
-0@@ -2699,6 +2699,119 @@ static struct generic_pm_domain *genpd_get_from_provider(return genpd; } +static bool genpd_should_wait_for_consumer (struct device_node *np) +{ +struct generic_pm_domain *genpd; +bool should_wait = false; + +mutex_lock (&gpd_list_lock); +list_for_each_entry (genpd, &gpd_list, gpd_list_node) { +if (genpd->provider ==of_fwnode_handle (np)) { +genpd_lock (genpd); + +/* Clear the previous state before reevaluating. */ + genpd->wait_for_consumer = false; + +/* +* Unless there is at least one genpd for the provider drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2726
Quoted 10 lines
drivers/pmdomain/core.c +10
-0+* that is being kept powered-on, we don't have to care +* about waiting for consumers. +*/ +if (genpd->stay_on) + should_wait = true; + +genpd_unlock (genpd); + } + } +mutex_unlock (&gpd_list_lock);I think I understand the intent of this function, but haven't dug into genpd code enough to comment on this yet. I'll come back to this later.
Quoted 11 lines
drivers/pmdomain/core.c +11
-0+ +return should_wait; +} + +static void genpd_parse_for_consumer (struct device_node *sup, +struct device_node *con) +{ +struct generic_pm_domain *genpd; + +for (unsigned int i =0 ; ; i++) { +struct of_phandle_args pd_args;
Quoted 8 lines
drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2742
Quoted 5 lines
drivers/pmdomain/core.c +5
-0+ +if (of_parse_phandle_with_args (con,"power-domains" , +"#power-domain-cells" , + i, &pd_args)) +break ;Why not use a while or a do
while()instead of this infinite for loop with a break?
I guess it's a matter of personal preference. I'm not sure the code gets any nicer with a do/while, but if you really insist I can change it.
Quoted 52 lines
Quoted 41 lines
drivers/pmdomain/core.c +40
-0+ +/* +* The phandle must correspond to the supplier's genpd provider +* to be relevant else let's move to the next index. +*/ +if (sup != pd_args.np) { +of_node_put (pd_args.np); +continue ; + } + +mutex_lock (&gpd_list_lock); + genpd =genpd_get_from_provider (&pd_args); +if (!IS_ERR (genpd)) { +genpd_lock (genpd); + genpd->wait_for_consumer = true; +genpd_unlock (genpd); + } +mutex_unlock (&gpd_list_lock); + +of_node_put (pd_args.np); + } +} + +static void _genpd_queue_sync_state (struct device_node *np) +{ +struct generic_pm_domain *genpd; + +mutex_lock (&gpd_list_lock); +list_for_each_entry (genpd, &gpd_list, gpd_list_node) { +if (genpd->provider ==of_fwnode_handle (np)) { +genpd_lock (genpd); +if (genpd->stay_on && !genpd->wait_for_consumer) { + genpd->stay_on = false; +genpd_queue_power_off_work (genpd); + } +genpd_unlock (genpd); + } + } +mutex_unlock (&gpd_list_lock); +}drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2792
Quoted 10 lines
drivers/pmdomain/core.c +10
-0+ +static void genpd_queue_sync_state (struct device *dev) +{ +struct device_node *np = dev->of_node; +struct device_link *link; + +if (!genpd_should_wait_for_consumer (np)) +return ; + +list_for_each_entry (link, &dev->links.consumers, s_node) {
Quoted 7 lines
Couple of issues:
1. I don't want the frameworks to be so deeply aware of driver core internals. I want the driver core maintainers to be able to change the devlink implementation without having to worry about going and fixing all the frameworks. So, please add afor_each_consumer_dev(supplier, callback)andfor_each_supplier_dev(consumer, callback)helper functions.
I understand your concern and I like the idea. However, maybe it's better to get this landed (the series is complicated as is) first and then can continue to improve the code on top, with helper functions etc.
Quoted 4 lines
2. This doesn't ignore "
SYNC_STATE_ONLY" links and that's going to confuse the consumer count/check you might do or at the least waste parsing those.
I am not sure I understand how I should take SYNC_STATE_ONLY links into account here.
At each call to the genpd_queue_sync_state(), we walk through all the provided genpds for the provider. No previous state is cached to track consumer counts.
Quoted 11 lines
3. **Device** links are not the complete list of consumers because they can only link consumer **devices** once the consumer **device** is created.
4. What you really need is a
for_each_consumer_fwnode(supplier, callback)that first loops through all the consumer device links and calls thecallback()on their fwnode and then the same function needs to loop through all the fwnode links and then pass those consumer fwnodes to the callback. And inside that callback you can do whatever you want.
The ->queue_sync_state() callback is invoked *after* __device_links_queue_sync_state() has been called for the device, which is also when the conditions for calling ->sync_state() is checked.
If there are problems with not yet registered consumer device links, why isn't that as problem for regular ->sync_state() in __device_links_queue_sync_state()?
Quoted 23 lines
5. You might want to add a
for_each_inactive_consumer(supplier, callback)too to simplify your need for checking if a fwnode has a device and then checking if it's probed.Thanks,
SaravanaQuoted 14 lines
drivers/pmdomain/core.c +14
-0+struct device *consumer = link->consumer; + +if (!device_link_test (link,DL_FLAG_MANAGED )) +continue ; + +if (link->status ==DL_STATE_ACTIVE ) +continue ; + +if (!consumer->of_node) +continue ; + +/* +* A consumer device has not been probed yet. Let's parse its +* device node for the power-domains property, to find out the
Quoted 8 lines
drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2814
Quoted 8 lines
drivers/pmdomain/core.c +8
-0+* genpds it may belong to and then prevent sync state for them. +*/ +genpd_parse_for_consumer (np, consumer->of_node); + } + +_genpd_queue_sync_state (np); +} +
[...]
Kind regards
Uffe
Re: [PATCH v3 06/13] pmdomain: core: Add initial fine grained sync_state support
Quoted 150 lines · Ulf Hansson
Quoted 75 lines · Saravana Kannan
Quoted 47 lines · Ulf Hansson
A onecell (#power-domain-cells = <1 or 2>; in DT) power domain provider typically provides multiple independent power domains, each with their own corresponding consumers. In these cases we have to wait for all consumers for all the provided power domains before the ->sync_state() callback gets called for the supplier.
In a first step to improve this, let's implement support for fine grained
sync_statesupport a per genpd basis by using the ->queue_sync_state() callback. To take step by step, let's initially limit the improvement to the internal genpd provider driver and to its corresponding genpd devices for onecell providers.Signed-off-by Ulf Hansson <[email protected]>---
Changes in v3:
- Addressed some cosmetic comments from Geert.--- drivers/pmdomain/core.c | 124 ++++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 1 + 2 files changed, 125 insertions(+)drivers/pmdomain/core.c +15
-0@@ -2699,6 +2699,119 @@ static struct generic_pm_domain *genpd_get_from_provider(return genpd; } +static bool genpd_should_wait_for_consumer (struct device_node *np) +{ +struct generic_pm_domain *genpd; +bool should_wait = false; + +mutex_lock (&gpd_list_lock); +list_for_each_entry (genpd, &gpd_list, gpd_list_node) { +if (genpd->provider ==of_fwnode_handle (np)) { +genpd_lock (genpd); + +/* Clear the previous state before reevaluating. */ + genpd->wait_for_consumer = false; + +/* +* Unless there is at least one genpd for the provider drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2726
Quoted 10 lines
drivers/pmdomain/core.c +10
-0+* that is being kept powered-on, we don't have to care +* about waiting for consumers. +*/ +if (genpd->stay_on) + should_wait = true; + +genpd_unlock (genpd); + } + } +mutex_unlock (&gpd_list_lock);I think I understand the intent of this function, but haven't dug into genpd code enough to comment on this yet. I'll come back to this later.
Quoted 11 lines
drivers/pmdomain/core.c +11
-0+ +return should_wait; +} + +static void genpd_parse_for_consumer (struct device_node *sup, +struct device_node *con) +{ +struct generic_pm_domain *genpd; + +for (unsigned int i =0 ; ; i++) { +struct of_phandle_args pd_args;Quoted 8 lines
drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2742
Quoted 5 lines
drivers/pmdomain/core.c +5
-0+ +if (of_parse_phandle_with_args (con,"power-domains" , +"#power-domain-cells" , + i, &pd_args)) +break ;Why not use a while or a do
while()instead of this infinite for loop with a break?I guess it's a matter of personal preference. I'm not sure the code gets any nicer with a do/while, but if you really insist I can change it.
Quoted 52 lines
Quoted 41 lines
drivers/pmdomain/core.c +40
-0+ +/* +* The phandle must correspond to the supplier's genpd provider +* to be relevant else let's move to the next index. +*/ +if (sup != pd_args.np) { +of_node_put (pd_args.np); +continue ; + } + +mutex_lock (&gpd_list_lock); + genpd =genpd_get_from_provider (&pd_args); +if (!IS_ERR (genpd)) { +genpd_lock (genpd); + genpd->wait_for_consumer = true; +genpd_unlock (genpd); + } +mutex_unlock (&gpd_list_lock); + +of_node_put (pd_args.np); + } +} + +static void _genpd_queue_sync_state (struct device_node *np) +{ +struct generic_pm_domain *genpd; + +mutex_lock (&gpd_list_lock); +list_for_each_entry (genpd, &gpd_list, gpd_list_node) { +if (genpd->provider ==of_fwnode_handle (np)) { +genpd_lock (genpd); +if (genpd->stay_on && !genpd->wait_for_consumer) { + genpd->stay_on = false; +genpd_queue_power_off_work (genpd); + } +genpd_unlock (genpd); + } + } +mutex_unlock (&gpd_list_lock); +}drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2792
Quoted 10 lines
drivers/pmdomain/core.c +10
-0+ +static void genpd_queue_sync_state (struct device *dev) +{ +struct device_node *np = dev->of_node; +struct device_link *link; + +if (!genpd_should_wait_for_consumer (np)) +return ; + +list_for_each_entry (link, &dev->links.consumers, s_node) {Quoted 7 lines
Couple of issues:
1. I don't want the frameworks to be so deeply aware of driver core internals. I want the driver core maintainers to be able to change the devlink implementation without having to worry about going and fixing all the frameworks. So, please add afor_each_consumer_dev(supplier, callback)andfor_each_supplier_dev(consumer, callback)helper functions.
Quoted 4 lines
I understand your concern and I like the idea. However, maybe it's better to get this landed (the series is complicated as is) first and then can continue to improve the code on top, with helper functions etc.
That patch should be pretty simple, so let's just do it? You are literally just moving the code to another file and massaging it a bit. I can send one out if you want/
Quoted 11 lines
Quoted 4 lines
2. This doesn't ignore "
SYNC_STATE_ONLY" links and that's going to confuse the consumer count/check you might do or at the least waste parsing those.I am not sure I understand how I should take
SYNC_STATE_ONLYlinks into account here.At each call to the
genpd_queue_sync_state(), we walk through all the provided genpds for the provider. No previous state is cached to track consumer counts.
Ok, correct me if I'm wrong here, but it looks like you are looking at all the consumers, finding the ones that haven't probed yet and then trying to see which specific genpd provider each one of them is using by parsing their dt properties and then keep those ON.
If my understanding above is wrong then, please help me understand what the code is trying to do.
If it's right, then here's the issue:
fw_devlink relies on device links and fwnode links to keep track of consumers. fwnode links get created first and then get converted to device links when both the supplier AND consumer devices are created.
Consider a case when the supplier S is created and the consumer device C is several levels deep inside a parent device A.
S { #power-domain-cells = <1>; }
A { B { C { power-domains = <&S MY_DOMAIN>; } } }
fw_devlink can't just go "oh there's no consumer device that hasn't probed yet, let me call sync_state()". It needs to wait for C. But there's no way to create a device link to C. So, here's the sequence that happens:
1. When device A gets added, it creates a "proxy" SYNC_STATE_ONLY link between S and A.
2. When A probes, it adds device B.
3. The SYNC_STATE_ONLY link between S to B is created.
4. The SYNC_STATE_ONLY link between S to A is deleted.
5. When B probes, it adds device C.
6. The actual device link between S and C is created.
7. The SYNC_STATE_ONLY link between S to B is deleted.
8. Device C probes, the device links get updated, sync_state() gets called.
So, if your code doesn't account for SYNC_STATE_ONLY links, you are going to check device "A" to see which providers are used. You'll think that MY_DOMAIN isn't used by any unprobed consumer and turn it off.
Quoted 13 lines
Quoted 6 lines
3. **Device** links are not the complete list of consumers because they can only link consumer **devices** once the consumer **device** is created.
Quoted 6 lines
4. What you really need is a
for_each_consumer_fwnode(supplier, callback)that first loops through all the consumer device links and calls thecallback()on their fwnode and then the same function needs to loop through all the fwnode links and then pass those consumer fwnodes to the callback. And inside that callback you can do whatever you want.
Quoted 4 lines
The ->queue_sync_state() callback is invoked *after*
__device_links_queue_sync_state()has been called for the device, which is also when the conditions for calling ->sync_state() is checked.
I'm not sure what you are trying to say here. Yes, what you are saying is true. But at the point the current code returns before calling sync_state(), your patch 2/13 ends up calling the "consumer_probed()" callback.
If you see the example I gave above, there is a SYNC_STATE_ONLY link all the way up to step 7 that'll prevent sync_state() from being called. And until step 5, there is no device link between S and C and you'll have to go look at S's fwnode links to find C.
Quoted 3 lines
If there are problems with not yet registered consumer device links, why isn't that as problem for regular ->sync_state() in
__device_links_queue_sync_state()?
Does my explanation above make sense?
Welcome to the annoying worlds of fw_devlink corner cases/nuances. There's a case where the child is the supplier of the parent/grandparent. There's a comment for that in the fw_devlink code.
Thanks,
Saravana
Quoted 36 lines
Quoted 23 lines
5. You might want to add a
for_each_inactive_consumer(supplier, callback)too to simplify your need for checking if a fwnode has a device and then checking if it's probed.Thanks,
SaravanaQuoted 14 lines
drivers/pmdomain/core.c +14
-0+struct device *consumer = link->consumer; + +if (!device_link_test (link,DL_FLAG_MANAGED )) +continue ; + +if (link->status ==DL_STATE_ACTIVE ) +continue ; + +if (!consumer->of_node) +continue ; + +/* +* A consumer device has not been probed yet. Let's parse its +* device node for the power-domains property, to find out the Quoted 8 lines
drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2814
Quoted 8 lines
drivers/pmdomain/core.c +8
-0+* genpds it may belong to and then prevent sync state for them. +*/ +genpd_parse_for_consumer (np, consumer->of_node); + } + +_genpd_queue_sync_state (np); +} +[...]
Kind regards
Uffe
Re: [PATCH v3 06/13] pmdomain: core: Add initial fine grained sync_state support
Quoted 152 lines · Saravana Kannan
Quoted 150 lines · Ulf Hansson
Quoted 75 lines · Saravana Kannan
Quoted 47 lines · Ulf Hansson
A onecell (#power-domain-cells = <1 or 2>; in DT) power domain provider typically provides multiple independent power domains, each with their own corresponding consumers. In these cases we have to wait for all consumers for all the provided power domains before the ->sync_state() callback gets called for the supplier.
In a first step to improve this, let's implement support for fine grained
sync_statesupport a per genpd basis by using the ->queue_sync_state() callback. To take step by step, let's initially limit the improvement to the internal genpd provider driver and to its corresponding genpd devices for onecell providers.Signed-off-by Ulf Hansson <[email protected]>---
Changes in v3:
- Addressed some cosmetic comments from Geert.--- drivers/pmdomain/core.c | 124 ++++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 1 + 2 files changed, 125 insertions(+)drivers/pmdomain/core.c +15
-0@@ -2699,6 +2699,119 @@ static struct generic_pm_domain *genpd_get_from_provider(return genpd; } +static bool genpd_should_wait_for_consumer (struct device_node *np) +{ +struct generic_pm_domain *genpd; +bool should_wait = false; + +mutex_lock (&gpd_list_lock); +list_for_each_entry (genpd, &gpd_list, gpd_list_node) { +if (genpd->provider ==of_fwnode_handle (np)) { +genpd_lock (genpd); + +/* Clear the previous state before reevaluating. */ + genpd->wait_for_consumer = false; + +/* +* Unless there is at least one genpd for the provider drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2726
Quoted 10 lines
drivers/pmdomain/core.c +10
-0+* that is being kept powered-on, we don't have to care +* about waiting for consumers. +*/ +if (genpd->stay_on) + should_wait = true; + +genpd_unlock (genpd); + } + } +mutex_unlock (&gpd_list_lock);I think I understand the intent of this function, but haven't dug into genpd code enough to comment on this yet. I'll come back to this later.
Quoted 11 lines
drivers/pmdomain/core.c +11
-0+ +return should_wait; +} + +static void genpd_parse_for_consumer (struct device_node *sup, +struct device_node *con) +{ +struct generic_pm_domain *genpd; + +for (unsigned int i =0 ; ; i++) { +struct of_phandle_args pd_args;Quoted 8 lines
drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2742
Quoted 5 lines
drivers/pmdomain/core.c +5
-0+ +if (of_parse_phandle_with_args (con,"power-domains" , +"#power-domain-cells" , + i, &pd_args)) +break ;Why not use a while or a do
while()instead of this infinite for loop with a break?I guess it's a matter of personal preference. I'm not sure the code gets any nicer with a do/while, but if you really insist I can change it.
Quoted 59 lines
Quoted 41 lines
drivers/pmdomain/core.c +40
-0+ +/* +* The phandle must correspond to the supplier's genpd provider +* to be relevant else let's move to the next index. +*/ +if (sup != pd_args.np) { +of_node_put (pd_args.np); +continue ; + } + +mutex_lock (&gpd_list_lock); + genpd =genpd_get_from_provider (&pd_args); +if (!IS_ERR (genpd)) { +genpd_lock (genpd); + genpd->wait_for_consumer = true; +genpd_unlock (genpd); + } +mutex_unlock (&gpd_list_lock); + +of_node_put (pd_args.np); + } +} + +static void _genpd_queue_sync_state (struct device_node *np) +{ +struct generic_pm_domain *genpd; + +mutex_lock (&gpd_list_lock); +list_for_each_entry (genpd, &gpd_list, gpd_list_node) { +if (genpd->provider ==of_fwnode_handle (np)) { +genpd_lock (genpd); +if (genpd->stay_on && !genpd->wait_for_consumer) { + genpd->stay_on = false; +genpd_queue_power_off_work (genpd); + } +genpd_unlock (genpd); + } + } +mutex_unlock (&gpd_list_lock); +}drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2792
Quoted 10 lines
drivers/pmdomain/core.c +10
-0+ +static void genpd_queue_sync_state (struct device *dev) +{ +struct device_node *np = dev->of_node; +struct device_link *link; + +if (!genpd_should_wait_for_consumer (np)) +return ; + +list_for_each_entry (link, &dev->links.consumers, s_node) {Couple of issues:
1. I don't want the frameworks to be so deeply aware of driver core internals. I want the driver core maintainers to be able to change the devlink implementation without having to worry about going and fixing all the frameworks. So, please add afor_each_consumer_dev(supplier, callback)andfor_each_supplier_dev(consumer, callback)helper functions.
Quoted 8 lines
Quoted 4 lines
I understand your concern and I like the idea. However, maybe it's better to get this landed (the series is complicated as is) first and then can continue to improve the code on top, with helper functions etc.
That patch should be pretty simple, so let's just do it? You are literally just moving the code to another file and massaging it a bit. I can send one out if you want/
Okay, I will fold in a patch into my series that adds the helper. No point you sending it as it needs to be apart of my series to have a user for it.
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
2. This doesn't ignore "
SYNC_STATE_ONLY" links and that's going to confuse the consumer count/check you might do or at the least waste parsing those.I am not sure I understand how I should take
SYNC_STATE_ONLYlinks into account here.
Quoted 8 lines
Quoted 3 lines
At each call to the
genpd_queue_sync_state(), we walk through all the provided genpds for the provider. No previous state is cached to track consumer counts.Ok, correct me if I'm wrong here, but it looks like you are looking at all the consumers, finding the ones that haven't probed yet and then trying to see which specific genpd provider each one of them is using by parsing their dt properties and then keep those ON.
The code cares only about the genpd OF provider that the supplier device belongs to, if any. Any other genpd OF providers and their genpds is untouched.
The corresponding genpd OF provider may provide multiple genpds through the same fwnode.
Quoted 58 lines
If my understanding above is wrong then, please help me understand what the code is trying to do.
If it's right, then here's the issue:
fw_devlinkrelies on device links and fwnode links to keep track of consumers. fwnode links get created first and then get converted to device links when both the supplier AND consumer devices are created.Consider a case when the supplier S is created and the consumer device C is several levels deep inside a parent device A.
S { #power-domain-cells = <1>; }
A { B { C { power-domains = <&SMY_DOMAIN>; } } }
fw_devlinkcan't just go "oh there's no consumer device that hasn't probed yet, let me callsync_state()". It needs to wait for C. But there's no way to create a device link to C. So, here's the sequence that happens:1. When device A gets added, it creates a "proxy"
SYNC_STATE_ONLYlink between S and A.
2. When A probes, it adds device B.
3. TheSYNC_STATE_ONLYlink between S to B is created.
4. TheSYNC_STATE_ONLYlink between S to A is deleted.
5. When B probes, it adds device C.
6. The actual device link between S and C is created.
7. TheSYNC_STATE_ONLYlink between S to B is deleted.
8. Device C probes, the device links get updated,sync_state()gets called.So, if your code doesn't account for
SYNC_STATE_ONLYlinks, you are going to check device "A" to see which providers are used. You'll think thatMY_DOMAINisn't used by any unprobed consumer and turn it off.Quoted 13 lines
Quoted 6 lines
3. **Device** links are not the complete list of consumers because they can only link consumer **devices** once the consumer **device** is created.
Quoted 6 lines
4. What you really need is a
for_each_consumer_fwnode(supplier, callback)that first loops through all the consumer device links and calls thecallback()on their fwnode and then the same function needs to loop through all the fwnode links and then pass those consumer fwnodes to the callback. And inside that callback you can do whatever you want.Quoted 4 lines
The ->queue_sync_state() callback is invoked *after*
__device_links_queue_sync_state()has been called for the device, which is also when the conditions for calling ->sync_state() is checked.I'm not sure what you are trying to say here. Yes, what you are saying is true. But at the point the current code returns before calling
sync_state(), your patch 2/13 ends up calling the "consumer_probed()" callback.
Quoted 4 lines
If you see the example I gave above, there is a
SYNC_STATE_ONLYlink all the way up to step 7 that'll preventsync_state()from being called. And until step 5, there is no device link between S and C and you'll have to go look at S's fwnode links to find C.
Thanks for the details, but I don't think the code in genpd needs to take these details into account. Or at least that is my goal, if possible.
As I understand it, all of the above should already been taken care of when __device_links_queue_sync_state() is called, as it's at that point when we can validate whether all consumers for a supplier have been probed, right?
Quoted 6 lines
Quoted 4 lines
If there are problems with not yet registered consumer device links, why isn't that as problem for regular ->sync_state() in
__device_links_queue_sync_state()?Does my explanation above make sense?
I think you may have misunderstood how the code in $subject patch works. Let's try again.
Quoted 4 lines
Welcome to the annoying worlds of
fw_devlinkcorner cases/nuances. There's a case where the child is the supplier of the parent/grandparent. There's a comment for that in thefw_devlinkcode.
Yeah, I am fully aware of the high level of complexity and as I said, I don't want genpd to have to know about *all* of that.
[...]
Kind regards
Uffe
Re: [PATCH v3 06/13] pmdomain: core: Add initial fine grained sync_state support
Quoted 159 lines · Ulf Hansson
Quoted 157 lines · Saravana Kannan
Quoted 154 lines · Ulf Hansson
Quoted 75 lines · Saravana Kannan
Quoted 47 lines · Ulf Hansson
A onecell (#power-domain-cells = <1 or 2>; in DT) power domain provider typically provides multiple independent power domains, each with their own corresponding consumers. In these cases we have to wait for all consumers for all the provided power domains before the ->sync_state() callback gets called for the supplier.
In a first step to improve this, let's implement support for fine grained
sync_statesupport a per genpd basis by using the ->queue_sync_state() callback. To take step by step, let's initially limit the improvement to the internal genpd provider driver and to its corresponding genpd devices for onecell providers.Signed-off-by Ulf Hansson <[email protected]>---
Changes in v3:
- Addressed some cosmetic comments from Geert.--- drivers/pmdomain/core.c | 124 ++++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 1 + 2 files changed, 125 insertions(+)drivers/pmdomain/core.c +15
-0@@ -2699,6 +2699,119 @@ static struct generic_pm_domain *genpd_get_from_provider(return genpd; } +static bool genpd_should_wait_for_consumer (struct device_node *np) +{ +struct generic_pm_domain *genpd; +bool should_wait = false; + +mutex_lock (&gpd_list_lock); +list_for_each_entry (genpd, &gpd_list, gpd_list_node) { +if (genpd->provider ==of_fwnode_handle (np)) { +genpd_lock (genpd); + +/* Clear the previous state before reevaluating. */ + genpd->wait_for_consumer = false; + +/* +* Unless there is at least one genpd for the provider drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2726
Quoted 10 lines
drivers/pmdomain/core.c +10
-0+* that is being kept powered-on, we don't have to care +* about waiting for consumers. +*/ +if (genpd->stay_on) + should_wait = true; + +genpd_unlock (genpd); + } + } +mutex_unlock (&gpd_list_lock);I think I understand the intent of this function, but haven't dug into genpd code enough to comment on this yet. I'll come back to this later.
Quoted 11 lines
drivers/pmdomain/core.c +11
-0+ +return should_wait; +} + +static void genpd_parse_for_consumer (struct device_node *sup, +struct device_node *con) +{ +struct generic_pm_domain *genpd; + +for (unsigned int i =0 ; ; i++) { +struct of_phandle_args pd_args;Quoted 8 lines
drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2742
Quoted 5 lines
drivers/pmdomain/core.c +5
-0+ +if (of_parse_phandle_with_args (con,"power-domains" , +"#power-domain-cells" , + i, &pd_args)) +break ;Why not use a while or a do
while()instead of this infinite for loop with a break?I guess it's a matter of personal preference. I'm not sure the code gets any nicer with a do/while, but if you really insist I can change it.
Quoted 52 lines
Quoted 41 lines
drivers/pmdomain/core.c +40
-0+ +/* +* The phandle must correspond to the supplier's genpd provider +* to be relevant else let's move to the next index. +*/ +if (sup != pd_args.np) { +of_node_put (pd_args.np); +continue ; + } + +mutex_lock (&gpd_list_lock); + genpd =genpd_get_from_provider (&pd_args); +if (!IS_ERR (genpd)) { +genpd_lock (genpd); + genpd->wait_for_consumer = true; +genpd_unlock (genpd); + } +mutex_unlock (&gpd_list_lock); + +of_node_put (pd_args.np); + } +} + +static void _genpd_queue_sync_state (struct device_node *np) +{ +struct generic_pm_domain *genpd; + +mutex_lock (&gpd_list_lock); +list_for_each_entry (genpd, &gpd_list, gpd_list_node) { +if (genpd->provider ==of_fwnode_handle (np)) { +genpd_lock (genpd); +if (genpd->stay_on && !genpd->wait_for_consumer) { + genpd->stay_on = false; +genpd_queue_power_off_work (genpd); + } +genpd_unlock (genpd); + } + } +mutex_unlock (&gpd_list_lock); +}drivers/pmdomain/core.c static struct generic_pm_domain *genpd_get_from_provider( · line 2792
Quoted 10 lines
drivers/pmdomain/core.c +10
-0+ +static void genpd_queue_sync_state (struct device *dev) +{ +struct device_node *np = dev->of_node; +struct device_link *link; + +if (!genpd_should_wait_for_consumer (np)) +return ; + +list_for_each_entry (link, &dev->links.consumers, s_node) {Quoted 7 lines
Couple of issues:
1. I don't want the frameworks to be so deeply aware of driver core internals. I want the driver core maintainers to be able to change the devlink implementation without having to worry about going and fixing all the frameworks. So, please add afor_each_consumer_dev(supplier, callback)andfor_each_supplier_dev(consumer, callback)helper functions.I understand your concern and I like the idea. However, maybe it's better to get this landed (the series is complicated as is) first and then can continue to improve the code on top, with helper functions etc.
Quoted 7 lines
Quoted 3 lines
That patch should be pretty simple, so let's just do it? You are literally just moving the code to another file and massaging it a bit. I can send one out if you want/
Okay, I will fold in a patch into my series that adds the helper. No point you sending it as it needs to be apart of my series to have a user for it.
Ok, thanks.
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
2. This doesn't ignore "
SYNC_STATE_ONLY" links and that's going to confuse the consumer count/check you might do or at the least waste parsing those.I am not sure I understand how I should take
SYNC_STATE_ONLYlinks into account here.Quoted 8 lines
Quoted 3 lines
At each call to the
genpd_queue_sync_state(), we walk through all the provided genpds for the provider. No previous state is cached to track consumer counts.Ok, correct me if I'm wrong here, but it looks like you are looking at all the consumers, finding the ones that haven't probed yet and then trying to see which specific genpd provider each one of them is using by parsing their dt properties and then keep those ON.
Quoted 6 lines
The code cares only about the genpd OF provider that the supplier device belongs to, if any. Any other genpd OF providers and their genpds is untouched.
The corresponding genpd OF provider may provide multiple genpds through the same fwnode.
Yeah, that's what I meant. Since I don't look at the genpd code often I was conflating the "genpd OF provider" vs "genpd" terminology,
Quoted 64 lines
Quoted 59 lines
If my understanding above is wrong then, please help me understand what the code is trying to do.
If it's right, then here's the issue:
fw_devlinkrelies on device links and fwnode links to keep track of consumers. fwnode links get created first and then get converted to device links when both the supplier AND consumer devices are created.Consider a case when the supplier S is created and the consumer device C is several levels deep inside a parent device A.
S { #power-domain-cells = <1>; }
A { B { C { power-domains = <&SMY_DOMAIN>; } } }
fw_devlinkcan't just go "oh there's no consumer device that hasn't probed yet, let me callsync_state()". It needs to wait for C. But there's no way to create a device link to C. So, here's the sequence that happens:1. When device A gets added, it creates a "proxy"
SYNC_STATE_ONLYlink between S and A.
2. When A probes, it adds device B.
3. TheSYNC_STATE_ONLYlink between S to B is created.
4. TheSYNC_STATE_ONLYlink between S to A is deleted.
5. When B probes, it adds device C.
6. The actual device link between S and C is created.
7. TheSYNC_STATE_ONLYlink between S to B is deleted.
8. Device C probes, the device links get updated,sync_state()gets called.So, if your code doesn't account for
SYNC_STATE_ONLYlinks, you are going to check device "A" to see which providers are used. You'll think thatMY_DOMAINisn't used by any unprobed consumer and turn it off.Quoted 13 lines
Quoted 6 lines
3. **Device** links are not the complete list of consumers because they can only link consumer **devices** once the consumer **device** is created.
Quoted 6 lines
4. What you really need is a
for_each_consumer_fwnode(supplier, callback)that first loops through all the consumer device links and calls thecallback()on their fwnode and then the same function needs to loop through all the fwnode links and then pass those consumer fwnodes to the callback. And inside that callback you can do whatever you want.Quoted 4 lines
The ->queue_sync_state() callback is invoked *after*
__device_links_queue_sync_state()has been called for the device, which is also when the conditions for calling ->sync_state() is checked.I'm not sure what you are trying to say here. Yes, what you are saying is true. But at the point the current code returns before calling
sync_state(), your patch 2/13 ends up calling the "consumer_probed()" callback.Quoted 4 lines
If you see the example I gave above, there is a
SYNC_STATE_ONLYlink all the way up to step 7 that'll preventsync_state()from being called. And until step 5, there is no device link between S and C and you'll have to go look at S's fwnode links to find C.
Quoted 8 lines
Thanks for the details, but I don't think the code in genpd needs to take these details into account. Or at least that is my goal, if possible.
As I understand it, all of the above should already been taken care of when
__device_links_queue_sync_state()is called, as it's at that point when we can validate whether all consumers for a supplier have been probed, right?
Not really, and I explained it in my earlier email.
Let me explain it in a different way. For now, forget what sync_state() does or how it's called.
When you get your new callback:
1. You agree that you want to check the actual consumer DT nodes that have the "power-domains" property?
2. You agree that if you miss checking a consumer node then you'll incorrectly calculate wait_for_consumer for a genpd belonging to a one-cell genpd OF provider?
3. You agree that if wait_for_consumer is set to false before all consumers explicitly pointing to that specific genpd using the cell number, then you'll turn off the genpd too early?
I'm pretty sure you'll agree to (1) (2) and (3).
I'm saying that since this new callback is called way more often than sync_state() it will end up being called when some consumer struct devices haven't been created yet (I explained why in my earlier email -- I'm 100% certain this will happen). So, you'll also have to check the fwnode link consumers too to make sure you don't set wait_for_consumer = false too early.
The SYNC_STATE_ONLY link ignoring is just an optimization. If you don't ignore those, you'll be parsing their DT nodes unnecessarily because they are just proxy consumers (I explain this in my earlier email too).
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
If there are problems with not yet registered consumer device links, why isn't that as problem for regular ->sync_state() in
__device_links_queue_sync_state()?Does my explanation above make sense?
I think you may have misunderstood how the code in $subject patch works. Let's try again.
I took a closer look today and I'm sure I understand this patch correctly. There is a "turns off too early" bug.
Thanks,
Saravana
Quoted 13 lines
Quoted 5 lines
Welcome to the annoying worlds of
fw_devlinkcorner cases/nuances. There's a case where the child is the supplier of the parent/grandparent. There's a comment for that in thefw_devlinkcode.Yeah, I am fully aware of the high level of complexity and as I said, I don't want genpd to have to know about *all* of that.
[...]
Kind regards
Uffe
PATCH v3 7/13 pmdomain: core: Extend fine grained sync_state to more onecell providers
In reply to Ulf HanssonA onecell power domain provider driver that we can assign a common ->sync_state() callback for, should be able to benefit from the improved fine grained sync_state support in genpd. Therefore, let's also assign the ->queue_sync_state() callback for these types of provider drivers.
---
Changes in v3:
- No changes.
--- drivers/pmdomain/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/pmdomain/core.c +4 -2
@@ -2917,10 +2917,12 @@ int of_genpd_add_provider_onecell(struct device_node *np, fwnode =of_fwnode_handle (np); dev =get_dev_from_fwnode (fwnode); -if (!dev) +if (!dev) { sync_state = true; -else + }else if (!dev_has_sync_state (dev)) {dev_set_drv_sync_state (dev, genpd_sync_state); +dev_set_drv_queue_sync_state (dev, genpd_queue_sync_state); + }put_device (dev);
Signature · 1 line
2.43.0
PATCH v3 8/13 pmdomain: core: Export a common function for ->queue_sync_state()
In reply to Ulf HanssonAlong with of_genpd_sync_state() that genpd provider drivers may use to manage sync_state, let's add and export of_genpd_queue_sync_state() for those that may need it. It's expected that the genpd provider driver assigns it's own ->queue_sync_state() callback and invoke the new helper from there.
---
Changes in v3:
- No changes.
--- drivers/pmdomain/core.c | 14 +++++++++----- include/linux/pm_domain.h | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-)
drivers/pmdomain/core.c +9 -5
@@ -2763,7 +2763,7 @@ static void genpd_parse_for_consumer(struct device_node *sup, } } -static void _genpd_queue_sync_state (struct device_node *np) +static void genpd_queue_sync_state (struct device_node *np) {struct generic_pm_domain *genpd;
@@ -2781,11 +2781,14 @@ static void _genpd_queue_sync_state(struct device_node *np)mutex_unlock (&gpd_list_lock); } -static void genpd_queue_sync_state (struct device *dev) +void of_genpd_queue_sync_state (struct device *dev) {struct device_node *np = dev->of_node;struct device_link *link; +if (!np) +return ; +if (!genpd_should_wait_for_consumer (np))return ;
@@ -2809,8 +2812,9 @@ static void genpd_queue_sync_state(struct device *dev)genpd_parse_for_consumer (np, consumer->of_node); } -_genpd_queue_sync_state (np); +genpd_queue_sync_state (np); } +EXPORT_SYMBOL_GPL (of_genpd_queue_sync_state);static void genpd_sync_state (struct device *dev) {
@@ -2921,7 +2925,7 @@ int of_genpd_add_provider_onecell(struct device_node *np, sync_state = true; }else if (!dev_has_sync_state (dev)) {dev_set_drv_sync_state (dev, genpd_sync_state); -dev_set_drv_queue_sync_state (dev, genpd_queue_sync_state); +dev_set_drv_queue_sync_state (dev, of_genpd_queue_sync_state); }put_device (dev);
@@ -3653,7 +3657,7 @@ static void genpd_provider_queue_sync_state(struct device *dev)if (genpd->sync_state !=GENPD_SYNC_STATE_ONECELL )return ; -genpd_queue_sync_state (dev); +of_genpd_queue_sync_state (dev); }static void genpd_provider_sync_state (struct device *dev)
include/linux/pm_domain.h +2 -0
@@ -467,6 +467,7 @@ int of_genpd_remove_subdomain(const struct of_phandle_args *parent_spec,struct generic_pm_domain *of_genpd_remove_last (struct device_node *np);int of_genpd_parse_idle_states (struct device_node *dn,struct genpd_power_state **states,int *n); +void of_genpd_queue_sync_state (struct device *dev);void of_genpd_sync_state (struct device_node *np);int genpd_dev_pm_attach (struct device *dev);
@@ -513,6 +514,7 @@ static inline int of_genpd_parse_idle_states(struct device_node *dn,return -ENODEV ; } +static inline void of_genpd_queue_sync_state (struct device *dev) {}static inline void of_genpd_sync_state (struct device_node *np) {}static inline int genpd_dev_pm_attach (struct device *dev)
Signature · 1 line
2.43.0
PATCH v3 9/13 pmdomain: renesas: rcar-gen4-sysc: Drop GENPD_FLAG_NO_STAY_ON
In reply to Ulf HanssonDue to the new fine grained sync_state support for onecell genpd provider drivers, we should no longer need use the legacy behaviour. Therefore, let's drop GENPD_FLAG_NO_STAY_ON.
---
Changes in v3:
- No changes.
--- drivers/pmdomain/renesas/rcar-gen4-sysc.c | 1 - 1 file changed, 1 deletion(-)
drivers/pmdomain/renesas/rcar-gen4-sysc.c +0 -1
@@ -251,7 +251,6 @@ static int __init rcar_gen4_sysc_pd_setup(struct rcar_gen4_sysc_pd *pd) genpd->detach_dev = cpg_mssr_detach_dev; } - genpd->flags |=GENPD_FLAG_NO_STAY_ON ; genpd->power_off = rcar_gen4_sysc_pd_power_off; genpd->power_on = rcar_gen4_sysc_pd_power_on;
Signature · 1 line
2.43.0
PATCH v3 10/13 pmdomain: renesas: rcar-sysc: Drop GENPD_FLAG_NO_STAY_ON
In reply to Ulf HanssonDue to the new fine grained sync_state support for onecell genpd provider drivers, we should no longer need use the legacy behaviour. Therefore, let's drop GENPD_FLAG_NO_STAY_ON.
---
Changes in v3:
- No changes.
--- drivers/pmdomain/renesas/rcar-sysc.c | 1 - 1 file changed, 1 deletion(-)
drivers/pmdomain/renesas/rcar-sysc.c +0 -1
@@ -241,7 +241,6 @@ static int __init rcar_sysc_pd_setup(struct rcar_sysc_pd *pd) } } - genpd->flags |=GENPD_FLAG_NO_STAY_ON ; genpd->power_off = rcar_sysc_pd_power_off; genpd->power_on = rcar_sysc_pd_power_on;
Signature · 1 line
2.43.0
PATCH v3 11/13 pmdomain: renesas: rmobile-sysc: Drop GENPD_FLAG_NO_STAY_ON
In reply to Ulf HanssonRmobile-sysc is not a onecell provider and didn't really needed the GENPD_FLAG_NO_STAY_ON flag in the first place. Let's drop it.
---
Changes in v3:
- No changes.
--- drivers/pmdomain/renesas/rmobile-sysc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/pmdomain/renesas/rmobile-sysc.c +1 -2
@@ -100,8 +100,7 @@ static void rmobile_init_pm_domain(struct rmobile_pm_domain *rmobile_pd)struct generic_pm_domain *genpd = &rmobile_pd->genpd;struct dev_power_governor *gov = rmobile_pd->gov; - genpd->flags |=GENPD_FLAG_PM_CLK |GENPD_FLAG_ACTIVE_WAKEUP | -GENPD_FLAG_NO_STAY_ON ; + genpd->flags |=GENPD_FLAG_PM_CLK |GENPD_FLAG_ACTIVE_WAKEUP ; genpd->attach_dev = cpg_mstp_attach_dev; genpd->detach_dev = cpg_mstp_detach_dev;
Signature · 1 line
2.43.0
PATCH v3 12/13 pmdomain: core: Avoid an unnecessary power off at sync_state
In reply to Ulf HanssonIf the PM domain was not powered on during initialization, genpd will not prevent it from being powered off during boot. In these cases there is no need to call genpd_power_off() at sync_state, hence let's avoid it.
---
Changes in v3:
- New patch.
--- drivers/pmdomain/core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/pmdomain/core.c +8 -4
@@ -3636,8 +3636,10 @@ void of_genpd_sync_state(struct device_node *np)list_for_each_entry (genpd, &gpd_list, gpd_list_node) {if (genpd->provider ==of_fwnode_handle (np)) {genpd_lock (genpd); - genpd->stay_on = false; -genpd_power_off (genpd, false,0 ); +if (genpd->stay_on) { + genpd->stay_on = false; +genpd_power_off (genpd, false,0 ); + }genpd_unlock (genpd); } }
@@ -3674,8 +3676,10 @@ static void genpd_provider_sync_state(struct device *dev)case GENPD_SYNC_STATE_SIMPLE :genpd_lock (genpd); - genpd->stay_on = false; -genpd_power_off (genpd, false,0 ); +if (genpd->stay_on) { + genpd->stay_on = false; +genpd_power_off (genpd, false,0 ); + }genpd_unlock (genpd);break ;
Signature · 1 line
2.43.0
PATCH v3 13/13 pmdomain: core: Add a couple of debug prints for sync_state
In reply to Ulf HanssonTo inform the developer of what is happening during sync_state transitions in genpd, let's add a couple of debug prints for it.
---
Changes in v3:
- New patch.
--- drivers/pmdomain/core.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/pmdomain/core.c +11 -0
@@ -2756,6 +2756,9 @@ static void genpd_parse_for_consumer(struct device_node *sup,genpd_lock (genpd); genpd->wait_for_consumer = true;genpd_unlock (genpd); + +pr_debug ("%s: wait for consumer %pOF\n" , +dev_name (&genpd->dev), con); }mutex_unlock (&gpd_list_lock);
@@ -2772,6 +2775,9 @@ static void genpd_queue_sync_state(struct device_node *np)if (genpd->provider ==of_fwnode_handle (np)) {genpd_lock (genpd);if (genpd->stay_on && !genpd->wait_for_consumer) { +pr_debug ("%s: queuing sync state\n" , +dev_name (&genpd->dev)); + genpd->stay_on = false;genpd_queue_power_off_work (genpd); }
@@ -3637,6 +3643,9 @@ void of_genpd_sync_state(struct device_node *np)if (genpd->provider ==of_fwnode_handle (np)) {genpd_lock (genpd);if (genpd->stay_on) { +pr_debug ("%s: sync state\n" , +dev_name (&genpd->dev)); + genpd->stay_on = false;genpd_power_off (genpd, false,0 ); }
@@ -3677,6 +3686,8 @@ static void genpd_provider_sync_state(struct device *dev)case GENPD_SYNC_STATE_SIMPLE :genpd_lock (genpd);if (genpd->stay_on) { +pr_debug ("%s: sync state\n" ,dev_name (&genpd->dev)); + genpd->stay_on = false;genpd_power_off (genpd, false,0 ); }
Signature · 1 line
2.43.0