On Mon, Nov 25, 2019 at 11:50 AM Peter Veentjer <pe...@hazelcast.com> wrote:

> I have a question about MESI.
>
> My question isn't about atomic operations; but about an ordinary write to
> the same cacheline done by 2 cores.
>
> If a CPU does a write, the write is placed on the store buffer.
>
> Then the CPU will send a invalidation request to the other cores (RFO)
> for the given cacheline if the cacheline isn't in Exclusive or Modified
> state, and once acknowledgement of the other cores have been received, the
> write is allowed to move from the store buffer into the L1 cache.
>
> My confusion is about the 'atomic' behavior of requesting ownership till
> writing the change on the cacheline in the L1 cache. What prevents another
> core directly after the first core has requested ownership to do the same?
>
Nothing prevents it :) In fact, that's what one will get if they hammer
writes to shared memory across cores - an RFO storm.

> So what prevents another core getting lucky and yanking away the cacheline
> after the acknowledgements to the first core have been received, but before
> the first cores write to the L1 cache  (so the first core ending up with a
> write on a cacheline he owned for a short time, but before you could
> complete his action got yanked from under his feet).
>
Core 1 must ack the RFO from Core 2 - it can't just yank ownership away,
it's a cooperative protocol.

>
> I guess that the first CPU will just ignore any competing bus transactions
> as long as it has not completed the write. There is a ton of information
> about MESI, but I could not found a lot of sensible information about this
> behavior.
>
What likely happens is Core 2's RFO will sit in Core 1's "invalidate" (I've
seen this referred to via other names as well) queue.  Once Core 1 commits
the write from the store buffer to L1D, it can then reply to Core 2's RFO
and send the updated cacheline (data) along the way.  At least on Intel,
RFOs and moving writes from the store buffer to L1D happen after the store
instruction retires, so it's fairly late in the process and I'd imagine the
window of time between RFO ack and moving data to L1D is fairly small.

> --
> You received this message because you are subscribed to the Google Groups
> "mechanical-sympathy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mechanical-sympathy+unsubscr...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/mechanical-sympathy/64a40287-3e44-4b83-9971-dc04814e4ae8%40googlegroups.com
> <https://groups.google.com/d/msgid/mechanical-sympathy/64a40287-3e44-4b83-9971-dc04814e4ae8%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mechanical-sympathy+unsubscr...@googlegroups.com.
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/mechanical-sympathy/CAHjP37E%3D_owm%2BjXLvXdr4q-WU%2Bpvuxn%2BRe%2BnMjJNNQDZR6K%2BkA%40mail.gmail.com.

Reply via email to