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