Does `isync` prevent Store-Load reordering on CPU PowerPC?

后端 未结 1 1370
礼貌的吻别
礼貌的吻别 2021-01-02 23:26

As known, PowerPC has weak memory model, that permit any speculative reordering: Store-Store, Load-Store, Store-Load, Load-Load.

There are at least 3 Fences:

<
相关标签:
1条回答
  • 2021-01-02 23:51

    As you have guessed and most of your excellent sources imply, there are two properties of a memory access involved here:

    Visibility

    If other processors can obverse the memory access.
    The use of processor-specific buffers or caches can make a store complete on a processor yet make it not visible to other ones.

    Ordering

    When the memory access is executed with respected to other instructions on the same processor.


    Ordering is an intra-processor aspect of a memory access, it controls the out-of-order capability of a processor.
    Ordering cannot be done with respect to other processors' instructions.

    Visibility is an inter-processor aspect, it ensures that the side effects of a memory access are visible to other processors (or in general, to other agents).
    A store primary side effect is changing a memory location.

    By controlling both aspects it is possible to enforce a inter-process Ordering, that is, the order in which other processors see a sequence of memory accesses.
    It goes untold that the word "ordering" usually refers to this second meaning unless used in a context where no other agents are present.
    It is admittedly a confusing terminology.


    Beware that I'm not confident with the PowerPC architecture, I'm just applying the theory with the help of a few official documents found online and the quotes you provided.

    isync, just like sc and rfi are Context-Synchronizing instructions, their main purpose is to guarantee that subsequent instructions execute in the context established by the previous ones. For example, executing a system call changes the context and we don't want the privileged code to execute in an unprivileged context and vice versa.

    These instructions wait for all previously dispatched instructions to be completed but not to be visible

    All previously issued instructions have completed, at least to a point where they can no longer cause an exception.
    However, memory accesses that these instructions cause need not have completed with respect to other processors and mechanisms.

    So, depending on what you mean by reordering, isync does or does not prevent Load-Load, Load-Store etc. reordering.
    It does prevent any of such reordering from the perspective of the processor it is executed on (intra-process reordering) - all previous loads and stores are completed before isync complete but they are not necessarily visible.
    It does not prevent reordering from the perspective of other processors (inter-process reordering) as it doesn't ensure the visibility of previous instructions.


    But does isync prevent reordering stwcx.,bne <--> any following instructions?

    Only intra-process reordering.

    I.e. can Store-stwcx. begins earlier than the following Load-lwz, and finishes performed later than Load-lwz?

    Not from the point-of-view of the processor executing them, stwcx. is completed by the time lwz begins but, using Intel terminology, it is completed locally - other processors may not see it completed by the time lwz begins.

    I.e. can Store-stwcx. preforms Store to the Store-Buffer earlier than the following Load-lwz begun, but the actual Store to the cache that visible for all CPU-cores occurs later than the Load-lwz finished?

    Yes, exactly.

    0 讨论(0)
提交回复
热议问题