Skip to contentSkip to conversation

Patch: linux-2.5.42/kernel/sys.c - warm reboot should not suspend devices

DISCUSSION Adam J. Richter 5 participants 7 messages Oct 13, 2002 – Oct 20, 2002 Driver core

lore
Share & tools
lore
#0 lore raw
Quoted 9 lines · Eric W. Biederman
Quoted 5 lines · Eric Blade
Quoted 4 lines · Adam J. Richter

At first, I suspected IDE, but I think the new behavior in IDE
of spinning down the hard drives on suspend is correct. The problem is that the warm reboot system call is trying to suspend all of the devices before a warm reboot for no reason.

Quoted 3 lines

There is a very good reason for calling the driver->remove() function on a reboot so that we place the devices in a consistent state. And stop any on going DMA etc.

A warm reboot is supposed to do this by the platform dependent
machine_restart(), and whatever processes machine_restart sets off (e.g., by making a RESET signal active). If a device driver needs some special processing prior to that, that is what the reboot notifier chain is for.

Quoted 2 lines

The reboot notifier call chain, is highly underused, and all of the drivers already have the code they need in their remove function.

What specific drivers are you referring to that meet all three
of the criteria you have stated?:

1. They need to use reboot_notifier because the machine_restart() is not enough to reset them,

2. They do not currently use reboot_notifier,

3. They have a device->remove() that does what the reboot_notifier should do (shuts down ongoing DMA, because they have a some device that ignores a reset signal or something like that).

In general I would expective that a driver->remove(device)
function would not be able to touch much of the hardware at all, because it would have to assume that the device has been or is being physically yanked out of the computer, so it should do software cleanup and maybe talk to the PCMCIA socket, USB hub port, etc. that previously held the device.

If you have a platform where, for example, somehow PCI devices
are able to continue jabbering away after the computer has been reset, then that could probably be done more consistently for most drivers by having machine_restart on that platform walk the PCI bus and shut down everything (drivers that need to do something really special would still use the reboot notifier).

I could even see calling device_shutdown from machine_restart
on that platform only, and I could even image "if(buggy_motherboard) device_shutdown();", but I would be really surprised to learn that sort of thorough resetting is necessary for most hardware on ordinary x86 PC's.

I could also understand something like your system call for
booting Linux from Linux needing to do more thorough shutdowns and resets, but not something that uses machine_restart().

Quoted 9 lines
Quoted 5 lines

I am not talking about

Quoted 4 lines

eliminating that. I am only talking about the soft reboot putting devices into a power saving mode that is allowed to take a long recovery time, especially given that the reboot is likely to want to talk to every hardware device connected to the system.

If
driver->remove()
does that it is an issue with that device driver.

device_shutdown and device_suspend are for power management.
It is important to turn the device off as soon as possible if a power management routine has told you that the device is not going to be used any more.

If you've identified a bunch of devices that need
reboot_notifier, please list them so we can fix them rather than taxing the users with unnecessarily slow reboots or poor battery life (due to device not being shut down when they are no longer being used).

Adam J. Richter     __     ______________   575 Oroville Road
[email protected]     \ /                  Milpitas, California 95035
+1 408 309-6081         | g g d r a s i l   United States of America

"Free Software For The Rest Of Us."

#1 lore raw
Quoted 9 lines · Adam J. Richter
Quoted 3 lines

There is a very good reason for calling the driver->remove() function on a reboot so that we place the devices in a consistent state. And stop any on going DMA etc.

A warm reboot is supposed to do this by the platform dependent
machine_restart(), and whatever processes machine_restart sets off (e.g., by making a RESET signal active). If a device driver needs some special processing prior to that, that is what the reboot notifier chain is for.

I'd imagine the reboot notifier chain is going away - especially as stuff would need to be shut down in the right order, which is one of the reasons we have the device model. It already knows the right order.

Quoted 6 lines

If you have a platform where, for example, somehow PCI devices
are able to continue jabbering away after the computer has been reset, then that could probably be done more consistently for most drivers by having machine_restart on that platform walk the PCI bus and shut down everything (drivers that need to do something really special would still use the reboot notifier).

x86, I believe, is one example of such a platform that can leave PCI devices jabbering over a warm reboot.

Quoted 4 lines

device_shutdown and device_suspend are for power management.
It is important to turn the device off as soon as possible if a power management routine has told you that the device is not going to be used any more.

I'd think the sane solution would be a device_reboot() call, and kill off the reboot notifier. That's just my opinion though, given that I have some devices that definitely need this type of treatment.

I'd rather have one registration system for this type of device management, not multiple random lists to register stuff with all over the place.

Signature · 2 lines
Russell King ([email protected])                The developer of ARM Linux
             http://www.arm.linux.org.uk/personal/aboutme.html
#2 lore raw
In reply to Adam J. Richter

O.k. After having been away from active development on the kernel for a while I have now reviewed what you are seeing and I have a much firmer grasp of what is going on.

The change that merged device_shutdown and device_suspend was buggy. There really should have been a second state added so no behaviour would change. This does not affect the reboot case, but it does affect the other users of SUSPEND_POWER_DOWN which does request devices be powered off. Which is noticeably from what you want in device_shutdown() which is the preparation for reboot/halt.

