Linux MultiMedia Card development
 help / color / mirror / Atom feed
* Question regarding informing MMC subsystem about upcoming power loss.
@ 2024-03-05 15:22 Patryk
  2024-03-05 15:33 ` Christian Loehle
  0 siblings, 1 reply; 4+ messages in thread
From: Patryk @ 2024-03-05 15:22 UTC (permalink / raw)
  To: linux-mmc

Hi,
I'm wondering - is there a way/interface that I could use to notify
the Linux kernel that the power is about to go down? I'm thinking
about SD cards in particular and how to make them more immune to
unexpected power loss, and I've found that some SD cards support
something like "mmc_poweroff_notify", which is called in the
mmc_suspend function.

Assuming that I have the information about upcoming power loss
(provided by e.g. external interrupt, PSU voltage monitoring etc) how
should I pass this information to the Kernel so that it will try to
clean up resources - in particular MMC subsystem?

Let me show some background - we have a SoM which has a lot of
components. On the SoM we have a PSU which operates on 24V voltage. We
would like to monitor the PSU's voltage and when we detect that the
voltage has dropped from 24V to 12V this is highly likely an
unexpected power loss/cut, therefore we would like to inform the
Kernel (in particular mmc subsystem) that the power loss is coming. I
can imagine something like this - we have a driver that does voltage
measurements or waits for an external interrupt (triggered when PSU's
voltage drops from 24V to 12V) and then calls some functions that will
allow the Kernel to do some cleanups, but the question is what are
these functions? Are there any?

BR
Patryk

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Question regarding informing MMC subsystem about upcoming power loss.
  2024-03-05 15:22 Question regarding informing MMC subsystem about upcoming power loss Patryk
@ 2024-03-05 15:33 ` Christian Loehle
  2024-03-05 15:59   ` Patryk
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Loehle @ 2024-03-05 15:33 UTC (permalink / raw)
  To: Patryk, linux-mmc

On 05/03/2024 15:22, Patryk wrote:
> Hi,
> I'm wondering - is there a way/interface that I could use to notify
> the Linux kernel that the power is about to go down? I'm thinking
> about SD cards in particular and how to make them more immune to
> unexpected power loss, and I've found that some SD cards support
> something like "mmc_poweroff_notify", which is called in the
> mmc_suspend function.

Immune to what exactly?
- (User) data loss of data that is still in the cache of the sd card?
(That would be saved by a timely cache flush)
- (User) data loss of data that should've been written to flash already?
- SD cards breaking?
- Explosions?

(Anything but the first IMO should be fixed by procurement and not by the
kernel, but I'm not sure if that's consensus).

> Assuming that I have the information about upcoming power loss
> (provided by e.g. external interrupt, PSU voltage monitoring etc) how
> should I pass this information to the Kernel so that it will try to
> clean up resources - in particular MMC subsystem?
>
> Let me show some background - we have a SoM which has a lot of
> components. On the SoM we have a PSU which operates on 24V voltage. We
> would like to monitor the PSU's voltage and when we detect that the
> voltage has dropped from 24V to 12V this is highly likely an
> unexpected power loss/cut, therefore we would like to inform the
> Kernel (in particular mmc subsystem) that the power loss is coming. I
> can imagine something like this - we have a driver that does voltage
> measurements or waits for an external interrupt (triggered when PSU's
> voltage drops from 24V to 12V) and then calls some functions that will
> allow the Kernel to do some cleanups, but the question is what are
> these functions? Are there any?

There was a discussion, currently there aren't really, but it depends
on the scenario you're afraid of. Just issuing a cache flush might be fine.
https://www.phoronix.com/news/Linux-Priority-Based-Shutdown
https://lore.kernel.org/lkml/2023112403-laxative-lustiness-6a7f@gregkh/T/

One of the fundamental questions IMO remains: How much time do we actually
have between being notified?

Best Regards.
Christian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Question regarding informing MMC subsystem about upcoming power loss.
  2024-03-05 15:33 ` Christian Loehle
