blob: 082af412e3d581241c6a5c35bf9ca70929a36c9a [file] [log] [blame]
Joakim Bech8e5c5b32018-10-25 08:18:32 +02001.. _benchmark_framework:
2
3Benchmark framework
4###################
5Due to its nature, OP-TEE is being a solution spanning over several
6architectural layers, where each layer includes its own complex parts. For
7further optimizations of performance, there is a need of tool which will
8provide detailed and precise profiling information for each layer.
9
10It is necessary to receive latency values for:
11
12 * The roundtrip time for going from a client application in normal world,
13 down to a Trusted Application and back again.
14
15 * Detailed information for amount of time taken to go through each layer:
16
17 * libTEEC -> Linux OP-TEE kernel driver
18 * Linux OP-TEE kernel driver -> OP-TEE OS Core
19 * OP-TEE OS Core -> TA entry point (**not supported yet**)
20 * The same way back
21
22Implementation details
23**********************
24
25Design overview
26===============
27Benchmark framework consists of such components:
28
29 1. **Benchmark Client Application (CA)**: a dedicated client application,
30 which is responsible for allocating timestamp circular buffers,
31 registering these buffers in the Benchmark PTA and consuming all
32 timestamp data generated by all OP-TEE layers. Finally, it puts timestamp
33 data into appropriate file with ``.ts`` extension. Additional build
34 details can be found at :ref:`optee_benchmark`.
35
36 2. **Benchmark Pseudo Trusted Application (PTA)**: which owns all per-cpu
37 circular non-secure buffers from a shared memory. Benchmark PTA must be
38 invoked (by a CA) to register the timestamp circular buffers. In turn,
39 the Benchmark PTA invokes the OP-TEE Linux driver (through some RPC mean)
40 to register this circular buffers in the Linux kernel layer.
41
42 3. **libTEEC** and **Linux kernel OP-TEE driver** include functionality for
43 handling timestamp buffer registration requests from the Benchmark
44 PTA.
45
46When the benchmark is enabled, all OP-TEE layers (libTEEC, Linux kernel OP-TEE
47driver, OP-TEE OS core) do fill the registered timestamp circular buffer with
48timestamp data for all invocation requests on condition that the circular buffer
49is allocated/registered.
50
51.. image:: ../images/benchmark/benchmark_design.png
52
53.. To edit benchmark_design diagram use http://draw.io and benchmark_design.xml
54 source file
55
56Timestamp source
57================
58Arm Performance Monitor Units are used as the main source of timestamp values.
59The reason why this technology was chosen is that it is supported on all
60Armv7-A/Armv8-A cores. Besides it can provide precise pre-cpu cycle counter
61values, it is possible to enable EL0 access to all events, so usermode
62applications can directly read cpu counter values from coprocessor registers,
63achieving minimal latency by avoiding additional syscalls to EL1 core.
64
65Besides CPU cycle counter values, timestamp by itself contains also information
66about:
67
68 * Executing CPU core index
69
70 * OP-TEE layer id, where this timestamp was obtained from
71
72 * Program counter value when timestamp was logged, which can be used for
73 getting a symbol name (a filename and line number)
74
75Call sequence diagram
76=====================
77.. image:: ../images/benchmark/benchmark_sequence.png
78
79.. For benchmark call sequence diagram use http://mscgen.js.org and
80 benchmark_sequence.msc source file
81
82Adding custom timestamps
83************************
84
85Currently, timestamping is done only for ``InvokeCommand`` calls, but it's also
86possible to choose custom places in the supported OP-TEE layers. To add
87timestamp storing command to custom c source file:
88
89 1. Include appropriate header:
90
91 * OP-TEE OS Core: ``bench.h``
92
93 * Linux kernel OP-TEE module: ``optee_bench.h``
94
95 * libTEEC: ``teec_benchmark.h``
96
97 2. Invoke ``bm_timestamp()`` (for linux kmod use ``optee_bm_timestamp()``)
98 in the function, where you want to put timestamp from.
99
100.. todo::
101
102 Joakim: Igor's planned tool should go here.
103 Analyzing results
104 =================
105 Will be added soon.
106
107Build and run benchmark
108***********************
109Please see the instructions available at :ref:`optee_benchmark`.
110
111
112Limitations and further steps
113*****************************
114
115 * Implementation of application which will analyze timestamp data and
116 provide statistics for different types of calls providing avg/min/max
117 values (both CPU cycles and time values).
118
119 * Add support for all platforms, where OP-TEE is supported.
120
121 * Adding support of S-EL0 timestamping.
122
123 * Attaching additional payload information to each timestamp, for example,
124 session.
125
126 * Timestamping within interrupt context in the OP-TEE OS Core.