Home » How does a computer restart itself?

How does a computer restart itself?

Solutons:


tl;dr: 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.

Here’s a starting point:

Chips usually don’t turn off and then turn on. Instead, there’s a reset line which will bring processor in so-called reset state when usually all memory is cleared and processor looks like it’s just been powered on. While that pin is held high (or low, depending on the processor), the processor is in reset. Once the pin is released, it will continue booting normally, just as if it was turned on for the first time. The point of this is that there’s no power cut itself.

So how does this scale to larger systems like modern PCs? Well modern computers are made out of computers which are sometimes made out of computers themselves. So when you set computer to reset, “computers” which make the computer will start saving their states (if the reset is controlled), or just have their reset pins pulled.

Some processors and microcontrollers (which are miniature self-contained computers, usually 20 years behind the modern desktop computers) can reset themselves using internal switches. As I said, once the signal which generates reset is gone, the computer will start up. So the premise in the question isn’t completely right. Computer doesn’t know when to turn on. In know when it needs to be “off” or in reset and when the signal which keeps it there is gone, it will turn on.

This behavior may look strange on modern computer which can be set to turn on at specific time or over network and so on. As I said computers are made of computers. So while the main processor may be off, there could be numerous other chips and microcontrollers inside which are on. The most obvious case is the real-time clock which is often battery powered. It can then turn on other chips which will turn on other chips and the chain reaction goes until the whole computer is on. On today’s computers, there’s a PSU line called +5 VDC Standby Voltage. It provides around 50 mW power to various devices that are on when computer is “off”.

A little bit of trivia:
Reset pin on Intel 386 EX processor is pin number 110.

386EX datasheet figure 2

On Intel i7-900 it’s land number AL39.

I hope that someone will be able to provide an answer which will explain how things work from the high level point of view, since it’s quite complicated system.

This blog post describes how Linux triggers a reboot.

Excerpt:

Linux has a bunch of different ways to reset an x86. Some of them are 32-bit only and so I’m just going to ignore them because honestly just what are you doing with your life. Also, they’re horrible. So, that leaves us with five of them.

  • kbd – reboot via the keyboard controller. The original IBM PC had the CPU reset line tied to the keyboard controller. Writing the appropriate magic value pulses the line and the machine resets. This is all very straightforward, except for the fact that modern machines don’t have keyboard controllers (they’re actually part of the embedded controller) and even more modern machines don’t even pretend to have a keyboard controller. Now, embedded controllers run software. And, as we all know, software is dreadful. But, worse, the software on the embedded controller has been written by BIOS authors. So clearly any pretence that this ever works is some kind of elaborate fiction. Some machines are very picky about hardware being in the exact state that Windows would program. Some machines work 9 times out of 10 and then lock up due to some odd timing issue. And others simply don’t work at all. Hurrah!

  • triple – attempt to generate a triple fault. This is done by loading an empty interrupt descriptor table and then calling int(3). The interrupt fails (there’s no IDT), the fault handler fails (there’s no IDT) and the CPU enters a condition which should, in theory, then trigger a reset. Except there doesn’t seem to be a requirement that this happen and it just doesn’t work on a bunch of machines.

  • pci – not actually pci. Traditional PCI config space access is achieved by writing a 32 bit value to io port 0xcf8 to identify the bus, device, function and config register. Port 0xcfc then contains the register in question. But if you write the appropriate pair of magic values to 0xcf9, the machine will reboot. Spectacular! And not standardised in any way (certainly not part of the PCI spec), so different chipsets may have different requirements. Booo.

  • efi – EFI runtime services provide an entry point to reboot the machine. It usually even works! As long as EFI runtime services are working at all, which may be a stretch.

  • acpi – Recent versions of the ACPI spec let you provide an address (typically memory or system IO space) and a value to write there. The idea is that writing the value to the address resets the system. It turns out that doing so often fails. It’s also impossible to represent the PCI reboot method via ACPI, because the PCI reboot method requires a pair of values and ACPI only gives you one.

Related Solutions

Performance issue with this code [closed]

In short: You should create,open,use,close,dispose Connections where you're using them. The best way is to use the using-statement. By not closing the connection as soon as possible, the Connection-Pool needs to create new physical connections to the dbms which...

Compare a pointer to an integer in C [closed]

