public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* patch to put IDE drives in sleep-mode after an halt
@ 2001-05-24 11:03 Rodrigo Ventura
  2001-05-24 11:11 ` Russell King
  2001-05-24 13:20 ` Erik Mouw
  0 siblings, 2 replies; 10+ messages in thread
From: Rodrigo Ventura @ 2001-05-24 11:03 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 245 bytes --]


        I am submitting a patch to kernel/sys.c that walks through all
IDE drives (#ifdef CONFIG_BLK_DEV_IDE, of course), and issues a
"sleep" command (as code in hdparam) to each one of them right before
the kernel halts. Here goes the diff:


[-- Attachment #2: sys.diff --]
[-- Type: text/plain, Size: 2113 bytes --]

--- sys.c.ORIG	Thu May 24 00:56:50 2001
+++ sys.c	Thu May 24 01:40:31 2001
@@ -15,6 +15,11 @@
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
+#ifdef CONFIG_BLK_DEV_IDE
+#include "../drivers/block/ide.h"
+#endif
+
+
 /*
  * this indicates whether you can reboot with ctrl-alt-del: the default is yes
  */
@@ -146,6 +151,45 @@
 
 
 /*
+ * Puts IDE disks in sleep mode
+ */
+void disks_sleep(void) {
+#ifdef CONFIG_BLK_DEV_IDE
+#define WIN_SLEEPNOW1 0xE6
+#define WIN_SLEEPNOW2 0x99
+	int i, d, ret;
+	unsigned char args[4];
+	ide_drive_t *drv;
+
+	for ( i=0 ; i<MAX_HWIFS ; i++ ) {
+		if ( !ide_hwifs[i].present )
+			continue;
+		/*printk(KERN_DEBUG "HD iface %s\n", ide_hwifs[i].name);*/
+		for ( d=0 ; d<MAX_DRIVES ; d++ ) {
+			if ( !ide_hwifs[i].drives[d].present )
+				continue;
+			/*printk(KERN_DEBUG "  - drive %s\n", ide_hwifs[i].drives[d].name);*/
+			drv = &ide_hwifs[i].drives[d];
+			args[0] = WIN_SLEEPNOW1;
+			args[1] = args[2] = args[3] = 0;
+			ret = ide_wait_cmd(drv, args[0], args[1], args[2], args[3], args);
+			if (ret) {
+				args[0] = WIN_SLEEPNOW2;
+				args[1] = args[2] = args[3] = 0;
+				ret = ide_wait_cmd(drv, args[0], args[1], args[2], args[3], args);
+				if (ret)
+					printk(KERN_NOTICE "Putting %s to sleep failed.\n", drv->name);
+				else
+					printk(KERN_NOTICE "Putting %s to sleep at second attempt.\n", drv->name);
+			} else
+				printk(KERN_NOTICE "Putting %s to sleep.\n", drv->name);
+		}
+	}
+#endif
+}
+
+
+/*
  * Reboot system call: for obvious reasons only root may call it,
  * and even root needs to set up some magic numbers in the registers
  * so that some mistake won't make this reboot the whole machine.
@@ -186,6 +230,7 @@
 	case LINUX_REBOOT_CMD_HALT:
 		notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL);
 		printk(KERN_EMERG "System halted.\n");
+		disks_sleep();
 		machine_halt();
 		do_exit(0);
 		break;
@@ -193,6 +238,7 @@
 	case LINUX_REBOOT_CMD_POWER_OFF:
 		notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL);
 		printk(KERN_EMERG "Power down.\n");
+		disks_sleep();
 		machine_power_off();
 		do_exit(0);
 		break;

[-- Attachment #3: Type: text/plain, Size: 386 bytes --]


        Please comment!

        Cheers,


-- 

*** Rodrigo Martins de Matos Ventura <yoda@isr.ist.utl.pt>
***  Web page: http://www.isr.ist.utl.pt/~yoda
***   Teaching Assistant and PhD Student at ISR:
***    Instituto de Sistemas e Robotica, Polo de Lisboa
***     Instituto Superior Tecnico, Lisboa, PORTUGAL
*** PGP fingerprint = 0119 AD13 9EEE 264A 3F10  31D3 89B3 C6C4 60C6 4585

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

* Re: patch to put IDE drives in sleep-mode after an halt
  2001-05-24 11:03 Rodrigo Ventura
@ 2001-05-24 11:11 ` Russell King
  2001-05-24 13:20 ` Erik Mouw
  1 sibling, 0 replies; 10+ messages in thread
From: Russell King @ 2001-05-24 11:11 UTC (permalink / raw)
  To: Rodrigo Ventura; +Cc: linux-kernel

On Thu, May 24, 2001 at 12:03:49PM +0100, Rodrigo Ventura wrote:
>         I am submitting a patch to kernel/sys.c that walks through all
> IDE drives (#ifdef CONFIG_BLK_DEV_IDE, of course), and issues a
> "sleep" command (as code in hdparam) to each one of them right before
> the kernel halts. Here goes the diff:

I'm not going to comment on the idea, just the implementation.  Eww.

First point is that this has no business being in kernel/sys.c - it
belongs in the ide layer, not the generic kernel.

Secondly, you have this wonderous reboot notifier list which you can
arbitarily register functions with throughout the kernel, and they
will get called prior to halt/reboot.  You should be using this, via
the register_reboot_notifier() hooks.

--
Russell King (rmk@arm.linux.org.uk)                The developer of ARM Linux
             http://www.arm.linux.org.uk/personal/aboutme.html


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

* Re: patch to put IDE drives in sleep-mode after an halt
@ 2001-05-24 12:29 peter k.
  2001-05-24 12:46 ` Adrian V. Bono
  0 siblings, 1 reply; 10+ messages in thread
From: peter k. @ 2001-05-24 12:29 UTC (permalink / raw)
  To: linux-kernel


> On Thu, May 24, 2001 at 12:03:49PM +0100, Rodrigo Ventura wrote:
> >         I am submitting a patch to kernel/sys.c that walks through all
> > IDE drives (#ifdef CONFIG_BLK_DEV_IDE, of course), and issues a
> > "sleep" command (as code in hdparam) to each one of them right before
> > the kernel halts. Here goes the diff:
>
> I'm not going to comment on the idea, just the implementation.  Eww.

imho the idea is very good
i was already wondering why the kernel doesnt spin down the hds when i
shutdown...
and its necessary because if you want to move your box the hd heads should
be parked!
 
 - peter k.
 


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

* Re: patch to put IDE drives in sleep-mode after an halt
  2001-05-24 12:29 patch to put IDE drives in sleep-mode after an halt peter k.
@ 2001-05-24 12:46 ` Adrian V. Bono
  2001-05-24 12:59   ` peter k.
  0 siblings, 1 reply; 10+ messages in thread
From: Adrian V. Bono @ 2001-05-24 12:46 UTC (permalink / raw)
  Cc: linux-kernel

"peter k." wrote:

> > I'm not going to comment on the idea, just the implementation.  Eww.
> 
> imho the idea is very good
> i was already wondering why the kernel doesnt spin down the hds when i
> shutdown...
> and its necessary because if you want to move your box the hd heads should
> be parked!
> 
>  - peter k.

Aren't all IDE drives built today auto-parking? Auto-parking became an
inherent feature in voice coil drives (stepper-motor drives weren't
auto-parking), and since all drives are voice coil drives, then they
should auto-park. But i've had problems with some hard drives that were
spinned down (when Win____ was shutdown)..  if i reset the PC (instead
of turning it off), the hard drives wouldn't come back on so i'd have to
do a full shutdown of the machine.

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

* Re: patch to put IDE drives in sleep-mode after an halt
  2001-05-24 12:46 ` Adrian V. Bono
@ 2001-05-24 12:59   ` peter k.
  2001-05-24 13:18     ` Erik Mouw
  0 siblings, 1 reply; 10+ messages in thread
From: peter k. @ 2001-05-24 12:59 UTC (permalink / raw)
  To: Adrian V. Bono; +Cc: linux-kernel

> > imho the idea is very good
> > i was already wondering why the kernel doesnt spin down the hds when i
> > shutdown...
> > and its necessary because if you want to move your box the hd heads
should
> > be parked!
> >
> >  - peter k.
>
> Aren't all IDE drives built today auto-parking? Auto-parking became an
> inherent feature in voice coil drives (stepper-motor drives weren't
> auto-parking), and since all drives are voice coil drives, then they
> should auto-park. But i've had problems with some hard drives that were
> spinned down (when Win____ was shutdown)..  if i reset the PC (instead
> of turning it off), the hard drives wouldn't come back on so i'd have to
> do a full shutdown of the machine.

well, my new 40gb ones are auto-parking i think but all the other ones from
last year aren't
and older hardware (although 1 year isnt even old for a hd) should be
supported by the kernel, right?
plus, its really not difficult to implement spinning down the hds before
halt anyway and then the kernel
leaves the system as clean as it was before booting ;) !!

- peter k.


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

* Re: patch to put IDE drives in sleep-mode after an halt
  2001-05-24 12:59   ` peter k.
@ 2001-05-24 13:18     ` Erik Mouw
  0 siblings, 0 replies; 10+ messages in thread
From: Erik Mouw @ 2001-05-24 13:18 UTC (permalink / raw)
  To: peter k.; +Cc: Adrian V. Bono, linux-kernel

On Thu, May 24, 2001 at 02:59:18PM +0200, peter k. wrote:
> well, my new 40gb ones are auto-parking i think but all the other ones from
> last year aren't
> and older hardware (although 1 year isnt even old for a hd) should be
> supported by the kernel, right?

All drives with voice coils for head movement do auto park on power off
by design. Only really old drives with stepper motors (Seagate ST225
and friends, over 15 years old) don't do it, but the capacity of those
drives don't make it worthwile supporting anyway.

> plus, its really not difficult to implement spinning down the hds before
> halt anyway

It's so easy that it should be done from the init scripts instead of
from kernel. "hdparm -Y device" forces the drive to sleep mode.

>  and then the kernel
> leaves the system as clean as it was before booting ;) !!

That's a silly argument. Why should the OS leave the system clean? It's
the boot code's task to set up the system in a proper way.


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2783635  Fax: +31-15-2781843  Email: J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/

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

* Re: patch to put IDE drives in sleep-mode after an halt
  2001-05-24 11:03 Rodrigo Ventura
  2001-05-24 11:11 ` Russell King
@ 2001-05-24 13:20 ` Erik Mouw
  2001-05-24 13:52   ` Rodrigo Ventura
  1 sibling, 1 reply; 10+ messages in thread
From: Erik Mouw @ 2001-05-24 13:20 UTC (permalink / raw)
  To: Rodrigo Ventura; +Cc: linux-kernel

On Thu, May 24, 2001 at 12:03:49PM +0100, Rodrigo Ventura wrote:
>         I am submitting a patch to kernel/sys.c that walks through all
> IDE drives (#ifdef CONFIG_BLK_DEV_IDE, of course), and issues a
> "sleep" command (as code in hdparam) to each one of them right before
> the kernel halts. Here goes the diff:

What was wrong with "hdparm -Y /dev/hd*" in the halt/reboot script that
you need to do it in kernel?


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2783635  Fax: +31-15-2781843  Email: J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/

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

* Re: patch to put IDE drives in sleep-mode after an halt
  2001-05-24 13:20 ` Erik Mouw
@ 2001-05-24 13:52   ` Rodrigo Ventura
  0 siblings, 0 replies; 10+ messages in thread
From: Rodrigo Ventura @ 2001-05-24 13:52 UTC (permalink / raw)
  To: Erik Mouw; +Cc: linux-kernel

>>>>> "Erik" == Erik Mouw <J.A.K.Mouw@ITS.TUDelft.NL> writes:

    Erik> What was wrong with "hdparm -Y /dev/hd*" in the halt/reboot
    Erik> script that you need to do it in kernel?

        Must be sure there is no disk access after the hdparm is
run. It makes sense to me that IDE drivers could shut the drives off
after their last access.

        Anyway, you've made a good point -- I'll try that tonight.

        Cheers,

-- 

*** Rodrigo Martins de Matos Ventura <yoda@isr.ist.utl.pt>
***  Web page: http://www.isr.ist.utl.pt/~yoda
***   Teaching Assistant and PhD Student at ISR:
***    Instituto de Sistemas e Robotica, Polo de Lisboa
***     Instituto Superior Tecnico, Lisboa, PORTUGAL
*** PGP fingerprint = 0119 AD13 9EEE 264A 3F10  31D3 89B3 C6C4 60C6 4585

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

* Re: patch to put IDE drives in sleep-mode after an halt
@ 2001-05-24 15:16 Petr Vandrovec
  2001-05-24 17:38 ` idalton
  0 siblings, 1 reply; 10+ messages in thread
From: Petr Vandrovec @ 2001-05-24 15:16 UTC (permalink / raw)
  To: peter k.; +Cc: linux-kernel, adrianb

On 24 May 01 at 14:59, peter k. wrote:

> > auto-parking), and since all drives are voice coil drives, then they
> > should auto-park. But i've had problems with some hard drives that were
> > spinned down (when Win____ was shutdown)..  if i reset the PC (instead
> > of turning it off), the hard drives wouldn't come back on so i'd have to
> > do a full shutdown of the machine.
> 
> well, my new 40gb ones are auto-parking i think but all the other ones from
> last year aren't
> and older hardware (although 1 year isnt even old for a hd) should be
> supported by the kernel, right?
> plus, its really not difficult to implement spinning down the hds before
> halt anyway and then the kernel
> leaves the system as clean as it was before booting ;) !!

I'm using (at the end of /etc/init.d/halt):

cat /sbin/halt > /dev/null
cat /bin/sleep > /dev/null
hdparm -Y /dev/hdd
hdparm -Y /dev/hdc
hdparm -Y /dev/hdb
hdparm -Y /dev/hda
/bin/sleep 2
/sbin/halt -d -f -i -p

It works fine for me for years... I had to put sleep 2 here, as otherwise
CDROM drive does not park its head correctly (as hdparm /dev/hdc causes
ide-cd/cdrom to load - and this causes CDROM to spin up :-( )
So I do not see any reason for doing HDD park by kernel...
                                                 Best regards,
                                                      Petr Vandrovec
                                                      vandrove@vc.cvut.cz

P.S.: AFAIK all IDE disks autopark. At least my 41MB KALOK from 1990
did. Or at least tried...

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

* Re: patch to put IDE drives in sleep-mode after an halt
  2001-05-24 15:16 Petr Vandrovec
@ 2001-05-24 17:38 ` idalton
  0 siblings, 0 replies; 10+ messages in thread
From: idalton @ 2001-05-24 17:38 UTC (permalink / raw)
  To: Petr Vandrovec; +Cc: peter k., linux-kernel, adrianb

On Thu, May 24, 2001 at 03:16:44PM +0000, Petr Vandrovec wrote:
> On 24 May 01 at 14:59, peter k. wrote:
> 
> > > auto-parking), and since all drives are voice coil drives, then they
> > > should auto-park. But i've had problems with some hard drives that were
> > > spinned down (when Win____ was shutdown)..  if i reset the PC (instead
> > > of turning it off), the hard drives wouldn't come back on so i'd have to
> > > do a full shutdown of the machine.
> > 
> > well, my new 40gb ones are auto-parking i think but all the other ones from
> > last year aren't
> > and older hardware (although 1 year isnt even old for a hd) should be
> > supported by the kernel, right?
> > plus, its really not difficult to implement spinning down the hds before
> > halt anyway and then the kernel
> > leaves the system as clean as it was before booting ;) !!
> 
> I'm using (at the end of /etc/init.d/halt):
> 
> cat /sbin/halt > /dev/null
> cat /bin/sleep > /dev/null
> hdparm -Y /dev/hdd
> hdparm -Y /dev/hdc
> hdparm -Y /dev/hdb
> hdparm -Y /dev/hda
> /bin/sleep 2
> /sbin/halt -d -f -i -p
> 
> It works fine for me for years... I had to put sleep 2 here, as otherwise
> CDROM drive does not park its head correctly (as hdparm /dev/hdc causes
> ide-cd/cdrom to load - and this causes CDROM to spin up :-( )
> So I do not see any reason for doing HDD park by kernel...

I do something similar to this on my non-poweroff machines, except currently
I have only the hard drives coded in. Also, since two of the machines are SCSI,
I have generic built-in so I can spin those down too. (unless hdparm no longer
needs sg loaded to spin down a drive)

Though, having a compile-time or boot-time kernel option to spin down all
attached drives at halt may not be a bad idea.

-- Ferret

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

end of thread, other threads:[~2001-05-24 17:39 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-05-24 12:29 patch to put IDE drives in sleep-mode after an halt peter k.
2001-05-24 12:46 ` Adrian V. Bono
2001-05-24 12:59   ` peter k.
2001-05-24 13:18     ` Erik Mouw
  -- strict thread matches above, loose matches on Subject: below --
2001-05-24 15:16 Petr Vandrovec
2001-05-24 17:38 ` idalton
2001-05-24 11:03 Rodrigo Ventura
2001-05-24 11:11 ` Russell King
2001-05-24 13:20 ` Erik Mouw
2001-05-24 13:52   ` Rodrigo Ventura

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