Skip to contentSkip to conversation

don't put IDE disks in standby mode on halt on Alpha

PATCH In review Ivan Kokshaysky 5 participants 13 messages May 27, 2004 – May 29, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 don't put IDE disks in standby mode on halt on Alpha

Spinning the disks down across a 'halt' on Alpha is even worse than doing that on reboot on i386 (assuming the boot device is IDE disk).
Typically, the sequence to boot another kernel is:

# halt
kernel shuts down, firmware re-initializes,
then on firmware prompt we type something like
Quoted 1 line
Quoted 1 line
Quoted 1 line

boot -file new_kernel_image.gz

Unfortunately, the firmware does not expect the IDE drive to be in standby mode and reports 'bootstrap failure' on the first and all subsequent boot attempts until the drive spins up, which is extremely annoying and confuses users a lot.

This patch allows architectures override the default behavior (don't spin the disks down on reboot only) in asm/ide.h.

Ivan.

drivers/ide/ide-disk.c +1 -1
@@ -1723,7 +1723,7 @@ static void ide_device_shutdown(struct d
 {
 	ide_drive_t *drive = container_of(dev, ide_drive_t, gendev);
 
-	if (system_state == SYSTEM_RESTART) {
+	if (ide_shutdown_omit_standby(system_state)) {
 		ide_cacheflush_p(drive);
 		return;
 	}
include/linux/ide.h +4 -0
@@ -1709,4 +1709,8 @@ static inline int ata_can_queue(ide_driv
 
 extern struct bus_type ide_bus_type;
 
+#ifndef ide_shutdown_omit_standby
+#define ide_shutdown_omit_standby(sys_state)	(sys_state == SYSTEM_RESTART)
+#endif
+
 #endif /* _IDE_H */
include/asm-alpha/ide.h +2 -0
@@ -52,6 +52,8 @@ static inline unsigned long ide_default_
 #define ide_init_default_irq(base)	ide_default_irq(base)
 #endif
 
+#define ide_shutdown_omit_standby(sys_state)	(sys_state != SYSTEM_POWER_OFF)
+
 #include <asm-generic/ide_iops.h>
 
 #endif /* __KERNEL__ */
#1 lore raw
Quoted 7 lines · Ivan Kokshaysky

Spinning the disks down across a 'halt' on Alpha is even worse than doing that on reboot on i386 (assuming the boot device is IDE disk).
Typically, the sequence to boot another kernel is:

# halt
kernel shuts down, firmware re-initializes,
then on firmware prompt we type something like
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

boot -file new_kernel_image.gz

Unfortunately, the firmware does not expect the IDE drive to be in standby mode and reports 'bootstrap failure' on the first and all subsequent boot attempts until the drive spins up, which is extremely annoying and confuses users a lot.

how do you flush the disks' writecache then? Halting the disk seems to be the only reliable way to do so.

#2 lore raw
Quoted 2 lines · Arjan van de Ven

how do you flush the disks' writecache then? Halting the disk seems to be the only reliable way to do so.

Isn't ide_cacheflush_p() supposed to do that on modern drives?

Ivan.

#3 lore raw
Quoted 5 lines · Ivan Kokshaysky
Quoted 2 lines · Arjan van de Ven

how do you flush the disks' writecache then? Halting the disk seems to be the only reliable way to do so.

Isn't ide_cacheflush_p() supposed to do that on modern drives?

that command seems to be optional to implement for drives unfortionately ;(

#4 lore raw
In reply to Arjan van de Ven

In article <[email protected]>,

Quoted 7 lines · Arjan van de Ven
Quoted 3 lines · Ivan Kokshaysky

Spinning the disks down across a 'halt' on Alpha is even worse than doing that on reboot on i386 (assuming the boot device is IDE disk).

how do you flush the disks' writecache then? Halting the disk seems to be the only reliable way to do so.

On Alpha, Sun and other hardware, "halt" puts you into the firmware monitor. It doesn't actually turn the machine off, so it's not critical to flush the write cache of the disk - the only time that is really neccesary is right before poweroff, in all other cases the disk will expire the write cache itself.

Mike.

#5 lore raw
In reply to Ivan Kokshaysky
Quoted 9 lines · Ivan Kokshaysky

Spinning the disks down across a 'halt' on Alpha is even worse than doing that on reboot on i386 (assuming the boot device is IDE disk).
Typically, the sequence to boot another kernel is:

# halt
kernel shuts down, firmware re-initializes,
then on firmware prompt we type something like
Quoted 1 line
Quoted 1 line
Quoted 1 line

boot -file new_kernel_image.gz

How is it different from reboot?
[ I don't know much about alpha. ]

Quoted 5 lines

Unfortunately, the firmware does not expect the IDE drive to be in standby mode and reports 'bootstrap failure' on the first and all subsequent boot attempts until the drive spins up, which is extremely annoying and confuses users a lot.

So how does it work in 2.4?

Quoted 3 lines

This patch allows architectures override the default behavior (don't spin the disks down on reboot only) in asm/ide.h.

No more <asm/ide.h> crap, please.

Quoted 35 lines

Ivan.

drivers/ide/ide-disk.c +1 -1
@@ -1723,7 +1723,7 @@ static void ide_device_shutdown(struct d
 {
 	ide_drive_t *drive = container_of(dev, ide_drive_t, gendev);
 
-	if (system_state == SYSTEM_RESTART) {
+	if (ide_shutdown_omit_standby(system_state)) {
 		ide_cacheflush_p(drive);
 		return;
 	}
include/linux/ide.h +4 -0
@@ -1709,4 +1709,8 @@ static inline int ata_can_queue(ide_driv
 
 extern struct bus_type ide_bus_type;
 
+#ifndef ide_shutdown_omit_standby
+#define ide_shutdown_omit_standby(sys_state)	(sys_state == SYSTEM_RESTART)
+#endif
+
 #endif /* _IDE_H */
include/asm-alpha/ide.h +1 -0
@@ -52,6 +52,8 @@ static inline unsigned long ide_default_
 #define ide_init_default_irq(base)	ide_default_irq(base)
 #endif
 
+#define ide_shutdown_omit_standby(sys_state)	(sys_state !=

SYSTEM_POWER_OFF) +
#include <asm-generic/ide_iops.h>

#endif /* __KERNEL__ */

#6 lore raw
Quoted 3 lines · Bartlomiej Zolnierkiewicz
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

boot -file new_kernel_image.gz

How is it different from reboot?

In this scenario it's not different, except you boot to another kernel.

Quoted 1 line

So how does it work in 2.4?

2.4 needs similar fix.

Quoted 1 line

No more <asm/ide.h> crap, please.

Would #ifdef __alpha__ be better?

Ivan.

#7 lore raw
Quoted 7 lines · Ivan Kokshaysky
Quoted 3 lines · Bartlomiej Zolnierkiewicz
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

boot -file new_kernel_image.gz

How is it different from reboot?

In this scenario it's not different, except you boot to another kernel.

Eh.

Quoted 7 lines
Quoted 1 line

So how does it work in 2.4?

2.4 needs similar fix.

Quoted 1 line

No more <asm/ide.h> crap, please.

Would #ifdef __alpha__ be better?

actually CONFIG_ALPHA + comment why it is needed

Thanks,
Bartlomiej

#8 lore raw
Quoted 3 lines · Bartlomiej Zolnierkiewicz
Quoted 1 line

Would #ifdef __alpha__ be better?

actually CONFIG_ALPHA + comment why it is needed

Ok, but now I'm thinking of probably better solution:
consider sys_state == SYSTEM_HALT as another special case where we put the disk into standby mode *only* if it does have write cache but doesn't suppurt cache flush command (or cache flush fails for some reason).

Hopefully, most drives won't be spun down on halt. I think that it should be acceptable for x86 as well.

Ivan.

drivers/ide/ide-disk.c +17 -5
@@ -1686,13 +1686,19 @@ static void idedisk_setup (ide_drive_t *
 #endif
 }
 
-static void ide_cacheflush_p(ide_drive_t *drive)
+static int ide_cacheflush_p(ide_drive_t *drive)
 {
-	if (!drive->wcache || !ide_id_has_flush_cache(drive->id))
-		return;
+	if (!drive->wcache)
+		return 0;
+
+	if (!ide_id_has_flush_cache(drive->id))
+		return 1;
 
-	if (do_idedisk_flushcache(drive))
-		printk(KERN_INFO "%s: wcache flush failed!\n", drive->name);
+	if (!do_idedisk_flushcache(drive))
+		return 0;
+
+	printk(KERN_INFO "%s: wcache flush failed!\n", drive->name);
+	return 1;
 }
 
 static int idedisk_cleanup (ide_drive_t *drive)
@@ -1713,10 +1719,16 @@ static void ide_device_shutdown(struct d
 {
 	ide_drive_t *drive = container_of(dev, ide_drive_t, gendev);
 
+	/* Never spin the disk down on reboot. */
 	if (system_state == SYSTEM_RESTART) {
 		ide_cacheflush_p(drive);
 		return;
 	}
+
+	/* Spin the disk down on halt only if attempt to flush the
+	   write cache fails. */
+	if (system_state == SYSTEM_HALT && !ide_cacheflush_p(drive))
+		return;
 
 	printk("Shutdown: %s\n", drive->name);
 	dev->bus->suspend(dev, PM_SUSPEND_STANDBY);
#9 lore raw
Quoted 5 lines · Ivan Kokshaysky
Quoted 3 lines · Bartlomiej Zolnierkiewicz
Quoted 1 line

Would #ifdef __alpha__ be better?

actually CONFIG_ALPHA + comment why it is needed

Quoted 8 lines

Ok, but now I'm thinking of probably better solution:
consider sys_state == SYSTEM_HALT as another special case where we put the disk into standby mode *only* if it does have write cache but doesn't suppurt cache flush command (or cache flush fails for some reason).

Hopefully, most drives won't be spun down on halt. I think that it should be acceptable for x86 as well.

- AFAIR there are some buggy disks having flush cache bits that need standby anyway

- you will hit 'halt problem' on alpha if your disk has write cache enabled and it doesn't have flush cache bits

-EAGAIN ;)

Quoted 46 lines

Ivan.

drivers/ide/ide-disk.c +17 -5
@@ -1686,13 +1686,19 @@ static void idedisk_setup (ide_drive_t *
 #endif
 }
 
-static void ide_cacheflush_p(ide_drive_t *drive)
+static int ide_cacheflush_p(ide_drive_t *drive)
 {
-	if (!drive->wcache || !ide_id_has_flush_cache(drive->id))
-		return;
+	if (!drive->wcache)
+		return 0;
+
+	if (!ide_id_has_flush_cache(drive->id))
+		return 1;
 
-	if (do_idedisk_flushcache(drive))
-		printk(KERN_INFO "%s: wcache flush failed!\n", drive->name);
+	if (!do_idedisk_flushcache(drive))
+		return 0;
+
+	printk(KERN_INFO "%s: wcache flush failed!\n", drive->name);
+	return 1;
 }
 
 static int idedisk_cleanup (ide_drive_t *drive)
@@ -1713,10 +1719,16 @@ static void ide_device_shutdown(struct d
 {
 	ide_drive_t *drive = container_of(dev, ide_drive_t, gendev);
 
+	/* Never spin the disk down on reboot. */
 	if (system_state == SYSTEM_RESTART) {
 		ide_cacheflush_p(drive);
 		return;
 	}
+
+	/* Spin the disk down on halt only if attempt to flush the
+	   write cache fails. */
+	if (system_state == SYSTEM_HALT && !ide_cacheflush_p(drive))
+		return;
 
 	printk("Shutdown: %s\n", drive->name);
 	dev->bus->suspend(dev, PM_SUSPEND_STANDBY);
#10 lore raw
Quoted 2 lines · Bartlomiej Zolnierkiewicz

- AFAIR there are some buggy disks having flush cache bits that need standby anyway

Oh horror. I wouldn't be surprised if some drives don't flush the cache even on standby...

Quoted 4 lines

- you will hit 'halt problem' on alpha if your disk has write cache enabled and it doesn't have flush cache bits

-EAGAIN ;)

Yep... :-(

Here's variant of the first patch with CONFIG_ALPHA and a Very Big Comment.

Ivan.

drivers/ide/ide-disk.c +15 -0
@@ -1713,7 +1713,22 @@ static void ide_device_shutdown(struct d
 {
 	ide_drive_t *drive = container_of(dev, ide_drive_t, gendev);
 
+#ifdef	CONFIG_ALPHA
+	/* On Alpha, halt(8) doesn't actually turn the machine off,
+	   it puts you into the sort of firmware monitor. Typically,
+	   it's used to boot another kernel image, so it's not much
+	   different from reboot(8). Therefore, we don't need to
+	   spin down the disk in this case, especially since Alpha
+	   firmware doesn't handle disks in standby mode properly.
+	   On the other hand, it's reasonably safe to turn the power
+	   off when the shutdown process reaches the firmware prompt,
+	   as the firmware initialization takes rather long time -
+	   at least 10 seconds, which should be sufficient for
+	   the disk to expire its write cache. */
+	if (system_state != SYSTEM_POWER_OFF) {
+#else
 	if (system_state == SYSTEM_RESTART) {
+#endif
 		ide_cacheflush_p(drive);
 		return;
 	}
#11 lore raw
Quoted 7 lines · Ivan Kokshaysky
Quoted 2 lines · Bartlomiej Zolnierkiewicz

- AFAIR there are some buggy disks having flush cache bits that need standby anyway

Oh horror. I wouldn't be surprised if some drives don't flush the cache even on standby...

Quoted 8 lines
Quoted 4 lines

- you will hit 'halt problem' on alpha if your disk has write cache enabled and it doesn't have flush cache bits

-EAGAIN ;)

Yep... :-(

Here's variant of the first patch with CONFIG_ALPHA and a Very Big Comment.

Looks good, thanks!

Quoted 27 lines

Ivan.

drivers/ide/ide-disk.c +15 -0
@@ -1713,7 +1713,22 @@ static void ide_device_shutdown(struct d
 {
 	ide_drive_t *drive = container_of(dev, ide_drive_t, gendev);
 
+#ifdef	CONFIG_ALPHA
+	/* On Alpha, halt(8) doesn't actually turn the machine off,
+	   it puts you into the sort of firmware monitor. Typically,
+	   it's used to boot another kernel image, so it's not much
+	   different from reboot(8). Therefore, we don't need to
+	   spin down the disk in this case, especially since Alpha
+	   firmware doesn't handle disks in standby mode properly.
+	   On the other hand, it's reasonably safe to turn the power
+	   off when the shutdown process reaches the firmware prompt,
+	   as the firmware initialization takes rather long time -
+	   at least 10 seconds, which should be sufficient for
+	   the disk to expire its write cache. */
+	if (system_state != SYSTEM_POWER_OFF) {
+#else
 	if (system_state == SYSTEM_RESTART) {
+#endif
 		ide_cacheflush_p(drive);
 		return;
 	}
#12 lore raw
In reply to Ivan Kokshaysky
Quoted 17 lines · Ivan Kokshaysky

Spinning the disks down across a 'halt' on Alpha is even worse than doing that on reboot on i386 (assuming the boot device is IDE disk).
Typically, the sequence to boot another kernel is:

# halt
kernel shuts down, firmware re-initializes,
then on firmware prompt we type something like
Quoted 1 line
Quoted 1 line
Quoted 1 line

boot -file new_kernel_image.gz

Unfortunately, the firmware does not expect the IDE drive to be in standby mode and reports 'bootstrap failure' on the first and all subsequent boot attempts until the drive spins up, which is extremely annoying and confuses users a lot.

Quoted 3 lines

This patch allows architectures override the default behavior (don't spin the disks down on reboot only) in asm/ide.h.

This isn't completely safe. I sometimes power off my Alpha after rebooting to the monitor program, for various reasons.

Wouldn't it be better to spin the disks down like normal, but then spin them back up just before rebooting?

Signature · 2 lines
Mark McClelland
[email protected]