This series intends to improve how genpd manages performance states votes while
device are becoming attached/detached to it. More details are available in the
commit messages for each patch.
Ulf Hansson (3):
PM: domains: Drop the performance state vote for a device at detach
PM: domains: Restructure some code in __genpd_dev_pm_attach()
PM: domains: Add a ->dev_get_performance_state() callback to genpd
drivers/base/power/domain.c | 26 +++++++++++++++++---------
include/linux/pm_domain.h | 3 ++-
2 files changed, 19 insertions(+), 10 deletions(-)
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
When a device is detached from its genpd, genpd loses track of the device,
including its performance state vote that may have been requested for it.
Rather than relying on the consumer driver to drop the performance state
vote for its device, let's do it internally in genpd when the device is
getting detached. In this way, we makes sure that the aggregation of the
votes in genpd becomes correct.
Signed-off-by: Ulf Hansson <redacted>
---
drivers/base/power/domain.c | 9 ++-------
include/linux/pm_domain.h | 1 -
2 files changed, 2 insertions(+), 8 deletions(-)
To slightly improve readability of the code, but also to prepare for a
subsequent change on top, let's move the code that calls
of_get_required_opp_performance_state() into a new separate function.
Signed-off-by: Ulf Hansson <redacted>
---
drivers/base/power/domain.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
@@ -2690,8 +2701,8 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,}/* Set the default performance state */-pstate=of_get_required_opp_performance_state(dev->of_node,index);-if(pstate<0&&pstate!=-ENODEV&&pstate!=-EOPNOTSUPP){+pstate=genpd_get_default_performance_state(dev,index);+if(pstate<0){ret=pstate;gotoerr;}elseif(pstate>0){
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hardware may be preprogrammed to a specific performance state, which may
not be zero initially during boot. This may lead to that genpd's current
performance state becomes inconsistent with the state of the hardware. To
deal with this, the driver for a device that is being attached to its
genpd, need to request an initial performance state vote, which is
typically done by calling some of the OPP APIs while probing.
In some cases this would lead to boilerplate code in the drivers. Let's
make it possible to avoid this, by adding a new optional callback to genpd
and invoke it per device during the attach process. In this way, the genpd
provider driver can inform genpd about the initial performance state that
is needed for the device.
Signed-off-by: Ulf Hansson <redacted>
---
drivers/base/power/domain.c | 8 +++++---
include/linux/pm_domain.h | 2 ++
2 files changed, 7 insertions(+), 3 deletions(-)
@@ -2701,7 +2703,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,}/* Set the default performance state */-pstate=genpd_get_default_performance_state(dev,index);+pstate=genpd_get_default_performance_state(pd,dev,index);if(pstate<0){ret=pstate;gotoerr;
@@ -131,6 +131,8 @@ struct generic_pm_domain {structopp_table*opp_table;/* OPP table of the genpd */unsignedint(*opp_to_performance_state)(structgeneric_pm_domain*genpd,structdev_pm_opp*opp);+int(*dev_get_performance_state)(structgeneric_pm_domain*genpd,+structdevice*dev);int(*set_performance_state)(structgeneric_pm_domain*genpd,unsignedintstate);structgpd_dev_opsdev_ops;
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hardware may be preprogrammed to a specific performance state, which may
not be zero initially during boot. This may lead to that genpd's current
performance state becomes inconsistent with the state of the hardware. To
deal with this, the driver for a device that is being attached to its
genpd, need to request an initial performance state vote, which is
typically done by calling some of the OPP APIs while probing.
In some cases this would lead to boilerplate code in the drivers. Let's
make it possible to avoid this, by adding a new optional callback to genpd
and invoke it per device during the attach process. In this way, the genpd
provider driver can inform genpd about the initial performance state that
is needed for the device.
Signed-off-by: Ulf Hansson <redacted>
---
drivers/base/power/domain.c | 8 +++++---
include/linux/pm_domain.h | 2 ++
2 files changed, 7 insertions(+), 3 deletions(-)
@@ -2701,7 +2703,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,}/* Set the default performance state */-pstate=genpd_get_default_performance_state(dev,index);+pstate=genpd_get_default_performance_state(pd,dev,index);
If base device is suspended, then its performance state is zero.
When device will be rpm-resumed, then its performance should be set to
the default state.
You're setting performance state of the wrong device, it should be the
base device and not the virtual domain device.
These all is handled properly by my patch [1]. Hence it's complicated
for the reason.
[1]
https://patchwork.ozlabs.org/project/linux-tegra/patch/20210831135450.26070-5-digetx@gmail.com/
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
When a device is detached from its genpd, genpd loses track of the device,
including its performance state vote that may have been requested for it.
Rather than relying on the consumer driver to drop the performance state
vote for its device, let's do it internally in genpd when the device is
getting detached. In this way, we makes sure that the aggregation of the
votes in genpd becomes correct.
This is a dangerous behaviour in a case where performance state
represents voltage. If hardware is kept active on detachment, say it's
always-on, then it may be a disaster to drop the voltage for the active
hardware.
It's safe to drop performance state only if you assume that there is a
firmware behind kernel which has its own layer of performance management
and it will prevent the disaster by saying 'nope, I'm not doing this'.
The performance state should be persistent for a device and it should be
controlled in a conjunction with runtime PM. If platform wants to drop
performance state to zero on detachment, then this behaviour should be
specific to that platform.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Fri, 3 Sept 2021 at 08:01, Dmitry Osipenko [off-list ref] wrote:
02.09.2021 13:16, Ulf Hansson пишет:
quoted
When a device is detached from its genpd, genpd loses track of the device,
including its performance state vote that may have been requested for it.
Rather than relying on the consumer driver to drop the performance state
vote for its device, let's do it internally in genpd when the device is
getting detached. In this way, we makes sure that the aggregation of the
votes in genpd becomes correct.
This is a dangerous behaviour in a case where performance state
represents voltage. If hardware is kept active on detachment, say it's
always-on, then it may be a disaster to drop the voltage for the active
hardware.
It's safe to drop performance state only if you assume that there is a
firmware behind kernel which has its own layer of performance management
and it will prevent the disaster by saying 'nope, I'm not doing this'.
The performance state should be persistent for a device and it should be
controlled in a conjunction with runtime PM. If platform wants to drop
performance state to zero on detachment, then this behaviour should be
specific to that platform.
I understand your concern, but at this point, genpd can't help to fix this.
Genpd has no information about the device, unless it's attached to it.
For now and for these always on HWs, we simply need to make sure the
device stays attached, in one way or the other.
Kind regards
Uffe
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Fri, 3 Sept 2021 at 08:00, Dmitry Osipenko [off-list ref] wrote:
02.09.2021 13:16, Ulf Hansson пишет:
quoted
Hardware may be preprogrammed to a specific performance state, which may
not be zero initially during boot. This may lead to that genpd's current
performance state becomes inconsistent with the state of the hardware. To
deal with this, the driver for a device that is being attached to its
genpd, need to request an initial performance state vote, which is
typically done by calling some of the OPP APIs while probing.
In some cases this would lead to boilerplate code in the drivers. Let's
make it possible to avoid this, by adding a new optional callback to genpd
and invoke it per device during the attach process. In this way, the genpd
provider driver can inform genpd about the initial performance state that
is needed for the device.
Signed-off-by: Ulf Hansson <redacted>
---
drivers/base/power/domain.c | 8 +++++---
include/linux/pm_domain.h | 2 ++
2 files changed, 7 insertions(+), 3 deletions(-)
@@ -2701,7 +2703,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,}/* Set the default performance state */-pstate=genpd_get_default_performance_state(dev,index);+pstate=genpd_get_default_performance_state(pd,dev,index);
If base device is suspended, then its performance state is zero.
When device will be rpm-resumed, then its performance should be set to
the default state.
You're setting performance state of the wrong device, it should be the
base device and not the virtual domain device.
No I am not. :-) Let me elaborate.
For the single PM domain case, 'dev' and 'base_dev' are pointing to
the same device. So this works fine.
For the multiple PM domain case or when attaching goes via
genpd_dev_pm_attach_by_id(), 'dev' is the virtual device registered in
genpd_dev_pm_attach_by_id(). In this case, it's 'dev' that is becoming
attached to genpd and not the 'base_dev'. Note also that, runtime PM
has not been enabled for 'dev' yet at this point and 'dev' has been
assigned the same OF node as 'base_dev", to allow OF parsing to work
as is for it.
Moreover, to deal with runtime PM in the multiple PM domain case, the
consumer driver should create a device link. Along the lines of this:
device_link_add(base_dev, dev, DL_FLAG_PM_RUNTIME |
DL_FLAG_STATELESS), thus assigning the virtual device ('dev') as the
supplier for its consumer device ('base_dev').
These all is handled properly by my patch [1]. Hence it's complicated
for the reason.
See above. It shouldn't have to be complicated. If it still is, there
is something to fix for the multiple PM domain case.
On Fri, 3 Sept 2021 at 08:01, Dmitry Osipenko [off-list ref] wrote:
quoted
02.09.2021 13:16, Ulf Hansson пишет:
quoted
When a device is detached from its genpd, genpd loses track of the device,
including its performance state vote that may have been requested for it.
Rather than relying on the consumer driver to drop the performance state
vote for its device, let's do it internally in genpd when the device is
getting detached. In this way, we makes sure that the aggregation of the
votes in genpd becomes correct.
This is a dangerous behaviour in a case where performance state
represents voltage. If hardware is kept active on detachment, say it's
always-on, then it may be a disaster to drop the voltage for the active
hardware.
It's safe to drop performance state only if you assume that there is a
firmware behind kernel which has its own layer of performance management
and it will prevent the disaster by saying 'nope, I'm not doing this'.
The performance state should be persistent for a device and it should be
controlled in a conjunction with runtime PM. If platform wants to drop
performance state to zero on detachment, then this behaviour should be
specific to that platform.
I understand your concern, but at this point, genpd can't help to fix this.
Genpd has no information about the device, unless it's attached to it.
For now and for these always on HWs, we simply need to make sure the
device stays attached, in one way or the other.
This indeed requires to redesign GENPD to make it more coupled with a
device, but this is not a real problem for any of the current API users
AFAIK. Ideally the state should be persistent to make API more universal.
Since for today we assume that device should be suspended at the time of
the detachment (if the default OPP state isn't used), it may be better
to add a noisy warning message if pstate!=0, keeping the state untouched
if it's not zero.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Fri, 3 Sept 2021 at 08:00, Dmitry Osipenko [off-list ref] wrote:
quoted
02.09.2021 13:16, Ulf Hansson пишет:
quoted
Hardware may be preprogrammed to a specific performance state, which may
not be zero initially during boot. This may lead to that genpd's current
performance state becomes inconsistent with the state of the hardware. To
deal with this, the driver for a device that is being attached to its
genpd, need to request an initial performance state vote, which is
typically done by calling some of the OPP APIs while probing.
In some cases this would lead to boilerplate code in the drivers. Let's
make it possible to avoid this, by adding a new optional callback to genpd
and invoke it per device during the attach process. In this way, the genpd
provider driver can inform genpd about the initial performance state that
is needed for the device.
Signed-off-by: Ulf Hansson <redacted>
---
drivers/base/power/domain.c | 8 +++++---
include/linux/pm_domain.h | 2 ++
2 files changed, 7 insertions(+), 3 deletions(-)
@@ -2701,7 +2703,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,}/* Set the default performance state */-pstate=genpd_get_default_performance_state(dev,index);+pstate=genpd_get_default_performance_state(pd,dev,index);
If base device is suspended, then its performance state is zero.
When device will be rpm-resumed, then its performance should be set to
the default state.
You're setting performance state of the wrong device, it should be the
Are you okay with my variant of handling the suspended device?
quoted
base device and not the virtual domain device.
No I am not. :-) Let me elaborate.
For the single PM domain case, 'dev' and 'base_dev' are pointing to
the same device. So this works fine.
For the multiple PM domain case or when attaching goes via
genpd_dev_pm_attach_by_id(), 'dev' is the virtual device registered in
genpd_dev_pm_attach_by_id(). In this case, it's 'dev' that is becoming
attached to genpd and not the 'base_dev'. Note also that, runtime PM
has not been enabled for 'dev' yet at this point and 'dev' has been
assigned the same OF node as 'base_dev", to allow OF parsing to work
as is for it.
Moreover, to deal with runtime PM in the multiple PM domain case, the
consumer driver should create a device link. Along the lines of this:
device_link_add(base_dev, dev, DL_FLAG_PM_RUNTIME |
DL_FLAG_STATELESS), thus assigning the virtual device ('dev') as the
supplier for its consumer device ('base_dev').
quoted
These all is handled properly by my patch [1]. Hence it's complicated
for the reason.
See above. It shouldn't have to be complicated. If it still is, there
is something to fix for the multiple PM domain case.
quoted
[1]
Alright, it actually works now on Tegra using the dev in the callback
for the case of multiple domains, I re-checked it. Previously, when I
tried that, there was a conflict in regards to OPP usage, I don't
remember details anymore. Maybe the recent changes that were suggested
by Viresh helped with that. So yes, there is no need to pass the base
device anymore.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Fri, 3 Sept 2021 at 11:58, Dmitry Osipenko [off-list ref] wrote:
03.09.2021 11:22, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 08:01, Dmitry Osipenko [off-list ref] wrote:
quoted
02.09.2021 13:16, Ulf Hansson пишет:
quoted
When a device is detached from its genpd, genpd loses track of the device,
including its performance state vote that may have been requested for it.
Rather than relying on the consumer driver to drop the performance state
vote for its device, let's do it internally in genpd when the device is
getting detached. In this way, we makes sure that the aggregation of the
votes in genpd becomes correct.
This is a dangerous behaviour in a case where performance state
represents voltage. If hardware is kept active on detachment, say it's
always-on, then it may be a disaster to drop the voltage for the active
hardware.
It's safe to drop performance state only if you assume that there is a
firmware behind kernel which has its own layer of performance management
and it will prevent the disaster by saying 'nope, I'm not doing this'.
The performance state should be persistent for a device and it should be
controlled in a conjunction with runtime PM. If platform wants to drop
performance state to zero on detachment, then this behaviour should be
specific to that platform.
I understand your concern, but at this point, genpd can't help to fix this.
Genpd has no information about the device, unless it's attached to it.
For now and for these always on HWs, we simply need to make sure the
device stays attached, in one way or the other.
This indeed requires to redesign GENPD to make it more coupled with a
device, but this is not a real problem for any of the current API users
AFAIK. Ideally the state should be persistent to make API more universal.
Right. In fact this has been discussed in the past. In principle, the
idea was to attach to genpd at device registration, rather than at
driver probe.
Although, this is not very easy to implement - and it seems like the
churns to do, have not been really worth it. At least so far.
Since for today we assume that device should be suspended at the time of
the detachment (if the default OPP state isn't used), it may be better
to add a noisy warning message if pstate!=0, keeping the state untouched
if it's not zero.
That would just be very silly in my opinion.
When the device is detached (suspended or not), it may cause it's PM
domain to be powered off - and there is really nothing we can do about
that from the genpd point of view.
As stated, the only current short term solution is to avoid detaching
the device. Anything else, would just be papering of the issue.
Kind regards
Uffe
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Fri, 3 Sept 2021 at 12:06, Dmitry Osipenko [off-list ref] wrote:
03.09.2021 11:55, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 08:00, Dmitry Osipenko [off-list ref] wrote:
quoted
02.09.2021 13:16, Ulf Hansson пишет:
quoted
Hardware may be preprogrammed to a specific performance state, which may
not be zero initially during boot. This may lead to that genpd's current
performance state becomes inconsistent with the state of the hardware. To
deal with this, the driver for a device that is being attached to its
genpd, need to request an initial performance state vote, which is
typically done by calling some of the OPP APIs while probing.
In some cases this would lead to boilerplate code in the drivers. Let's
make it possible to avoid this, by adding a new optional callback to genpd
and invoke it per device during the attach process. In this way, the genpd
provider driver can inform genpd about the initial performance state that
is needed for the device.
Signed-off-by: Ulf Hansson <redacted>
---
drivers/base/power/domain.c | 8 +++++---
include/linux/pm_domain.h | 2 ++
2 files changed, 7 insertions(+), 3 deletions(-)
@@ -2701,7 +2703,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,}/* Set the default performance state */-pstate=genpd_get_default_performance_state(dev,index);+pstate=genpd_get_default_performance_state(pd,dev,index);
If base device is suspended, then its performance state is zero.
When device will be rpm-resumed, then its performance should be set to
the default state.
You're setting performance state of the wrong device, it should be the
Are you okay with my variant of handling the suspended device?
Not sure if you intended to post this line?
In any case, I am happy to help and review to move things forward.
quoted
quoted
base device and not the virtual domain device.
No I am not. :-) Let me elaborate.
For the single PM domain case, 'dev' and 'base_dev' are pointing to
the same device. So this works fine.
For the multiple PM domain case or when attaching goes via
genpd_dev_pm_attach_by_id(), 'dev' is the virtual device registered in
genpd_dev_pm_attach_by_id(). In this case, it's 'dev' that is becoming
attached to genpd and not the 'base_dev'. Note also that, runtime PM
has not been enabled for 'dev' yet at this point and 'dev' has been
assigned the same OF node as 'base_dev", to allow OF parsing to work
as is for it.
Moreover, to deal with runtime PM in the multiple PM domain case, the
consumer driver should create a device link. Along the lines of this:
device_link_add(base_dev, dev, DL_FLAG_PM_RUNTIME |
DL_FLAG_STATELESS), thus assigning the virtual device ('dev') as the
supplier for its consumer device ('base_dev').
quoted
These all is handled properly by my patch [1]. Hence it's complicated
for the reason.
See above. It shouldn't have to be complicated. If it still is, there
is something to fix for the multiple PM domain case.
quoted
[1]
Alright, it actually works now on Tegra using the dev in the callback
for the case of multiple domains, I re-checked it. Previously, when I
tried that, there was a conflict in regards to OPP usage, I don't
remember details anymore. Maybe the recent changes that were suggested
by Viresh helped with that. So yes, there is no need to pass the base
device anymore.
Great! So, it seems like $subject patch should be a way forward for you then?
BTW, I forgot to add your Suggested-by: tag for the patch, you
certainly deserve at least that. Or perhaps you are fine with
co-developed by tag?
Kind regards
Uffe
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Fri, 3 Sept 2021 at 11:58, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 11:22, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 08:01, Dmitry Osipenko [off-list ref] wrote:
quoted
02.09.2021 13:16, Ulf Hansson пишет:
quoted
When a device is detached from its genpd, genpd loses track of the device,
including its performance state vote that may have been requested for it.
Rather than relying on the consumer driver to drop the performance state
vote for its device, let's do it internally in genpd when the device is
getting detached. In this way, we makes sure that the aggregation of the
votes in genpd becomes correct.
This is a dangerous behaviour in a case where performance state
represents voltage. If hardware is kept active on detachment, say it's
always-on, then it may be a disaster to drop the voltage for the active
hardware.
It's safe to drop performance state only if you assume that there is a
firmware behind kernel which has its own layer of performance management
and it will prevent the disaster by saying 'nope, I'm not doing this'.
The performance state should be persistent for a device and it should be
controlled in a conjunction with runtime PM. If platform wants to drop
performance state to zero on detachment, then this behaviour should be
specific to that platform.
I understand your concern, but at this point, genpd can't help to fix this.
Genpd has no information about the device, unless it's attached to it.
For now and for these always on HWs, we simply need to make sure the
device stays attached, in one way or the other.
This indeed requires to redesign GENPD to make it more coupled with a
device, but this is not a real problem for any of the current API users
AFAIK. Ideally the state should be persistent to make API more universal.
Right. In fact this has been discussed in the past. In principle, the
idea was to attach to genpd at device registration, rather than at
driver probe.
Although, this is not very easy to implement - and it seems like the
churns to do, have not been really worth it. At least so far.
quoted
Since for today we assume that device should be suspended at the time of
the detachment (if the default OPP state isn't used), it may be better
to add a noisy warning message if pstate!=0, keeping the state untouched
if it's not zero.
That would just be very silly in my opinion.
When the device is detached (suspended or not), it may cause it's PM
domain to be powered off - and there is really nothing we can do about
that from the genpd point of view.
As stated, the only current short term solution is to avoid detaching
the device. Anything else, would just be papering of the issue.
What about to re-evaluate the performance state of the domain after
detachment instead of setting the state to zero? This way PD driver may
take an action on detachment if performance isn't zero, before hardware
is crashed, for example it may emit a warning.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Fri, 3 Sept 2021 at 12:06, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 11:55, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 08:00, Dmitry Osipenko [off-list ref] wrote:
quoted
02.09.2021 13:16, Ulf Hansson пишет:
quoted
Hardware may be preprogrammed to a specific performance state, which may
not be zero initially during boot. This may lead to that genpd's current
performance state becomes inconsistent with the state of the hardware. To
deal with this, the driver for a device that is being attached to its
genpd, need to request an initial performance state vote, which is
typically done by calling some of the OPP APIs while probing.
In some cases this would lead to boilerplate code in the drivers. Let's
make it possible to avoid this, by adding a new optional callback to genpd
and invoke it per device during the attach process. In this way, the genpd
provider driver can inform genpd about the initial performance state that
is needed for the device.
Signed-off-by: Ulf Hansson <redacted>
---
drivers/base/power/domain.c | 8 +++++---
include/linux/pm_domain.h | 2 ++
2 files changed, 7 insertions(+), 3 deletions(-)
@@ -2701,7 +2703,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,}/* Set the default performance state */-pstate=genpd_get_default_performance_state(dev,index);+pstate=genpd_get_default_performance_state(pd,dev,index);
If base device is suspended, then its performance state is zero.
When device will be rpm-resumed, then its performance should be set to
the default state.
You're setting performance state of the wrong device, it should be the
Are you okay with my variant of handling the suspended device?
Not sure if you intended to post this line?
In any case, I am happy to help and review to move things forward.
It's not clear to me whether you omitted handling the case of
rpm-suspended device on purpose or not. I think it should be a part of
this patch, but sounds like you want to work on it separately, correct?
quoted
quoted
quoted
base device and not the virtual domain device.
No I am not. :-) Let me elaborate.
For the single PM domain case, 'dev' and 'base_dev' are pointing to
the same device. So this works fine.
For the multiple PM domain case or when attaching goes via
genpd_dev_pm_attach_by_id(), 'dev' is the virtual device registered in
genpd_dev_pm_attach_by_id(). In this case, it's 'dev' that is becoming
attached to genpd and not the 'base_dev'. Note also that, runtime PM
has not been enabled for 'dev' yet at this point and 'dev' has been
assigned the same OF node as 'base_dev", to allow OF parsing to work
as is for it.
Moreover, to deal with runtime PM in the multiple PM domain case, the
consumer driver should create a device link. Along the lines of this:
device_link_add(base_dev, dev, DL_FLAG_PM_RUNTIME |
DL_FLAG_STATELESS), thus assigning the virtual device ('dev') as the
supplier for its consumer device ('base_dev').
quoted
These all is handled properly by my patch [1]. Hence it's complicated
for the reason.
See above. It shouldn't have to be complicated. If it still is, there
is something to fix for the multiple PM domain case.
quoted
[1]
Alright, it actually works now on Tegra using the dev in the callback
for the case of multiple domains, I re-checked it. Previously, when I
tried that, there was a conflict in regards to OPP usage, I don't
remember details anymore. Maybe the recent changes that were suggested
by Viresh helped with that. So yes, there is no need to pass the base
device anymore.
Great! So, it seems like $subject patch should be a way forward for you then?
The current behaviour is incorrect for Tegra because it needs to set the
rpm_pstate for rpm-suspended device, instead of bumping the state
immediately.
Power management is defeated without it on Tegra because SoC will start
to consume extra power while device that needs this power is suspended.
Otherwise $subject looks okay.
BTW, I forgot to add your Suggested-by: tag for the patch, you
certainly deserve at least that. Or perhaps you are fine with
co-developed by tag?
Either is fine. Although, won't it be easier to keep these PD patches
within the Tegra series since it depends on them? I can pick up the
patches into the next version of Tegra series.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Sun, 5 Sept 2021 at 10:26, Dmitry Osipenko [off-list ref] wrote:
03.09.2021 17:03, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 11:58, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 11:22, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 08:01, Dmitry Osipenko [off-list ref] wrote:
quoted
02.09.2021 13:16, Ulf Hansson пишет:
quoted
When a device is detached from its genpd, genpd loses track of the device,
including its performance state vote that may have been requested for it.
Rather than relying on the consumer driver to drop the performance state
vote for its device, let's do it internally in genpd when the device is
getting detached. In this way, we makes sure that the aggregation of the
votes in genpd becomes correct.
This is a dangerous behaviour in a case where performance state
represents voltage. If hardware is kept active on detachment, say it's
always-on, then it may be a disaster to drop the voltage for the active
hardware.
It's safe to drop performance state only if you assume that there is a
firmware behind kernel which has its own layer of performance management
and it will prevent the disaster by saying 'nope, I'm not doing this'.
The performance state should be persistent for a device and it should be
controlled in a conjunction with runtime PM. If platform wants to drop
performance state to zero on detachment, then this behaviour should be
specific to that platform.
I understand your concern, but at this point, genpd can't help to fix this.
Genpd has no information about the device, unless it's attached to it.
For now and for these always on HWs, we simply need to make sure the
device stays attached, in one way or the other.
This indeed requires to redesign GENPD to make it more coupled with a
device, but this is not a real problem for any of the current API users
AFAIK. Ideally the state should be persistent to make API more universal.
Right. In fact this has been discussed in the past. In principle, the
idea was to attach to genpd at device registration, rather than at
driver probe.
Although, this is not very easy to implement - and it seems like the
churns to do, have not been really worth it. At least so far.
quoted
Since for today we assume that device should be suspended at the time of
the detachment (if the default OPP state isn't used), it may be better
to add a noisy warning message if pstate!=0, keeping the state untouched
if it's not zero.
That would just be very silly in my opinion.
When the device is detached (suspended or not), it may cause it's PM
domain to be powered off - and there is really nothing we can do about
that from the genpd point of view.
As stated, the only current short term solution is to avoid detaching
the device. Anything else, would just be papering of the issue.
What about to re-evaluate the performance state of the domain after
detachment instead of setting the state to zero?
I am not suggesting to set the performance state of the genpd to zero,
but to drop a potential vote for a performance state for the *device*
that is about to be detached.
Calling genpd_set_performance_state(dev, 0), during detach will have
the same effect as triggering a re-evaluation of the performance state
for the genpd, but after the detach.
This way PD driver may
take an action on detachment if performance isn't zero, before hardware
is crashed, for example it may emit a warning.
Not sure I got that. Exactly when do you want to emit a warning and
for what reason?
Do you want to add a check somewhere to see if
'gpd_data->performance_state' is non zero - and then print a warning?
Kind regards
Uffe
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Sun, 5 Sept 2021 at 11:11, Dmitry Osipenko [off-list ref] wrote:
03.09.2021 17:09, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 12:06, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 11:55, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 08:00, Dmitry Osipenko [off-list ref] wrote:
quoted
02.09.2021 13:16, Ulf Hansson пишет:
quoted
Hardware may be preprogrammed to a specific performance state, which may
not be zero initially during boot. This may lead to that genpd's current
performance state becomes inconsistent with the state of the hardware. To
deal with this, the driver for a device that is being attached to its
genpd, need to request an initial performance state vote, which is
typically done by calling some of the OPP APIs while probing.
In some cases this would lead to boilerplate code in the drivers. Let's
make it possible to avoid this, by adding a new optional callback to genpd
and invoke it per device during the attach process. In this way, the genpd
provider driver can inform genpd about the initial performance state that
is needed for the device.
Signed-off-by: Ulf Hansson <redacted>
---
drivers/base/power/domain.c | 8 +++++---
include/linux/pm_domain.h | 2 ++
2 files changed, 7 insertions(+), 3 deletions(-)
@@ -2701,7 +2703,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,}/* Set the default performance state */-pstate=genpd_get_default_performance_state(dev,index);+pstate=genpd_get_default_performance_state(pd,dev,index);
If base device is suspended, then its performance state is zero.
When device will be rpm-resumed, then its performance should be set to
the default state.
You're setting performance state of the wrong device, it should be the
Are you okay with my variant of handling the suspended device?
Not sure if you intended to post this line?
In any case, I am happy to help and review to move things forward.
It's not clear to me whether you omitted handling the case of
rpm-suspended device on purpose or not. I think it should be a part of
this patch, but sounds like you want to work on it separately, correct?
I didn't omit the handling, but instead relied solely on the
pm_runtime_suspended() check in dev_pm_genpd_set_performance_state().
quoted
quoted
quoted
quoted
base device and not the virtual domain device.
No I am not. :-) Let me elaborate.
For the single PM domain case, 'dev' and 'base_dev' are pointing to
the same device. So this works fine.
For the multiple PM domain case or when attaching goes via
genpd_dev_pm_attach_by_id(), 'dev' is the virtual device registered in
genpd_dev_pm_attach_by_id(). In this case, it's 'dev' that is becoming
attached to genpd and not the 'base_dev'. Note also that, runtime PM
has not been enabled for 'dev' yet at this point and 'dev' has been
assigned the same OF node as 'base_dev", to allow OF parsing to work
as is for it.
Moreover, to deal with runtime PM in the multiple PM domain case, the
consumer driver should create a device link. Along the lines of this:
device_link_add(base_dev, dev, DL_FLAG_PM_RUNTIME |
DL_FLAG_STATELESS), thus assigning the virtual device ('dev') as the
supplier for its consumer device ('base_dev').
quoted
These all is handled properly by my patch [1]. Hence it's complicated
for the reason.
See above. It shouldn't have to be complicated. If it still is, there
is something to fix for the multiple PM domain case.
quoted
[1]
Alright, it actually works now on Tegra using the dev in the callback
for the case of multiple domains, I re-checked it. Previously, when I
tried that, there was a conflict in regards to OPP usage, I don't
remember details anymore. Maybe the recent changes that were suggested
by Viresh helped with that. So yes, there is no need to pass the base
device anymore.
Great! So, it seems like $subject patch should be a way forward for you then?
The current behaviour is incorrect for Tegra because it needs to set the
rpm_pstate for rpm-suspended device, instead of bumping the state
immediately.
Power management is defeated without it on Tegra because SoC will start
to consume extra power while device that needs this power is suspended.
Okay, I understand your concern.
For devices that may remain runtime suspended when their consumer
drivers probes them, the behaviour may be suboptimal. This because it
could lead to having an active performance state vote for a runtime
suspended device, at least until it gets runtime resumed and then
runtime suspended again.
This all boils down to how the consumer driver deploys support for
runtime PM - and genpd doesn't know nor can control that.
I wonder if we perhaps should just leave this as is then. In other
words, rely on the consumer driver to vote for an initial performance
state of the device during ->probe(). In this way, the consumer driver
can decide what is the best thing to do, rather than letting genpd
make guesses.
Note that, comparing what we have done for power on/off during
attach/probe. For the legacy case (the single PM domain case) we power
on the PM domain. For the multiple PM domain case, we leave the PM
domain as is.
Otherwise $subject looks okay.
quoted
BTW, I forgot to add your Suggested-by: tag for the patch, you
certainly deserve at least that. Or perhaps you are fine with
co-developed by tag?
Either is fine. Although, won't it be easier to keep these PD patches
within the Tegra series since it depends on them? I can pick up the
patches into the next version of Tegra series.
Let's see. If we can agree on how to deal with this series, maybe we
can ask Rafael to send another pull-request before rc1 is out, so you
can base your series for Tegra more easily on top.
Kind regards
Uffe
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Sun, 5 Sept 2021 at 10:26, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 17:03, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 11:58, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 11:22, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 08:01, Dmitry Osipenko [off-list ref] wrote:
quoted
02.09.2021 13:16, Ulf Hansson пишет:
quoted
When a device is detached from its genpd, genpd loses track of the device,
including its performance state vote that may have been requested for it.
Rather than relying on the consumer driver to drop the performance state
vote for its device, let's do it internally in genpd when the device is
getting detached. In this way, we makes sure that the aggregation of the
votes in genpd becomes correct.
This is a dangerous behaviour in a case where performance state
represents voltage. If hardware is kept active on detachment, say it's
always-on, then it may be a disaster to drop the voltage for the active
hardware.
It's safe to drop performance state only if you assume that there is a
firmware behind kernel which has its own layer of performance management
and it will prevent the disaster by saying 'nope, I'm not doing this'.
The performance state should be persistent for a device and it should be
controlled in a conjunction with runtime PM. If platform wants to drop
performance state to zero on detachment, then this behaviour should be
specific to that platform.
I understand your concern, but at this point, genpd can't help to fix this.
Genpd has no information about the device, unless it's attached to it.
For now and for these always on HWs, we simply need to make sure the
device stays attached, in one way or the other.
This indeed requires to redesign GENPD to make it more coupled with a
device, but this is not a real problem for any of the current API users
AFAIK. Ideally the state should be persistent to make API more universal.
Right. In fact this has been discussed in the past. In principle, the
idea was to attach to genpd at device registration, rather than at
driver probe.
Although, this is not very easy to implement - and it seems like the
churns to do, have not been really worth it. At least so far.
quoted
Since for today we assume that device should be suspended at the time of
the detachment (if the default OPP state isn't used), it may be better
to add a noisy warning message if pstate!=0, keeping the state untouched
if it's not zero.
That would just be very silly in my opinion.
When the device is detached (suspended or not), it may cause it's PM
domain to be powered off - and there is really nothing we can do about
that from the genpd point of view.
As stated, the only current short term solution is to avoid detaching
the device. Anything else, would just be papering of the issue.
What about to re-evaluate the performance state of the domain after
detachment instead of setting the state to zero?
I am not suggesting to set the performance state of the genpd to zero,
but to drop a potential vote for a performance state for the *device*
that is about to be detached.
By removing the vote of the *device*, you will drop the performance
state of the genpd. If device is active and it's wrong to drop its
state, then you may cause the damage.
Calling genpd_set_performance_state(dev, 0), during detach will have
the same effect as triggering a re-evaluation of the performance state
for the genpd, but after the detach.
Yes
quoted
This way PD driver may
take an action on detachment if performance isn't zero, before hardware
is crashed, for example it may emit a warning.
Not sure I got that. Exactly when do you want to emit a warning and
for what reason?
Do you want to add a check somewhere to see if
'gpd_data->performance_state' is non zero - and then print a warning?
I want to check the 'gpd_data->performance_state' from the detachment
callback and emit the warning + lock further performance changes in the
PD driver since it's a error condition.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Sun, 5 Sept 2021 at 11:11, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 17:09, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 12:06, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 11:55, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 08:00, Dmitry Osipenko [off-list ref] wrote:
quoted
02.09.2021 13:16, Ulf Hansson пишет:
quoted
Hardware may be preprogrammed to a specific performance state, which may
not be zero initially during boot. This may lead to that genpd's current
performance state becomes inconsistent with the state of the hardware. To
deal with this, the driver for a device that is being attached to its
genpd, need to request an initial performance state vote, which is
typically done by calling some of the OPP APIs while probing.
In some cases this would lead to boilerplate code in the drivers. Let's
make it possible to avoid this, by adding a new optional callback to genpd
and invoke it per device during the attach process. In this way, the genpd
provider driver can inform genpd about the initial performance state that
is needed for the device.
Signed-off-by: Ulf Hansson <redacted>
---
drivers/base/power/domain.c | 8 +++++---
include/linux/pm_domain.h | 2 ++
2 files changed, 7 insertions(+), 3 deletions(-)
@@ -2701,7 +2703,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,}/* Set the default performance state */-pstate=genpd_get_default_performance_state(dev,index);+pstate=genpd_get_default_performance_state(pd,dev,index);
If base device is suspended, then its performance state is zero.
When device will be rpm-resumed, then its performance should be set to
the default state.
You're setting performance state of the wrong device, it should be the
Are you okay with my variant of handling the suspended device?
Not sure if you intended to post this line?
In any case, I am happy to help and review to move things forward.
It's not clear to me whether you omitted handling the case of
rpm-suspended device on purpose or not. I think it should be a part of
this patch, but sounds like you want to work on it separately, correct?
I didn't omit the handling, but instead relied solely on the
pm_runtime_suspended() check in dev_pm_genpd_set_performance_state().
It doesn't work as expected for Tegra because pm_runtime_suspended()
returns false while RPM is disabled and it's normally disabled at the
attachment time.
quoted
quoted
quoted
quoted
quoted
base device and not the virtual domain device.
No I am not. :-) Let me elaborate.
For the single PM domain case, 'dev' and 'base_dev' are pointing to
the same device. So this works fine.
For the multiple PM domain case or when attaching goes via
genpd_dev_pm_attach_by_id(), 'dev' is the virtual device registered in
genpd_dev_pm_attach_by_id(). In this case, it's 'dev' that is becoming
attached to genpd and not the 'base_dev'. Note also that, runtime PM
has not been enabled for 'dev' yet at this point and 'dev' has been
assigned the same OF node as 'base_dev", to allow OF parsing to work
as is for it.
Moreover, to deal with runtime PM in the multiple PM domain case, the
consumer driver should create a device link. Along the lines of this:
device_link_add(base_dev, dev, DL_FLAG_PM_RUNTIME |
DL_FLAG_STATELESS), thus assigning the virtual device ('dev') as the
supplier for its consumer device ('base_dev').
quoted
These all is handled properly by my patch [1]. Hence it's complicated
for the reason.
See above. It shouldn't have to be complicated. If it still is, there
is something to fix for the multiple PM domain case.
quoted
[1]
Alright, it actually works now on Tegra using the dev in the callback
for the case of multiple domains, I re-checked it. Previously, when I
tried that, there was a conflict in regards to OPP usage, I don't
remember details anymore. Maybe the recent changes that were suggested
by Viresh helped with that. So yes, there is no need to pass the base
device anymore.
Great! So, it seems like $subject patch should be a way forward for you then?
The current behaviour is incorrect for Tegra because it needs to set the
rpm_pstate for rpm-suspended device, instead of bumping the state
immediately.
Power management is defeated without it on Tegra because SoC will start
to consume extra power while device that needs this power is suspended.
Okay, I understand your concern.
For devices that may remain runtime suspended when their consumer
drivers probes them, the behaviour may be suboptimal. This because it
could lead to having an active performance state vote for a runtime
suspended device, at least until it gets runtime resumed and then
runtime suspended again.
This all boils down to how the consumer driver deploys support for
runtime PM - and genpd doesn't know nor can control that.
I wonder if we perhaps should just leave this as is then. In other
words, rely on the consumer driver to vote for an initial performance
state of the device during ->probe(). In this way, the consumer driver
can decide what is the best thing to do, rather than letting genpd
make guesses.
The point of this series is to remove the boilerplate code from consumer
drivers.
I already implemented variant with the explicit state syncing done by
consumer drivers, but Viresh suggested that it should be done by the PD
driver, this is why we're discussing it all over again.
We either need to add quirks to consumer drivers or make PD API more
flexible. You're not in favor of extending the PD API. To me the variant
with the PD API extension is a bit nicer since it removes the
boilerplate code, but I also see why you don't like it.
Viresh, are you okay with going back to the variant with the
dev_pm_opp_sync() helper?
Note that, comparing what we have done for power on/off during
attach/probe. For the legacy case (the single PM domain case) we power
on the PM domain. For the multiple PM domain case, we leave the PM
domain as is.
That is a similar situation here. If PD driver doesn't implement the new
dev_get_performance_state() callback, then nothing is changed for the
consumer drivers.
quoted
Otherwise $subject looks okay.
quoted
BTW, I forgot to add your Suggested-by: tag for the patch, you
certainly deserve at least that. Or perhaps you are fine with
co-developed by tag?
Either is fine. Although, won't it be easier to keep these PD patches
within the Tegra series since it depends on them? I can pick up the
patches into the next version of Tegra series.
Let's see. If we can agree on how to deal with this series, maybe we
can ask Rafael to send another pull-request before rc1 is out, so you
can base your series for Tegra more easily on top.
On Mon, 6 Sept 2021 at 16:11, Dmitry Osipenko [off-list ref] wrote:
06.09.2021 13:24, Ulf Hansson пишет:
quoted
On Sun, 5 Sept 2021 at 10:26, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 17:03, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 11:58, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 11:22, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 08:01, Dmitry Osipenko [off-list ref] wrote:
quoted
02.09.2021 13:16, Ulf Hansson пишет:
quoted
When a device is detached from its genpd, genpd loses track of the device,
including its performance state vote that may have been requested for it.
Rather than relying on the consumer driver to drop the performance state
vote for its device, let's do it internally in genpd when the device is
getting detached. In this way, we makes sure that the aggregation of the
votes in genpd becomes correct.
This is a dangerous behaviour in a case where performance state
represents voltage. If hardware is kept active on detachment, say it's
always-on, then it may be a disaster to drop the voltage for the active
hardware.
It's safe to drop performance state only if you assume that there is a
firmware behind kernel which has its own layer of performance management
and it will prevent the disaster by saying 'nope, I'm not doing this'.
The performance state should be persistent for a device and it should be
controlled in a conjunction with runtime PM. If platform wants to drop
performance state to zero on detachment, then this behaviour should be
specific to that platform.
I understand your concern, but at this point, genpd can't help to fix this.
Genpd has no information about the device, unless it's attached to it.
For now and for these always on HWs, we simply need to make sure the
device stays attached, in one way or the other.
This indeed requires to redesign GENPD to make it more coupled with a
device, but this is not a real problem for any of the current API users
AFAIK. Ideally the state should be persistent to make API more universal.
Right. In fact this has been discussed in the past. In principle, the
idea was to attach to genpd at device registration, rather than at
driver probe.
Although, this is not very easy to implement - and it seems like the
churns to do, have not been really worth it. At least so far.
quoted
Since for today we assume that device should be suspended at the time of
the detachment (if the default OPP state isn't used), it may be better
to add a noisy warning message if pstate!=0, keeping the state untouched
if it's not zero.
That would just be very silly in my opinion.
When the device is detached (suspended or not), it may cause it's PM
domain to be powered off - and there is really nothing we can do about
that from the genpd point of view.
As stated, the only current short term solution is to avoid detaching
the device. Anything else, would just be papering of the issue.
What about to re-evaluate the performance state of the domain after
detachment instead of setting the state to zero?
I am not suggesting to set the performance state of the genpd to zero,
but to drop a potential vote for a performance state for the *device*
that is about to be detached.
By removing the vote of the *device*, you will drop the performance
state of the genpd. If device is active and it's wrong to drop its
state, then you may cause the damage.
quoted
Calling genpd_set_performance_state(dev, 0), during detach will have
the same effect as triggering a re-evaluation of the performance state
for the genpd, but after the detach.
Yes
quoted
quoted
This way PD driver may
take an action on detachment if performance isn't zero, before hardware
is crashed, for example it may emit a warning.
Not sure I got that. Exactly when do you want to emit a warning and
for what reason?
Do you want to add a check somewhere to see if
'gpd_data->performance_state' is non zero - and then print a warning?
I want to check the 'gpd_data->performance_state' from the detachment
callback and emit the warning + lock further performance changes in the
PD driver since it's a error condition.
Alright, so if I understand correctly, you intend to do the check for
the "error condition" of the device in the genpd->detach_dev()
callback?
What exactly do you intend to do beyond this point, if you detect the
"error condition"? Locking further changes of the performance state
seems fragile too, especially if some other device/driver requires the
performance state to be raised. It sounds like you simply need to call
BUG_ON() then?
Also note that a very similar problem exists, *before* the device gets
attached in the first place. More precisely, nothing prevents the
performance state from being set to a non-compatible value for an
always-on HW/device that hasn't been attached yet. So maybe you need
to set the maximum performance state at genpd initializations, then
use the ->sync_state() callback to very that all consumers have been
attached to the genpd provider, before allowing the state to be
changed/lowered?
Kind regards
Uffe
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Mon, 6 Sept 2021 at 16:11, Dmitry Osipenko [off-list ref] wrote:
quoted
06.09.2021 13:24, Ulf Hansson пишет:
quoted
On Sun, 5 Sept 2021 at 10:26, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 17:03, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 11:58, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 11:22, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 08:01, Dmitry Osipenko [off-list ref] wrote:
quoted
02.09.2021 13:16, Ulf Hansson пишет:
quoted
When a device is detached from its genpd, genpd loses track of the device,
including its performance state vote that may have been requested for it.
Rather than relying on the consumer driver to drop the performance state
vote for its device, let's do it internally in genpd when the device is
getting detached. In this way, we makes sure that the aggregation of the
votes in genpd becomes correct.
This is a dangerous behaviour in a case where performance state
represents voltage. If hardware is kept active on detachment, say it's
always-on, then it may be a disaster to drop the voltage for the active
hardware.
It's safe to drop performance state only if you assume that there is a
firmware behind kernel which has its own layer of performance management
and it will prevent the disaster by saying 'nope, I'm not doing this'.
The performance state should be persistent for a device and it should be
controlled in a conjunction with runtime PM. If platform wants to drop
performance state to zero on detachment, then this behaviour should be
specific to that platform.
I understand your concern, but at this point, genpd can't help to fix this.
Genpd has no information about the device, unless it's attached to it.
For now and for these always on HWs, we simply need to make sure the
device stays attached, in one way or the other.
This indeed requires to redesign GENPD to make it more coupled with a
device, but this is not a real problem for any of the current API users
AFAIK. Ideally the state should be persistent to make API more universal.
Right. In fact this has been discussed in the past. In principle, the
idea was to attach to genpd at device registration, rather than at
driver probe.
Although, this is not very easy to implement - and it seems like the
churns to do, have not been really worth it. At least so far.
quoted
Since for today we assume that device should be suspended at the time of
the detachment (if the default OPP state isn't used), it may be better
to add a noisy warning message if pstate!=0, keeping the state untouched
if it's not zero.
That would just be very silly in my opinion.
When the device is detached (suspended or not), it may cause it's PM
domain to be powered off - and there is really nothing we can do about
that from the genpd point of view.
As stated, the only current short term solution is to avoid detaching
the device. Anything else, would just be papering of the issue.
What about to re-evaluate the performance state of the domain after
detachment instead of setting the state to zero?
I am not suggesting to set the performance state of the genpd to zero,
but to drop a potential vote for a performance state for the *device*
that is about to be detached.
By removing the vote of the *device*, you will drop the performance
state of the genpd. If device is active and it's wrong to drop its
state, then you may cause the damage.
quoted
Calling genpd_set_performance_state(dev, 0), during detach will have
the same effect as triggering a re-evaluation of the performance state
for the genpd, but after the detach.
Yes
quoted
quoted
This way PD driver may
take an action on detachment if performance isn't zero, before hardware
is crashed, for example it may emit a warning.
Not sure I got that. Exactly when do you want to emit a warning and
for what reason?
Do you want to add a check somewhere to see if
'gpd_data->performance_state' is non zero - and then print a warning?
I want to check the 'gpd_data->performance_state' from the detachment
callback and emit the warning + lock further performance changes in the
PD driver since it's a error condition.
Alright, so if I understand correctly, you intend to do the check for
the "error condition" of the device in the genpd->detach_dev()
callback?
Yes
What exactly do you intend to do beyond this point, if you detect the
"error condition"? Locking further changes of the performance state
seems fragile too, especially if some other device/driver requires the
performance state to be raised. It sounds like you simply need to call
BUG_ON() then?
I can lock it to high performance state.
Also note that a very similar problem exists, *before* the device gets
attached in the first place. More precisely, nothing prevents the
performance state from being set to a non-compatible value for an
always-on HW/device that hasn't been attached yet. So maybe you need
to set the maximum performance state at genpd initializations, then
use the ->sync_state() callback to very that all consumers have been
attached to the genpd provider, before allowing the state to be
changed/lowered?
Viresh, are you okay with going back to the variant with the
dev_pm_opp_sync() helper?
I have missed a lot of stuff in between and wasn't following this
carefully as I thought my half was resolved :)
Can you describe what to propose to do again ? From what I remember,
doing this one time from probe() is okay, doing it from
suspend/resume, not so much.
--
viresh
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Viresh, are you okay with going back to the variant with the
dev_pm_opp_sync() helper?
I have missed a lot of stuff in between and wasn't following this
carefully as I thought my half was resolved :)
Can you describe what to propose to do again ? From what I remember,
doing this one time from probe() is okay, doing it from
suspend/resume, not so much.
Hmm.. actually, it's not a problem to set up the performance state from
probe() now with that recent change that was made to the PD core. [1]
[1]
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=3c5a272202c28c1f9309566f206ba40787246149
And then we indeed don't need neither the dev_get_performance_state()
callback, nor the dev_pm_opp_sync() helper.
The devm_tegra_core_dev_init_opp_table() already supports performance
state syncing, so I will just need to call it after the RPM setup made
by consumer driver, allowing PD core to set the rpm_pstate. I already
gave it a quick test and it works perfectly.
Ulf, are you okay with abandoning the dev_get_performance_state()
callback? We don't need it anymore.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Mon, 6 Sept 2021 at 16:35, Dmitry Osipenko [off-list ref] wrote:
06.09.2021 13:53, Ulf Hansson пишет:
quoted
On Sun, 5 Sept 2021 at 11:11, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 17:09, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 12:06, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 11:55, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 08:00, Dmitry Osipenko [off-list ref] wrote:
quoted
02.09.2021 13:16, Ulf Hansson пишет:
quoted
Hardware may be preprogrammed to a specific performance state, which may
not be zero initially during boot. This may lead to that genpd's current
performance state becomes inconsistent with the state of the hardware. To
deal with this, the driver for a device that is being attached to its
genpd, need to request an initial performance state vote, which is
typically done by calling some of the OPP APIs while probing.
In some cases this would lead to boilerplate code in the drivers. Let's
make it possible to avoid this, by adding a new optional callback to genpd
and invoke it per device during the attach process. In this way, the genpd
provider driver can inform genpd about the initial performance state that
is needed for the device.
Signed-off-by: Ulf Hansson <redacted>
---
drivers/base/power/domain.c | 8 +++++---
include/linux/pm_domain.h | 2 ++
2 files changed, 7 insertions(+), 3 deletions(-)
@@ -2701,7 +2703,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,}/* Set the default performance state */-pstate=genpd_get_default_performance_state(dev,index);+pstate=genpd_get_default_performance_state(pd,dev,index);
If base device is suspended, then its performance state is zero.
When device will be rpm-resumed, then its performance should be set to
the default state.
You're setting performance state of the wrong device, it should be the
Are you okay with my variant of handling the suspended device?
Not sure if you intended to post this line?
In any case, I am happy to help and review to move things forward.
It's not clear to me whether you omitted handling the case of
rpm-suspended device on purpose or not. I think it should be a part of
this patch, but sounds like you want to work on it separately, correct?
I didn't omit the handling, but instead relied solely on the
pm_runtime_suspended() check in dev_pm_genpd_set_performance_state().
It doesn't work as expected for Tegra because pm_runtime_suspended()
returns false while RPM is disabled and it's normally disabled at the
attachment time.
Runtime PM is in most cases (probably all) not enabled for the device
when attaching.
This isn't specific to Tegra, but a common behavior of how it works
during attach.
quoted
quoted
quoted
quoted
quoted
quoted
base device and not the virtual domain device.
No I am not. :-) Let me elaborate.
For the single PM domain case, 'dev' and 'base_dev' are pointing to
the same device. So this works fine.
For the multiple PM domain case or when attaching goes via
genpd_dev_pm_attach_by_id(), 'dev' is the virtual device registered in
genpd_dev_pm_attach_by_id(). In this case, it's 'dev' that is becoming
attached to genpd and not the 'base_dev'. Note also that, runtime PM
has not been enabled for 'dev' yet at this point and 'dev' has been
assigned the same OF node as 'base_dev", to allow OF parsing to work
as is for it.
Moreover, to deal with runtime PM in the multiple PM domain case, the
consumer driver should create a device link. Along the lines of this:
device_link_add(base_dev, dev, DL_FLAG_PM_RUNTIME |
DL_FLAG_STATELESS), thus assigning the virtual device ('dev') as the
supplier for its consumer device ('base_dev').
quoted
These all is handled properly by my patch [1]. Hence it's complicated
for the reason.
See above. It shouldn't have to be complicated. If it still is, there
is something to fix for the multiple PM domain case.
quoted
[1]
Alright, it actually works now on Tegra using the dev in the callback
for the case of multiple domains, I re-checked it. Previously, when I
tried that, there was a conflict in regards to OPP usage, I don't
remember details anymore. Maybe the recent changes that were suggested
by Viresh helped with that. So yes, there is no need to pass the base
device anymore.
Great! So, it seems like $subject patch should be a way forward for you then?
The current behaviour is incorrect for Tegra because it needs to set the
rpm_pstate for rpm-suspended device, instead of bumping the state
immediately.
Power management is defeated without it on Tegra because SoC will start
to consume extra power while device that needs this power is suspended.
Okay, I understand your concern.
For devices that may remain runtime suspended when their consumer
drivers probes them, the behaviour may be suboptimal. This because it
could lead to having an active performance state vote for a runtime
suspended device, at least until it gets runtime resumed and then
runtime suspended again.
This all boils down to how the consumer driver deploys support for
runtime PM - and genpd doesn't know nor can control that.
Unfortunately, no, it still doesn't. Let me try to elaborate why below.
quoted
I wonder if we perhaps should just leave this as is then. In other
words, rely on the consumer driver to vote for an initial performance
state of the device during ->probe(). In this way, the consumer driver
can decide what is the best thing to do, rather than letting genpd
make guesses.
The point of this series is to remove the boilerplate code from consumer
drivers.
I already implemented variant with the explicit state syncing done by
consumer drivers, but Viresh suggested that it should be done by the PD
driver, this is why we're discussing it all over again.
We either need to add quirks to consumer drivers or make PD API more
flexible. You're not in favor of extending the PD API. To me the variant
with the PD API extension is a bit nicer since it removes the
boilerplate code, but I also see why you don't like it.
I don't mind extending the genpd API, but it needs to serve a good purpose.
As I said earlier, genpd doesn't know nor can control how the consumer
driver deploys runtime PM. Unfortunately, that also includes genpd
providers, as the behavior isn't a platform or PM domain specific
thing. This means genpd needs to be generic enough so it works for all
cases.
In the $subject patch, we rely on the pm_runtime_suspended() check in
dev_pm_genpd_set_performance_state(), which should work for all cases,
even if it may be sub-optimal for some scenarios.
Note that, in the approach your suggested [1],
pm_runtime_status_suspended() is used instead. This doesn't work when
a consumer driver doesn't enable runtime PM - or calls
pm_runtime_set_active() during ->probe(), because
genpd_runtime_resume() won't be invoked to restore the gpd->rpm_state.
That said, I wouldn't mind to simply skip adding the
->dev_get_performance_state() all together, if that is what you
prefer? In this way, it becomes the responsibility for the consumer
driver to do right thing, with the cost of some boilerplate code added
in its ->probe() routine.
Viresh, are you okay with going back to the variant with the
dev_pm_opp_sync() helper?
Rather than trying this again, I would suggest you start by open
coding these parts, for now. But I leave that to Viresh to decide.
[...]
Kind regards
Uffe
[1]
[PATCH v10 4/8] PM: domains: Add dev_get_performance_state() callback
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Mon, 6 Sept 2021 at 21:33, Dmitry Osipenko [off-list ref] wrote:
06.09.2021 20:34, Ulf Hansson пишет:
quoted
On Mon, 6 Sept 2021 at 16:11, Dmitry Osipenko [off-list ref] wrote:
quoted
06.09.2021 13:24, Ulf Hansson пишет:
quoted
On Sun, 5 Sept 2021 at 10:26, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 17:03, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 11:58, Dmitry Osipenko [off-list ref] wrote:
quoted
03.09.2021 11:22, Ulf Hansson пишет:
quoted
On Fri, 3 Sept 2021 at 08:01, Dmitry Osipenko [off-list ref] wrote:
quoted
02.09.2021 13:16, Ulf Hansson пишет:
quoted
When a device is detached from its genpd, genpd loses track of the device,
including its performance state vote that may have been requested for it.
Rather than relying on the consumer driver to drop the performance state
vote for its device, let's do it internally in genpd when the device is
getting detached. In this way, we makes sure that the aggregation of the
votes in genpd becomes correct.
This is a dangerous behaviour in a case where performance state
represents voltage. If hardware is kept active on detachment, say it's
always-on, then it may be a disaster to drop the voltage for the active
hardware.
It's safe to drop performance state only if you assume that there is a
firmware behind kernel which has its own layer of performance management
and it will prevent the disaster by saying 'nope, I'm not doing this'.
The performance state should be persistent for a device and it should be
controlled in a conjunction with runtime PM. If platform wants to drop
performance state to zero on detachment, then this behaviour should be
specific to that platform.
I understand your concern, but at this point, genpd can't help to fix this.
Genpd has no information about the device, unless it's attached to it.
For now and for these always on HWs, we simply need to make sure the
device stays attached, in one way or the other.
This indeed requires to redesign GENPD to make it more coupled with a
device, but this is not a real problem for any of the current API users
AFAIK. Ideally the state should be persistent to make API more universal.
Right. In fact this has been discussed in the past. In principle, the
idea was to attach to genpd at device registration, rather than at
driver probe.
Although, this is not very easy to implement - and it seems like the
churns to do, have not been really worth it. At least so far.
quoted
Since for today we assume that device should be suspended at the time of
the detachment (if the default OPP state isn't used), it may be better
to add a noisy warning message if pstate!=0, keeping the state untouched
if it's not zero.
That would just be very silly in my opinion.
When the device is detached (suspended or not), it may cause it's PM
domain to be powered off - and there is really nothing we can do about
that from the genpd point of view.
As stated, the only current short term solution is to avoid detaching
the device. Anything else, would just be papering of the issue.
What about to re-evaluate the performance state of the domain after
detachment instead of setting the state to zero?
I am not suggesting to set the performance state of the genpd to zero,
but to drop a potential vote for a performance state for the *device*
that is about to be detached.
By removing the vote of the *device*, you will drop the performance
state of the genpd. If device is active and it's wrong to drop its
state, then you may cause the damage.
quoted
Calling genpd_set_performance_state(dev, 0), during detach will have
the same effect as triggering a re-evaluation of the performance state
for the genpd, but after the detach.
Yes
quoted
quoted
This way PD driver may
take an action on detachment if performance isn't zero, before hardware
is crashed, for example it may emit a warning.
Not sure I got that. Exactly when do you want to emit a warning and
for what reason?
Do you want to add a check somewhere to see if
'gpd_data->performance_state' is non zero - and then print a warning?
I want to check the 'gpd_data->performance_state' from the detachment
callback and emit the warning + lock further performance changes in the
PD driver since it's a error condition.
Alright, so if I understand correctly, you intend to do the check for
the "error condition" of the device in the genpd->detach_dev()
callback?
Yes
Okay.
quoted
What exactly do you intend to do beyond this point, if you detect the
"error condition"? Locking further changes of the performance state
seems fragile too, especially if some other device/driver requires the
performance state to be raised. It sounds like you simply need to call
BUG_ON() then?
I can lock it to high performance state.
Alright.
quoted
Also note that a very similar problem exists, *before* the device gets
attached in the first place. More precisely, nothing prevents the
performance state from being set to a non-compatible value for an
always-on HW/device that hasn't been attached yet. So maybe you need
to set the maximum performance state at genpd initializations, then
use the ->sync_state() callback to very that all consumers have been
attached to the genpd provider, before allowing the state to be
changed/lowered?
Yes, I already knew that, but forgot it. :-) Thanks for the pointer.
Let me rethink the approach.
In a way, it kind of sounds like this is a generic problem - so
perhaps we should think of adding a ->withdraw_sync_state() callback
that can be assigned by provider drivers, to get informed when a
consumer driver is getting unbinded.
Kind regards
Uffe
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
I don't mind extending the genpd API, but it needs to serve a good purpose.
As I said earlier, genpd doesn't know nor can control how the consumer
driver deploys runtime PM. Unfortunately, that also includes genpd
providers, as the behavior isn't a platform or PM domain specific
thing. This means genpd needs to be generic enough so it works for all
cases.
In the $subject patch, we rely on the pm_runtime_suspended() check in
dev_pm_genpd_set_performance_state(), which should work for all cases,
even if it may be sub-optimal for some scenarios.
Note that, in the approach your suggested [1],
pm_runtime_status_suspended() is used instead. This doesn't work when
a consumer driver doesn't enable runtime PM - or calls
pm_runtime_set_active() during ->probe(), because
genpd_runtime_resume() won't be invoked to restore the gpd->rpm_state.
That said, I wouldn't mind to simply skip adding the
->dev_get_performance_state() all together, if that is what you
prefer? In this way, it becomes the responsibility for the consumer
driver to do right thing, with the cost of some boilerplate code added
in its ->probe() routine.
Until a day ago, it wasn't clear to me that consumer drivers now can set
up rpm_pstate during probe(), which is a cleaner solution that works
well. So let's skip adding the questionable ->dev_get_performance_state().
The boilerplate code in the probe() is minimal in comparison to a
previous variant with the state-syncing done by rpm-resume callbacks of
consumer drivers, it's good enough.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Also note that a very similar problem exists, *before* the device gets
attached in the first place. More precisely, nothing prevents the
performance state from being set to a non-compatible value for an
always-on HW/device that hasn't been attached yet. So maybe you need
to set the maximum performance state at genpd initializations, then
use the ->sync_state() callback to very that all consumers have been
attached to the genpd provider, before allowing the state to be
changed/lowered?
Yes, I already knew that, but forgot it. :-) Thanks for the pointer.
Let me rethink the approach.
In a way, it kind of sounds like this is a generic problem - so
perhaps we should think of adding a ->withdraw_sync_state() callback
that can be assigned by provider drivers, to get informed when a
consumer driver is getting unbinded.
Not sure, doesn't feel to me that this is necessary for today. A bit too
cumbersome for a simple sanity-check, IMO.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Thu, 9 Sept 2021 at 15:48, Dmitry Osipenko [off-list ref] wrote:
07.09.2021 12:57, Ulf Hansson пишет:
quoted
I don't mind extending the genpd API, but it needs to serve a good purpose.
As I said earlier, genpd doesn't know nor can control how the consumer
driver deploys runtime PM. Unfortunately, that also includes genpd
providers, as the behavior isn't a platform or PM domain specific
thing. This means genpd needs to be generic enough so it works for all
cases.
In the $subject patch, we rely on the pm_runtime_suspended() check in
dev_pm_genpd_set_performance_state(), which should work for all cases,
even if it may be sub-optimal for some scenarios.
Note that, in the approach your suggested [1],
pm_runtime_status_suspended() is used instead. This doesn't work when
a consumer driver doesn't enable runtime PM - or calls
pm_runtime_set_active() during ->probe(), because
genpd_runtime_resume() won't be invoked to restore the gpd->rpm_state.
That said, I wouldn't mind to simply skip adding the
->dev_get_performance_state() all together, if that is what you
prefer? In this way, it becomes the responsibility for the consumer
driver to do right thing, with the cost of some boilerplate code added
in its ->probe() routine.
Until a day ago, it wasn't clear to me that consumer drivers now can set
up rpm_pstate during probe(), which is a cleaner solution that works
well. So let's skip adding the questionable ->dev_get_performance_state().
The boilerplate code in the probe() is minimal in comparison to a
previous variant with the state-syncing done by rpm-resume callbacks of
consumer drivers, it's good enough.
Alright, that sounds good to me as well.
I am happy to help with review of the consumer driver changes, just
keep me posted.
Thanks and kind regards
Uffe
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Thu, 9 Sept 2021 at 15:48, Dmitry Osipenko [off-list ref] wrote:
07.09.2021 13:16, Ulf Hansson пишет:
...
quoted
quoted
quoted
Also note that a very similar problem exists, *before* the device gets
attached in the first place. More precisely, nothing prevents the
performance state from being set to a non-compatible value for an
always-on HW/device that hasn't been attached yet. So maybe you need
to set the maximum performance state at genpd initializations, then
use the ->sync_state() callback to very that all consumers have been
attached to the genpd provider, before allowing the state to be
changed/lowered?
Yes, I already knew that, but forgot it. :-) Thanks for the pointer.
Let me rethink the approach.
In a way, it kind of sounds like this is a generic problem - so
perhaps we should think of adding a ->withdraw_sync_state() callback
that can be assigned by provider drivers, to get informed when a
consumer driver is getting unbinded.
Not sure, doesn't feel to me that this is necessary for today. A bit too
cumbersome for a simple sanity-check, IMO.
Maybe, but I can bring it up with the fw_devlinks people to see what they think.
In any case, we should not move forward with $subject patch as is.
Let me think about it.
Kind regards
Uffe
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Thu, 9 Sept 2021 at 15:48, Dmitry Osipenko [off-list ref] wrote:
quoted
07.09.2021 12:57, Ulf Hansson пишет:
quoted
I don't mind extending the genpd API, but it needs to serve a good purpose.
As I said earlier, genpd doesn't know nor can control how the consumer
driver deploys runtime PM. Unfortunately, that also includes genpd
providers, as the behavior isn't a platform or PM domain specific
thing. This means genpd needs to be generic enough so it works for all
cases.
In the $subject patch, we rely on the pm_runtime_suspended() check in
dev_pm_genpd_set_performance_state(), which should work for all cases,
even if it may be sub-optimal for some scenarios.
Note that, in the approach your suggested [1],
pm_runtime_status_suspended() is used instead. This doesn't work when
a consumer driver doesn't enable runtime PM - or calls
pm_runtime_set_active() during ->probe(), because
genpd_runtime_resume() won't be invoked to restore the gpd->rpm_state.
That said, I wouldn't mind to simply skip adding the
->dev_get_performance_state() all together, if that is what you
prefer? In this way, it becomes the responsibility for the consumer
driver to do right thing, with the cost of some boilerplate code added
in its ->probe() routine.
Until a day ago, it wasn't clear to me that consumer drivers now can set
up rpm_pstate during probe(), which is a cleaner solution that works
well. So let's skip adding the questionable ->dev_get_performance_state().
The boilerplate code in the probe() is minimal in comparison to a
previous variant with the state-syncing done by rpm-resume callbacks of
consumer drivers, it's good enough.
Alright, that sounds good to me as well.
I am happy to help with review of the consumer driver changes, just
keep me posted.