Arm Community
Arm Community
  • Site
  • User
  • Site
  • Search
  • User
  • Groups
    • Arm Research
    • DesignStart
    • Education Hub
    • Innovation
    • Open Source Software and Platforms
  • Forums
    • AI and ML forum
    • Architectures and Processors forum
    • Arm Development Platforms forum
    • Arm Development Studio forum
    • Arm Virtual Hardware forum
    • Automotive forum
    • Compilers and Libraries forum
    • Graphics, Gaming, and VR forum
    • High Performance Computing (HPC) forum
    • Infrastructure Solutions forum
    • Internet of Things (IoT) forum
    • Keil forum
    • Morello Forum
    • Operating Systems forum
    • SoC Design and Simulation forum
    • 中文社区论区
  • Blogs
    • AI and ML blog
    • Announcements
    • Architectures and Processors blog
    • Automotive blog
    • Graphics, Gaming, and VR blog
    • High Performance Computing (HPC) blog
    • Infrastructure Solutions blog
    • Innovation blog
    • Internet of Things (IoT) blog
    • Mobile blog
    • Operating Systems blog
    • Research Articles
    • SoC Design and Simulation blog
    • Smart Homes
    • Tools, Software and IDEs blog
    • Works on Arm blog
    • 中文社区博客
  • Support
    • Open a support case
    • Documentation
    • Downloads
    • Training
    • Arm Approved program
    • Arm Design Reviews
  • Community Help
  • More
  • Cancel
Arm Community blogs
Arm Community blogs
Architectures and Processors blog A working example of how to use the herd7 Memory Model Tool
  • Blogs
  • Mentions
  • Sub-Groups
  • Tags
  • Jump...
  • Cancel
More blogs in Arm Community blogs
  • AI and ML blog

  • Announcements

  • Architectures and Processors blog

  • Automotive blog

  • Embedded blog

  • Graphics, Gaming, and VR blog

  • High Performance Computing (HPC) blog

  • Infrastructure Solutions blog

  • Internet of Things (IoT) blog

  • Operating Systems blog

  • SoC Design and Simulation blog

  • Tools, Software and IDEs blog

Tell us what you think
Tags
  • Memory Model Tool
  • Processor Architecture
  • Memory Architecture
Actions
  • RSS
  • More
  • Cancel
Related blog posts
Related forum threads

A working example of how to use the herd7 Memory Model Tool

Jade Alglave
Jade Alglave
February 18, 2020

This blog is a working example of how to use the Memory Model Tool. It provides an opportunity to experiment with the model and develop an intuitive understanding of how it works. The information is useful to software developers, compiler writers, and verification engineers. This is the first installment in a series of blogs about the Memory Model Tool. You can access the tool through the Arm Developer website and at the bottom of this blog. 

1. First steps

Here we’re going to learn about the essential concepts to use the tool.

1.1. Litmus tests

