Documentation/driver-api/cxl/linux/access-coordinates.rst GitHub 원문 ↗

Linux 6.18.37 · Driver API / CXL / Linux

CXL Access Coordinates Computation

SRAT, HMAT, CDAT와 link 정보를 이용한 CXL latency·bandwidth 및 QTG 계산을 설명합니다.

Source pathDocumentation/driver-api/cxl/linux/access-coordinates.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

access-coordinates.rst:1-178

SRAT, HMAT, CDAT와 link 정보를 이용한 CXL latency·bandwidth 및 QTG 계산을 설명합니다. 영어 원문 전체와 한국어 전문 번역을 함께 제공하며 수식, topology, 함수명, ACPI table, source path와 원문 줄 좌표를 보존합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Latency와 bandwidth 데이터 소스

1-38
.. SPDX-License-Identifier: GPL-2.0
.. include:: <isonum.txt>

메모리 region의 성능 좌표인 latency와 bandwidth는 보통 ACPI `SRAT <../platform/acpi/srat>`와 `HMAT <../platform/acpi/hmat>` table이 제공합니다. 그러나 hot-plug되는 CXL 장치는 firmware 초기화 때 존재하지 않으므로 BIOS가 이 정보를 표시할 수 없습니다. CXL 드라이버는 여러 구성 요소의 데이터를 가져와 성능 좌표를 계산합니다.

SRAT의 Generic Port Affinity subtable은 proximity domain을 장치 handle, 여기서는 CXL host bridge와 연결합니다. 이 연관을 사용해 HMAT subtable에서 Generic Port의 성능 좌표를 가져오며, 이는 CPU와 Generic Port(CXL host bridge) 사이의 좌표입니다.

CDAT는 CXL 장치 자체의 성능 좌표, 즉 장치 memory region에 접근하는 bandwidth와 latency를 제공합니다. DSMAS subtable은 Device Physical Address(DPA) 범위와 연결된 `DSMADHandle`을 제공하고, DSLBIS subtable은 같은 handle에 연결된 성능 좌표를 제공합니다.

이 두 CDAT 항목을 연결하면 각 DPA region의 좌표를 얻습니다. 예를 들어 장치가 DRAM region과 PMEM region을 모두 내보내면 두 region의 성능 특성이 서로 다릅니다.

topology에 CXL switch가 있으면 SSLBIS subtable이 switch의 성능 좌표를 제공합니다. 이는 switch upstream port와 endpoint를 향하는 downstream port 사이를 통과하는 bandwidth와 latency입니다.

단순 topology의 좌표 계산

39-84

다음 예에서는 root port와 endpoint 사이에 CXL switch 하나가 있습니다.

GP0/HB0/ACPI0016-0
       RP0
        |
        | L0
        |
    SW 0 / USP0
    SW 0 / DSP0
        |
        | L1
        |
       EP0
단순 CXL endpoint 접근 경로
CPU / GP0-HB0 (`ACPI0016-0`)RP0Link L0SW0 USP0 → DSP0Link L1EP0

CPU 쪽 Generic Port에서 Root Port와 Switch를 거쳐 Endpoint에 도달하는 latency·bandwidth 경로입니다.

latency는 EP0의 CDAT DSMAS+DSLBIS, EP0과 SW0 DSP0 사이 link L1, SW0 CDAT SSLBIS의 switch latency, SW0과 RP0 사이 link L0, SRAT와 HMAT Generic Port가 제공하는 RP0에서 CPU까지의 latency를 모두 더해 계산합니다. read와 write latency 모두 이 부분의 합입니다.

L(EP0) - Latency from EP0 CDAT DSMAS+DSLBIS
L(L1) - Link latency between EP0 and SW0DSP0
L(SW0) - Latency for the switch from SW0 CDAT SSLBIS.
L(L0) - Link latency between SW0 and RP0
L(RP0) - Latency from root port to CPU via SRAT and HMAT (Generic Port).
Total read and write latencies are the sum of all these parts.

Bandwidth in this example is calculated as such:
B(EP0) - Bandwidth from EP0 CDAT DSMAS+DSLBIS
B(L1) - Link bandwidth between EP0 and SW0DSP0
B(SW0) - Bandwidth for the switch from SW0 CDAT SSLBIS.
B(L0) - Link bandwidth between SW0 and RP0
B(RP0) - Bandwidth from root port to CPU via SRAT and HMAT (Generic Port).
The total read and write bandwidth is the min() of all these parts.

