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/cik.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/cik.c')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/cik.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/cik.c b/drivers/gpu/drm/amd/amdgpu/cik.c index 71c50d8900e3..6277de51483f 100644 --- a/drivers/gpu/drm/amd/amdgpu/cik.c +++ b/drivers/gpu/drm/amd/amdgpu/cik.c | |||
@@ -1741,6 +1741,52 @@ static bool cik_need_full_reset(struct amdgpu_device *adev) | |||
1741 | return true; | 1741 | return true; |
1742 | } | 1742 | } |
1743 | 1743 | ||
1744 | static void cik_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0, | ||
1745 | uint64_t *count1) | ||
1746 | { | ||
1747 | uint32_t perfctr = 0; | ||
1748 | uint64_t cnt0_of, cnt1_of; | ||
1749 | int tmp; | ||
1750 | |||
1751 | /* This reports 0 on APUs, so return to avoid writing/reading registers | ||
1752 | * that may or may not be different from their GPU counterparts | ||
1753 | */ | ||
1754 | if (adev->flags & AMD_IS_APU) | ||
1755 | return; | ||
1756 | |||
1757 | /* Set the 2 events that we wish to watch, defined above */ | ||
1758 | /* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ | ||
1759 | perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK, EVENT0_SEL, 40); | ||
1760 | perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK, EVENT1_SEL, 104); | ||
1761 | |||
1762 | /* Write to enable desired perf counters */ | ||
1763 | WREG32_PCIE(ixPCIE_PERF_CNTL_TXCLK, perfctr); | ||
1764 | /* Zero out and enable the perf counters | ||
1765 | * Write 0x5: | ||
1766 | * Bit 0 = Start all counters(1) | ||
1767 | * Bit 2 = Global counter reset enable(1) | ||
1768 | */ | ||
1769 | WREG32_PCIE(ixPCIE_PERF_COUNT_CNTL, 0x00000005); | ||
1770 | |||
1771 | msleep(1000); | ||
1772 | |||
1773 | /* Load the shadow and disable the perf counters | ||
1774 | * Write 0x2: | ||
1775 | * Bit 0 = Stop counters(0) | ||
1776 | * Bit 1 = Load the shadow counters(1) | ||
1777 | */ | ||
1778 | WREG32_PCIE(ixPCIE_PERF_COUNT_CNTL, 0x00000002); | ||
1779 | |||
1780 | /* Read register values to get any >32bit overflow */ | ||
1781 | tmp = RREG32_PCIE(ixPCIE_PERF_CNTL_TXCLK); | ||
1782 | cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER0_UPPER); | ||
1783 | cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER1_UPPER); | ||
1784 | |||
1785 | /* Get the values and add the overflow */ | ||
1786 | *count0 = RREG32_PCIE(ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of << 32); | ||
1787 | *count1 = RREG32_PCIE(ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of << 32); | ||
1788 | } | ||
1789 | |||
1744 | static const struct amdgpu_asic_funcs cik_asic_funcs = | 1790 | static const struct amdgpu_asic_funcs cik_asic_funcs = |
1745 | { | 1791 | { |
1746 | .read_disabled_bios = &cik_read_disabled_bios, | 1792 | .read_disabled_bios = &cik_read_disabled_bios, |
@@ -1756,6 +1802,7 @@ static const struct amdgpu_asic_funcs cik_asic_funcs = | |||
1756 | .invalidate_hdp = &cik_invalidate_hdp, | 1802 | .invalidate_hdp = &cik_invalidate_hdp, |
1757 | .need_full_reset = &cik_need_full_reset, | 1803 | .need_full_reset = &cik_need_full_reset, |
1758 | .init_doorbell_index = &legacy_doorbell_index_init, | 1804 | .init_doorbell_index = &legacy_doorbell_index_init, |
1805 | .get_pcie_usage = &cik_get_pcie_usage, | ||
1759 | }; | 1806 | }; |
1760 | 1807 | ||
1761 | static int cik_common_early_init(void *handle) | 1808 | static int cik_common_early_init(void *handle) |