Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 1 | |
Jerome Forissier | 69a11fd | 2022-06-08 17:21:08 +0200 | [diff] [blame] | 2 | .. 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 Bech | 0f1a4f8 | 2023-02-27 13:26:34 +0100 | [diff] [blame] | 29 | .. _benchmark_framework: |
| 30 | |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 31 | Benchmark framework |
| 32 | ################### |
| 33 | Due to its nature, OP-TEE is being a solution spanning over several |
| 34 | architectural layers, where each layer includes its own complex parts. For |
| 35 | further optimizations of performance, there is a need of tool which will |
| 36 | provide detailed and precise profiling information for each layer. |
| 37 | |
| 38 | It 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 | |
| 50 | Implementation details |
| 51 | ********************** |
| 52 | |
| 53 | Design overview |
| 54 | =============== |
| 55 | Benchmark 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 | |
| 74 | When the benchmark is enabled, all OP-TEE layers (libTEEC, Linux kernel OP-TEE |
| 75 | driver, OP-TEE OS core) do fill the registered timestamp circular buffer with |
| 76 | timestamp data for all invocation requests on condition that the circular buffer |
| 77 | is 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 | |
| 84 | Timestamp source |
| 85 | ================ |
| 86 | Arm Performance Monitor Units are used as the main source of timestamp values. |
| 87 | The reason why this technology was chosen is that it is supported on all |
| 88 | Armv7-A/Armv8-A cores. Besides it can provide precise pre-cpu cycle counter |
| 89 | values, it is possible to enable EL0 access to all events, so usermode |
| 90 | applications can directly read cpu counter values from coprocessor registers, |
| 91 | achieving minimal latency by avoiding additional syscalls to EL1 core. |
| 92 | |
| 93 | Besides CPU cycle counter values, timestamp by itself contains also information |
| 94 | about: |
| 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 | |
| 103 | Call 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 | |
| 110 | Adding custom timestamps |
| 111 | ************************ |
| 112 | |
| 113 | Currently, timestamping is done only for ``InvokeCommand`` calls, but it's also |
| 114 | possible to choose custom places in the supported OP-TEE layers. To add |
| 115 | timestamp 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 | |
| 135 | Build and run benchmark |
| 136 | *********************** |
| 137 | Please see the instructions available at :ref:`optee_benchmark`. |
| 138 | |
| 139 | |
| 140 | Limitations 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. |