If the cache and memory subsystem is working properly on a multiprocessor
system, a write to a word completed in clock X should be seen by all other
processors in clock X+1. If only one processor is writing and all others
are reading you can quite efficiently use normal read and write actions.
HOWEVER, beware of how C code gets compiled! If the variables aren’t
declared volatile, the actual read many have been done dozens of
instructions earlier and the variable stored in a register or other temp
field. So the write may hapen immediately before some other code and that
code not see the change, because in reality its read had been done long
before the change.
If multiple processors are writing to the word, AND they are constructing
the value to write ONLY from local state, they can still do normal writes.
But if you need to do a read/modify/write you MUST use some sort of locking
protocol to insure that you don’t get the case of proc A reading the
variable, proc B writing it, and then proc A writing its updated value over
the value written by B. An interlocked operator will lock the bus and cause
appropriate cache and memory transactions to happen to insure that a read
followed by a write can be done atomically with reference to other
processors.
Since you seem to have an interlock of your own on writes, you should be
able to do simple writes with no problem, as long as everyone acquires the
interlock before doing the write.
Loren
----- Original Message -----
From: “Sandor LUKACS”
To: “Windows System Software Devs Interest List”
Sent: Tuesday, January 29, 2008 2:58 AM
Subject: Re: [ntdev] memory access consistency across SMP nodes
> Ananthu Rao wrote:
>> Writing into the DWORD is done using an atomic instruction?
>>
> Not necessarily. I mean, I would like to use normal C code to change those
> values. However, in this case I’m afraid that the answer to my initial
> question is NO (meaning, no consistency is guaranteed instantly - correct
> me if I’m wrong). On the other hand, if I would use Interlocked()
> operations, then the answer might be YES (consistency is guaranteed across
> SMP nodes because of LOCK). However, the point why I would like to avoid
> using Interlocked() ops for write is that they can be costly, and I
> already own a lock (spinlock/pushlock) for the write operation (and, the
> reason for why I can’t get rid completely of the spinlock and use one
> single atomic interlocked() is, that in several scenarios I need to set an
> entire bit field, several bits, to a given value/pattern; for this, I need
> AFAIK two operations at least, an AND - to clear the mask and an OR - to
> set the mask).
>
> Could you clarify if the consistency is assured in the two above cases
> (with Interlocked() and without).
>
> thank you,
>
> –
> Sandor LUKACS
> Analyst Programmer, R&D
> BitDefender
> --------------------------------
> E-mail: xxxxx@bitdefender.com
> Phone : +40 264 443 008
> --------------------------------
> www.bitdefender.com
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer