Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does linux synchronize preempt count

Tags:

c

linux-kernel

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 ?

like image 636
mousey Avatar asked Sep 03 '10 00:09

mousey


1 Answers

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.
like image 145
caf Avatar answered Sep 23 '22 11:09

caf