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