tags:

views:

74

answers:

2

http://lxr.linux.no/linux+v2.6.35/include/linux/preempt.h#L21

I am just trying get the linux source. I saw this preempt count and how does linux ensure the preempt count is atomic ? The code just increments the value.

Also I have an another question. why does interrupt handles need to maintain mutual exclusion. Because only one can execute at a time right ?

Also when interrupts are disabled what does OS do ? Ignore interrups or maintain a queue ?

A: 

Every modern processor has some variant of the atomic test-and-set instruction.

msw
check the source. It doesnt use any system specific instructions. It just increments
mousey
+3  A: 

It increments preempt_count() - notice the () - which is a macro is defined as:

#define preempt_count() (current_thread_info()->preempt_count)

So it is incrementing a per-thread variable, which doesn't require any locking and is safe.


It's best to ask your multiple questions as separate questions, but briefly:

  • Interrupt handlers can in general be interrupted by other interrupt handlers;
  • Interrupt handlers can run on one CPU core while other kernel code is running on another core;
  • Interrupts are usually disabled using a hardware mechanism. These tend to remember pending interrupts, but only up to a maximum of one per interrupt vector.
caf
@caf Thank you very much. can you pls answer my next questions too pls.
mousey
@Caf thank you very much.
mousey