Re: [PATCH v2 3/3] PM: hibernate: log the task that initiated the power down

From: Bradley Morgan

Date: Thu Jul 23 2026 - 10:52:30 EST


On July 23, 2026 2:55:41 PM GMT+01:00, "Rafael J. Wysocki (Intel)"
<rafael@xxxxxxxxxx> wrote:
>On Tue, Jul 21, 2026 at 5:14 PM Bradley Morgan <include@xxxxxxxxx> wrote:
>>
>> Give the hibernation power down the same treatment as the reboot
>> syscall commands.
>
>Why?

1: Andrew suggested it [1]
2: because going down for hibernation is the same as "Wait, who the hell took the box down?!"


>
>> hibernate() runs in the context of the task that
>> asked for it, whether through the reboot syscall or a write to
>
>It doesn't use the reboot syscall.

Hmmm.... I may embarrass myself here, but it *could* (wink)

See kernel/reboot.c:

#ifdef CONFIG_HIBERNATION
case LINUX_REBOOT_CMD_SW_SUSPEND:
ret = hibernate();
break;
#endif


>> /sys/power/disk,

I'm wrong: /sys/power/state

so when power_down() runs current is still the
>> initiating task.
>>
>> Log it once the image has been written and the machine is committed
>> to going down:
>>
>> reboot: initiated by systemd-sleep[812]
>> reboot: Power down
>>
>> The line comes from kernel/reboot.c so it keeps the "reboot:" prefix
>> and sits right next to the final "Restarting system", "Power down"
>> or "System halted" line, same as a plain reboot.
>>
>> The one exception is platform mode rolling back on a pending wakeup
>> event after the line has been printed. The existing "Wakeup event
>> detected during hibernation, rolling back." line follows immediately
>> in that case, so the log stays real about what happened.
>
>(a) Why is this information in the log useful?

when the box just randomly goes down, some people prefer to know
"And what process did this? Or what did this?", say

"Was it systemd-sleep? Or some random power daemon?? Or some stray
reboot(SW_SUSPEND)??"

Userspace logging can't really do this...

There is software out there which can do this, but it's not the greatest.
[2]

Hence, this series!

>(b) Do you realize that it only appears in the log when hibernation
>fails or it may appear on a serial console or similar?

yeah. The image is written when the line prints, so after a successful
hibernate and resume dmesg won't have it.

Thats exactly the
same visibility as the final "Power down" / "Restarting system" line it
sits next to

Well, if you want it, please say.


[1]:
https://lore.kernel.org/all/20260719231540.455bd5c3eac842686c05bd7f@xxxxxxxxxxxxxxxxxxxx/

[2]: https://docs.memfault.com/docs/linux/reboot-reason-tracking


(oh and btw, if you don't buy in, it's ok, just say.. any questions, ask)
:)

>
>> Signed-off-by: Bradley Morgan <include@xxxxxxxxx>
>> ---
>> kernel/power/hibernate.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
>> index d2479c69d71a..bec91bf6a63c 100644
>> --- a/kernel/power/hibernate.c
>> +++ b/kernel/power/hibernate.c
>> @@ -687,6 +687,8 @@ static void power_down(void)
>> }
>> #endif
>>
>> + reboot_log_initiator();
>> +
>> switch (hibernation_mode) {
>> case HIBERNATION_REBOOT:
>> kernel_restart(NULL);
>> --
>

Thanks!