Indeed, Arlie, it’s not my custom to look at other people’s machine code.
Now, if I’m going to use your report over that piece of code, I may be able
to safely say, it does not use test-and-test-and-set. I made one suggestion,
which was, try to use test-and-test-and-set to see if there’s any
performance increase: that suggestion is still valid. Further, if what you
write about that code is right, they don’t use any kind of backoff in case
of a test and set conflict either. Which was the second suggestion I made:
try to put some backoff between retries to see if things improve: that
suggestion is still valid.
Now, why blast the poster with internals of spinlock design ? Because this
is an elementary part of Operating Systems 101, which every kernel developer
should know inside out. If you don’t know what’s a test and set, if you
limit yourself to believe that a spinlock is a Windows call, then I’m not
sure I’m going to call you a kernel developer - I’ll send you to the lab and
give you a homework: implement a test and set, implement a
test-test-and-set, add a pause to it, add backoff to it, experiment with
exponential backoff, grok the difference - now you are ready to use the API,
because you know some of the things that are going on under the hood.
We’re talking about two lines of code, no ? Big deal. And ah, it’s YOU GUYS
who keep bringing this nonsense over and again. All I did was to give two
rather pertinent suggestions of how to address a performance problem.
Alberto.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Arlie Davis
Sent: Friday, December 19, 2003 4:01 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] RE: Synchronizing access to a linked list
Oh, puh-leeze. You do too have a clue how the NT implementation of
KeAcquireSpinLock works. Any monkey with a debugger can read the
assembly. “I have no clue!” is a disengenuous lie, unless you’ve
intentionally avoided looking at it. It’s all of 20 lines of assembly.
It consists – shockingly! – of an interlocked bts instruction, a test
instruction, a pause instruction, a conditional return, and and
unconditional jump to the top of the loop. How simple can you get??
The original poster is obviously rather new to kernel-mode development.
Why blast them with the internals of spin-lock design? They need to
learn the basics (like wtf KeAcquireSpinLock is) before building their
own.
And it doesn’t really MATTER how KeAcquireSpinLock is implemented.
Empirically, it works fairly well. Certainly well enough for a new
developer to use. And I guarantee that it has been tested and debugged
on far more platforms than whatever you can concoct has. Unless you’ve
built your own WHQL lab and had hundreds of vendors bring their
platforms to you for certification.
Oh, god, we’re really going to have this argument all over again. This
is nauseating.
– arlie
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Moreira, Alberto
Sent: Friday, December 19, 2003 3:32 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] RE: Synchronizing access to a linked list
Golly, Mark, I’ve seen lemming behavior before, but this is one step
beyond.
I didn’t look inside their code, and I won’t, so, I’ll reverse the
charges: give me one good reason to use a facility I have no clue how
it’s implemented, specially in a performance-sensitive case !
In this case I have many questions: do they or do they not use
test-and-test-and-set ? Do they have exponential backoff after each
test-and-set, if so, which exponent do they use ? Do they use the pause
instruction, how, and where ? Do they use test-and-set, compare-replace,
exchange-add, what ?
And if they do it the most possible effective way, why is Inaki having
performance issues ?
There’s no such a thing as “correctly written” here. There’s a zillion
ways of implementing a lock. No harm done in experimenting and trying to
find a faster one.
Alberto.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Roddy, Mark
Sent: Friday, December 19, 2003 3:16 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] RE: Synchronizing access to a linked list
Alberto, you are a one-trick pony these days. KeAcquireSpinlock is
correctly written, so there is no need to reinvent that particular
wheel.
=====================
Mark Roddy
From: Moreira, Alberto [mailto:xxxxx@compuware.com]
Sent: Friday, December 19, 2003 2:50 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] RE: Synchronizing access to a linked list
Readers/Writers is a well known problem, get yourself a copy of
any standard OS book and copy the algorithm into your code; the strategy
changes depending on whether you want to give priority to reads, to
writes, or no special priority. You may be able to speed up your
spinlocks by using test-test-and-set instead of plain vanilla
test-end-set, and you should consider inserting a pause instruction into
your code, as Intel recommends. The test-test-and-set works like this:
while (yourlock);
while (testAndSet(yourlock));
It moves much of the testing to the local processor cache and
basically generates no bus traffic and little contention, the reason is,
the first while loop operates on the processor’s cached copy of that
“yourlock” synchronization variable.
Another trick is waiting a little bit before retrying , that
again reduces contention and may reduce latency as well. You can also
try to structure your list as a circular array of dword pointers, for
example, use a ticket algorithm and have it synchornize itself with a
lock-exchange-add, but that’s trickier because of the boundary
conditions.
Hope this helps…
Alberto.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Iñaki Castillo
Sent: Friday, December 19, 2003 12:49 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Synchronizing access to a linked list
I have a linked list that grows dinamically. I use this
list to store data that is used in different threads in a kernel driver.
By one side, updating(writing) to the list occurs a few
times (say several times per minute) while reading the list occurs many
times (say thousand of times per minute).
The writing routine works always at passive level, while
the reading routine works always at above passive level (sometimes at
DPC level, sometimes at DISPATCH level).
I have detected that working on multi processor machines
this scheme does not work well. It does work, but it incurs in great
performance penalty.
If I remove the reading synchronization it works much
faster, but removing it is not a solution because the list can be
updated at any time from the writing thread.
I use SpinLocks to synchronize.
Having this picture, what would be the best method to
synchronize access to the list ?
I have been thinking on remove synchronization at
reading
and replacing the linked dynamic list by a static list, though it sounds
a little dirty method.
Any suggestions ?
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as:
xxxxx@compuware.com
To unsubscribe send a blank email to
xxxxx@lists.osr.com
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to
xxxxx@lists.osr.com
The contents of this e-mail are intended for the named addressee
only. It contains information that may be confidential. Unless you are
the named addressee or an authorized designee, you may not copy or use
it, or disclose it to anyone else. If you received it in error please
notify us immediately and then destroy it.
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@compuware.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
The contents of this e-mail are intended for the named addressee only.
It contains information that may be confidential. Unless you are the
named addressee or an authorized designee, you may not copy or use it,
or disclose it to anyone else. If you received it in error please notify
us immediately and then destroy it.
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@sublinear.org To
unsubscribe send a blank email to xxxxx@lists.osr.com
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@compuware.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.