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