bandwidth는 같은 다섯 구간의 값 가운데 최솟값 `min()`으로 정합니다. endpoint, 각 link, switch와 Generic Port 중 가장 좁은 구간이 전체 read·write bandwidth를 제한하기 때문입니다.

link bandwidth는 현재 협상된 link 속도인 `LinkOperatingFrequency(GT/s)`를 8로 나눈 `DataRatePerLink(MB/s)`에 lane 수인 `PCIeCurrentLinkWidth`를 곱해 계산합니다. link latency는 `FlitSize / LinkBandwidth(MB/s)`로 계산하며 단위는 picosecond입니다.

To calculate the link bandwidth:
LinkOperatingFrequency (GT/s) is the current negotiated link speed.
DataRatePerLink (MB/s) = LinkOperatingFrequency / 8
Bandwidth (MB/s) = PCIeCurrentLinkWidth * DataRatePerLink
Where PCIeCurrentLinkWidth is the number of lanes in the link.

To calculate the link latency:
LinkLatency (picoseconds) = FlitSize / LinkBandwidth (MB/s)

자세한 내용은 CXL Memory Device Software Guide r1.0의 2.11.3과 2.11.4를 참고하십시오. 최종적으로 구성된 memory region의 access coordinates는 각 CXL 장치에 있는 하나 이상의 memory partition으로부터 계산됩니다.

공유 upstream link의 제한

85-104

CXL switch나 Root Port 뒤에 endpoint가 있는 일부 region 구성에서는 한 switch 뒤의 모든 endpoint bandwidth 합이 switch upstream link보다 클 수 있습니다. host 내부에서 Root Port보다 upstream인 구간에서도 비슷한 상황이 생길 수 있습니다.

CXL 드라이버는 region의 target이 모두 도착한 뒤 추가 pass를 수행해 upstream link가 제한 요소일 수 있음을 반영하여 bandwidth를 다시 계산합니다.

알고리즘은 성능을 최대화하는 대칭 topology를 가정합니다. 비대칭 topology를 발견하면 계산을 중단합니다. topology 순회 중 grandparent로 발견한 RP 수가 같은 반복에서 순회한 장치 수와 다르면 비대칭으로 판단합니다. 속성의 미세한 비대칭은 없고 모든 endpoint 경로가 같다고 가정합니다.

한 RP 아래에 switch가 여러 개 있을 수 있고, CXL Host Bridge(HB) 아래에 RP가 여러 개 있을 수 있으며, CEDT의 CXL Fixed Memory Window Structure(CFMWS) 아래에도 HB가 여러 개 있을 수 있습니다.

다중 CFMWS 계층의 계산식

105-137

다음 예는 CFMWS 하나 아래 두 Host Bridge와 여덟 Endpoint가 있는 계층입니다.

               CFMWS 0
                 |
        _________|_________
       |                   |
   ACPI0017-0          ACPI0017-1
GP0/HB0/ACPI0016-0   GP1/HB1/ACPI0016-1
   |          |        |           |
  RP0        RP1      RP2         RP3
   |          |        |           |
 SW 0       SW 1     SW 2        SW 3
 |   |      |   |    |   |       |   |
EP0 EP1    EP2 EP3  EP4  EP5    EP6 EP7
공유 upstream CXL 계층
CFMWS 0HB0 / GP0RP0SW0EP0 + EP1
CFMWS 0HB0 / GP0RP1SW1EP2 + EP3
CFMWS 0HB1 / GP1RP2SW2EP4 + EP5
CFMWS 0HB1 / GP1RP3SW3EP6 + EP7

CFMWS 0에서 두 Host Bridge, 네 Root Port와 Switch를 거쳐 여덟 Endpoint로 분기되는 대칭 topology입니다.

각 endpoint 경로에서는 switch downstream SSLBIS, endpoint DSLBIS와 endpoint upstream link의 최솟값을 구합니다. 같은 switch에 속한 endpoint 값을 합한 뒤 switch upstream link bandwidth와 다시 최솟값을 취합니다.

