public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* 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 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
* 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

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