Harrison Mutai | 1a72975 | 2023-03-08 12:01:48 +0000 | [diff] [blame] | 1 | PSCI Performance Measurement |
| 2 | ============================ |
| 3 | |
| 4 | TF-A provides two instrumentation tools for performing analysis of the PSCI |
| 5 | implementation: |
| 6 | |
| 7 | * PSCI STAT |
| 8 | * Runtime Instrumentation |
| 9 | |
| 10 | This page explains how they may be enabled and used to perform all varieties of |
| 11 | analysis. |
| 12 | |
| 13 | Performance Measurement Framework |
| 14 | --------------------------------- |
| 15 | |
| 16 | The Performance Measurement Framework `PMF`_ is a framework that provides |
| 17 | mechanisms for collecting and retrieving timestamps at runtime from the |
| 18 | Performance Measurement Unit (`PMU`_). The PMU is a generalized abstraction for |
| 19 | accessing CPU hardware registers used to measure hardware events. This means, |
| 20 | for instance, that the PMU might be used to place instrumentation points at |
| 21 | logical locations in code for tracing purposes. |
| 22 | |
| 23 | TF-A utilises the PMF as a backend for the two instrumentation services it |
| 24 | provides--PSCI Statistics and Runtime Instrumentation. The PMF is used by |
| 25 | these services to facilitate collection and retrieval of timestamps. For |
| 26 | instance, the PSCI Statistics service registers the PMF service |
| 27 | ``psci_svc`` to track its residency statistics. |
| 28 | |
| 29 | This is reserved a unique ID, name, and space in memory by the PMF. The |
| 30 | framework provides a convenient interface for PSCI Statistics to retrieve |
| 31 | values from ``psci_svc`` at runtime. Alternatively, the service may be |
| 32 | configured such that the PMF dumps those values to the console. A platform may |
| 33 | choose to expose SMCs that allow retrieval of these timestamps from the |
| 34 | service. |
| 35 | |
| 36 | This feature is enabled with the Boolean flag ``ENABLE_PMF``. |
| 37 | |
| 38 | PSCI Statistics |
| 39 | --------------- |
| 40 | |
| 41 | PSCI Statistics is a runtime service that provides residency statistics for |
| 42 | power states used by the platform. The service tracks residency time and |
| 43 | entry count. Residency time is the total time spent in a particular power |
| 44 | state by a PE. The entry count is the number of times the PE has entered |
| 45 | the power state. PSCI Statistics implements the optional functions |
| 46 | ``PSCI_STAT_RESIDENCY`` and ``PSCI_STAT_COUNT`` from the `PSCI`_ |
| 47 | specification. |
| 48 | |
| 49 | |
| 50 | .. c:macro:: PSCI_STAT_RESIDENCY |
| 51 | |
| 52 | :param target_cpu: Contains copy of affinity fields in the MPIDR register |
| 53 | for identifying the target core (See section 5.1.4 of `PSCI`_ |
| 54 | specifications for more details). |
| 55 | :param power_state: identifier for a specific local |
| 56 | state. Generally, this parameter takes the same form as the power_state |
| 57 | parameter described for CPU_SUSPEND in section 5.4.2. |
| 58 | |
| 59 | :returns: Time spent in ``power_state``, in microseconds, by ``target_cpu`` |
| 60 | and the highest level expressed in ``power_state``. |
| 61 | |
| 62 | |
| 63 | .. c:macro:: PSCI_STAT_COUNT |
| 64 | |
| 65 | :param target_cpu: follows the same format as ``PSCI_STAT_RESIDENCY``. |
| 66 | :param power_state: follows the same format as ``PSCI_STAT_RESIDENCY``. |
| 67 | |
| 68 | :returns: Number of times the state expressed in ``power_state`` has been |
| 69 | used by ``target_cpu`` and the highest level expressed in |
| 70 | ``power_state``. |
| 71 | |
| 72 | The implementation provides residency statistics only for low power states, |
| 73 | and does this regardless of the entry mechanism into those states. The |
| 74 | statistics it collects are set to 0 during shutdown or reset. |
| 75 | |
| 76 | PSCI Statistics is enabled with the Boolean build flag |
| 77 | ``ENABLE_PSCI_STAT``. All Arm platforms utilise the PMF unless another |
| 78 | collection backend is provided (``ENABLE_PMF`` is implicitly enabled). |
| 79 | |
| 80 | Runtime Instrumentation |
| 81 | ----------------------- |
| 82 | |
| 83 | The Runtime Instrumentation Service is an instrumentation tool that wraps |
| 84 | around the PMF to provide timestamp data. Although the service is not |
| 85 | restricted to PSCI, it is used primarily in TF-A to quantify the total time |
| 86 | spent in the PSCI implementation. The tool can be used to instrument other |
| 87 | components in TF-A as well. It is enabled with the Boolean flag |
| 88 | ``ENABLE_RUNTIME_INSTRUMENTATION``, and as with PSCI STAT, requires PMF to |
| 89 | be enabled. |
| 90 | |
| 91 | In PSCI, this service provides instrumentation points in the |
| 92 | following code paths: |
| 93 | |
| 94 | * Entry into the PSCI SMC handler |
| 95 | * Exit from the PSCI SMC handler |
| 96 | * Entry to low power state |
| 97 | * Exit from low power state |
| 98 | * Entry into cache maintenance operations in PSCI |
| 99 | * Exit from cache maintenance operations in PSCI |
| 100 | |
| 101 | The service captures the cycle count, which allows for the time spent in the |
| 102 | implementation to be calculated, given the frequency counter. |
| 103 | |
| 104 | PSCI SMC Handler Instrumentation |
| 105 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 106 | |
| 107 | The timestamp during entry into the handler is captured as early as possible |
| 108 | during the runtime exception, prior to entry into the handler itself. All |
| 109 | timestamps are stored in memory for later retrieval. The exit timestamp is |
| 110 | captured after normal return from the PSCI SMC handler, or, if a low power state |
| 111 | was requested, it is captured in the warm boot path. |
| 112 | |
| 113 | *Copyright (c) 2023, Arm Limited. All rights reserved.* |
| 114 | |
| 115 | .. _PMF: ../design/firmware-design.html#performance-measurement-framework |
| 116 | .. _PMU: performance-monitoring-unit.html |
| 117 | .. _PSCI: https://developer.arm.com/documentation/den0022/latest/ |