drivers: base: add support to skip power management in device/driver model
Subsystems (4)
PATCH v2 1/1 drivers: base: add support to skip power management in device/driver model
All device objects in the driver model contain fields that control the handling of various power management activities. However, it's not always useful. There are few instances where pseudo devices are added to the model just to take advantage of many other features like kobjects, udev events, and so on. One such example is cpu devices and their caches.
The sysfs for the cpu caches are managed by adding devices with cpu as the parent in cpu_device_create() when secondary cpu is brought online. Generally when the secondary CPUs are hotplugged back in as part of resume from suspend-to-ram, we call cpu_device_create() from the cpu hotplug state machine while the cpu device associated with that CPU is not yet ready to be resumed as the device_resume() call happens bit later. It's not really needed to set the flag is_prepared for cpu devices as they are mostly pseudo device and hotplug framework deals with state machine and not managed through the cpu device.
This often results in annoying warning when resuming:
Enabling non-boot CPUs ...
CPU1: Booted secondary processor
cache: parent cpu1 should not be sleeping
CPU1 is up
CPU2: Booted secondary processor
cache: parent cpu2 should not be sleeping
CPU2 is up
.... and so on.
So in order to fix these kind of errors, we could just completely avoid doing any power management related initialisations and operations if they are not used by these devices.
Lets add no_pm_required flags to indicate that the device doesn't require any sort of pm activities and all of them can be completely skipped. We can use the same flag to also avoid adding not used *power* sysfs entries for these devices. For now, lets use this for cpu cache devices.
--- drivers/base/cpu.c | 1 + drivers/base/power/main.c | 7 +++++++ drivers/base/power/sysfs.c | 4 ++++ include/linux/device.h | 10 ++++++++++ include/linux/pm.h | 1 + 5 files changed, 23 insertions(+)
v1->v2:
- dropped setting the flag for cpu devices, for now just cpu caches will make use of this new flag.
RFC->v1:
- dropped the idea of adding cpu hotplug callback to deal just with cpu devices, instead add a new flag in the device pm_info structure
[RFC] : https://marc.info/?l=linux-pm&m=154842896407904&w=2
[v1] : https://marc.info/?l=linux-pm&m=154946578717730&w=2
drivers/base/cpu.c +1 -0
@@ -427,6 +427,7 @@ __cpu_device_create(struct device *parent, void *drvdata, dev->parent = parent; dev->groups = groups; dev->release = device_create_release; +device_set_pm_not_required (dev);dev_set_drvdata (dev, drvdata); retval =kobject_set_name_vargs (&dev->kobj, fmt, args);
drivers/base/power/main.c +7 -0
@@ -124,6 +124,10 @@ void device_pm_unlock(void)*/ void device_pm_add (struct device *dev) { +/* No need to create pm sysfs if explicitly specified as not required */ +if (device_pm_not_required (dev)) +return ; +pr_debug ("PM: Adding info for %s:%s\n" , dev->bus ? dev->bus->name :"No Bus" ,dev_name (dev));device_pm_check_callbacks (dev);
@@ -142,6 +146,9 @@ void device_pm_add(struct device *dev)*/ void device_pm_remove (struct device *dev) { +if (device_pm_not_required (dev)) +return ; +pr_debug ("PM: Removing info for %s:%s\n" , dev->bus ? dev->bus->name :"No Bus" ,dev_name (dev));complete_all (&dev->power.completion);
drivers/base/power/sysfs.c +4 -0
@@ -648,6 +648,10 @@ int dpm_sysfs_add(struct device *dev) {int rc; +/* No need to create pm sysfs if explicitly disabled */ +if (device_pm_not_required (dev)) +return 0 ; + rc =sysfs_create_group (&dev->kobj, &pm_attr_group);if (rc)return rc;
include/linux/device.h +10 -0
@@ -1165,6 +1165,16 @@ static inline bool device_async_suspend_enabled(struct device *dev)return !!dev->power.async_suspend; } +static inline bool device_pm_not_required (struct device *dev) +{ +return dev->power.no_pm_required; +} + +static inline void device_set_pm_not_required (struct device *dev) +{ + dev->power.no_pm_required = true; +} +static inline void dev_pm_syscore_device (struct device *dev,bool val) {#ifdef CONFIG_PM_SLEEP
include/linux/pm.h +1 -0
@@ -592,6 +592,7 @@ struct dev_pm_info { bool is_suspended:1; /* Ditto */ bool is_noirq_suspended:1; bool is_late_suspended:1; + bool no_pm_required:1; bool early_init:1; /* Owned by the PM core */ bool direct_complete:1; /* Owned by the PM core */u32 driver_flags;
--
2.17.1
Quoted 38 lines · Sudeep Holla
All device objects in the driver model contain fields that control the handling of various power management activities. However, it's not always useful. There are few instances where pseudo devices are added to the model just to take advantage of many other features like kobjects, udev events, and so on. One such example is cpu devices and their caches.
The sysfs for the cpu caches are managed by adding devices with cpu as the parent in
cpu_device_create()when secondary cpu is brought online. Generally when the secondary CPUs are hotplugged back in as part of resume from suspend-to-ram, we callcpu_device_create()from the cpu hotplug state machine while the cpu device associated with that CPU is not yet ready to be resumed as thedevice_resume()call happens bit later. It's not really needed to set the flagis_preparedfor cpu devices as they are mostly pseudo device and hotplug framework deals with state machine and not managed through the cpu device.This often results in annoying warning when resuming:
Enabling non-boot CPUs ...
CPU1: Booted secondary processor
cache: parent cpu1 should not be sleeping
CPU1 is up
CPU2: Booted secondary processor
cache: parent cpu2 should not be sleeping
CPU2 is up
.... and so on.So in order to fix these kind of errors, we could just completely avoid doing any power management related initialisations and operations if they are not used by these devices.
Lets add
no_pm_requiredflags to indicate that the device doesn't require any sort of pm activities and all of them can be completely skipped. We can use the same flag to also avoid adding not used *power* sysfs entries for these devices. For now, lets use this for cpu cache devices.
Quoted 3 lines
Cc Greg Kroah-Hartman <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Signed-off-by Sudeep Holla <[email protected]>
Kind regards
Uffe
Quoted 108 lines
--- drivers/base/cpu.c | 1 + drivers/base/power/main.c | 7 +++++++ drivers/base/power/sysfs.c | 4 ++++ include/linux/device.h | 10 ++++++++++ include/linux/pm.h | 1 + 5 files changed, 23 insertions(+)
v1->v2:
- dropped setting the flag for cpu devices, for now just cpu caches will make use of this new flag.
RFC->v1:
- dropped the idea of adding cpu hotplug callback to deal just with cpu devices, instead add a new flag in the devicepm_infostructure[RFC] : https://marc.info/?l=linux-pm&m=154842896407904&w=2
[v1] : https://marc.info/?l=linux-pm&m=154946578717730&w=2drivers/base/cpu.c +1
-0@@ -427,6 +427,7 @@ __cpu_device_create(struct device *parent, void *drvdata, dev->parent = parent; dev->groups = groups; dev->release = device_create_release; +device_set_pm_not_required (dev);dev_set_drvdata (dev, drvdata); retval =kobject_set_name_vargs (&dev->kobj, fmt, args);drivers/base/power/main.c +7
-0@@ -124,6 +124,10 @@ void device_pm_unlock(void)*/ void device_pm_add (struct device *dev) { +/* No need to create pm sysfs if explicitly specified as not required */ +if (device_pm_not_required (dev)) +return ; +pr_debug ("PM: Adding info for %s:%s\n" , dev->bus ? dev->bus->name :"No Bus" ,dev_name (dev));device_pm_check_callbacks (dev);@@ -142,6 +146,9 @@ void device_pm_add(struct device *dev)*/ void device_pm_remove (struct device *dev) { +if (device_pm_not_required (dev)) +return ; +pr_debug ("PM: Removing info for %s:%s\n" , dev->bus ? dev->bus->name :"No Bus" ,dev_name (dev));complete_all (&dev->power.completion);drivers/base/power/sysfs.c +4
-0@@ -648,6 +648,10 @@ int dpm_sysfs_add(struct device *dev) {int rc; +/* No need to create pm sysfs if explicitly disabled */ +if (device_pm_not_required (dev)) +return 0 ; + rc =sysfs_create_group (&dev->kobj, &pm_attr_group);if (rc)return rc;include/linux/device.h +10
-0@@ -1165,6 +1165,16 @@ static inline bool device_async_suspend_enabled(struct device *dev)return !!dev->power.async_suspend; } +static inline bool device_pm_not_required (struct device *dev) +{ +return dev->power.no_pm_required; +} + +static inline void device_set_pm_not_required (struct device *dev) +{ + dev->power.no_pm_required = true; +} +static inline void dev_pm_syscore_device (struct device *dev,bool val) {#ifdef CONFIG_PM_SLEEP include/linux/pm.h +1
-1@@ -592,6 +592,7 @@ struct dev_pm_info { bool is_suspended:1; /* Ditto */ bool is_noirq_suspended:1; bool is_late_suspended:1; + bool no_pm_required:1; bool early_init:1; /* Owned by the PM core */ bool direct_complete:1; /* Owned by the PM core */u32 driver_flags; --2.17.1
Rafael J. Wysocki
maintainerQuoted 78 lines · Sudeep Holla
All device objects in the driver model contain fields that control the handling of various power management activities. However, it's not always useful. There are few instances where pseudo devices are added to the model just to take advantage of many other features like kobjects, udev events, and so on. One such example is cpu devices and their caches.
The sysfs for the cpu caches are managed by adding devices with cpu as the parent in
cpu_device_create()when secondary cpu is brought online. Generally when the secondary CPUs are hotplugged back in as part of resume from suspend-to-ram, we callcpu_device_create()from the cpu hotplug state machine while the cpu device associated with that CPU is not yet ready to be resumed as thedevice_resume()call happens bit later. It's not really needed to set the flagis_preparedfor cpu devices as they are mostly pseudo device and hotplug framework deals with state machine and not managed through the cpu device.This often results in annoying warning when resuming:
Enabling non-boot CPUs ...
CPU1: Booted secondary processor
cache: parent cpu1 should not be sleeping
CPU1 is up
CPU2: Booted secondary processor
cache: parent cpu2 should not be sleeping
CPU2 is up
.... and so on.So in order to fix these kind of errors, we could just completely avoid doing any power management related initialisations and operations if they are not used by these devices.
Lets add
no_pm_requiredflags to indicate that the device doesn't require any sort of pm activities and all of them can be completely skipped. We can use the same flag to also avoid adding not used *power* sysfs entries for these devices. For now, lets use this for cpu cache devices.Cc Greg Kroah-Hartman <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Signed-off-by Sudeep Holla <[email protected]>--- drivers/base/cpu.c | 1 + drivers/base/power/main.c | 7 +++++++ drivers/base/power/sysfs.c | 4 ++++ include/linux/device.h | 10 ++++++++++ include/linux/pm.h | 1 + 5 files changed, 23 insertions(+)
v1->v2:
- dropped setting the flag for cpu devices, for now just cpu caches will make use of this new flag.
RFC->v1:
- dropped the idea of adding cpu hotplug callback to deal just with cpu devices, instead add a new flag in the devicepm_infostructure[RFC] : https://marc.info/?l=linux-pm&m=154842896407904&w=2
[v1] : https://marc.info/?l=linux-pm&m=154946578717730&w=2drivers/base/cpu.c +1
-0@@ -427,6 +427,7 @@ __cpu_device_create(struct device *parent, void *drvdata, dev->parent = parent; dev->groups = groups; dev->release = device_create_release; +device_set_pm_not_required (dev);dev_set_drvdata (dev, drvdata); retval =kobject_set_name_vargs (&dev->kobj, fmt, args);drivers/base/power/main.c +0
-0
drivers/base/power/main.c void device_pm_unlock(void) · line 127
Quoted 4 lines
drivers/base/power/main.c +1
-0@@ -124,6 +124,10 @@ void device_pm_unlock(void)*/ void device_pm_add (struct device *dev) { +/* No need to create pm sysfs if explicitly specified as not required */
Is this really about sysfs?
drivers/base/power/main.c void device_pm_unlock(void) · line 128
Quoted 1 line
drivers/base/power/main.c +1
-0+if (device_pm_not_required (dev))
Should power.disable_depth be bumped up here or while setting the "no PM" flag?
Quoted 56 lines
drivers/base/power/main.c +5
-0+return ; +pr_debug ("PM: Adding info for %s:%s\n" , dev->bus ? dev->bus->name :"No Bus" ,dev_name (dev));device_pm_check_callbacks (dev);@@ -142,6 +146,9 @@ void device_pm_add(struct device *dev)*/ void device_pm_remove (struct device *dev) { +if (device_pm_not_required (dev)) +return ; +pr_debug ("PM: Removing info for %s:%s\n" , dev->bus ? dev->bus->name :"No Bus" ,dev_name (dev));complete_all (&dev->power.completion);drivers/base/power/sysfs.c +4
-0@@ -648,6 +648,10 @@ int dpm_sysfs_add(struct device *dev) {int rc; +/* No need to create pm sysfs if explicitly disabled */ +if (device_pm_not_required (dev)) +return 0 ; + rc =sysfs_create_group (&dev->kobj, &pm_attr_group);if (rc)return rc;include/linux/device.h +10
-0@@ -1165,6 +1165,16 @@ static inline bool device_async_suspend_enabled(struct device *dev)return !!dev->power.async_suspend; } +static inline bool device_pm_not_required (struct device *dev) +{ +return dev->power.no_pm_required; +} + +static inline void device_set_pm_not_required (struct device *dev) +{ + dev->power.no_pm_required = true; +} +static inline void dev_pm_syscore_device (struct device *dev,bool val) {#ifdef CONFIG_PM_SLEEP include/linux/pm.h +0
-0
include/linux/pm.h struct dev_pm_info { · line 595
Quoted 4 lines
include/linux/pm.h +1
-0@@ -592,6 +592,7 @@ struct dev_pm_info { bool is_suspended:1; /* Ditto */ bool is_noirq_suspended:1; bool is_late_suspended:1; + bool no_pm_required:1;
Maybe call it "no_pm"?
Quoted 4 lines
include/linux/pm.h +0
-1bool early_init:1; /* Owned by the PM core */ bool direct_complete:1; /* Owned by the PM core */u32 driver_flags; --
Quoted 73 lines · Rafael J. Wysocki
Quoted 72 lines · Sudeep Holla
All device objects in the driver model contain fields that control the handling of various power management activities. However, it's not always useful. There are few instances where pseudo devices are added to the model just to take advantage of many other features like kobjects, udev events, and so on. One such example is cpu devices and their caches.
The sysfs for the cpu caches are managed by adding devices with cpu as the parent in
cpu_device_create()when secondary cpu is brought online. Generally when the secondary CPUs are hotplugged back in as part of resume from suspend-to-ram, we callcpu_device_create()from the cpu hotplug state machine while the cpu device associated with that CPU is not yet ready to be resumed as thedevice_resume()call happens bit later. It's not really needed to set the flagis_preparedfor cpu devices as they are mostly pseudo device and hotplug framework deals with state machine and not managed through the cpu device.This often results in annoying warning when resuming:
Enabling non-boot CPUs ...
CPU1: Booted secondary processor
cache: parent cpu1 should not be sleeping
CPU1 is up
CPU2: Booted secondary processor
cache: parent cpu2 should not be sleeping
CPU2 is up
.... and so on.So in order to fix these kind of errors, we could just completely avoid doing any power management related initialisations and operations if they are not used by these devices.
Lets add
no_pm_requiredflags to indicate that the device doesn't require any sort of pm activities and all of them can be completely skipped. We can use the same flag to also avoid adding not used *power* sysfs entries for these devices. For now, lets use this for cpu cache devices.Cc Greg Kroah-Hartman <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Signed-off-by Sudeep Holla <[email protected]>--- drivers/base/cpu.c | 1 + drivers/base/power/main.c | 7 +++++++ drivers/base/power/sysfs.c | 4 ++++ include/linux/device.h | 10 ++++++++++ include/linux/pm.h | 1 + 5 files changed, 23 insertions(+)
v1->v2:
- dropped setting the flag for cpu devices, for now just cpu caches will make use of this new flag.
RFC->v1:
- dropped the idea of adding cpu hotplug callback to deal just with cpu devices, instead add a new flag in the devicepm_infostructure[RFC] : https://marc.info/?l=linux-pm&m=154842896407904&w=2
[v1] : https://marc.info/?l=linux-pm&m=154946578717730&w=2drivers/base/cpu.c +1
-0@@ -427,6 +427,7 @@ __cpu_device_create(struct device *parent, void *drvdata, dev->parent = parent; dev->groups = groups; dev->release = device_create_release; +device_set_pm_not_required (dev);dev_set_drvdata (dev, drvdata);
Quoted 13 lines
drivers/base/power/main.c void device_pm_unlock(void) · line 127
Quoted 10 lines
drivers/base/cpu.c +0
-0retval =kobject_set_name_vargs (&dev->kobj, fmt, args);drivers/base/power/main.c +1
-0@@ -124,6 +124,10 @@ void device_pm_unlock(void)*/ void device_pm_add (struct device *dev) { +/* No need to create pm sysfs if explicitly specified as not required */ Is this really about sysfs?
Nope, copy-paste from dpm_sysfs_add, will drop it.
Quoted 4 lines
drivers/base/power/main.c void device_pm_unlock(void) · line 128
Quoted 1 line
drivers/base/power/main.c +1
-0+if (device_pm_not_required (dev))Should power.disable_depth be bumped up here or while setting the "no PM" flag?
OK, I missed that.
Also I did have extra check in dpm_sysfs_remove but dropped it as redundant. Based on Eugeniu report, I need to add it back.
[...]
Quoted 12 lines
include/linux/pm.h struct dev_pm_info { · line 595
Quoted 9 lines
include/linux/pm.h +1
-0@@ -592,6 +592,7 @@ struct dev_pm_info { bool is_suspended:1; /* Ditto */ bool is_noirq_suspended:1; bool is_late_suspended:1; + bool no_pm_required:1;Maybe call it "
no_pm"?
Sure.
--
Regards,
Sudeep
Quoted 2 lines · Sudeep Holla
Quoted 1 line · Rafael J. Wysocki
On Wed, Feb 13, 2019 at 1:01 PM Sudeep Holla <[email protected]> wrote:
[...]
Quoted 13 lines
Quoted 12 lines
drivers/base/power/main.c void device_pm_unlock(void) · line 127
Quoted 9 lines
drivers/base/power/main.c +1
-0@@ -124,6 +124,10 @@ void device_pm_unlock(void)*/ void device_pm_add (struct device *dev) { +/* No need to create pm sysfs if explicitly specified as not required */ Is this really about sysfs?
Quoted 9 lines
Nope, copy-paste from
dpm_sysfs_add, will drop it.Quoted 4 lines
drivers/base/power/main.c void device_pm_unlock(void) · line 128
Quoted 1 line
drivers/base/power/main.c +1
-0+if (device_pm_not_required (dev))Should power.disable_depth be bumped up here or while setting the "no PM" flag?
OK, I missed that.
Looking at it,
1. We can't set it when we set "no PM" flag as pm_runtime_init called later initialise it to 1
2. We can bump it here, but I see it's usage self contained in runtime.c and may look odd to access it here.
More basic question is should we really need to bump it to 2 as its initialised to 1 in runtime_init.
--
Regards,
Sudeep
Rafael J. Wysocki
maintainerQuoted 30 lines · Sudeep Holla
Quoted 2 lines · Sudeep Holla
Quoted 1 line · Rafael J. Wysocki
On Wed, Feb 13, 2019 at 1:01 PM Sudeep Holla <[email protected]> wrote:
[...]
Quoted 13 lines
Quoted 12 lines
drivers/base/power/main.c void device_pm_unlock(void) · line 127
Quoted 9 lines
drivers/base/power/main.c +1
-0@@ -124,6 +124,10 @@ void device_pm_unlock(void)*/ void device_pm_add (struct device *dev) { +/* No need to create pm sysfs if explicitly specified as not required */ Is this really about sysfs?
Quoted 9 lines
Nope, copy-paste from
dpm_sysfs_add, will drop it.Quoted 4 lines
drivers/base/power/main.c void device_pm_unlock(void) · line 128
Quoted 1 line
drivers/base/power/main.c +1
-0+if (device_pm_not_required (dev))Should power.disable_depth be bumped up here or while setting the "no PM" flag?
OK, I missed that.
Quoted 8 lines
Looking at it,
1. We can't set it when we set "no PM" flag aspm_runtime_initcalled later initialise it to 1
2. We can bump it here, but I see it's usage self contained inruntime.cand may look odd to access it here.More basic question is should we really need to bump it to 2 as its initialised to 1 in
runtime_init.
Right, I thought about that.
Let's leave it as is maybe. :-)
Hello Sudeep,
I appreciate your efforts. Currently, this patch generates below warnings during s2ram on R-Car H3-Salvator-X:
[ 46.874214] PM: suspend entry (deep) [ 46.878211] PM: Syncing filesystems ... done. [ 46.989148] Freezing user space processes ... (elapsed 0.004 seconds) done. [ 47.000428] OOM killer disabled. [ 47.003895] Freezing remaining freezable tasks ... (elapsed 0.003 seconds) done. [ 47.226363] PM: suspend devices took 0.210 seconds [ 47.280553] Disabling non-boot CPUs ... [ 47.289157] ------------[ cut here ]------------ [ 47.294524] sysfs group 'power' not found for kobject 'index0' [ 47.300622] WARNING: CPU: 1 PID: 14 at fs/sysfs/group.c:256 sysfs_remove_group+0x78/0xc4 ---snip--- [ 47.550425] sysfs group 'power' not found for kobject 'index1' ---snip--- [ 47.807005] sysfs group 'power' not found for kobject 'index2' ---snip--- [ 48.063703] sysfs group 'power' not found for kobject 'cache'
---snip---
Complete log and .config are shared in
https://gist.github.com/erosca/da9ea551033a503121de61049d77b834
Thank you,
Eugeniu.
Quoted 21 lines · Eugeniu Rosca
Hello Sudeep,
I appreciate your efforts. Currently, this patch generates below warnings during s2ram on R-Car H3-Salvator-X:
[ 46.874214] PM: suspend entry (deep) [ 46.878211] PM: Syncing filesystems ... done. [ 46.989148] Freezing user space processes ... (elapsed 0.004 seconds) done. [ 47.000428] OOM killer disabled. [ 47.003895] Freezing remaining freezable tasks ... (elapsed 0.003 seconds) done. [ 47.226363] PM: suspend devices took 0.210 seconds [ 47.280553] Disabling non-boot CPUs ... [ 47.289157] ------------[ cut here ]------------ [ 47.294524] sysfs group 'power' not found for kobject 'index0' [ 47.300622] WARNING: CPU: 1 PID: 14 at fs/sysfs/group.c:256 sysfs_remove_group+0x78/0xc4 ---snip--- [ 47.550425] sysfs group 'power' not found for kobject 'index1' ---snip--- [ 47.807005] sysfs group 'power' not found for kobject 'index2' ---snip--- [ 48.063703] sysfs group 'power' not found for kobject 'cache'
Quoted 2 lines
---snip---
Thanks for the report, looks like I am not able to reproduce this, will check if I am missing something while testing.
Quoted 3 lines
Complete log and .config are shared in
https://gist.github.com/erosca/da9ea551033a503121de61049d77b834
Thanks again, much appreciated for providing full log.
--
Regards,
Sudeep