psci-performance-instr.rst 4.8 KB

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