You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/memory_consistency/arm_mem_model.md
+47-14Lines changed: 47 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,47 +6,80 @@ layout: "learningpathall"
6
6
7
7
## CPU Memory Model vs Language/Runtime Memory Models
8
8
9
-
It's important to understand that the majority of developers will not need to concern themselves with the memory consistency model of the CPU their code will execute on. This is because programming languages and runtime engines abstract away the CPUs memory model by presenting the programmer with a language/runtime memory model. This abstraction is achieved by providing developers with a set of language/runtime specific memory ordering rules, synchronization constructs, and supporting libraries. So long as the developer uses these correctly, language compilers and runtime engines will make sure the code executes correctly on any CPU regardless of how strong or weakly ordered it is.
9
+
Majority of developers will not need to be deeply familiar with the memory consistency model of the CPU their code will execute on. This is because programming languages and runtime engines abstract away the CPUs memory model by presenting the programmer with a language/runtime memory model. This abstraction is achieved by providing developers with a set of language/runtime specific memory ordering rules, synchronization constructs, and supporting libraries. As long as the developer uses these correctly, language compilers and runtime engines will make sure the code executes correctly on any CPU regardless of how strong or weakly ordered it is.
10
10
11
11
That said, developers may want to dig deeper into this topic for various reasons including:
12
12
13
-
- Extract more performance from weakly ordered CPUs (like Arm).
14
-
-Keep in mind that compilers and runtimes will do a good job of maximizing performance. Only in well understood niche cases will there be a potential for performance gain by going beyond what the compiler/runtime would do to higher level code. For most cases, all it takes to get more performance is to use the latest compilers, compiler switches, and runtimes.
13
+
- Extract more performance from weakly ordered CPUs (like Arm CPUs).
14
+
-Compilers and runtimes will do a good job of maximizing performance. Only in well understood niche cases will there be a potential for performance gain by going beyond what the compiler/runtime would do to higher level code. For most cases, all it takes to get more performance is to use the latest compilers, compiler switches, and runtimes.
15
15
- Develop confidence in the correctness of synchronization constructs.
16
16
- Develop an understanding of how compilers and runtimes select different machine instructions while still honoring the memory ordering rules of the language/runtime and CPU.
17
-
- General learning.
18
17
19
-
## What We Will Do
20
-
21
-
In this Learning Path, we will use publicly available tools to explore thread synchronization on Arm CPUs. This will provide the reader with enough working knowledge of the tools to be able to explore on their own. At the end of this Learning Path, we will provide more information on where readers can find a more formal (and complex) treatment of this subject.
18
+
In this Learning Path, you will use publicly available tools to explore thread synchronization on Arm CPUs. You will gain enough working knowledge of the tools to be able to explore thread synchronization concepts. At the end of this Learning Path, you will be able access more information to get a deeper understanding of this subject.
22
19
23
20
## The Formal Definition of the Arm Memory Model
24
21
25
-
The formal definition of the Arm memory model is in the [Arm Architecture Reference Manual for A-profile architecture](https://developer.arm.com/documentation/ddi0487/la) (Arm ARM) under the section called `The AArch64 Application Level Memory Model`. The ordering requirements defined in the Arm ARM is a transliteration of the `aarch64.cat` file hosted on the Arm [herd7 simulator tool](https://developer.arm.com/herd7). In fact, this `aarch64.cat` file is the authoritative definition of the Arm memory model. Since it is a formal definition, it is complex.
22
+
The formal definition of the Arm memory model is in the [Arm Architecture Reference Manual for A-profile architecture](https://developer.arm.com/documentation/ddi0487/la) (Arm ARM) under the section called `The AArch64 Application Level Memory Model`. The ordering requirements defined in the Arm ARM is a transliteration of the `aarch64.cat` file hosted on the Arm [herd7 simulator tool](https://developer.arm.com/herd7). In fact, this `aarch64.cat` file is the authoritative definition of the Arm memory model. As it is a formal definition, it is complex.
26
23
27
24
## Herd7 Simulator & Litmus7 Tool
28
25
29
-
The herd7 simulator provides a way to test snippets of Arm assembly against the formal definition of the Arm memory model (the `aarch64.cat` file mentioned above). The litmus7 tool can take the same snippets of assembly that run on herd7 and run them on actual Arm HW. This allows for comparing the formal memory model to the memory model of an actual Arm CPU. These snippets of assembly are called litmus tests.
26
+
The herd7 simulator provides a way to test snippets of Arm assembly against the formal definition of the Arm memory model (the `aarch64.cat` file mentioned above). The litmus7 tool can take the same snippets of assembly that run on herd7 and run them on actual Arm hardware. This allows for comparing the formal memory model to the memory model of an actual Arm CPU. These snippets of assembly are called litmus tests.
30
27
31
28
It's important to understand that it is possible for an implementation of an Arm CPU to be more strongly ordered than the formally defined Arm memory model. This case is not a violation of the memory model because it will still execute code in a way that is compliant with the memory ordering rules.
32
29
33
-
## Installing the Tools
30
+
## Install the Tools
31
+
32
+
Herd7 and Litmus7 are part of the [diy7](http://diy.inria.fr/) tool suite. The diy7 tool suite can be installed by following the [installation instructions](http://diy.inria.fr/sources/index.html). You will install the tools on an Arm Linux system so that both herd7 and litmus7 can be compared side by side on the same system.
33
+
34
+
Start an Arm-based cloud instance. This example uses a `t4g.xlarge` AWS instance running Ubuntu 22.04 LTS, but other instances types are possible.
35
+
36
+
If you are new to cloud-based virtual machines, refer to [Get started with Servers and Cloud Computing](/learning-paths/servers-and-cloud-computing/intro/).
37
+
38
+
First confirm you are using a Arm-based instance with the following command.
39
+
40
+
```bash
41
+
uname -m
42
+
```
43
+
You should see the following output.
44
+
45
+
```output
46
+
aarch64
47
+
```
48
+
49
+
Next, install OCaml Package Manager (opam). You will need `opam` to install the `herdtools7` tool suite:
50
+
```bash
51
+
sudo apt update
52
+
sudo apt install opam -y
53
+
```
54
+
55
+
Setup `opam` to install the tools:
56
+
```bash
57
+
opam init
58
+
opam update
59
+
eval$(opam env)
60
+
```
34
61
35
-
Herd7 and Litmus7 are part of the [diy7](http://diy.inria.fr/) tool suite. The diy7 tool suite can be installed by following the [installation instructions](http://diy.inria.fr/sources/index.html). We suggest installing this on an Arm system so that both herd7 and litmus7 can be compared side by side on the same system.
62
+
Now install the `herdtool7` tool suite which include both `litmus7` and `herd7`:
36
63
64
+
```bash
65
+
opam install herdtools7
66
+
```
37
67
38
-
## Running Herd7 and Litmus7 Example Commands
39
68
40
-
The test file is assumed to be called `test.litmus`and is in the current directory.
69
+
## Herd7 and Litmus7 Example Commands
41
70
42
-
The help menu shows all options.
71
+
You can run `--help` on both the tools to review all the options available.
43
72
```
44
73
herd7 --help
45
74
```
46
75
```
47
76
litmus7 --help
48
77
```
49
78
79
+
The input to both `herd7` and `litmus7` tools are snippets of assembly code, called litmus tests.
80
+
81
+
Shown below are some example of running the tools with a litmus test. In the next section, you will go through an actual litmus test example.
0 commit comments