access-coordinates.rst 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. .. SPDX-License-Identifier: GPL-2.0
  2. .. include:: <isonum.txt>
  3. ==================================
  4. CXL Access Coordinates Computation
  5. ==================================
  6. Latency and Bandwidth Calculation
  7. =================================
  8. A memory region performance coordinates (latency and bandwidth) are typically
  9. provided via ACPI tables :doc:`SRAT <../platform/acpi/srat>` and
  10. :doc:`HMAT <../platform/acpi/hmat>`. However, the platform firmware (BIOS) is
  11. not able to annotate those for CXL devices that are hot-plugged since they do
  12. not exist during platform firmware initialization. The CXL driver can compute
  13. the performance coordinates by retrieving data from several components.
  14. The :doc:`SRAT <../platform/acpi/srat>` provides a Generic Port Affinity
  15. subtable that ties a proximity domain to a device handle, which in this case
  16. would be the CXL hostbridge. Using this association, the performance
  17. coordinates for the Generic Port can be retrieved from the
  18. :doc:`HMAT <../platform/acpi/hmat>` subtable. This piece represents the
  19. performance coordinates between a CPU and a Generic Port (CXL hostbridge).
  20. The :doc:`CDAT <../platform/cdat>` provides the performance coordinates for
  21. the CXL device itself. That is the bandwidth and latency to access that device's
  22. memory region. The DSMAS subtable provides a DSMADHandle that is tied to a
  23. Device Physical Address (DPA) range. The DSLBIS subtable provides the
  24. performance coordinates that's tied to a DSMADhandle and this ties the two
  25. table entries together to provide the performance coordinates for each DPA
  26. region. For example, if a device exports a DRAM region and a PMEM region,
  27. then there would be different performance characteristsics for each of those
  28. regions.
  29. If there's a CXL switch in the topology, then the performance coordinates for the
  30. switch is provided by SSLBIS subtable. This provides the bandwidth and latency
  31. for traversing the switch between the switch upstream port and the switch
  32. downstream port that points to the endpoint device.
  33. Simple topology example::
  34. GP0/HB0/ACPI0016-0
  35. RP0
  36. |
  37. | L0
  38. |
  39. SW 0 / USP0
  40. SW 0 / DSP0
  41. |
  42. | L1
  43. |
  44. EP0
  45. In this example, there is a CXL switch between an endpoint and a root port.
  46. Latency in this example is calculated as such:
  47. L(EP0) - Latency from EP0 CDAT DSMAS+DSLBIS
  48. L(L1) - Link latency between EP0 and SW0DSP0
  49. L(SW0) - Latency for the switch from SW0 CDAT SSLBIS.
  50. L(L0) - Link latency between SW0 and RP0
  51. L(RP0) - Latency from root port to CPU via SRAT and HMAT (Generic Port).
  52. Total read and write latencies are the sum of all these parts.
  53. Bandwidth in this example is calculated as such:
  54. B(EP0) - Bandwidth from EP0 CDAT DSMAS+DSLBIS
  55. B(L1) - Link bandwidth between EP0 and SW0DSP0
  56. B(SW0) - Bandwidth for the switch from SW0 CDAT SSLBIS.
  57. B(L0) - Link bandwidth between SW0 and RP0
  58. B(RP0) - Bandwidth from root port to CPU via SRAT and HMAT (Generic Port).
  59. The total read and write bandwidth is the min() of all these parts.
  60. To calculate the link bandwidth:
  61. LinkOperatingFrequency (GT/s) is the current negotiated link speed.
  62. DataRatePerLink (MB/s) = LinkOperatingFrequency / 8
  63. Bandwidth (MB/s) = PCIeCurrentLinkWidth * DataRatePerLink
  64. Where PCIeCurrentLinkWidth is the number of lanes in the link.
  65. To calculate the link latency:
  66. LinkLatency (picoseconds) = FlitSize / LinkBandwidth (MB/s)
  67. See `CXL Memory Device SW Guide r1.0 <https://www.intel.com/content/www/us/en/content-details/643805/cxl-memory-device-software-guide.html>`_,
  68. section 2.11.3 and 2.11.4 for details.
  69. In the end, the access coordinates for a constructed memory region is calculated from one
  70. or more memory partitions from each of the CXL device(s).
  71. Shared Upstream Link Calculation
  72. ================================
  73. For certain CXL region construction with endpoints behind CXL switches (SW) or
  74. Root Ports (RP), there is the possibility of the total bandwidth for all
  75. the endpoints behind a switch being more than the switch upstream link.
  76. A similar situation can occur within the host, upstream of the root ports.
  77. The CXL driver performs an additional pass after all the targets have
  78. arrived for a region in order to recalculate the bandwidths with possible
  79. upstream link being a limiting factor in mind.
  80. The algorithm assumes the configuration is a symmetric topology as that
  81. maximizes performance. When asymmetric topology is detected, the calculation
  82. is aborted. An asymmetric topology is detected during topology walk where the
  83. number of RPs detected as a grandparent is not equal to the number of devices
  84. iterated in the same iteration loop. The assumption is made that subtle
  85. asymmetry in properties does not happen and all paths to EPs are equal.
  86. There can be multiple switches under an RP. There can be multiple RPs under
  87. a CXL Host Bridge (HB). There can be multiple HBs under a CXL Fixed Memory
  88. Window Structure (CFMWS) in the :doc:`CEDT <../platform/acpi/cedt>`.
  89. An example hierarchy::
  90. CFMWS 0
  91. |
  92. _________|_________
  93. | |
  94. ACPI0017-0 ACPI0017-1
  95. GP0/HB0/ACPI0016-0 GP1/HB1/ACPI0016-1
  96. | | | |
  97. RP0 RP1 RP2 RP3
  98. | | | |
  99. SW 0 SW 1 SW 2 SW 3
  100. | | | | | | | |
  101. EP0 EP1 EP2 EP3 EP4 EP5 EP6 EP7
  102. Computation for the example hierarchy:
  103. Min (GP0 to CPU BW,
  104. Min(SW 0 Upstream Link to RP0 BW,
  105. Min(SW0SSLBIS for SW0DSP0 (EP0), EP0 DSLBIS, EP0 Upstream Link) +
  106. Min(SW0SSLBIS for SW0DSP1 (EP1), EP1 DSLBIS, EP1 Upstream link)) +
  107. Min(SW 1 Upstream Link to RP1 BW,
  108. Min(SW1SSLBIS for SW1DSP0 (EP2), EP2 DSLBIS, EP2 Upstream Link) +
  109. Min(SW1SSLBIS for SW1DSP1 (EP3), EP3 DSLBIS, EP3 Upstream link))) +
  110. Min (GP1 to CPU BW,
  111. Min(SW 2 Upstream Link to RP2 BW,
  112. Min(SW2SSLBIS for SW2DSP0 (EP4), EP4 DSLBIS, EP4 Upstream Link) +
  113. Min(SW2SSLBIS for SW2DSP1 (EP5), EP5 DSLBIS, EP5 Upstream link)) +
  114. Min(SW 3 Upstream Link to RP3 BW,
  115. Min(SW3SSLBIS for SW3DSP0 (EP6), EP6 DSLBIS, EP6 Upstream Link) +
  116. Min(SW3SSLBIS for SW3DSP1 (EP7), EP7 DSLBIS, EP7 Upstream link))))
  117. The calculation starts at cxl_region_shared_upstream_perf_update(). A xarray
  118. is created to collect all the endpoint bandwidths via the
  119. cxl_endpoint_gather_bandwidth() function. The min() of bandwidth from the
  120. endpoint CDAT and the upstream link bandwidth is calculated. If the endpoint
  121. has a CXL switch as a parent, then min() of calculated bandwidth and the
  122. bandwidth from the SSLBIS for the switch downstream port that is associated
  123. with the endpoint is calculated. The final bandwidth is stored in a
  124. 'struct cxl_perf_ctx' in the xarray indexed by a device pointer. If the
  125. endpoint is direct attached to a root port (RP), the device pointer would be an
  126. RP device. If the endpoint is behind a switch, the device pointer would be the
  127. upstream device of the parent switch.
  128. At the next stage, the code walks through one or more switches if they exist
  129. in the topology. For endpoints directly attached to RPs, this step is skipped.
  130. If there is another switch upstream, the code takes the min() of the current
  131. gathered bandwidth and the upstream link bandwidth. If there's a switch
  132. upstream, then the SSLBIS of the upstream switch.
  133. Once the topology walk reaches the RP, whether it's direct attached endpoints
  134. or walking through the switch(es), cxl_rp_gather_bandwidth() is called. At
  135. this point all the bandwidths are aggregated per each host bridge, which is
  136. also the index for the resulting xarray.
  137. The next step is to take the min() of the per host bridge bandwidth and the
  138. bandwidth from the Generic Port (GP). The bandwidths for the GP are retrieved
  139. via ACPI tables (:doc:`SRAT <../platform/acpi/srat>` and
  140. :doc:`HMAT <../platform/acpi/hmat>`). The minimum bandwidth are aggregated
  141. under the same ACPI0017 device to form a new xarray.
  142. Finally, the cxl_region_update_bandwidth() is called and the aggregated
  143. bandwidth from all the members of the last xarray is updated for the
  144. access coordinates residing in the cxl region (cxlr) context.
  145. QTG ID
  146. ======
  147. Each :doc:`CEDT <../platform/acpi/cedt>` has a QTG ID field. This field provides
  148. the ID that associates with a QoS Throttling Group (QTG) for the CFMWS window.
  149. Once the access coordinates are calculated, an ACPI Device Specific Method can
  150. be issued to the ACPI0016 device to retrieve the QTG ID depends on the access
  151. coordinates provided. The QTG ID for the device can be used as guidance to match
  152. to the CFMWS to setup the best Linux root decoder for the device performance.