같은 Host Bridge 아래 RP별 결과를 합하고 Generic Port에서 CPU까지의 bandwidth와 최솟값을 취합니다. 마지막으로 각 Host Bridge 결과를 합해 전체 region bandwidth를 계산합니다.

Min (GP0 to CPU BW,
     Min(SW 0 Upstream Link to RP0 BW,
         Min(SW0SSLBIS for SW0DSP0 (EP0), EP0 DSLBIS, EP0 Upstream Link) +
         Min(SW0SSLBIS for SW0DSP1 (EP1), EP1 DSLBIS, EP1 Upstream link)) +
     Min(SW 1 Upstream Link to RP1 BW,
         Min(SW1SSLBIS for SW1DSP0 (EP2), EP2 DSLBIS, EP2 Upstream Link) +
         Min(SW1SSLBIS for SW1DSP1 (EP3), EP3 DSLBIS, EP3 Upstream link))) +
Min (GP1 to CPU BW,
     Min(SW 2 Upstream Link to RP2 BW,
         Min(SW2SSLBIS for SW2DSP0 (EP4), EP4 DSLBIS, EP4 Upstream Link) +
         Min(SW2SSLBIS for SW2DSP1 (EP5), EP5 DSLBIS, EP5 Upstream link)) +
     Min(SW 3 Upstream Link to RP3 BW,
         Min(SW3SSLBIS for SW3DSP0 (EP6), EP6 DSLBIS, EP6 Upstream Link) +
         Min(SW3SSLBIS for SW3DSP1 (EP7), EP7 DSLBIS, EP7 Upstream link))))

Linux bandwidth 집계 구현

138-170

계산은 `cxl_region_shared_upstream_perf_update()`에서 시작합니다. `xarray`를 만들고 `cxl_endpoint_gather_bandwidth()`로 모든 endpoint bandwidth를 수집합니다. endpoint CDAT bandwidth와 upstream link bandwidth의 `min()`을 계산합니다.

endpoint의 parent가 CXL switch라면 앞의 계산값과 그 endpoint에 연결된 switch downstream port의 SSLBIS bandwidth 사이에서 다시 `min()`을 구합니다. 최종 bandwidth는 장치 pointer로 index한 xarray의 `struct cxl_perf_ctx`에 저장합니다.

endpoint가 Root Port에 직접 연결됐다면 장치 pointer는 RP 장치입니다. switch 뒤에 있다면 parent switch의 upstream 장치가 pointer가 됩니다.

다음 단계에서는 topology에 존재하는 switch를 하나 이상 순회합니다. RP에 직접 연결된 endpoint는 이 단계를 건너뜁니다. upstream에 switch가 더 있으면 현재 수집한 bandwidth와 upstream link bandwidth의 최솟값을 취하고, upstream switch가 있다면 그 SSLBIS도 반영합니다.

순회가 RP에 도달하면 직접 연결 여부나 중간 switch 수와 관계없이 `cxl_rp_gather_bandwidth()`를 호출합니다. 이때 bandwidth를 Host Bridge별로 집계하며 Host Bridge가 결과 xarray의 index가 됩니다.

그 다음 Host Bridge별 bandwidth와 Generic Port bandwidth의 최솟값을 구합니다. GP 좌표는 ACPI SRAT와 HMAT에서 가져오고, 같은 `ACPI0017` 장치 아래 값을 집계해 새 xarray를 만듭니다.

마지막으로 `cxl_region_update_bandwidth()`를 호출해 마지막 xarray의 모든 member에서 집계한 bandwidth를 CXL region의 `cxlr` context에 있는 access coordinates에 반영합니다.

QTG ID 선택

171-178

각 CEDT에는 CFMWS window의 QoS Throttling Group(QTG)과 연결되는 ID를 제공하는 QTG ID field가 있습니다.

access coordinates를 계산한 뒤 `ACPI0016` 장치에 ACPI Device Specific Method를 실행하면 제공된 좌표에 따라 QTG ID를 가져올 수 있습니다. 장치의 QTG ID는 CFMWS와 대응시켜 장치 성능에 가장 적합한 Linux Root Decoder를 설정하는 지침으로 사용할 수 있습니다.