Re: NdisInterLockedIncrement/Decrement macros



Stephan,

How about "LOCK MOV ..."?

You are allowed to use LOCK prefix only with the instructions that I
mentioned above, and MOV is not among them. Therefore, "LOCK MOV ..."
is undefined opcode. You will get an exception of you try something
like that - even if your code passes through compiler, you still have
no chance to get it actually executed. Please check Intel Developer's
Manual, Volume 2 for more info....


Anton Bassov

Stephan Wolf [MVP] wrote:
soviet_bl...@xxxxxxxxxxx wrote:
[..]
The problem that, in order to use interlocked operation, you need bus
locking, which applies to the following instructions:

ADD, ADC, AND, BTC, BTR, BTS, CMPXCHG, DEC, INC, NEG, NOT, OR, SBB,
SUB, XOR, XADD, and XCHG.

However, reads and writes are MOV instruction, so that there is no way
to lock a bus on read and write operations....
[..]

How about "LOCK MOV ..."?

Anyway, if the variable in question uses the "usual" alignment (i.e.
16-bit aligned if 16 bits wide, 32-bit aligned if 32 bits wide, don't
care for 8 bits), any read operation is for sure always atomic. Simply
because the hardware will always read 16 or 32 bits as one entity then
(even 64 bits on 64 bit machines).

Also, any other synchronization is useless for read operations by
nature (if all bits are read at once). There is nothing to synchronize
with here.

If some other task/CPU/DMA/whatever writes to the same location, well,
you have no control as to when this happens. This is true even if you
*would* add some locking mechanism.

foo()
{
AcquireSomeLock();
ReadData();
ReleaseSomeLock();
}

The use of the locking mechainim is just useless here. So this is
equivalent to:

foo()
{
ReadData();
}

If (and only if) the read variable is *not* aligned, e.g. if it crosses
any 32-bit alignment boundary, then you need to add some locking
mechanism (like the LOCK instruction on x86).

Stephan

.



Relevant Pages

  • Re: [PATCH RFC/RFB] x86_64, i386: interrupt dispatch changes
    ... cycles to the bus. ... LOCK slowness is not because of the bus. ... maybe 150-200 regular pipelined, superscalar instructions. ...
    (Linux-Kernel)
  • Re: Teaching Assembly Language Programming
    ... at the description of the "Test and Set"-ish instructions in the Intel ... With only a mutex or a spin lock, ... is acquire lock, increment counter, release lock. ... lets say you have a pointer to the first element ...
    (alt.lang.asm)
  • Re: Compile Barrier
    ... > Barrier addressing issue with instructions reordering (pipelining feature on ... So a barrier is a mechanism for a programmer ... To address this issue compiler writes recognize some functions ... > - a will be written to the main memory before the lock is released ...
    (microsoft.public.win32.programmer.kernel)
  • Re: More on Canon Rebel XT noise at high ISO - 2 main new data points
    ... circumstance where you need to take an exposure lock the English used to describe operation of it is clear, concise, and has no evidence of the poor 'literal' translation that I have seen in some instructions. ... it is more profitable and that no one else that because Canon 'must be right' then you would probably have received less references to your stupidity, it was only quite recently that you understood the implication of the function described on page 101 of the camera instruction manual ("FE (flash exposure) lock obtains and locks the correct flash exposure reading for any part of the subject"). ...
    (rec.photo.digital.slr-systems)
  • Re: WaitForSingleObject() will not deadlock
    ... I'd like to see the EXACT SEQUENCE OF INSTRUCTIONS issued in the locking sequence, ... My issue about the 2 CPU clock cycles is that once the lock is set, ... cycle detection using non-recursive mutex: ...
    (microsoft.public.vc.mfc)