@ 2024-03-05 15:59   ` Patryk
  2024-03-06 11:11     ` Christian Loehle
  0 siblings, 1 reply; 4+ messages in thread
From: Patryk @ 2024-03-05 15:59 UTC (permalink / raw)
  To: Christian Loehle; +Cc: linux-mmc

wt., 5 mar 2024 o 16:33 Christian Loehle <christian.loehle@arm.com> napisał(a):
> Immune to what exactly?
> - (User) data loss of data that is still in the cache of the sd card?
> (That would be saved by a timely cache flush)
> - (User) data loss of data that should've been written to flash already?
> - SD cards breaking?
> - Explosions?

Data loss of data that is still in the cache of the sd card

> (Anything but the first IMO should be fixed by procurement and not by the
> kernel, but I'm not sure if that's consensus).
>
> > Assuming that I have the information about upcoming power loss
> > (provided by e.g. external interrupt, PSU voltage monitoring etc) how
> > should I pass this information to the Kernel so that it will try to
> > clean up resources - in particular MMC subsystem?

> There was a discussion, currently there aren't really, but it depends
> on the scenario you're afraid of. Just issuing a cache flush might be fine.
> https://www.phoronix.com/news/Linux-Priority-Based-Shutdown
> https://lore.kernel.org/lkml/2023112403-laxative-lustiness-6a7f@gregkh/T/

Thanks, I didn't know about this, I will check it.

> One of the fundamental questions IMO remains: How much time do we actually
> have between being notified?

I haven't done any measurements yet, sorry.

Best regards
Patryk

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Question regarding informing MMC subsystem about upcoming power loss.
  2024-03-05 15:59   ` Patryk
@ 2024-03-06 11:11     ` Christian Loehle
  0 siblings, 0 replies; 4+ messages in thread
From: Christian Loehle @ 2024-03-06 11:11 UTC (permalink / raw)
  To: Patryk; +Cc: linux-mmc, Oleksij Rempel

On 05/03/2024 15:59, Patryk wrote:
> wt., 5 mar 2024 o 16:33 Christian Loehle <christian.loehle@arm.com> napisał(a):
>> Immune to what exactly?
>> - (User) data loss of data that is still in the cache of the sd card?
>> (That would be saved by a timely cache flush)
>> - (User) data loss of data that should've been written to flash already?
>> - SD cards breaking?
>> - Explosions?
> 
> Data loss of data that is still in the cache of the sd card

Then my (very biased) opinion is:
Anything >1s window between being notified and power-loss a userspace umount/fsync
might be an improvement enough for your case.
Anything <1s window is then so storage-module-implementation specific that
it's hard to draft a solution that actually provides a measurable improvement.
Of course, turning off the SD cache completely is always an option (with drawbacks
like reduced performance and endurance).

> 
>> (Anything but the first IMO should be fixed by procurement and not by the
>> kernel, but I'm not sure if that's consensus).
>>
>>> Assuming that I have the information about upcoming power loss
>>> (provided by e.g. external interrupt, PSU voltage monitoring etc) how
>>> should I pass this information to the Kernel so that it will try to
>>> clean up resources - in particular MMC subsystem?
> 
>> There was a discussion, currently there aren't really, but it depends
>> on the scenario you're afraid of. Just issuing a cache flush might be fine.
>> https://www.phoronix.com/news/Linux-Priority-Based-Shutdown
>> https://lore.kernel.org/lkml/2023112403-laxative-lustiness-6a7f@gregkh/T/
> 
> Thanks, I didn't know about this, I will check it.

Forgot to CC Oleksij before, did it now.

Kind Regards,
Christian

> 
>> One of the fundamental questions IMO remains: How much time do we actually
>> have between being notified?
> 
> I haven't done any measurements yet, sorry.
> 
> Best regards
> Patryk


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-06 11:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-05 15:22 Question regarding informing MMC subsystem about upcoming power loss Patryk
2024-03-05 15:33 ` Christian Loehle
2024-03-05 15:59   ` Patryk
2024-03-06 11:11     ` Christian Loehle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox