The Idle Brain is Still Busy

Dear [Mentat],

I agree. But allow me to offer just a point of clarification: When I described the idling CPU, perhaps I should have paid more verbiage to what actually goes on in that “infinite loop.” I gave the impression that nothing worthwhile is accomplished in this loop, which may be true enough if you’re looking at the computer from the outside as a black box. However, I haven’t examined the code for the idle process, and so cannot say precisely what goes on.

But one thing I omitted is that when in this idling state, the CPU, by virtue of its hardware construction (nothing to do with Windows per se) monitors its 16 interrupt lines for requests. As you probably know, each of the important devices in the computer is tied to one or more of these IRQ lines (mouse, sound card, USB card, network card, disk drive, RAM memory, and so on). Should such a device require service (such as when the mouse is moved or the sound card needs more sound data sent to it while playing a file), it sends a signal down its IRQ to the CPU. When the CPU receives this, it puts aside its idle activities and executes the interrupt handler routine associated with the IRQ line. For the sound card wanting more data to play for example, its interrupt handler copies more data from the sound file into the sound card’s buffer. This routine is usually provided either by the operating system, the BIOS, or some third party. At any rate, IRQ routines are usually found in software driver components.

Also, while executing the Windows OS idle code, the CPU periodically checks what they call the system message queue. In Windows, anything that happens from the opening of a new window to a mouse click or movement, generates a sequence of one or more _events_ . Such events include things like MOUSE_MOVE_UP, MOUSE_MOVE_DOWN, MOUSE_LEFT_CLICK, WINDOW_FOCUS_IN, WINDOW_FOCUS_OUT, WINDOW_MINIMIZE, WINDOW_MAXIMIZE, NEW_MAIL_NOTIFICATION, and hundreds of others. When such an event is received, the CPU, once again, is diverted from the idle activities, and executes what they call an event handler routine. The event message is discarded when its handler finishes.

Events are much like interrupts except that they’re entirely generated and handled through software, and they do not require interrupt lines and associated specialized circuitry in the hardware. Now an interrupt is usually translated by the device driver into a string of Windows events, such as when we click the mouse. When the CPU receives the mouse interrupt request, it executes the mouse interrupt handler in the mouse device driver code. That routine figures out what sort of mouse action happened – MOUSE_MOVE_UP, MOUSE_MOVE_DOWN, MOUSE_LEFT_CLICK, MOUSE_MOVE_WHEEL_UP, KEYBOARD_KEY_DOWN, KEYBOARD_KEY_UP, and so on. Then, it inserts appropriate event messages into the system message queue. When the CPU returns to idle from the interrupt handler, it checks the message queue and finds the events just added, and then executes the appropriate event handlers to cause the mouse pointer on the screen to move according to the actual mouse action. A MOUSE_MOVE_UP event causes the pointer on the screen to move one or more pixels up for example.  Thus even when idle, the CPU is still quite busy. 

Thus, even though the CPU is in an infinite loop while idling, it is accomplishing the meaningful task of monitoring the system for interrupts. So I was wrong to say that absolutely nothing is accomplished in this loop.  Indeed, there’s much utility activity that happens as the CPU executes the idle process; activity that may not be meaningful to the outside world, but that is necessary to accomplish proper system monitoring.

The brain’s neurons are similar to the CPU in that they must fire periodically to perform internal brain maintenance and bodily monitoring activities such as dreaming, subconscious organizing of new data, monitoring the blood for homeostasis and then taking corrective action if imbalances are found such as when the blood is too warm or cold, has too much or too little sugar or salt, and so on. The maintenance activities keep the CPU as well as the brain busy but do not completely utilize its maximum potential.

I hope that this amended description of the CPU and the idle process shows better the similarity between the brain and CPU I wanted to illustrate in the last post. While much of the activity in the idle process could be rightly dubbed as meaningless, wasteful activity, there are nonetheless necessary things that happen there as well, just as in the idle brain. Indeed, the idle brain is still quite busy. 

Yes, I know how difficult it is to silence the mind chatter when trying to “get into the zone” and focus fully on a specific task or problem.

Tom Hesley

Leave a Reply

You must be logged in to post a comment.