Litmus tests are small snippets of assembly or pseudo-assembly code that allow us to examine the behavior of a chip (see http://diy.inria.fr/doc/litmus.html), or a model (see http://diy.inria.fr/doc/herd.html).

The following is our first litmus test. In this test, called MP (short for message passing), two processors P0 and P1 communicate VIA two shared memory locations x and y, both initialized to 0:

AArch64 MP 
{
0:X1=x; 0:X3=y;
1:X1=y; 1:X3=x;
}
 P0          | P1          ;
 MOV W0,#1   | LDR W0,[X1] ;
 STR W0,[X1] | LDR W2,[X3] ;
 MOV W2,#1   |             ;
 STR W2,[X3] |             ;
exists (1:X0=1 /\ 1:X2=0)

On the left, the thread P0 writes 1 to memory location x, and 1 to memory location y. On the right, the thread P1 reads from y and places the result into register W0 and reads from x and places the result into register W2. The registers W0 and W2 are private to P1.

Essentially, P0 writes a message in x, then sets up a flag in y, so that when P1 sees the flag (via its read from y), it can read the message in x.

At the bottom of the test, we ask “is there an execution of this test such that register W0 contains the value 1 and register W2 contains the value 0?”.

What do you think? Do you think such an execution is possible?

1.2. The herd7 tool

Now, let us try it out. The herd7 tool lets us simulate a model, and run litmus tests against that model, to determine which executions are allowed by this model. So let us go to https://developer.arm.com/architectures/cpu-architecture/a-profile/memory-model-tool.

At the bottom of that page, you will find a button which lets you access the memory model tool - the herd7 tool.

In the “litmus test” box, find the file mp.litmus in the drop box. Let us click on the play button.

1.2.1. Histograms

In the “histogram” box, we see the following result:

Test MP Allowed
States 4
1:X1=0; 1:X2=0;
1:X1=0; 1:X2=1;
1:X1=1; 1:X2=0;
1:X1=1; 1:X2=1;
Ok

Note that we see the result 1:X0=1; 1:X2=0; which we asked about in our test. This result is reachable by our test, and therefore the tool says Ok; otherwise it would say No.

1.2.2. Executions

In the “executions” box, we see that this test can have four different executions. Note that you can download the drawings if you wish (there's a button at the bottom-right corner).

Memory model - executions

(Figure 1)

In all of them we see four events: writes to x or y, of the shape Wx=1, which means that value 1 was written to the memory location x, and reads from x or y, of the shape Ry=0, meaning that memory location y was read, and the value read was 0. We also see three types of relations over these events: po arrows, rf arrows, and fr arrows.

Program order

The po arrows represent the program order. The program order intuitively corresponds to the order in which the events occur on a thread. For example, in our test, on P0, the write of x appears in program order before the write of y. Therefore, the two corresponding events in Fig. 1 are related by po. Similarly, the read of y on P1 appears in our test in program order before the read of x; therefore, the two corresponding events in Fig. 1 are related by po.

Note also that po is transitive. In Fig. 1, suppose there was an extra event e occurring on P1 with a po arrow from d to e. In this case, there would also be a po arrow from c to e. That is, e is after c in the program order.

Read-from

The rf (read-from) arrows depict who reads from where; more precisely, for each read of a certain location, it finds a unique write of the same location and value.

Coherence order

In most models I know of, there is a notion of a coherence order. Intuitively it is a history of all writes to a given memory location x, that represents the order in which writes to x hit x. If you are sitting in memory location x, looking at writes falling onto you, and recording their values as they come by, you would get the coherence order. More precisely, the coherence order co is a total order overwrites to a given memory location.

From-read

Using the read-from and coherence relations, we can build a relation called from-read:

Memory model - from read

(Figure 2)

Intuitively, a from-read arrow starts from a read of a given location x, for example the read r just above, and points to all the writes that overwrite the value this read has taken. In the drawing above, the read r takes its value from the write w0, as shown by the rf arrow between them. The write w0 is then overwritten by the write w1, as shown by the co arrow between them. Therefore, there is an fr arrow between r and w1, as w1 overwrites the write w0 from which r reads. The write w1 is then overwritten by the write w2, as shown by the co arrow between them. There is an fr arrow between r and w2 too.

1.2.3. Reading the output of the tool

Let’s go through each state and execution one by one.

State 1:X0=1; 1:X2=1;

This is the state where P1 does see that the flag y has been set to 1 and sees that the data x has been updated to 1. In other words, the read of y on P1 reads 1 from the update of y by P0, and the read of x on P1 reads 1 from the update of x by P0. We represent this as follows:

Memory model - MP4

(Figure 3)

  • a read-from (rf) arrow between the write of x on P0 and the read of x on P1
  • a read-from (rf) arrow between the write of y on P0 and the read of y on P1.

State 1:X0=0; 1:X2=1;

This is the state where P1 does not see that the flag y has been set to 1, but sees that the data x has been updated to 1. In other words, the read of y on P1 reads 0 from the initial state, and the read of x on P1 reads 1 from the update of x by P0. We represent this as follows:

Memory model - MP2

(Figure 4)

  • A read-from (rf) arrow between the write of x on P0 and the read of x on P1
  • A from-read (fr) arrow between the read of y on P1 and the write of x on P0; the reason behind this fr arrow is as follows:
    • The read of y on P1 reads from the initial state
    • The initial state for y is a notional write of y which precedes the write of y on P0 in the coherence order
    • Therefore, the value read by the read of y on P1 has been overwritten by the update of y on P0, hence the read of y on P1 is in from-read before
      the write of y on P0.

State 1:X0=0; 1:X2=0;

This is the state where P1's reads do not see the updates by P0, and both read from the initial state. We represent this as follows:

Memory model - MP1

(Figure 5)

  • A from-read (fr) arrow between the read of x on P1 and the write of x on P0
  • A from-read (fr) arrow between the read of y on P1 and the write of y on P0.

The reason behind each fr arrow is as follows:

  • The read on P1 reads from the initial state
  • The initial state is a notional write which precedes the update of the same variable on P0 in the coherence order
  • Therefore, the value read by the read on P1 has been overwritten by the update on P0, hence the read on P1 is in from-read before the write on P0.

State 1:X0=1; 1:X2=0;

This is the state where P1 sees that the flag y has been set to 1 and does not see that the data x has been updated. In other words, the read of y on P1 reads 1 from the update of y on P0, and the read of x on P1 reads 0 from the initial state. We represent this as follows:

Memory model - MP3

(Figure 6)

  • A read-from (rf) arrow between the write of y on P0 and the read of y on P1
  • A from-read (fr) arrow between the read of x on P1 and the write of x on P0

The reason behind this fr arrow is as follows:

  • The read of x on P1 reads from the initial state
  • The initial state for x is a notional write of x which precedes the update of x on P0 in the coherence order
  • Therefore, the value read by the read of x on P1 has been overwritten by the update of x on P0, hence the read of x on P1 is in from-read before the write of x on P0.

Access the Memory Model Tool via the Arm Developer website:

Memory Model Tool

Anonymous
  • zan
    Offline zan over 1 year ago

    Hi Jade,

    Is there anywhere we can download ARM memory model tool instead of just herdtools? Can we run the litmus tests in batch mode the similar way as to generate them?

    Thank you very much.

    Zan

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • Hernán Ponce de León
    Offline Hernán Ponce de León over 2 years ago

    Looking forward to read the whole series of blogs about the Memory Model Tool

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
Architectures and Processors blog
  • Arm SystemReady certifications reach 50 including the Morello System Development Platform

    Dong Wei
    Dong Wei
    The Arm SystemReady program has reached a significant milestone with over 50 certifications since its launch only two years ago.
    • May 9, 2022
  • Total Compute solutions for the XR market

    Philippe Bressy
    Philippe Bressy
    This blog introduces the different Arm Total Compute solutions for wearable devices in the XR market, like VR headsets and AR smartglasses.
    • March 28, 2022
  • Selecting the right CPU performance benchmark for the home market

    Ajay Joshi
    Ajay Joshi
    This blog explores the different CPU performance benchmarks for devices in the home market, including DTVs and set-top boxes (STBs).
    • February 16, 2022