Does the security barrier provide cache integrity?

Say I have two threads that control a global variable x. Each thread (or each core, I suppose) will have a cached copy x.

Now say that you Thread Aare following these instructions:

set x to 5
some other instruction

Now, when executed set x to 5, the cached value xwill be set to 5, this will cause the cache coherence protocol to act and update the caches of other kernels with a new value x.

Now my question is: when it xis actually installed in 5the cache Thread A, are the caches of other kernels updated before they are executed some other instruction? Or should a memory barrier be used for this ?:

set x to 5
memory barrier
some other instruction

Note. . Suppose that the instructions were executed in order, also suppose that when executed it is set x to 5 5immediately placed in Thread A` cache (therefore, the instruction was not queued or something that will be executed later).

+4
source share
3 answers

The memory gateways are present in the x86 architecture, but this in general - not only ensures that all previous downloads or repositories 1 are completed before any subsequent download or storage is performed - they also ensure that stores become globally visible .

, , , , .
, , , DMA, , , .
, x86: , .

Intel , .
: , , . .

, .
, Intel , .

x86 , .
, mov DWORD [eax+ebx*2+4], ecx, , eax, ebx ecx 2 , .
, (, ), .
, ( ).

OoO CPU , .

, , , , .
- First In, First .

.
, ( , ), WC, L1D, L2, L3 LLC, , - WB WT.
, - UC WT.


, : .
:

  • .
    , , , .
    WB, , - , . ( , DMA x86 -).
  • WC, .
    WC - - , , , . , , , - .

sfence : , .
, , . ( , , . mfence , ( L1d) , .)

sfence , ?
, .
- , .

MESI (MESIF Intel, MOESI AMD).
MESI.

, L , L .
CPU.

, L "", ( QPI Intel), L .

L S, (, L Exclusive [1]).

sfence .

.
L, , L , .
L S.

, L - , , , L ( , L Invalid, ).


, , sfence et , , .
, , , , , , ++, , .

, Intel: .
, , . , .

, , - .
, .

Memory ordering -- enforces --> Global visibility -- needs -> Cache coherency
'.______________________________'_____________.'                            '
                 Architectural  '                                           '
                                 '._______________________________________.'
                                             micro-architectural

:

  • .
  • . Intel mov [eax+ebx*2+4], ecx : store-address store-data. uop , eax ebx , , . , ( ) .

    ecx , uop store-data .

    , , , , , ( ) / . ( , x86, ​​ , , . - .)

+4

, x 5, x 5, , x.

x86 - (, MESI, MOESI), ( , , , , , ).

, ( x 5), CPU ( MTRR TLB), , , , , ( ).

, ( ) , CPU, , .

"" ( / ). CPU , / , , / .

, .

3 (sfence, lfence mfence), , , , , . , / / . , ( " ", , ..). ( ) / / .

+5

, , "". -op.

, . , , .

Intel, , (, ), . SPARC , StoreLoad, no-op.

x86 LOCKed, . , CPU , , (.. ) , , LOCK. , , .

What is a memory barrier or a barrier + op, this ensures that the operation will be visible to other agents in a relative order, which obeys all the restrictions of the barrier. This, of course, usually does not imply pushing the result to other processors as a matching operation, which you doubt.

+1
source

Source: https://habr.com/ru/post/1672088/


All Articles