Skip to content

Commit 413c7f2

Browse files
authored
Merge pull request #255 from EhsanKhodadad/patmos
Patmos docs updated to reflect lf-lang/lingua-franca#2383
2 parents 4c47da1 + 7c39f5f commit 413c7f2

File tree

1 file changed

+46
-83
lines changed

1 file changed

+46
-83
lines changed

docs/embedded/patmos.mdx

+46-83
Original file line numberDiff line numberDiff line change
@@ -7,101 +7,64 @@ Lingua Franca's C-runtime supports [Patmos](https://github.com/t-crest/patmos),
77
a bare-metal execution platform that is optimized for time-predictable execution.
88
The time-predictability aspect of Patmos makes it easier to obtain a worst-case
99
execution time (WCET) for reactions.
10+
## Prerequisites
11+
- Linux or macOS development system. (use WSL on Windows)
12+
- DE2-115 Development Kit, which is equipped with Altera Cyclone IV FPGA (optional)
13+
### Getting Started
14+
To know how to install the toolchain for building Patmos, read the Patmos project's readme at https://github.com/t-crest/patmos or study the sixth chapter of its handbook available here: [Patmos Reference Handbook](http://patmos.compute.dtu.dk/patmos_handbook.pdf)
15+
### Compiling and Running Lingua Franca codes
16+
Patmos can run in an FPGA, but there are also two simulators available:
17+
18+
1. `pasim`: a software ISA simulator that is written in C++.
19+
2. `patemu`: a cycle-accurate hardware emulator generated from the hardware description.
20+
21+
Consider the following simple LF program inside the HelloPatmos.lf file located in `test/C/src/patmos/HelloPatmos.lf`:
22+
```lf-c
23+
target C {
24+
platform: "Patmos",
25+
single-threaded: true,
26+
build-type: Debug,
27+
}
1028
11-
### Compiling and Running Reactors
12-
Patmos can run in an FPGA, but there are also two
13-
simulators available:
14-
15-
1. `pasim` a software ISA simulator that is written in C++.
16-
2. `patemu` a cycle-accurate hardware emulator generated from the hardware description.
17-
18-
To execute reactions on Patmos, the [Patmos toolchain](https://github.com/t-crest/patmos) needs
19-
to be installed. The web page contains a quick start, detailed information including how to
20-
perform WCET analysis is available in the
21-
[Patmos Reference Handbook](http://patmos.compute.dtu.dk/patmos_handbook.pdf).
22-
23-
To execute the "hello world" reactor on Patmos use the LF compiler to generate the C code.
24-
Compile the reactor with the Patmos compiler (in `src-gen`):
25-
26-
patmos-clang Minimal.c -o Minimal.elf
29+
main reactor {
30+
reaction(startup) {=
31+
printf("Hello World!\n");
32+
=}
33+
}
34+
2735
28-
The reactor can be executed on the SW simulator with:
36+
```
37+
You can generate C code using `lfc HelloPatmos.lf` command in the above folder:
2938

30-
pasim Minimal.elf
39+
```
40+
cd test/C/src/patmos/
41+
lfc HelloPatmos.lf
42+
```
3143

32-
As Patmos is a bare metal runtime that has no notion of calendar time, its start time
33-
is considered the epoch and the following output will be observed:
44+
If there is no error after making, an executable file must be generator inside `src-gen/patmos/HelloPatmos` folder. Then, the reactor can be executed on the SW simulator with the following command:
3445

3546
```
36-
Start execution at time Thu Jan 1 00:00:00 1970
37-
plus 640000 nanoseconds.
38-
Hello World.
39-
Elapsed logical time (in nsec): 0
40-
Elapsed physical time (in nsec): 3970000
47+
cd ../../src-gen/patmos/HelloPatmos/build
48+
pasim HelloPatmos
49+
```
50+
After executing the above command, the following lines must be printed.
51+
```
52+
Hello World!
53+
---- Elapsed logical time (in nsec): 0
54+
---- Elapsed physical time (in nsec): 770,000
4155
```
4256

4357
The reactor can also be executed on the hardware emulator of Patmos:
4458

45-
patemu Minimal.elf
46-
47-
This execution is considerably slower than the SW simulator, as the concrete hardware
48-
of Patmos is simulated cycle-accurate.
49-
50-
### Worst-Case Execution Time Analysis
51-
52-
Following example is a code fragment from
53-
[Wcet.lf](https://github.com/lf-lang/lingua-franca/blob/master/xtext/org.icyphy.linguafranca/src/test/C/src/Wcet.lf).
54-
55-
```lf-c
56-
reactor Work {
57-
input in1: int;
58-
input in2: int;
59-
output out:int;
60-
reaction(in1, in2) -> out {=
61-
int ret;
62-
if (in1 > 10) {
63-
ret = in2 * in1;
64-
} else {
65-
ret = in2 + in1;
66-
}
67-
lf_set(out, ret);
68-
=}
69-
}
59+
```
60+
patemu HelloPatmos
7061
```
7162

72-
We want to perform WCET analysis of the single reaction of the Work reactor.
73-
This reaction, depending on the input data, will either perform a multiplication,
74-
which is more expensive in Patmos, or an addition. The WCET analysis shall consider
75-
the multiplication path as the worst-case path. To generate the information for
76-
WCET analysis by the compiler we have to compile the application as follows:
77-
78-
patmos-clang -O2 -mserialize=wcet.pml Wcet.c
79-
80-
We investigate the C source code `Wcet.c` and find that the reaction we
81-
are interested is named `reaction_function1`. Therefore, we invoke WCET analysis
82-
as follows:
83-
84-
platin wcet -i wcet.pml -b a.out -e reaction_function1 --report
85-
86-
This results in following report:
63+
This execution is considerably slower than the SW simulator, as the concrete hardware
64+
of Patmos is simulated cycle-accurate. Here is a sample of its output:
8765

8866
```
89-
...
90-
[platin] INFO: Finished run WCET analysis (platin) in 62 ms
91-
[platin] INFO: best WCET bound: 242 cycles
92-
---
93-
- analysis-entry: reaction_function1
94-
source: platin
95-
cycles: 242
96-
...
67+
Hello World!
68+
---- Elapsed logical time (in nsec): 0
69+
---- Elapsed physical time (in nsec): 3,459,000
9770
```
98-
99-
The analysis gives the WCET of 242 clock cycles for the reaction,
100-
which includes clock cycles for data cache misses.
101-
Further details on the WCET analysis
102-
tool `platin` and e.g., how to annotate loop bounds can be found in the
103-
[Patmos Reference Handbook](http://patmos.compute.dtu.dk/patmos_handbook.pdf).
104-
105-
Note, that the WCET analysis of a reaction does only include the code of the
106-
reaction function, not the cache miss cost of calling the function from
107-
the scheduler or the cache miss cost when returning to the scheduler.

0 commit comments

Comments
 (0)