diff options
author | Kent Russell <kent.russell@amd.com> | 2019-01-03 08:12:39 -0500 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2019-01-14 15:04:54 -0500 |
commit | b45e18acd394954c24943762ada5d8dada75f2b9 (patch) | |
tree | 40ffc68e9c4e6c4449edf17d4401d4dcc5a54503 /drivers/gpu/drm/amd/amdgpu/vi.c | |
parent | a0bb79e2559c9330c82080d6e4f8c762d72ed0f1 (diff) |
drm/amdgpu: Add sysfs file for PCIe usage v5
Add a sysfs file that reports the number of bytes transmitted and
received in the last second. This can be used to approximate the PCIe
bandwidth usage over the last second.
v2: Clarify use of mps as estimation of bandwidth
v3: Don't make the file on APUs
v4: Early exit for APUs in the read function, change output to
display "packets-received packets-sent mps"
v5: fix missing header for si (Alex)
Signed-off-by: Kent Russell <kent.russell@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/vi.c')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/vi.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/vi.c b/drivers/gpu/drm/amd/amdgpu/vi.c index 03e7be595a0d..cdc8ab8d79d7 100644 --- a/drivers/gpu/drm/amd/amdgpu/vi.c +++ b/drivers/gpu/drm/amd/amdgpu/vi.c | |||
@@ -941,6 +941,52 @@ static bool vi_need_full_reset(struct amdgpu_device *adev) | |||
941 | } | 941 | } |
942 | } | 942 | } |
943 | 943 | ||
944 | static void vi_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0, | ||
945 | uint64_t *count1) | ||
946 | { | ||
947 | uint32_t perfctr = 0; | ||
948 | uint64_t cnt0_of, cnt1_of; | ||
949 | int tmp; | ||
950 | |||
951 | /* This reports 0 on APUs, so return to avoid writing/reading registers | ||
952 | * that may or may not be different from their GPU counterparts | ||
953 | */ | ||
954 | if (adev->flags & AMD_IS_APU) | ||
955 | return; | ||
956 | |||
957 | /* Set the 2 events that we wish to watch, defined above */ | ||
958 | /* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ | ||
959 | perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK, EVENT0_SEL, 40); | ||
960 | perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK, EVENT1_SEL, 104); | ||
961 | |||
962 | /* Write to enable desired perf counters */ | ||
963 | WREG32_PCIE(ixPCIE_PERF_CNTL_TXCLK, perfctr); | ||
964 | /* Zero out and enable the perf counters | ||
965 | * Write 0x5: | ||
966 | * Bit 0 = Start all counters(1) | ||
967 | * Bit 2 = Global counter reset enable(1) | ||
968 | */ | ||
969 | WREG32_PCIE(ixPCIE_PERF_COUNT_CNTL, 0x00000005); | ||
970 | |||
971 | msleep(1000); | ||
972 | |||
973 | /* Load the shadow and disable the perf counters | ||
974 | * Write 0x2: | ||
975 | * Bit 0 = Stop counters(0) | ||
976 | * Bit 1 = Load the shadow counters(1) | ||
977 | */ | ||
978 | WREG32_PCIE(ixPCIE_PERF_COUNT_CNTL, 0x00000002); | ||
979 | |||
980 | /* Read register values to get any >32bit overflow */ | ||
981 | tmp = RREG32_PCIE(ixPCIE_PERF_CNTL_TXCLK); | ||
982 | cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER0_UPPER); | ||
983 | cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER1_UPPER); | ||
984 | |||
985 | /* Get the values and add the overflow */ | ||
986 | *count0 = RREG32_PCIE(ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of << 32); | ||
987 | *count1 = RREG32_PCIE(ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of << 32); | ||
988 | } | ||
989 | |||
944 | static const struct amdgpu_asic_funcs vi_asic_funcs = | 990 | static const struct amdgpu_asic_funcs vi_asic_funcs = |
945 | { | 991 | { |
946 | .read_disabled_bios = &vi_read_disabled_bios, | 992 | .read_disabled_bios = &vi_read_disabled_bios, |
@@ -956,6 +1002,7 @@ static const struct amdgpu_asic_funcs vi_asic_funcs = | |||
956 | .invalidate_hdp = &vi_invalidate_hdp, | 1002 | .invalidate_hdp = &vi_invalidate_hdp, |
957 | .need_full_reset = &vi_need_full_reset, | 1003 | .need_full_reset = &vi_need_full_reset, |
958 | .init_doorbell_index = &legacy_doorbell_index_init, | 1004 | .init_doorbell_index = &legacy_doorbell_index_init, |
1005 | .get_pcie_usage = &vi_get_pcie_usage, | ||
959 | }; | 1006 | }; |
960 | 1007 | ||
961 | #define CZ_REV_BRISTOL(rev) \ | 1008 | #define CZ_REV_BRISTOL(rev) \ |