Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Say you had a decent spec'd computer (running Windows) with a dual core processor but you where pushing it to the limit a bit. Would it be possible for Windows not to detect any input at all for a second or two.

The reason I'm asking is because I understand that even on computers with more than one microprocessor on the CPU, the operating system still schedules processes to make sure they each get nanoseconds of processing power. So surely if the processor was busy enough and you were unlucky enough to try and move the mouse when the processor was processing a different process, Windows wouldn't be able to detect that?

Also, with a single-core processor, if the operating system has the task of scheduling processes, how does the CPU know to go back the operating system once one process has been executed if the process doesn't tell it to?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Generally, the way input devices work is, when they are used, an interrupt (IRQ) is generated. (The only devices not like this would be the old PC-style game port, and I'm not sure how the operating system deals with that.)

IRQs cause a CPU core to immediately jump to another place - the IRQ handler then needs to save the state of the CPU, deal with the device (such as capture the input and report it through whatever OS mechanism), and then return from interrupt.

IRQs also cause the CPU core to disable further interrupts. So for a brief period of time, it can't do anything else or be interrupted again, even if a device tries to trigger another interrupt. PCs have APIC hardware that is heavily involved in controlling, distributing, and managing interrupts, so consider this an oversimplification, though. (For example, I think the APIC can remember if another IRQ comes in while the CPU is processing one, and immediately trigger it on the CPU side right after the CPU tells the APIC "hey, I'm done with this IRQ.")

Windows deals with interrupts through something called a "deferred procedure call" - it does the minimum it needs in this "interrupted" state to get the device's request acknowledged and then hands off the rest of the processing to the actual device driver responsible, which takes care of it when the scheduler finds it convenient or necessary.

So because of this, Windows should acknowledge each device-caused IRQ unless it's stuck in an interrupted state somewhere due to a faulty driver, faulty device, or major corruption of operating system binaries. The DPCs which actually cause Windows to do something interesting with the device request may be what gets delayed.

The general way for an operating system to force a process to give up the CPU is to have a hardware timer that, when it runs out, causes an IRQ. The same type of IRQ as described above. IRQs always cause the CPU to switch to kernel mode. So at that point, the kernel has control and can switch to another process. Without this mechanism, you are wholly dependent on the process to tell the operating system when it is done, and this is what's called "cooperative multiltasking" as opposed to "pre-emptive multitasking."

share|improve this answer
    
Thank you very much for your answer. It was exactly what I was looking for! So just to clarify, the scheduling that takes place is actually done by the kernel and so it sets an IRQ to be sent when one process has been allocated enough time? –  Andy Jul 13 '13 at 13:41
    
That's a good way to summarize it. Linux uses the timer interrupt to achieve this - en.wikibooks.org/wiki/Operating_System_Design/… –  ultrasawblade Jul 13 '13 at 15:17
    
Thanks for the link and clarification :) Do you know how Windows achieves it? –  Andy Jul 13 '13 at 15:56
    
Would need to look at Windows source code to be sure, but since it runs on the same hardware as Linux it's probably done in the same way. –  ultrasawblade Jul 14 '13 at 0:13
    
Ah ok. It was just out of curiosity - didn't know if there was a similar link for Windows but I suppose with it being closed source few people would know. Thanks for your help. –  Andy Jul 14 '13 at 12:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.