Subject: Re: input needed - SMP
To: None <>
From: David Laight <>
List: tech-smp
Date: 02/19/2002 10:20:02
> I have got a Linux driver which runs on a uniprocessor machine.
> Now I m modifying the driver to port it to SMP system.
> In my driver I have an Interrupt handler.It is called extensively in
> the driver since it is an Interrupt driven I/O device.I have some set
> of global variables. These global variables are accessed in the
> interrupt handler. Since we know that in SMP system it is possible
> that the same interrupt handler could be executing on multiple
> processors at the same time.In this case I am required to give
> protection to those part of code which accesses global variables.
> Now my question is whether to provide separate Spin lock variable
> for each and every global variable or not ?
> If not then what is the solution.
> If yes then will it affect the system's performance.
> Need input as early as possible

Ok this is a Linux question on a netbsd mailing list so I'll give
the Unixware/Solaris answer!

Firstly the system will disable your IRQ while the ISR is active
so only one copy of your ISR will be running.

However you do need to protect the global variables from accesses
by the ISR and 'process' code.  This is done by spinlocks.
The number of locks required depends on how long they are held
for - ie whether there is likely to be contention.  If you
only need the lock for a short time then a single lock is
probably best - also simplifies coding (you are unlikely
to generate a 'hot spot' (where data is continuously snooped
from one cpu cache to another) in a single driver.

Remember that the lock ties two (or more) actions together,
often the read-write of an increment.   If you are only reading
a single variable you don't need to lock it - if an update
is in progress you might get the old or new value, but unless
your code is tying to to some other data controlled by the
lock it makes no difference.



David Laight: