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