The change that went into 2.5.42 was the behavior of the ide driver changed. device_shutdown has always called device->remove, and it has been in the reboot path for a very long time. The ide driver just implemented a remove method, replacing it's reboot notifier, and in that change the ide driver started spinning down disk on reboot as well as shutdown. So please talk to the author of the ide change if you do not like the current ide behaviour.

machine_restart returns control to the BIOS.
It works this way on both x86 and alpha. And the BIOS does not always toggle the RESET line on the machine. The frequent case of devices not working in Linux after rebooting from windows, and visa versa is evidence of this. On alpha the SRM doesn't even pretend to reset the machine.

Therefore the reboot code needs to put devices in a sane state, and given the general perversity of hardware and that there is not a defined way to do this generically except resetting the pci bus the device drivers need to be involved. A reboot notifier is an ugly way to do this, and walking the power management tree is a much cleaner way to accomplish this. Additionally it was decided quite a while ago that calling device->remove() was the correct way to accomplish this.

Reboot problems show up more clearly when booting linux from linux but that just makes it more explicit. It does not introduce any new potentials for problems, in this area.

Eric

#3 lore raw
In reply to Adam J. Richter
Quoted 5 lines

device_shutdown and device_suspend are for power management.
It is important to turn the device off as soon as possible if a power management routine has told you that the device is not going to be used any more.

device_suspend() is for power management. device_shutdown() is for quiescing devices before a system reboot or power off.

It's true that the same function is called when the device is physically removed from the system as when the system is shutting down, and that might be kinda bad. If it gets to the point where it's really difficult to deal with for drivers, we can create another callback: ->shutdown() for struct device_driver.

Quoted 4 lines

If you've identified a bunch of devices that need
reboot_notifier, please list them so we can fix them rather than taxing the users with unnecessarily slow reboots or poor battery life (due to device not being shut down when they are no longer being used).

No, reboot notifiers are the completely wrong way to go, for one reason
alone: ordering. device_shutdown() does a depth-first walk of the tree to shut down children devices before ancestors. You cannot guarantee that with reboot notifiers.

Please don't try and convolute the code because you're worried about a few microseconds. It's about correctness first; then we can worry about micro-optimizing the hell out of it.

-pat

#4 lore raw
Quoted 3 lines · Patrick Mochel

Please don't try and convolute the code because you're worried about a few microseconds. It's about correctness first; then we can worry about micro-optimizing the hell out of it.

5 seconds is quite a bit more than "a few microseconds". That's approximately how much longer it takes for my P4 to reboot, due to 2.5.42's "oh lets spin down the disks on reboot" change.

It's even slower to reboot than to do a cold boot because on a cold boot the disks start spinning up directly, but on a warm boot after 2.5.42 the disks don't start spinning up until the BIOS starts to identify them and look for a bootable device.

2.5.42 is a PITA.

#5 lore raw
In reply to Patrick Mochel
Quoted 5 lines · Patrick Mochel
Quoted 4 lines

device_shutdown and device_suspend are for power management.
It is important to turn the device off as soon as possible if a power management routine has told you that the device is not going to be used any more.

Quoted 8 lines

device_suspend() is for power management. device_shutdown() is for quiescing devices before a system reboot or power off.

It's true that the same function is called when the device is physically removed from the system as when the system is shutting down, and that might be kinda bad. If it gets to the point where it's really difficult to deal with for drivers, we can create another callback: ->shutdown() for struct device_driver.

Obviously you have decided this was worth it.

My feedback.
* dev->shutdown is not called on module removal.
* dev->shutdown does not update dev->state to anything like DEVICE_SHUTDOWN, that could be used as a sanity check, to not use a device after it has been shut down.

* The semantics of dev->shutdown() and are not clear, in their interactions with other parts of the system. Can the code from dev->remove() that shuts down a device be removed?

I care because getting devices to properly shutdown on when sys_kexec is what I need to do to get sys_kexec stable.

Would it be worth it for me to split out my fixes to smp shutdown, and i8259 shutdown and to send them along to you?

The smp shutdown case on x86 probably cannot be handled by the device model because it must be the very last code to run. When you stop interrupts from coming in several drivers get cranky and do not shutdown cleanly.

Hopefully I am not coming off harsh but I am a little cranky this morning, As before this change I thought things on the device side were pretty much under control they just needed a little stabilization and testing. And now someone possibly me has to go through every driver and write a shutdown method because someone figured calling free was expensive.

That was the point of calling dev->shutdown instead of dev->remove() wasn't it? If there was a way to reawaken a device after calling dev -> shutdown I might see it. But to do that you still need to call dev -> remove() followed by dev ->probe()

Eric

#6 lore raw

Assuming it is worth it to split remove into 2 parts, we need the following so rmmod calls ->shutdown. Otherwise we will get code duplication in the drivers.

And then we need all of the patches that split remove into 2 parts, in the drivers.

Eric

drivers/base/bus.c Sun Oct 20 03:44:46 2002 renamed from drivers/base/bus.c Sat Oct 19 00:57:58 2002 +2 -0
diff -uNr linux-2.5.44/drivers/base/bus.c linux-2.5.44.shutdown/drivers/base/bus.c
@@ -164,6 +164,8 @@
        if (drv) {
                list_del_init(&dev->driver_list);
                devclass_remove_device(dev);
+               if (drv->shutdown && device_present(drv))
+                       drv->shutdown(dev);
                if (drv->remove)
                        drv->remove(dev);
                dev->driver = NULL;