Here's what I think you meant to post, it still doesn't compile though, since you can't compare a pointer to a char /* *Description: Construction of a social network */ #include <stdio.h> #include <strings.h> #include <stdlib.h> #define SIZE...

Autocomplete json in textbox

If you are using jQuery UI, the jQuery documentation on autocomplete is straightforward. Put your array as the source: and it should work automatically. IMHO, You seriously need to spend some time for googling and looking into the documentations. jQuery UI...

having all my scores and names in one big array

You need to initialize your array outside of your loop: name_arr = [] while int(students)>int(student): name = input ("what is your name ") score = input ("what is your score ") student = student + 1 name_arr.append(name) name_arr.append(score)...

pacman “exists on filesystem” error

After pacman finally deprecated the --force option and made the surrogate --overwrite option work as expected, the following usage pattern should be noted. A command to reproduce the --force option that blindly overwrites anything that conflicts is this: sudo...

How to determine the maximum number to pass to make -j option?

nproc gives the number of CPU cores/threads available, e.g. 8 on a quad-core CPU supporting two-way SMT. The number of jobs you can run in parallel with make using the -j option depends on a number of factors: the amount of available memory the amount of memory...

Number of Nearest ‘True’ in a matrix or list of list

Definitely not the best way to do it, but it's one that works: import numpy as np mas1 = np.array([[True, False, True], [ False, True, True], [ False, True, False]]) mas_answer = np.ndarray(shape=mas1.shape) for i in range(mas1.shape[0]): for j in...

Trying to display Json data from a web url into a table

You can take this json and put it in the loop through length of the json and show data into the table. This is how i solved it <?php try{ $url="the json url goes here"; // path to your JSON file $data = file_get_contents($url); // put the contents of the...

View v is unreachable statement

Anything else is written after the return keyword it's unreachable. Remove return super.getView(position, convertView, parent); from the first line of your function. This is a warning, telling you that static analysis of the code shows that some of your code...

index out of range but is in fact in range [closed]

Well try to debug your code by yourself first. Anyhow for your question Why is this happening? : It gives you error in postCode = split_address[4] because your list has 4 elements 0,1,2,3 and you are accessing the 4th element which is not present.. you don't...

Ubuntu update error: “waiting for unattended-upgr to exit”

I would first try a softer way. Stop the automatic updater. sudo dpkg-reconfigure -plow unattended-upgrades At the first prompt, choose not to download and install updates. Make a reboot. Make sure any packages in an unclean state are installed correctly. sudo...

how to Styling classes with the same name in a file css [closed]

You need to use :nth-of-type(n) selector. // For First Right Class Div #container .right:nth-of-type(1) { } // For First Left Class Div #container .left:nth-of-type(1) { } Hence for every div you need to change n value. Your question is extremely unclear but I...

Java – different parameters resulting to different outputs

What I think you're trying to achieve is that when you call your method "horn" with some parameter it has to either use "Beep!" or "Boop!". First of: void horn(a,b) Is not a valid function signature in Java, in a java function you always have to specify what...

Cannot use method returned value into another method

Using @super's suggestion and a little warning fixing. The two important changes are in the line as suggested by @super: printf("r=%.3f; phi=%.3fn",distanta(),phi()); The variables 'r' and 'unghi' are both variables local to member functions and cannot be...

Class has no member speak? [closed]

void::speak(); //THE GLOBAL SCOPE HAS NO SPEAK It's interpreting this as void ::speak() where leading an identifier (a name) with :: indicates to C++, "Look in the global scope of all names". :: is the "scope resolution operator" In the header file, you should...

Convert code with multiple lines into one line

Read the docs! A simple statement is comprised within a single logical line. Several simple statements may occur on a single line separated by semicolons. Search Stack Overflow! How to put multiple statements in one line? Or google, to find converters for more...

How to POSITION my Marker to Always Follow the Slider-Handle?

Youc can set a position to image using Jquery See fiddle //set a begining position to img var slider = $(".slider")[0]; var sliderPos = slider.value / slider.max; var pixelPostion = slider.clientWidth * sliderPos; $(".img").css("left",pixelPostion-7 + "px");...

css nth-child() check board pattern [closed]

This is pretty simple, as the pattern is repeated over 2 rows of 4, you just need to apply styles to 8n + i for the chequered pattern: .flex { display: flex; width: 400px; /* width of four squares */ flex-direction: row; flex-wrap: wrap; } .square { width:...