* [PATCH v2] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()
@ 2025-01-09 17:54 Raphael Gallais-Pou
2025-01-10 5:19 ` Damien Le Moal
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Raphael Gallais-Pou @ 2025-01-09 17:54 UTC (permalink / raw)
To: Patrice Chotard, Damien Le Moal, Niklas Cassel
Cc: linux-arm-kernel, linux-ide, linux-kernel
Letting the compiler remove these functions when the kernel is built
without CONFIG_PM_SLEEP support is simpler and less error prone than the
use of #ifdef based kernel configuration guards.
Signed-off-by: Raphael Gallais-Pou <rgallaispou@gmail.com>
---
Changes in v2:
- Split serie in single patches
- Remove irrelevant 'Link:' from commit log
- Link to v1: https://lore.kernel.org/r/20241229-update_pm_macro-v1-4-c7d4c4856336@gmail.com
---
drivers/ata/ahci_st.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/ata/ahci_st.c b/drivers/ata/ahci_st.c
index 6b9b4a1dfa15..4336c8a6e208 100644
--- a/drivers/ata/ahci_st.c
+++ b/drivers/ata/ahci_st.c
@@ -176,7 +176,6 @@ static int st_ahci_probe(struct platform_device *pdev)
return 0;
}
-#ifdef CONFIG_PM_SLEEP
static int st_ahci_suspend(struct device *dev)
{
struct ata_host *host = dev_get_drvdata(dev);
@@ -221,9 +220,8 @@ static int st_ahci_resume(struct device *dev)
return ahci_platform_resume_host(dev);
}
-#endif
-static SIMPLE_DEV_PM_OPS(st_ahci_pm_ops, st_ahci_suspend, st_ahci_resume);
+static DEFINE_SIMPLE_DEV_PM_OPS(st_ahci_pm_ops, st_ahci_suspend, st_ahci_resume);
static const struct of_device_id st_ahci_match[] = {
{ .compatible = "st,ahci", },
@@ -234,7 +232,7 @@ MODULE_DEVICE_TABLE(of, st_ahci_match);
static struct platform_driver st_ahci_driver = {
.driver = {
.name = DRV_NAME,
- .pm = &st_ahci_pm_ops,
+ .pm = pm_sleep_ptr(&st_ahci_pm_ops),
.of_match_table = st_ahci_match,
},
.probe = st_ahci_probe,
--
2.47.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()
2025-01-09 17:54 [PATCH v2] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr() Raphael Gallais-Pou
@ 2025-01-10 5:19 ` Damien Le Moal
2025-01-10 11:23 ` Niklas Cassel
2025-01-10 11:20 ` Niklas Cassel
2025-01-15 14:23 ` Niklas Cassel
2 siblings, 1 reply; 10+ messages in thread
From: Damien Le Moal @ 2025-01-10 5:19 UTC (permalink / raw)
To: Raphael Gallais-Pou, Patrice Chotard, Niklas Cassel
Cc: linux-arm-kernel, linux-ide, linux-kernel
On 1/10/25 02:54, Raphael Gallais-Pou wrote:
> Letting the compiler remove these functions when the kernel is built
> without CONFIG_PM_SLEEP support is simpler and less error prone than the
> use of #ifdef based kernel configuration guards.
>
> Signed-off-by: Raphael Gallais-Pou <rgallaispou@gmail.com>
> ---
> Changes in v2:
> - Split serie in single patches
> - Remove irrelevant 'Link:' from commit log
> - Link to v1: https://lore.kernel.org/r/20241229-update_pm_macro-v1-4-c7d4c4856336@gmail.com
> ---
> drivers/ata/ahci_st.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/ata/ahci_st.c b/drivers/ata/ahci_st.c
> index 6b9b4a1dfa15..4336c8a6e208 100644
> --- a/drivers/ata/ahci_st.c
> +++ b/drivers/ata/ahci_st.c
> @@ -176,7 +176,6 @@ static int st_ahci_probe(struct platform_device *pdev)
> return 0;
> }
>
> -#ifdef CONFIG_PM_SLEEP
> static int st_ahci_suspend(struct device *dev)
> {
> struct ata_host *host = dev_get_drvdata(dev);
> @@ -221,9 +220,8 @@ static int st_ahci_resume(struct device *dev)
>
> return ahci_platform_resume_host(dev);
> }
> -#endif
I do not think you can remove the ifdef here. Otherwise, there is going to be a
compilation warning when CONFIG_PM_SLEEP is not enabled. No ?
>
> -static SIMPLE_DEV_PM_OPS(st_ahci_pm_ops, st_ahci_suspend, st_ahci_resume);
> +static DEFINE_SIMPLE_DEV_PM_OPS(st_ahci_pm_ops, st_ahci_suspend, st_ahci_resume);
>
> static const struct of_device_id st_ahci_match[] = {
> { .compatible = "st,ahci", },
> @@ -234,7 +232,7 @@ MODULE_DEVICE_TABLE(of, st_ahci_match);
> static struct platform_driver st_ahci_driver = {
> .driver = {
> .name = DRV_NAME,
> - .pm = &st_ahci_pm_ops,
> + .pm = pm_sleep_ptr(&st_ahci_pm_ops),
> .of_match_table = st_ahci_match,
> },
> .probe = st_ahci_probe,
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v2] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()
2025-01-10 5:19 ` Damien Le Moal
@ 2025-01-10 11:23 ` Niklas Cassel
2025-01-10 12:02 ` Damien Le Moal
0 siblings, 1 reply; 10+ messages in thread
From: Niklas Cassel @ 2025-01-10 11:23 UTC (permalink / raw)
To: Damien Le Moal
Cc: Raphael Gallais-Pou, Patrice Chotard, linux-arm-kernel, linux-ide,
linux-kernel
On Fri, Jan 10, 2025 at 02:19:06PM +0900, Damien Le Moal wrote:
> On 1/10/25 02:54, Raphael Gallais-Pou wrote:
> > Letting the compiler remove these functions when the kernel is built
> > without CONFIG_PM_SLEEP support is simpler and less error prone than the
> > use of #ifdef based kernel configuration guards.
> >
> > Signed-off-by: Raphael Gallais-Pou <rgallaispou@gmail.com>
> > ---
> > Changes in v2:
> > - Split serie in single patches
> > - Remove irrelevant 'Link:' from commit log
> > - Link to v1: https://lore.kernel.org/r/20241229-update_pm_macro-v1-4-c7d4c4856336@gmail.com
> > ---
> > drivers/ata/ahci_st.c | 6 ++----
> > 1 file changed, 2 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/ata/ahci_st.c b/drivers/ata/ahci_st.c
> > index 6b9b4a1dfa15..4336c8a6e208 100644
> > --- a/drivers/ata/ahci_st.c
> > +++ b/drivers/ata/ahci_st.c
> > @@ -176,7 +176,6 @@ static int st_ahci_probe(struct platform_device *pdev)
> > return 0;
> > }
> >
> > -#ifdef CONFIG_PM_SLEEP
> > static int st_ahci_suspend(struct device *dev)
> > {
> > struct ata_host *host = dev_get_drvdata(dev);
> > @@ -221,9 +220,8 @@ static int st_ahci_resume(struct device *dev)
> >
> > return ahci_platform_resume_host(dev);
> > }
> > -#endif
>
> I do not think you can remove the ifdef here. Otherwise, there is going to be a
> compilation warning when CONFIG_PM_SLEEP is not enabled. No ?
Look at the pm_sleep_ptr macro:
include/linux/pm.h:#define pm_sleep_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM_SLEEP), (_ptr))
I would expect the function should be optimized out by the compiler
using dead code elimination.
Raphael, perhaps you could show the before and after output
using ./scripts/bloat-o-meter ?
(When the config is not enabled: before and after your patch.)
>
> >
> > -static SIMPLE_DEV_PM_OPS(st_ahci_pm_ops, st_ahci_suspend, st_ahci_resume);
> > +static DEFINE_SIMPLE_DEV_PM_OPS(st_ahci_pm_ops, st_ahci_suspend, st_ahci_resume);
> >
> > static const struct of_device_id st_ahci_match[] = {
> > { .compatible = "st,ahci", },
> > @@ -234,7 +232,7 @@ MODULE_DEVICE_TABLE(of, st_ahci_match);
> > static struct platform_driver st_ahci_driver = {
> > .driver = {
> > .name = DRV_NAME,
> > - .pm = &st_ahci_pm_ops,
> > + .pm = pm_sleep_ptr(&st_ahci_pm_ops),
> > .of_match_table = st_ahci_match,
> > },
> > .probe = st_ahci_probe,
>
>
> --
> Damien Le Moal
> Western Digital Research
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v2] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()
2025-01-10 11:23 ` Niklas Cassel
@ 2025-01-10 12:02 ` Damien Le Moal
2025-01-13 20:28 ` Raphaël Gallais-Pou
0 siblings, 1 reply; 10+ messages in thread
From: Damien Le Moal @ 2025-01-10 12:02 UTC (permalink / raw)
To: Niklas Cassel
Cc: Raphael Gallais-Pou, Patrice Chotard, linux-arm-kernel, linux-ide,
linux-kernel
On 1/10/25 20:23, Niklas Cassel wrote:
>>> -#ifdef CONFIG_PM_SLEEP
>>> static int st_ahci_suspend(struct device *dev)
>>> {
>>> struct ata_host *host = dev_get_drvdata(dev);
>>> @@ -221,9 +220,8 @@ static int st_ahci_resume(struct device *dev)
>>>
>>> return ahci_platform_resume_host(dev);
>>> }
>>> -#endif
>>
>> I do not think you can remove the ifdef here. Otherwise, there is going to be a
>> compilation warning when CONFIG_PM_SLEEP is not enabled. No ?
>
> Look at the pm_sleep_ptr macro:
> include/linux/pm.h:#define pm_sleep_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM_SLEEP), (_ptr))
>
> I would expect the function should be optimized out by the compiler
> using dead code elimination.
Indeed. Just tried and no warning. I was expecting a "defined but not used"
warning, but none showed up. So all good.
> Raphael, perhaps you could show the before and after output
> using ./scripts/bloat-o-meter ?
> (When the config is not enabled: before and after your patch.)
No need to do that I guess. But there are 17 other ata driver that set .pm
operations. What about these ? Don't they need the same treatment as ahci_st ?
15 of these also use SIMPLE_DEV_PM_OPS() which can be replaced with
DEFINE_SIMPLE_DEV_PM_OPS() also, no ?
Do you want us to do that cleanup ? (fine with me).
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v2] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()
2025-01-10 12:02 ` Damien Le Moal
@ 2025-01-13 20:28 ` Raphaël Gallais-Pou
2025-01-14 0:59 ` Damien Le Moal
0 siblings, 1 reply; 10+ messages in thread
From: Raphaël Gallais-Pou @ 2025-01-13 20:28 UTC (permalink / raw)
To: Damien Le Moal, Niklas Cassel
Cc: Patrice Chotard, linux-arm-kernel, linux-ide, linux-kernel
Le 10/01/2025 à 13:02, Damien Le Moal a écrit :
> On 1/10/25 20:23, Niklas Cassel wrote:
>>>> -#ifdef CONFIG_PM_SLEEP
>>>> static int st_ahci_suspend(struct device *dev)
>>>> {
>>>> struct ata_host *host = dev_get_drvdata(dev);
>>>> @@ -221,9 +220,8 @@ static int st_ahci_resume(struct device *dev)
>>>>
>>>> return ahci_platform_resume_host(dev);
>>>> }
>>>> -#endif
>>>
>>> I do not think you can remove the ifdef here. Otherwise, there is going to be a
>>> compilation warning when CONFIG_PM_SLEEP is not enabled. No ?
>>
>> Look at the pm_sleep_ptr macro:
>> include/linux/pm.h:#define pm_sleep_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM_SLEEP), (_ptr))
>>
>> I would expect the function should be optimized out by the compiler
>> using dead code elimination.
>
> Indeed. Just tried and no warning. I was expecting a "defined but not used"
> warning, but none showed up. So all good.
>
>> Raphael, perhaps you could show the before and after output
>> using ./scripts/bloat-o-meter ?
>> (When the config is not enabled: before and after your patch.)
Hi,
I have not used the bloat-o-meter until now, thanks ! :)
Here are my results:
* with the configuration
$ ./scripts/bloat-o-meter ahci_st_no_patch_pm.o ahci_st_patch_pm.o
add/remove: 1/1 grow/shrink: 0/0 up/down: 4/-4 (0)
Function old new delta
__initcall__kmod_ahci_st__384_241_st_ahci_driver_init6 - 4
+4
__initcall__kmod_ahci_st__384_243_st_ahci_driver_init6 4 -
-4
Total: Before=2200, After=2200, chg +0.00%
* without the configuration
$ ./scripts/bloat-o-meter ahci_st_no_patch_no_pm.o ahci_st_patch_no_pm.o
add/remove: 1/2 grow/shrink: 0/0 up/down: 4/-96 (-92)
Function old new delta
__initcall__kmod_ahci_st__383_241_st_ahci_driver_init6 - 4
+4
__initcall__kmod_ahci_st__383_243_st_ahci_driver_init6 4 -
-4
st_ahci_pm_ops 92 - -92
Total: Before=1904, After=1812, chg -4.83%
Looks like the patch shrinks a bit more the driver. I also tested, so we
should be fine I think.
>
> No need to do that I guess. But there are 17 other ata driver that set .pm
> operations. What about these ? Don't they need the same treatment as ahci_st ?
> 15 of these also use SIMPLE_DEV_PM_OPS() which can be replaced with
> DEFINE_SIMPLE_DEV_PM_OPS() also, no ?
>
> Do you want us to do that cleanup ? (fine with me).
Regarding the other ata drivers, if you have the patience I can do this
in a few weeks. There is other things on the stove I would like to do.
Regards,
Raphaël
>
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v2] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()
2025-01-13 20:28 ` Raphaël Gallais-Pou
@ 2025-01-14 0:59 ` Damien Le Moal
2025-01-15 8:28 ` Raphaël Gallais-Pou
0 siblings, 1 reply; 10+ messages in thread
From: Damien Le Moal @ 2025-01-14 0:59 UTC (permalink / raw)
To: Raphaël Gallais-Pou, Niklas Cassel
Cc: Patrice Chotard, linux-arm-kernel, linux-ide, linux-kernel
On 1/14/25 05:28, Raphaël Gallais-Pou wrote:
>> Do you want us to do that cleanup ? (fine with me).
>
> Regarding the other ata drivers, if you have the patience I can do this
> in a few weeks. There is other things on the stove I would like to do.
OK. We will work on this.
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()
2025-01-14 0:59 ` Damien Le Moal
@ 2025-01-15 8:28 ` Raphaël Gallais-Pou
2025-01-15 10:44 ` Niklas Cassel
0 siblings, 1 reply; 10+ messages in thread
From: Raphaël Gallais-Pou @ 2025-01-15 8:28 UTC (permalink / raw)
To: Damien Le Moal, Niklas Cassel
Cc: Patrice Chotard, linux-arm-kernel, linux-ide, linux-kernel
Le 14/01/2025 à 01:59, Damien Le Moal a écrit :
> On 1/14/25 05:28, Raphaël Gallais-Pou wrote:
>>> Do you want us to do that cleanup ? (fine with me).
>>
>> Regarding the other ata drivers, if you have the patience I can do this
>> in a few weeks. There is other things on the stove I would like to do.
>
> OK. We will work on this.
Sorry to change my plans, I actually started working on this. Is this
okay to let me handle this ? I will try to submit something promptly.
Thanks,
Raphaël
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()
2025-01-15 8:28 ` Raphaël Gallais-Pou
@ 2025-01-15 10:44 ` Niklas Cassel
0 siblings, 0 replies; 10+ messages in thread
From: Niklas Cassel @ 2025-01-15 10:44 UTC (permalink / raw)
To: Raphaël Gallais-Pou
Cc: Damien Le Moal, Patrice Chotard, linux-arm-kernel, linux-ide,
linux-kernel
On Wed, Jan 15, 2025 at 09:28:08AM +0100, Raphaël Gallais-Pou wrote:
> Le 14/01/2025 à 01:59, Damien Le Moal a écrit :
> > On 1/14/25 05:28, Raphaël Gallais-Pou wrote:
> > > > Do you want us to do that cleanup ? (fine with me).
> > >
> > > Regarding the other ata drivers, if you have the patience I can do this
> > > in a few weeks. There is other things on the stove I would like to do.
> >
> > OK. We will work on this.
>
> Sorry to change my plans, I actually started working on this. Is this okay
> to let me handle this ? I will try to submit something promptly.
Of course, I know that both me and Damien are quite busy at the moment.
Looking forward to your patches!
Kind regards,
Niklas
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()
2025-01-09 17:54 [PATCH v2] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr() Raphael Gallais-Pou
2025-01-10 5:19 ` Damien Le Moal
@ 2025-01-10 11:20 ` Niklas Cassel
2025-01-15 14:23 ` Niklas Cassel
2 siblings, 0 replies; 10+ messages in thread
From: Niklas Cassel @ 2025-01-10 11:20 UTC (permalink / raw)
To: Raphael Gallais-Pou
Cc: Patrice Chotard, Damien Le Moal, linux-arm-kernel, linux-ide,
linux-kernel
On Thu, Jan 09, 2025 at 06:54:27PM +0100, Raphael Gallais-Pou wrote:
> Letting the compiler remove these functions when the kernel is built
> without CONFIG_PM_SLEEP support is simpler and less error prone than the
> use of #ifdef based kernel configuration guards.
>
> Signed-off-by: Raphael Gallais-Pou <rgallaispou@gmail.com>
> ---
> Changes in v2:
> - Split serie in single patches
> - Remove irrelevant 'Link:' from commit log
> - Link to v1: https://lore.kernel.org/r/20241229-update_pm_macro-v1-4-c7d4c4856336@gmail.com
> ---
> drivers/ata/ahci_st.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/ata/ahci_st.c b/drivers/ata/ahci_st.c
> index 6b9b4a1dfa15..4336c8a6e208 100644
> --- a/drivers/ata/ahci_st.c
> +++ b/drivers/ata/ahci_st.c
> @@ -176,7 +176,6 @@ static int st_ahci_probe(struct platform_device *pdev)
> return 0;
> }
>
> -#ifdef CONFIG_PM_SLEEP
> static int st_ahci_suspend(struct device *dev)
> {
> struct ata_host *host = dev_get_drvdata(dev);
> @@ -221,9 +220,8 @@ static int st_ahci_resume(struct device *dev)
>
> return ahci_platform_resume_host(dev);
> }
> -#endif
>
> -static SIMPLE_DEV_PM_OPS(st_ahci_pm_ops, st_ahci_suspend, st_ahci_resume);
> +static DEFINE_SIMPLE_DEV_PM_OPS(st_ahci_pm_ops, st_ahci_suspend, st_ahci_resume);
>
> static const struct of_device_id st_ahci_match[] = {
> { .compatible = "st,ahci", },
> @@ -234,7 +232,7 @@ MODULE_DEVICE_TABLE(of, st_ahci_match);
> static struct platform_driver st_ahci_driver = {
> .driver = {
> .name = DRV_NAME,
> - .pm = &st_ahci_pm_ops,
> + .pm = pm_sleep_ptr(&st_ahci_pm_ops),
> .of_match_table = st_ahci_match,
> },
> .probe = st_ahci_probe,
> --
> 2.47.1
>
Reviewed-by: Niklas Cassel <cassel@kernel.org>
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v2] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()
2025-01-09 17:54 [PATCH v2] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr() Raphael Gallais-Pou
2025-01-10 5:19 ` Damien Le Moal
2025-01-10 11:20 ` Niklas Cassel
@ 2025-01-15 14:23 ` Niklas Cassel
2 siblings, 0 replies; 10+ messages in thread
From: Niklas Cassel @ 2025-01-15 14:23 UTC (permalink / raw)
To: Patrice Chotard, Damien Le Moal, Raphael Gallais-Pou
Cc: linux-arm-kernel, linux-ide, linux-kernel
On Thu, 09 Jan 2025 18:54:27 +0100, Raphael Gallais-Pou wrote:
> Letting the compiler remove these functions when the kernel is built
> without CONFIG_PM_SLEEP support is simpler and less error prone than the
> use of #ifdef based kernel configuration guards.
>
>
Applied to libata/linux.git (for-6.14), thanks!
[1/1] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()
https://git.kernel.org/libata/linux/c/f2809aa4
Kind regards,
Niklas
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-01-15 14:25 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-09 17:54 [PATCH v2] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr() Raphael Gallais-Pou
2025-01-10 5:19 ` Damien Le Moal
2025-01-10 11:23 ` Niklas Cassel
2025-01-10 12:02 ` Damien Le Moal
2025-01-13 20:28 ` Raphaël Gallais-Pou
2025-01-14 0:59 ` Damien Le Moal
2025-01-15 8:28 ` Raphaël Gallais-Pou
2025-01-15 10:44 ` Niklas Cassel
2025-01-10 11:20 ` Niklas Cassel
2025-01-15 14:23 ` Niklas Cassel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).