요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
================================================
HiSilicon PCIe Performance Monitoring Unit (PMU)
================================================
On Hip09, HiSilicon PCIe Performance Monitoring Unit (PMU) could monitor
bandwidth, latency, bus utilization and buffer occupancy data of PCIe.
Each PCIe Core has a PMU to monitor multi Root Ports of this PCIe Core and
all Endpoints downstream these Root Ports.
HiSilicon PCIe PMU driver
=========================
The PCIe PMU driver registers a perf PMU with the name of its sicl-id and PCIe
Core id.::
/sys/bus/event_source/hisi_pcie<sicl>_core<core>
PMU driver provides description of available events and filter options in sysfs,
see /sys/bus/event_source/devices/hisi_pcie<sicl>_core<core>.
The "format" directory describes all formats of the config (events) and config1
(filter options) fields of the perf_event_attr structure. The "events" directory
describes all documented events shown in perf list.
The "identifier" sysfs file allows users to identify the version of the
PMU hardware device.
The "bus" sysfs file allows users to get the bus number of Root Ports
monitored by PMU. Furthermore users can get the Root Ports range in
[bdf_min, bdf_max] from "bdf_min" and "bdf_max" sysfs attributes
respectively.
Example usage of perf::
$# perf list
hisi_pcie0_core0/rx_mwr_latency/ [kernel PMU event]
hisi_pcie0_core0/rx_mwr_cnt/ [kernel PMU event]
------------------------------------------
$# perf stat -e hisi_pcie0_core0/rx_mwr_latency,port=0xffff/
$# perf stat -e hisi_pcie0_core0/rx_mwr_cnt,port=0xffff/
The related events usually used to calculate the bandwidth, latency or others.
They need to start and end counting at the same time, therefore related events
are best used in the same event group to get the expected value. There are two
ways to know if they are related events:
a) By event name, such as the latency events "xxx_latency, xxx_cnt" or
bandwidth events "xxx_flux, xxx_time".
b) By event type, such as "event=0xXXXX, event=0x1XXXX".
Example usage of perf group::
$# perf stat -e "{hisi_pcie0_core0/rx_mwr_latency,port=0xffff/,hisi_pcie0_core0/rx_mwr_cnt,port=0xffff/}"
The current driver does not support sampling. So "perf record" is unsupported.
Also attach to a task is unsupported for PCIe PMU.
Filter options
--------------
1. Target filter
PMU could only monitor the performance of traffic downstream target Root
Ports or downstream target Endpoint. PCIe PMU driver support "port" and
"bdf" interfaces for users.
Please notice that, one of these two interfaces must be set, and these two
interfaces aren't supported at the same time. If they are both set, only
"port" filter is valid.
If "port" filter not being set or is set explicitly to zero (default), the
"bdf" filter will be in effect, because "bdf=0" meaning 0000:000:00.0.
- port
"port" filter can be used in all PCIe PMU events, target Root Port can be
selected by configuring the 16-bits-bitmap "port". Multi ports can be
selected for AP-layer-events, and only one port can be selected for
TL/DL-layer-events.
For example, if target Root Port is 0000:00:00.0 (x8 lanes), bit0 of
bitmap should be set, port=0x1; if target Root Port is 0000:00:04.0 (x4
lanes), bit8 is set, port=0x100; if these two Root Ports are both
monitored, port=0x101.
Example usage of perf::
$# perf stat -e hisi_pcie0_core0/rx_mwr_latency,port=0x1/ sleep 5
- bdf
"bdf" filter can only be used in bandwidth events, target Endpoint is
selected by configuring BDF to "bdf". Counter only counts the bandwidth of
message requested by target Endpoint.
For example, "bdf=0x3900" means BDF of target Endpoint is 0000:39:00.0.
Example usage of perf::
$# perf stat -e hisi_pcie0_core0/rx_mrd_flux,bdf=0x3900/ sleep 5
2. Trigger filter
Event statistics start when the first time TLP length is greater/smaller
than trigger condition. You can set the trigger condition by writing
"trig_len", and set the trigger mode by writing "trig_mode". This filter can
only be used in bandwidth events.
For example, "trig_len=4" means trigger condition is 2^4 DW, "trig_mode=0"
means statistics start when TLP length > trigger condition, "trig_mode=1"
means start when TLP length < condition.
Example usage of perf::
$# perf stat -e hisi_pcie0_core0/rx_mrd_flux,port=0xffff,trig_len=0x4,trig_mode=1/ sleep 5
3. Threshold filter
Counter counts when TLP length within the specified range. You can set the
threshold by writing "thr_len", and set the threshold mode by writing
"thr_mode". This filter can only be used in bandwidth events.
For example, "thr_len=4" means threshold is 2^4 DW, "thr_mode=0" means
counter counts when TLP length >= threshold, and "thr_mode=1" means counts
when TLP length < threshold.
Example usage of perf::
$# perf stat -e hisi_pcie0_core0/rx_mrd_flux,port=0xffff,thr_len=0x4,thr_mode=1/ sleep 5
4. TLP Length filter
When counting bandwidth, the data can be composed of certain parts of TLP
packets. You can specify it through "len_mode":
- 2'b00: Reserved (Do not use this since the behaviour is undefined)
- 2'b01: Bandwidth of TLP payloads
- 2'b10: Bandwidth of TLP headers
- 2'b11: Bandwidth of both TLP payloads and headers
For example, "len_mode=2" means only counting the bandwidth of TLP headers
and "len_mode=3" means the final bandwidth data is composed of both TLP
headers and payloads. Default value if not specified is 2'b11.
Example usage of perf::
$# perf stat -e hisi_pcie0_core0/rx_mrd_flux,port=0xffff,len_mode=0x1/ sleep 5
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Hip09 PCIe Core PMU
1-10`HiSilicon PCIe Performance Monitoring Unit (PMU)`은 Hip09에서 PCIe의 bandwidth, latency, bus utilization, buffer occupancy 데이터를 감시할 수 있습니다.
각 PCIe Core에는 PMU 하나가 있으며, 이 PMU는 해당 PCIe Core의 여러 Root Port와 그 Root Port 아래에 연결된 모든 Endpoint를 감시합니다.
PMU 등록과 sysfs 속성
11-33PCIe PMU driver는 `sicl-id`와 PCIe Core ID를 조합한 이름으로 perf PMU를 등록합니다.
/sys/bus/event_source/hisi_pcie<sicl>_core<core>
사용 가능한 event와 filter option은 `/sys/bus/event_source/devices/hisi_pcie<sicl>_core<core>` 아래의 sysfs 속성으로 설명됩니다.
| 항목 | 의미 |
|---|---|
| PMU 경로 | `/sys/bus/event_source/hisi_pcie<sicl>_core<core>` |
| 장치 경로 | `/sys/bus/event_source/devices/hisi_pcie<sicl>_core<core>` |
| `format` | `config` event와 `config1` filter option 형식 |
| `events` | `perf list`에 표시할 문서화된 event |
| `identifier` | PMU hardware device 버전 |
| `bus` | PMU가 감시하는 Root Port의 bus 번호 |
| `bdf_min`, `bdf_max` | 감시 가능한 Root Port의 BDF 범위 |
`format` directory는 `perf_event_attr` 구조체의 `config` event field와 `config1` filter option field 형식을 정의하고, `events` directory는 `perf list`에 보이는 문서화된 event를 제공합니다.
`identifier`로 PMU hardware device 버전을 구분합니다. `bus`에서 감시 대상 Root Port의 bus 번호를 읽고, `bdf_min`과 `bdf_max`에서 각각 `[bdf_min, bdf_max]` 범위의 하한과 상한을 확인할 수 있습니다.
Perf event와 관련 event group
34-59`perf list`로 event alias를 확인한 뒤, `rx_mwr_latency`와 `rx_mwr_cnt`처럼 각 event를 `perf stat`으로 셉니다.
$# perf list
hisi_pcie0_core0/rx_mwr_latency/ [kernel PMU event]
hisi_pcie0_core0/rx_mwr_cnt/ [kernel PMU event]
------------------------------------------
$# perf stat -e hisi_pcie0_core0/rx_mwr_latency,port=0xffff/
$# perf stat -e hisi_pcie0_core0/rx_mwr_cnt,port=0xffff/
Bandwidth, latency 등의 값을 계산하는 관련 event는 같은 시점에 counting을 시작하고 끝내야 하므로 하나의 event group에 넣는 것이 좋습니다.
| 판별 기준 | 관련 event 쌍 |
|---|---|
| 이름 | Latency는 `xxx_latency, xxx_cnt`, bandwidth는 `xxx_flux, xxx_time` |
| 유형 | `event=0xXXXX, event=0x1XXXX` |
$# perf stat -e "{hisi_pcie0_core0/rx_mwr_latency,port=0xffff/,hisi_pcie0_core0/rx_mwr_cnt,port=0xffff/}"
현재 driver는 sampling을 지원하지 않아 `perf record`를 사용할 수 없습니다. PCIe PMU event를 task에 attach하는 것도 지원하지 않습니다.
Root Port와 Endpoint 선택
60-102Target filter는 하위 traffic을 감시할 Root Port 또는 Endpoint를 선택합니다. `port`와 `bdf` 중 하나를 설정해야 하며 둘을 동시에 사용할 수 없습니다. 둘 다 설정하면 `port`만 유효합니다.
`port`를 설정하지 않거나 명시적으로 기본값 0으로 설정하면 `bdf`가 적용됩니다. 이때 `bdf=0` 자체는 `0000:000:00.0`을 뜻합니다.
| Interface | 대상과 범위 |
|---|---|
| `port` | 16-bit bitmap으로 Root Port 선택; 모든 event에서 사용 가능 |
| `bdf` | Endpoint BDF 선택; bandwidth event에서만 사용 가능 |
`port`는 16-bit bitmap입니다. AP-layer event는 여러 port를 선택할 수 있지만 TL/DL-layer event는 port 하나만 선택할 수 있습니다.
`0000:00:00.0`이 x8 lane Root Port이면 bit 0을 켜 `port=0x1`로 지정합니다. `0000:00:04.0`이 x4 lane Root Port이면 bit 8을 켜 `port=0x100`으로 지정하며, 두 Root Port를 함께 감시하면 `port=0x101`입니다.
$# perf stat -e hisi_pcie0_core0/rx_mwr_latency,port=0x1/ sleep 5
`bdf` filter는 bandwidth event에서만 사용할 수 있습니다. 지정한 Endpoint가 요청한 message의 bandwidth만 counter가 세며, `bdf=0x3900`은 target Endpoint `0000:39:00.0`을 뜻합니다.
$# perf stat -e hisi_pcie0_core0/rx_mrd_flux,bdf=0x3900/ sleep 5
TLP 길이 trigger
103-117Trigger filter는 TLP length가 조건을 처음 만족하는 순간부터 event 통계를 시작합니다. `trig_len`으로 조건 길이를, `trig_mode`로 비교 방향을 설정하며 bandwidth event에서만 사용할 수 있습니다.
`trig_len=4`는 trigger condition이 `2^4 DW`임을 뜻합니다.
| Mode | 통계 시작 조건 |
|---|---|
| `trig_mode=0` | TLP length가 trigger condition보다 클 때 통계 시작 |
| `trig_mode=1` | TLP length가 trigger condition보다 작을 때 통계 시작 |
$# perf stat -e hisi_pcie0_core0/rx_mrd_flux,port=0xffff,trig_len=0x4,trig_mode=1/ sleep 5
TLP 길이 threshold
118-131Threshold filter는 TLP length가 지정한 범위에 있을 때만 counter를 증가시킵니다. `thr_len`으로 threshold를, `thr_mode`로 비교 방향을 설정하며 bandwidth event에서만 사용할 수 있습니다.
`thr_len=4`는 threshold가 `2^4 DW`임을 뜻합니다.
| Mode | Count 조건 |
|---|---|
| `thr_mode=0` | TLP length가 threshold 이상일 때 count |
| `thr_mode=1` | TLP length가 threshold보다 작을 때 count |
$# perf stat -e hisi_pcie0_core0/rx_mrd_flux,port=0xffff,thr_len=0x4,thr_mode=1/ sleep 5
Bandwidth를 구성할 TLP 부분
132-148Bandwidth를 셀 때 `len_mode`로 TLP packet의 어느 부분을 데이터에 포함할지 선택합니다.
| `len_mode` | Bandwidth 구성 |
|---|---|
| `2'b00` | Reserved; 동작이 정의되지 않았으므로 사용 금지 |
| `2'b01` | TLP payload bandwidth |
| `2'b10` | TLP header bandwidth |
| `2'b11` | TLP payload와 header bandwidth, 기본값 |
`len_mode=2`는 TLP header bandwidth만 세고, `len_mode=3`은 header와 payload를 모두 포함합니다. 옵션을 생략하면 기본값은 `2'b11`입니다.
$# perf stat -e hisi_pcie0_core0/rx_mrd_flux,port=0xffff,len_mode=0x1/ sleep 5
운영 요약
hisi-pcie-pmu.rst:1-148PCIe Core 단위 PMU를 찾아 관련 event를 한 group에서 측정하고, `port` 또는 `bdf`로 traffic 대상을 정한 뒤 TLP trigger, threshold, 길이 구성을 적용합니다.