Re: [PATCH v2] ahci: st: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()

From: Raphaël Gallais-Pou
Date: Mon Jan 13 2025 - 15:28:38 EST




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