This guide quickly present the basic procedure to use to compute a WCET (Worst Case Execution time).
Ths QuickStart guide assumes that:
- You have installed OTAWA with procedure presented here.
- OTAWA’s command are on the path:
$ export PATH=$PATH:OTAWA_PATH/bin
In addition, the following package has to be installed with
- otawa-arm (if you want to use ARM binaries)
- otawa-ppc (if you want to use PowerPC binaries)
$ otawa-install.py MODULE
You have also to download one or both of the binaries sets below and to extract them:
These benchmark are the cross-compiled of standard WCET benchmarks from Malärdalen.
The visualization of the program profile requires to install graphviz in your OS.
Computing a WCET
The basic activity of OTAWA is to compute a WCET. As the WCET heavily depends on the machine instruction shape of the program, one has to process the binary of the program, usually in ELF format. As the microprocessor running embedded real-time systems (ARM, PowerPC, RISC-V) are different from the ones running on your laptop (x86 compatible hardware), the program has to be cross-compiled and ELF format is currently a good choice the obtained binaries. The benchmarks provided in the Preparation section has already been compiled by ourselves.
So the command to a WCET is owcet. As there are so many different models of microprocessors implementing instruction sets as ARM, PowerPC, etc, we have to provide to owcet a script providing support to the model. For this quickstart, we will use an abstract model named
trivial that provides a very simple processor counting 5 cycles per instruction.
Let start to compute the WCET of
$ cd ARCH/bs $ owcet -s trivial bs.elf
This command should fail saying that OTAWA cannot compute weight for a loop in the program. Looking above in the message, one can identify the problem : bound for the concerned loop is missing. As computing loop bounds is complex and time-consuming task, it is separated from OTAWA WCET process.
Here, we will first computed loop bound by hand and put it in so-called flow-fact file generated with the command mkff:
$ mkff bs.elf > bs.ff INFO: plugged otawa::trivial (/home/casse/Dev/local/lib/otawa/otawa/trivial.so) WARNING: otawa::FlowFactLoader 1.4.0:no flow fact file for bs.elf WARNING: otawa::ipet::FlowFactLoader 2.0.0:no limit for the loop at binary_search + 0x2c (00008260). WARNING: otawa::ipet::FlowFactLoader 2.0.0: in the context [FUN(00008234)] WARNING: otawa::ipet::FlowFactConstraintBuilder 1.1.0:no flow fact constraint for loop at BB 6 (00008260) ERROR: otawa::Weighter (1.0.0):cannot compute weight for loop at BB 6 (00008260)
This creates a textual file named
bs.ff where you have to replace question marks by the actual loop bound found, for example, from the sources. Notice the mapping between sources and binaries is inserted in this file as comments. In fact, bs.c contains only one loop at line 83 which bound is 5. Finally, bs.ff must look like:
checksum "bs.elf" 0x4359a46d; // Function binary_search (bs.c:77) loop "binary_search" + 0x2c 5 ; // 0x8260 (bs.c:83)
Now we can relaunch the WCET calculation (notice that as the flow file is named
bs.ff, it will automatically be handled by owcet).
$ owcet -s trivial bs.elf INFO: plugged otawa::trivial (/home/casse/Dev/local/lib/otawa/otawa/trivial.so) WCET[main] = 805 cycle
And you get 805 cycles as the WCET. The WCET is usually expressed in cycles as it is the time unit inside the pipeline of the microprocessor. To get the time in seconds, you have divide the WCET by the frequency of the microprocessor.
Viewing the WCET
Having a WCET is very interesting but if it is over the budget time devoted to the program, we may want to optimize the program to reduce its execution time and it may be a good question to first try to optimize the part of the code in which the microprocessor spends most of its time. In brief, we would like to look at a time profile of the program in the WCET case.
To do that, we have first to ask OTAWA to generate statistics about the program:
$ owcet -s trivial bs.elf -W --stats
This creates a directory named
bs-otawa where the program profile and its statistics are stored.
This profile can be viewed with
$ obviews bs.elf
This opens a windows where your display the program as sources or as a binary and to display different statistics obtained by owcet: