Re: Device Driver for SMP

From: Richard B. Johnson
Date: Mon Feb 23 2004 - 11:59:01 EST


On Mon, 23 Feb 2004, Jinu M. wrote:

> Hi All,
>
> We have developed a PCI device driver which works well on both MAC
> (yellow dog) and x86 (RedHat) architectures.
> Now we need to provide the support for SMP machine. What generic
> changes will have to be made to the driver to get it working
> on a SMP machine.
>
> My first doubt is who takes care of the SMP support? Is it the kernel's
> job or the driver's job?
> As you can see I am not a guru at Linux device drivers, so I would
> be happy if you could provide me pointers or some good explanation
> on it.
>
> Thanks a lot!
> -Jinu
>

If the driver was properly written, there is nothing you need
to do to "convert" it to SMP. However, if the driver was written
using 'cli/sti' pairs to protect critical sections, you need
to rewrite those sections to use spin-locks.

OTOH, if the driver was written like a lot of so-called "perfectly
working..." drivers I've seen, you may need to start from scratch!
It all depends upon the techniques the writer used.

When you have two or more CPUs, you absolutely-positively need
to identify and protect critical sections of code. These are
the sections that would corrupt data, muck up hardware, or
otherwise screw up if two or more CPUs were executing the
code or messing with variables at nearly the same time.

For instance, let's say it took two instructions to hardware
to turn on an external light-bulb and no intermediate hardware
instructions were allowed between these two instructions. You
definately need to keep another CPU from touching the hardware
until these two instructions have completed. With only one
CPU, you can often write sloppy code because you know that
nothing else is going to touch your hardware until you are
done. Not so, with SMP machines.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/