In case of sudden power loss, my custom board will get an interrupt and will have few milliseconds of back up power. To improve upon SSD life span I need to save ssd data and issue STANDBY IMMEDIATE command as soon as power loss interrupt is received. I have already implemented the interrupt part but not sure how to handle SSD command. Any suggestions on how shall this be implemented ? My question is : Can STANDBY IMMEDIATE command be issued directly to SSD device ? How can I achieve it in most efficient way ? BR Rupesh
On Fri, 06 Apr 2018 12:12:31 +0530, Rupesh Kumar said:
My question is : Can STANDBY IMMEDIATE command be issued directly to SSD device ? How can I achieve it in most efficient way ?
In the source tree, see tools/laptop/freefall/freefall.c for how to do the daemon. The sample code does a read() on a device that blocks until the accellerometer indicates a freefall condition, after which it does a write to /sys/block/%s/device/unload_heads to park the heads. You'll need to change that to wait until a powerfail is indicated.
From there, you want to chase into ata/libata-scsi.c to see what the write() triggers - a call to ata_scsu_park_store(). Assuming your SSD acts like an ata-scsi device, you can probably steal most of that code.
You almost certainly want to do it in two separate parts (detect powerfail and alert userspace, and userspace drives an ATA UNLOAD command), because trying to launch an ATA I/O from inside the powerfail interrupt leads to madness and heavy drinking...
participants (2)
-
Rupesh Kumar -
valdis.kletnieks@vt.edu