Skip to contentSkip to conversation

kernel spinlocks; when to use; when appropriate?

DISCUSSION Lars Unin 2 participants 2 messages Jun 14, 2003 – Jun 15, 2003

lore
Share & tools
lore

Lars Unin

author
#0 lore raw

I wrote a while ago (thanks to you guys on LKML I almost
understand now):

Quoted 2 lines
Quoted 1 line

When is is appropriate to use spinlocks in the kernel,

<snipped>

Quoted 5 lines · Then Mark hahn

jeez. it's verging on rude to ask this sort of question, when you have the vast expanses of kernel code right there in front of you, chocked full of spinlocks. the mere fact that the list has tens of thousands of readers should make you try to help yourself first.

Well <sirens heard> its verging on rude to send me an email thats
rude <people heard in background> and has this theme:

You are a two year old, to learn what the words "quarks" mean you
should read Quantum Thoeries by Lazzengberg, then use a particle accelerator to Quantify and factualise it, OR

Like asking a 6 year old where babies come from... Lets face
it, how many 6 year olds can work out the full process without a book expalining it, or someone telling them...

Its verging on rude also to assume even though <Voices heard
"PUT THE GUN DOWN, NOBODY HAS TO DIE"> <Hahns palms held outstretched> nobody wants to read my question, that I would want to read such an answer, so tell me <"NOW BRAVO TEAM, GO GO,"> why the rant by you?

BRAVO TEAM GO GO! SUSPECT IS UNARMED. REPEAT. SUSPECT IS UNARMED.

Chill. ;-)
Lars.

Signature · 5 lines
______________________________________________
http://www.linuxmail.org/
Now with e-mail forwarding for only US$5.95/yr

Powered by Outblaze
#1 lore raw
Quoted 2 lines

I wrote a while ago (thanks to you guys on LKML I almost
understand now):

I missed the start of this thread, so forgive me if I state what was stated before.

Use semaphores when the average hold time will be much longer than two context switches, spinlocks for everything else. Semaphores when contended force the process to go to sleep (one context switch), later, the process will be switched back in when it gets the semaphore (another context switch). This double context switch takes a fixed amount of time and if you can get through your critical region much faster than that fixed time, then it should be protected by a spinlock.

There are places where you have to use spinlocks irrespective of the
above: when in interrupt code (where sleeping is not allowed), and in regions of code where some other spinlock is held (where sleeping is also not allowed). The latter is especially insideous -- the more kernel code protected by spinlocks, the more likely those existing spinlocks will force new code to have to use spinlocks instead of semaphores.

Joe