It’s such a common place activity that most of us have likely never stopped to even think about it: the automatic restart. Whether user or application-initiated, what exactly happens when your computer cycles its own power?
Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-drive grouping of Q&A web sites.
SuperUser reader Seth Carnegie wonders about computer power management:
How can a computer restart itself? After it’s off, how does it tell itself to come back on again? What kind of software is it that can do this?
How indeed? What combination of software/hardware magic makes it happen?
SuperUser contributor Jcrawfordor offers both a condensed and detailed response to the question that more than adequately addresses the question:
The too long;didn’t read it answer: Power states in your computer are controlled by an implementation of ACPI (advanced configuration and power interface). At the end of a shutdown process, your operating system sets an ACPI command indicating that the computer should reboot. In response, the motherboard resets all components using their respective reset commands or lines, and then follows the bootstrap process. The motherboard never actually turns off, it only resets various components and then behaves as if the power button has just been pressed.
Long and rambling but (in my opinion) more interesting answer:
Soft Power and How It Works
In the olden days (well, okay, to a college student like me the ’90s was a long time ago), we had AT (Advanced Technology) motherboards with AT power management. The AT power system was very, very simple. The power button on your computer was a hardware toggle (probably in the back of the case) and your 120vac input went right through it. It physically turned the power to your power supply on and off, and when this switch was in the Off position everything in your computer was completely dead (this made the CMOS battery very important, because without it there was no power supply to keep the hardware clock ticking). Because the power switch was a physical mechanism, there was no software way to turn power on and off. Windows would show the famous “It is now safe to turn off your computer” message because, although everything was parked and ready to turn off, it was not possible for the OS to actually flip the power switch. This configuration was sometimes referred to as hard power, because it’s all hardware.
Nowadays things are different, because of the wonders of ATX motherboards and ATX power (that’s Advanced Technology eXtended if you’re keeping track). Along with a number of other advances (mini-DIN PS/2, anyone?), ATX brought soft power. Soft power means that power to the computer can be controlled by software. This brought a few import changes:
- Standby power: you may have seen a “5v SB” or “5v standby” connector labeled in power supply pinouts. The standby power supply is a 5v line to your motherboard that is always on, even when the computer is turned off. This is why it is important to unplug or turn off a PSU hard switch (if present) when servicing modern computers, because even when it’s off you could potentially short the 5v SB and damage the motherboard. This is also why CMOS batteries aren’t really as important anymore – the 5v SB is used to replace the CMOS battery whenever the power supply has mains power, so the CMOS battery is only used when you unplug the computer entirely. The 5v SB line importantly allows components of your computer (most importantly the BIOS and the network adapters) to keep running some simple software even when the computer is turned off.
- Intelligent power supply control. If you look at a pinout for your power supply’s motherboard (P1) connector, you’ll notice two pins typically labeled PS_ON and PS_RDY. These stand for “power supply on” and “power supply ready”. If you like to experiment, take a power supply not in a computer, plug it in, and carefully short a ground line (one of the black wires) to the PS_ON line (the green wire). The power supply will visibly turn on, with the fan spinning up. The components of the motherboard running off of +5v SB actually turn your power supply on and off by connecting power to the PS_ON pin. Because there are some capacitors and other components in the power supply that take a moment to charge up, the voltages from the power supply’s main outputs may not be stable immediately after the PSU turns on. This is what the PS_RDY pin is for, it comes on when the power supply’s internal logic determines that the power supply is “ready” and will provide stable power. The motherboard waits until PS_RDY is on to continue booting.
So, your power switch no longer “turns on” the computer. Instead, it’s connected to your motherboard’s basic controllers, which detect that the button has been pressed and execute a number of steps to ready the system, including lighting up PS_ON so that power will be available. The power button isn’t the only way to trigger the startup process, devices on your expansion bus can also do so. This is important because your ethernet network adapters actually stay on when your computer is off and look for a very specific packet often referred to as the “Magic packet.” If they detect this packet addressed to their MAC address, they will trigger the startup process. This is how “Wake-on-LAN” (WoL) works. The clock can also initiate a boot (most BIOS allow you to set a time that the computer should boot each day), and USB and FireWire devices can trigger a boot, although I’m not aware of any implementation of this.
Understanding Power Control
Well, I explain the Soft Power thing both because I think it’s interesting (always a key reason that I explain things) and because it allows you to understand how the power and running/off state of your computer are all controlled by software. In most current computers, this software system is an implementation of the Advanced Configuration and Power Interface, or ACPI. ACPI is a standardized, unified system allowing software to control your computer’s power system. You may have heard of the ACPI power states. The basic mechanism of power control is these “power states”, your operating system switches through power modes by preparing for the switch (the shutdown/hibernate processes that occur prior to power actually flipping off), and then commanding the motherboard to switch power states. The power states look like this:
- G0: Working (your computer’s “on” state)
- G1: Sleeping (your computer’s standby states, divided in to the S substates)
- S1: power to CPU and RAM remains on, but CPU is not executing instructions. Peripheral devices are powered off.
- S2: CPU powered off, RAM maintained
- S3: All components powered down except for RAM and devices that will trigger a resume (keyboard). When you tell your OS to “Sleep”, it will stop processes and then enter this mode.
- S4: Hibernation. Absolutely everything is turned off. When you tell your operating system to Hibernate, it stops processes, saves the contents of RAM to disk, and then enters this mode.
- G2: Soft Off. this is your computer’s “off” state. Power is off to everything except for devices that can trigger a boot.
- G3: Mechanical off.
How reset actually happens
You’ll notice that reboot is not one of these states. So what actually happens when your computer when it reboots? The answer may be surprising, because from a power management perspective it’s almost nothing. There is an ACPI reset command. When you tell your operating system to reboot, it follows its normal shutdown process (stops all your processes, performs a bit of maintenance, dismounts your file systems, etc), and then as a final step, instead of sending the machine to power state G2 (as it would if you had simply told it to Shut Down) it sets the Reset command. This is generally referred to as the “Reset register”, because like most of the ACPI interface it’s just an address that a specific value should be written to in order to request a reset. I’ll quote the 2.0 specification on what it does:
The optional ACPI reset mechanism specifies a standard mechanism that provides a complete system reset. When implemented, this mechanism must reset the entire system. This includes processors, core logic, all buses, and all peripherals. From an OSPM perspective, asserting the reset mechanism is the logical equivalent to power cycling the machine. Upon gaining control after a reset, OSPM will perform actions in like manner to a cold boot.
So, when the reset register is set, a few things happen in sequence.
- All logic is reset. This means sending the respective reset commands to various bits of hardware including the CPU, memory controller, peripheral controllers, etc. In most cases this simply means lighting up a physical RST wire, as AndrejaKo showed up above.
- The computer is then bootstrapped. This is the “perform actions in like manner to a cold boot” part. The motherboard performs the same steps as it would if the power supply had just become ready after the power button being pressed.
The end effect of these two steps (which actually break down in to a lot more steps) is that it looks to everything just like the computer just booted, but the power was actually on the whole time. This means less time required to shut down and start up (since you don’t have to wait for the power supply to become ready), and importantly allows the bootup to be initiated by the operating system shutting down. This means that another startup trigger doesn’t need to be used (WoL etc), and allows you to use Reboot as an effective way to reset the system remotely, when you don’t have a way to trigger boot.
That was a long answer. But hey, hopefully you know more about computer power management now. I certainly learned some things researching this.
Have something to add to the explanation? Sound off in the the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.