drm/amdgpu: Add sysfs file for PCIe usage v3
Subsystems (2)
PATCH 1/1 drm/amdgpu: Add sysfs file for PCIe usage v3
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
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 38 +++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/cik.c | 41 +++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/si.c | 41 +++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/soc15.c | 44 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/vi.c | 41 +++++++++++++++++++++++++++++++ 6 files changed, 209 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
@@ -542,6 +542,9 @@ struct amdgpu_asic_funcs {bool (*need_full_reset)(struct amdgpu_device *adev);/* initialize doorbell layout for specific asic*/ void (*init_doorbell_index)(struct amdgpu_device *adev); +/* PCIe bandwidth usage */ +void (*get_pcie_usage)(struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1); };/*
@@ -1045,6 +1048,7 @@ int emu_soc_asic_init(struct amdgpu_device *adev);#define amdgpu_asic_invalidate_hdp (adev, r) (adev)->asic_funcs->invalidate_hdp((adev), (r))#define amdgpu_asic_need_full_reset (adev) (adev)->asic_funcs->need_full_reset((adev))#define amdgpu_asic_init_doorbell_index (adev) (adev)->asic_funcs->init_doorbell_index((adev)) +#define amdgpu_asic_get_pcie_usage (adev, cnt0, cnt1) ((adev)->asic_funcs->get_pcie_usage((adev), (cnt0), (cnt1)))/* Common functions */ bool amdgpu_device_should_recover_gpu (struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +38 -0
@@ -990,6 +990,33 @@ static ssize_t amdgpu_get_busy_percent(struct device *dev,return snprintf (buf,PAGE_SIZE ,"%d\n" , value); } +/** +* DOC: pcie_bw +* +* The amdgpu driver provides a sysfs API for reading how much data +* has been sent and received by the GPU in the last second through PCIe. +* The file pcie_bw is used for this. +* The Perf counters calculate this and return the number of sent and received +* messages, which we multiply by the maxsize of our PCIe packets (mps). +* Note that it is not possible to easily and quickly obtain the size of each +* packet transmitted, so we use the max payload size (mps) to estimate the +* PCIe bandwidth usage +*/ +static ssize_t amdgpu_get_pcie_bw (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct drm_device *ddev =dev_get_drvdata (dev); +struct amdgpu_device *adev = ddev->dev_private; +uint64_t mps =pcie_get_mps (adev->pdev); +uint64_t count0, count1; + +amdgpu_asic_get_pcie_usage (adev, &count0, &count1); +return snprintf (buf,PAGE_SIZE , +"Bytes received: %llu\nBytes sent: %llu\n" , + count0 * mps, count1 * mps); +} + static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR, amdgpu_get_dpm_state, amdgpu_set_dpm_state); static DEVICE_ATTR(power_dpm_force_performance_level, S_IRUGO | S_IWUSR, amdgpu_get_dpm_forced_performance_level,
@@ -1025,6 +1052,7 @@ static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO | S_IWUSR, amdgpu_set_pp_od_clk_voltage); static DEVICE_ATTR(gpu_busy_percent, S_IRUGO, amdgpu_get_busy_percent, NULL); +static DEVICE_ATTR(pcie_bw, S_IRUGO, amdgpu_get_pcie_bw, NULL); static ssize_t amdgpu_hwmon_show_temp(struct device *dev, struct device_attribute *attr,
@@ -2108,6 +2136,14 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev) "gpu_busy_level\n");return ret; } +/* PCIe Perf counters won't work on APU nodes */ +if (adev->flags & !AMD_IS_APU ) { + ret =device_create_file (adev->dev, &dev_attr_pcie_bw); +if (ret) { +DRM_ERROR ("failed to create device file pcie_bw\n" ); +return ret; + } + } ret =amdgpu_debugfs_pm_init (adev);if (ret) {DRM_ERROR ("Failed to register debugfs file for dpm!\n" );
@@ -2147,6 +2183,8 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)device_remove_file (adev->dev, &dev_attr_pp_od_clk_voltage);device_remove_file (adev->dev, &dev_attr_gpu_busy_percent); +if (adev->flags & !AMD_IS_APU ) +device_remove_file (adev->dev, &dev_attr_pcie_bw); }void amdgpu_pm_compute_clocks (struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/cik.c +41 -0
53 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/si.c +41 -0
53 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/soc15.c +44 -0
68 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/vi.c +41 -0
53 lines not on this page · raw message
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1546946900-1099-1-git-send-email-kent.russell-5C7GfCeVMHo@public.gmane.org
Quoted 5 lines · Kent
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
I think you only updated the code comment, but not the output in sysfs.
More generally, most amdgpu sysfs files report a single value, or a set of values separated by spaces. That makes it easier to parse by external tools. It's also supposed to be a stable API. They don't usually include human readable text such as "bytes received:". It would be up to a tool such as rocm-smi to turn this into human-readable text.
In keeping with that convention I'd suggest reporting the PCIe bandwidth as three numbers:
<recv count> <send count> <mps>
Then let the tool calculate the bytes estimate with the appropriate warnings about how accurate that is.
Alex does this match your understanding regarding sysfs conventions?
Regards,
Felix
Quoted 350 lines
v3: Don't make the file on APUs
Signed-off-by Kent Russell <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 38 +++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/cik.c | 41 +++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/si.c | 41 +++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/soc15.c | 44 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/vi.c | 41 +++++++++++++++++++++++++++++++ 6 files changed, 209 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +4
-0@@ -542,6 +542,9 @@ struct amdgpu_asic_funcs {bool (*need_full_reset)(struct amdgpu_device *adev);/* initialize doorbell layout for specific asic*/ void (*init_doorbell_index)(struct amdgpu_device *adev); +/* PCIe bandwidth usage */ +void (*get_pcie_usage)(struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1); };/* @@ -1045,6 +1048,7 @@ int emu_soc_asic_init(struct amdgpu_device *adev);#define amdgpu_asic_invalidate_hdp (adev, r) (adev)->asic_funcs->invalidate_hdp((adev), (r))#define amdgpu_asic_need_full_reset (adev) (adev)->asic_funcs->need_full_reset((adev))#define amdgpu_asic_init_doorbell_index (adev) (adev)->asic_funcs->init_doorbell_index((adev)) +#define amdgpu_asic_get_pcie_usage (adev, cnt0, cnt1) ((adev)->asic_funcs->get_pcie_usage((adev), (cnt0), (cnt1)))/* Common functions */ bool amdgpu_device_should_recover_gpu (struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +38
-0@@ -990,6 +990,33 @@ static ssize_t amdgpu_get_busy_percent(struct device *dev,return snprintf (buf,PAGE_SIZE ,"%d\n" , value); } +/** +* DOC: pcie_bw +* +* The amdgpu driver provides a sysfs API for reading how much data +* has been sent and received by the GPU in the last second through PCIe. +* The file pcie_bw is used for this. +* The Perf counters calculate this and return the number of sent and received +* messages, which we multiply by the maxsize of our PCIe packets (mps). +* Note that it is not possible to easily and quickly obtain the size of each +* packet transmitted, so we use the max payload size (mps) to estimate the +* PCIe bandwidth usage +*/ +static ssize_t amdgpu_get_pcie_bw (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct drm_device *ddev =dev_get_drvdata (dev); +struct amdgpu_device *adev = ddev->dev_private; +uint64_t mps =pcie_get_mps (adev->pdev); +uint64_t count0, count1; + +amdgpu_asic_get_pcie_usage (adev, &count0, &count1); +return snprintf (buf,PAGE_SIZE , +"Bytes received: %llu\nBytes sent: %llu\n" , + count0 * mps, count1 * mps); +} + static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR, amdgpu_get_dpm_state, amdgpu_set_dpm_state); static DEVICE_ATTR(power_dpm_force_performance_level, S_IRUGO | S_IWUSR, amdgpu_get_dpm_forced_performance_level,@@ -1025,6 +1052,7 @@ static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO | S_IWUSR, amdgpu_set_pp_od_clk_voltage); static DEVICE_ATTR(gpu_busy_percent, S_IRUGO, amdgpu_get_busy_percent, NULL); +static DEVICE_ATTR(pcie_bw, S_IRUGO, amdgpu_get_pcie_bw, NULL); static ssize_t amdgpu_hwmon_show_temp(struct device *dev, struct device_attribute *attr,@@ -2108,6 +2136,14 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev) "gpu_busy_level\n");return ret; } +/* PCIe Perf counters won't work on APU nodes */ +if (adev->flags & !AMD_IS_APU ) { + ret =device_create_file (adev->dev, &dev_attr_pcie_bw); +if (ret) { +DRM_ERROR ("failed to create device file pcie_bw\n" ); +return ret; + } + } ret =amdgpu_debugfs_pm_init (adev);if (ret) {DRM_ERROR ("Failed to register debugfs file for dpm!\n" );@@ -2147,6 +2183,8 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)device_remove_file (adev->dev, &dev_attr_pp_od_clk_voltage);device_remove_file (adev->dev, &dev_attr_gpu_busy_percent); +if (adev->flags & !AMD_IS_APU ) +device_remove_file (adev->dev, &dev_attr_pcie_bw); }void amdgpu_pm_compute_clocks (struct amdgpu_device *adev)drivers/gpu/drm/amd/amdgpu/cik.c +41
-0@@ -1741,6 +1741,46 @@ static bool cik_need_full_reset(struct amdgpu_device *adev)return true; } +static void cik_get_pcie_usage (struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1) +{ +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp; + +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT0_SEL ,40 ); + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: +* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK); + cnt0_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER0_UPPER ); + cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 =RREG32_PCIE (ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<32 ); + *count1 =RREG32_PCIE (ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of <<32 ); +} +static const struct amdgpu_asic_funcs cik_asic_funcs = { .read_disabled_bios = &cik_read_disabled_bios,@@ -1756,6 +1796,7 @@ static const struct amdgpu_asic_funcs cik_asic_funcs = .invalidate_hdp = &cik_invalidate_hdp, .need_full_reset = &cik_need_full_reset, .init_doorbell_index = &legacy_doorbell_index_init, + .get_pcie_usage = &cik_get_pcie_usage, };static int cik_common_early_init (void *handle)drivers/gpu/drm/amd/amdgpu/si.c +41
-0@@ -1323,6 +1323,46 @@ static void si_set_pcie_lanes(struct amdgpu_device *adev, int lanes)WREG32_PCIE_PORT (PCIE_LC_LINK_WIDTH_CNTL , link_width_cntl); } +static void si_get_pcie_usage (struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1) +{ +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp; + +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT0_SEL ,40 ); + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: +* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK); + cnt0_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER0_UPPER ); + cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 =RREG32_PCIE (ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<32 ); + *count1 =RREG32_PCIE (ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of <<32 ); +} +static const struct amdgpu_asic_funcs si_asic_funcs = { .read_disabled_bios = &si_read_disabled_bios,@@ -1339,6 +1379,7 @@ static const struct amdgpu_asic_funcs si_asic_funcs = .flush_hdp = &si_flush_hdp, .invalidate_hdp = &si_invalidate_hdp, .need_full_reset = &si_need_full_reset, + .get_pcie_usage = &si_get_pcie_usage, };static uint32_t si_get_rev_id (struct amdgpu_device *adev)drivers/gpu/drm/amd/amdgpu/soc15.c +44
-0@@ -43,6 +43,9 @@#include "hdp/hdp_4_0_sh_mask.h" #include "smuio/smuio_9_0_offset.h" #include "smuio/smuio_9_0_sh_mask.h" +#include "nbio/nbio_7_0_default.h" +#include "nbio/nbio_7_0_sh_mask.h" +#include "nbio/nbio_7_0_smn.h" #include "soc15.h" #include "soc15_common.h" @@ -601,6 +604,45 @@ static bool soc15_need_full_reset(struct amdgpu_device *adev)/* change this when we implement soft reset */ return true; } +static void soc15_get_pcie_usage (struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1) +{ +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp; + +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT0_SEL ,40 ); + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (smnPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (smnPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: +* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (smnPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (smnPCIE_PERF_CNTL_TXCLK); + cnt0_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER0_UPPER ); + cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 =RREG32_PCIE (smnPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<32 ); + *count1 =RREG32_PCIE (smnPCIE_PERF_COUNT1_TXCLK) | (cnt1_of <<32 ); +}static const struct amdgpu_asic_funcs soc15_asic_funcs = {@@ -617,6 +659,7 @@ static const struct amdgpu_asic_funcs soc15_asic_funcs = .invalidate_hdp = &soc15_invalidate_hdp, .need_full_reset = &soc15_need_full_reset, .init_doorbell_index = &vega10_doorbell_index_init, + .get_pcie_usage = &soc15_get_pcie_usage, }; static const struct amdgpu_asic_funcs vega20_asic_funcs =@@ -634,6 +677,7 @@ static const struct amdgpu_asic_funcs vega20_asic_funcs = .invalidate_hdp = &soc15_invalidate_hdp, .need_full_reset = &soc15_need_full_reset, .init_doorbell_index = &vega20_doorbell_index_init, + .get_pcie_usage = &soc15_get_pcie_usage, };static int soc15_common_early_init (void *handle)drivers/gpu/drm/amd/amdgpu/vi.c +40
-0@@ -941,6 +941,46 @@ static bool vi_need_full_reset(struct amdgpu_device *adev) } } +static void vi_get_pcie_usage (struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1) +{ +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp; + +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT0_SEL ,40 ); + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: +* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK); + cnt0_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER0_UPPER ); + cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 =RREG32_PCIE (ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<32 ); + *count1 =RREG32_PCIE (ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of <<32 ); +} +static const struct amdgpu_asic_funcs vi_asic_funcs = { .read_disabled_bios = &vi_read_disabled_bios,
drivers/gpu/drm/amd/amdgpu/vi.c static const struct amdgpu_asic_funcs vi_asic_funcs = · line 1002
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/vi.c +1
-0@@ -956,6 +996,7 @@ static const struct amdgpu_asic_funcs vi_asic_funcs = .invalidate_hdp = &vi_invalidate_hdp, .need_full_reset = &vi_need_full_reset, .init_doorbell_index = &legacy_doorbell_index_init, + .get_pcie_usage = &vi_get_pcie_usage, };#define CZ_REV_BRISTOL (rev) \
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): ffa0e6fd-ffef-45f4-fe1b-1b2c1513fdda-5C7GfCeVMHo@public.gmane.org
Quoted 20 lines · Felix
Quoted 5 lines · Kent
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
I think you only updated the code comment, but not the output in sysfs.
More generally, most amdgpu sysfs files report a single value, or a set of values separated by spaces. That makes it easier to parse by external tools. It's also supposed to be a stable API. They don't usually include human readable text such as "bytes received:". It would be up to a tool such as rocm-smi to turn this into human-readable text.
In keeping with that convention I'd suggest reporting the PCIe bandwidth as three numbers:
Quoted 6 lines
<recv count> <send count> <mps>
Then let the tool calculate the bytes estimate with the appropriate warnings about how accurate that is.
Alex does this match your understanding regarding sysfs conventions?
Yes, agreed.
Alex
Quoted 360 lines
Regards,
FelixQuoted 356 lines
v3: Don't make the file on APUs
Signed-off-by Kent Russell <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 38 +++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/cik.c | 41 +++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/si.c | 41 +++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/soc15.c | 44 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/vi.c | 41 +++++++++++++++++++++++++++++++ 6 files changed, 209 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +4
-0@@ -542,6 +542,9 @@ struct amdgpu_asic_funcs {bool (*need_full_reset)(struct amdgpu_device *adev);/* initialize doorbell layout for specific asic*/ void (*init_doorbell_index)(struct amdgpu_device *adev); +/* PCIe bandwidth usage */ +void (*get_pcie_usage)(struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1); };/* @@ -1045,6 +1048,7 @@ int emu_soc_asic_init(struct amdgpu_device *adev);#define amdgpu_asic_invalidate_hdp (adev, r) (adev)->asic_funcs->invalidate_hdp((adev), (r))#define amdgpu_asic_need_full_reset (adev) (adev)->asic_funcs->need_full_reset((adev))#define amdgpu_asic_init_doorbell_index (adev) (adev)->asic_funcs->init_doorbell_index((adev)) +#define amdgpu_asic_get_pcie_usage (adev, cnt0, cnt1) ((adev)->asic_funcs->get_pcie_usage((adev), (cnt0), (cnt1)))/* Common functions */ bool amdgpu_device_should_recover_gpu (struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +38
-0@@ -990,6 +990,33 @@ static ssize_t amdgpu_get_busy_percent(struct device *dev,return snprintf (buf,PAGE_SIZE ,"%d\n" , value); } +/** +* DOC: pcie_bw +* +* The amdgpu driver provides a sysfs API for reading how much data +* has been sent and received by the GPU in the last second through PCIe. +* The file pcie_bw is used for this. +* The Perf counters calculate this and return the number of sent and received +* messages, which we multiply by the maxsize of our PCIe packets (mps). +* Note that it is not possible to easily and quickly obtain the size of each +* packet transmitted, so we use the max payload size (mps) to estimate the +* PCIe bandwidth usage +*/ +static ssize_t amdgpu_get_pcie_bw (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct drm_device *ddev =dev_get_drvdata (dev); +struct amdgpu_device *adev = ddev->dev_private; +uint64_t mps =pcie_get_mps (adev->pdev); +uint64_t count0, count1; + +amdgpu_asic_get_pcie_usage (adev, &count0, &count1); +return snprintf (buf,PAGE_SIZE , +"Bytes received: %llu\nBytes sent: %llu\n" , + count0 * mps, count1 * mps); +} + static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR, amdgpu_get_dpm_state, amdgpu_set_dpm_state); static DEVICE_ATTR(power_dpm_force_performance_level, S_IRUGO | S_IWUSR, amdgpu_get_dpm_forced_performance_level,@@ -1025,6 +1052,7 @@ static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO | S_IWUSR, amdgpu_set_pp_od_clk_voltage); static DEVICE_ATTR(gpu_busy_percent, S_IRUGO, amdgpu_get_busy_percent, NULL); +static DEVICE_ATTR(pcie_bw, S_IRUGO, amdgpu_get_pcie_bw, NULL); static ssize_t amdgpu_hwmon_show_temp(struct device *dev, struct device_attribute *attr,@@ -2108,6 +2136,14 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev) "gpu_busy_level\n");return ret; } +/* PCIe Perf counters won't work on APU nodes */ +if (adev->flags & !AMD_IS_APU ) { + ret =device_create_file (adev->dev, &dev_attr_pcie_bw); +if (ret) { +DRM_ERROR ("failed to create device file pcie_bw\n" ); +return ret; + } + } ret =amdgpu_debugfs_pm_init (adev);if (ret) {DRM_ERROR ("Failed to register debugfs file for dpm!\n" );@@ -2147,6 +2183,8 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)device_remove_file (adev->dev, &dev_attr_pp_od_clk_voltage);device_remove_file (adev->dev, &dev_attr_gpu_busy_percent); +if (adev->flags & !AMD_IS_APU ) +device_remove_file (adev->dev, &dev_attr_pcie_bw); }void amdgpu_pm_compute_clocks (struct amdgpu_device *adev)drivers/gpu/drm/amd/amdgpu/cik.c +41
-0@@ -1741,6 +1741,46 @@ static bool cik_need_full_reset(struct amdgpu_device *adev)return true; } +static void cik_get_pcie_usage (struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1) +{ +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp; + +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT0_SEL ,40 ); + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: +* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK); + cnt0_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER0_UPPER ); + cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 =RREG32_PCIE (ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<32 ); + *count1 =RREG32_PCIE (ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of <<32 ); +} +static const struct amdgpu_asic_funcs cik_asic_funcs = { .read_disabled_bios = &cik_read_disabled_bios,@@ -1756,6 +1796,7 @@ static const struct amdgpu_asic_funcs cik_asic_funcs = .invalidate_hdp = &cik_invalidate_hdp, .need_full_reset = &cik_need_full_reset, .init_doorbell_index = &legacy_doorbell_index_init, + .get_pcie_usage = &cik_get_pcie_usage, };static int cik_common_early_init (void *handle)drivers/gpu/drm/amd/amdgpu/si.c +41
-0@@ -1323,6 +1323,46 @@ static void si_set_pcie_lanes(struct amdgpu_device *adev, int lanes)WREG32_PCIE_PORT (PCIE_LC_LINK_WIDTH_CNTL , link_width_cntl); } +static void si_get_pcie_usage (struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1) +{ +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp; + +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT0_SEL ,40 ); + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: +* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK); + cnt0_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER0_UPPER ); + cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 =RREG32_PCIE (ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<32 ); + *count1 =RREG32_PCIE (ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of <<32 ); +} +static const struct amdgpu_asic_funcs si_asic_funcs = { .read_disabled_bios = &si_read_disabled_bios,@@ -1339,6 +1379,7 @@ static const struct amdgpu_asic_funcs si_asic_funcs = .flush_hdp = &si_flush_hdp, .invalidate_hdp = &si_invalidate_hdp, .need_full_reset = &si_need_full_reset, + .get_pcie_usage = &si_get_pcie_usage, };static uint32_t si_get_rev_id (struct amdgpu_device *adev)drivers/gpu/drm/amd/amdgpu/soc15.c +44
-0@@ -43,6 +43,9 @@#include "hdp/hdp_4_0_sh_mask.h" #include "smuio/smuio_9_0_offset.h" #include "smuio/smuio_9_0_sh_mask.h" +#include "nbio/nbio_7_0_default.h" +#include "nbio/nbio_7_0_sh_mask.h" +#include "nbio/nbio_7_0_smn.h" #include "soc15.h" #include "soc15_common.h" @@ -601,6 +604,45 @@ static bool soc15_need_full_reset(struct amdgpu_device *adev)/* change this when we implement soft reset */ return true; } +static void soc15_get_pcie_usage (struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1) +{ +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp; + +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT0_SEL ,40 ); + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (smnPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (smnPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: +* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (smnPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (smnPCIE_PERF_CNTL_TXCLK); + cnt0_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER0_UPPER ); + cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 =RREG32_PCIE (smnPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<32 ); + *count1 =RREG32_PCIE (smnPCIE_PERF_COUNT1_TXCLK) | (cnt1_of <<32 ); +}static const struct amdgpu_asic_funcs soc15_asic_funcs = {@@ -617,6 +659,7 @@ static const struct amdgpu_asic_funcs soc15_asic_funcs = .invalidate_hdp = &soc15_invalidate_hdp, .need_full_reset = &soc15_need_full_reset, .init_doorbell_index = &vega10_doorbell_index_init, + .get_pcie_usage = &soc15_get_pcie_usage, }; static const struct amdgpu_asic_funcs vega20_asic_funcs =@@ -634,6 +677,7 @@ static const struct amdgpu_asic_funcs vega20_asic_funcs = .invalidate_hdp = &soc15_invalidate_hdp, .need_full_reset = &soc15_need_full_reset, .init_doorbell_index = &vega20_doorbell_index_init, + .get_pcie_usage = &soc15_get_pcie_usage, };static int soc15_common_early_init (void *handle)drivers/gpu/drm/amd/amdgpu/vi.c +41
-0@@ -941,6 +941,46 @@ static bool vi_need_full_reset(struct amdgpu_device *adev) } } +static void vi_get_pcie_usage (struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1) +{ +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp; + +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT0_SEL ,40 ); + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: +* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK); + cnt0_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER0_UPPER ); + cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 =RREG32_PCIE (ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<32 ); + *count1 =RREG32_PCIE (ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of <<32 ); +} +static const struct amdgpu_asic_funcs vi_asic_funcs = { .read_disabled_bios = &vi_read_disabled_bios,@@ -956,6 +996,7 @@ static const struct amdgpu_asic_funcs vi_asic_funcs = .invalidate_hdp = &vi_invalidate_hdp, .need_full_reset = &vi_need_full_reset, .init_doorbell_index = &legacy_doorbell_index_init, + .get_pcie_usage = &vi_get_pcie_usage, };
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/vi.c static const struct amdgpu_asic_funcs vi_asic_funcs = · line 1002
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/vi.c +0
-0#define CZ_REV_BRISTOL (rev) \_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CADnq5_OcHnLCoOZXPuBWgBR_R4sXrFJzS=1ZGPyyyGQR3V+Z5g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 35 lines
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Tuesday, January 08, 2019 11:26 AM
To: Kuehling, Felix <[email protected]>
Cc: Russell, Kent <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Add sysfs file for PCIe usage v3Quoted 9 lines · Felix
Quoted 5 lines · Kent
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
Quoted 7 lines
I think you only updated the code comment, but not the output in sysfs.
More generally, most amdgpu sysfs files report a single value, or a set of values separated by spaces. That makes it easier to parse by external tools. It's also supposed to be a stable API. They don't usually include human readable text such as "bytes received:". It would be up to a tool such as rocm-smi to turn this into human-readable
text.
Quoted 6 lines
In keeping with that convention I'd suggest reporting the PCIe bandwidth as three numbers:
<recv count> <send count> <mps>
Quoted 8 lines
Quoted 4 lines
Then let the tool calculate the bytes estimate with the appropriate warnings about how accurate that is.
Alex does this match your understanding regarding sysfs conventions?
Yes, agreed.
Alex
That works for me. I always let the sclk/mclk sysfs file with their multi-line outputs get into my head. I'll make the appropriate change, which will also make it easier for the SMI to communicate how the values are established.
Kent
Quoted 389 lines
Quoted 11 lines
Regards,
FelixQuoted 6 lines
v3: Don't make the file on APUs
Signed-off-by Kent Russell <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 38+++++++++++++++++++++++++++++
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/cik.c | 41+++++++++++++++++++++++++++++++
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/si.c | 41+++++++++++++++++++++++++++++++
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/soc15.c | 44++++++++++++++++++++++++++++++++++
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/vi.c | 41+++++++++++++++++++++++++++++++
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h struct amdgpu_asic_funcs { · line 546
Quoted 13 lines
6 files changed, 209 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -542,6 +542,9 @@ struct amdgpu_asic_funcs {bool (*need_full_reset)(struct amdgpu_device *adev);/* initialize doorbell layout for specific asic*/ void (*init_doorbell_index)(struct amdgpu_device *adev); +/* PCIe bandwidth usage */ + void (*get_pcie_usage)(struct amdgpu_device *adev, uint64_t*count0,
Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+ uint64_t *count1); };/* @@ -1045,6 +1048,7 @@ int emu_soc_asic_init(struct amdgpu_device *adev); #define amdgpu_asic_invalidate_hdp(adev, r)(adev)->asic_funcs->invalidate_hdp((adev), (r)) #define
amdgpu_asic_need_full_reset(adev)(adev)->asic_funcs->need_full_reset((adev))
#defineamdgpu_asic_init_doorbell_index(adev)
(adev)->asic_funcs->init_doorbell_index((adev))drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0+#define amdgpu_asic_get_pcie_usage (adev, cnt0, cnt1) +((adev)->asic_funcs->get_pcie_usage ((adev), (cnt0), (cnt1)))Quoted 2 lines
Quoted 2 lines
/* Common functions */
bool amdgpu_device_should_recover_gpu(structamdgpu_device*adev);
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c static ssize_t amdgpu_get_busy_percent(struct
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0
-0@@ -990,6 +990,33 @@ static ssize_t amdgpu_get_busy_percent(structdevice *dev,
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c static ssize_t amdgpu_get_busy_percent(struct device *dev,
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +5
-0return snprintf (buf,PAGE_SIZE ,"%d\n" , value); } +/** +* DOC: pcie_bw +* +* The amdgpu driver provides a sysfs API for reading how much data +* has been sent and received by the GPU in the last second through PCIe.
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c static ssize_t amdgpu_get_busy_percent(struct · line 1000
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +4
-0+* The file pcie_bw is used for this. +* The Perf counters calculate this and return the number of sent +and received +* messages, which we multiply by the maxsize of our PCIe packets (mps).
Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +14
-0+* Note that it is not possible to easily and quickly obtain the +size of each +* packet transmitted, so we use the max payload size (mps) to +estimate the +* PCIe bandwidth usage +*/ +static ssize_t amdgpu_get_pcie_bw (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct drm_device *ddev =dev_get_drvdata (dev); +struct amdgpu_device *adev = ddev->dev_private; +uint64_t mps =pcie_get_mps (adev->pdev); +uint64_t count0, count1;Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +6
-0+ +amdgpu_asic_get_pcie_usage (adev, &count0, &count1); +return snprintf (buf,PAGE_SIZE , +"Bytes received: %llu\nBytes sent: %llu\n" , + count0 * mps, count1 * mps); } + static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR,
amdgpu_get_dpm_state,amdgpu_set_dpm_state); staticDEVICE_ATTR(power_dpm_force_performance_level,
S_IRUGO|S_IWUSR,Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c static DEVICE_ATTR(pp_od_clk_voltage,
Quoted 2 lines
amdgpu_get_dpm_forced_performance_level,drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0
-0@@ -1025,6 +1052,7 @@ static DEVICE_ATTR(pp_od_clk_voltage,
S_IRUGO|S_IWUSR,Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c int amdgpu_pm_sysfs_init(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1
-0amdgpu_set_pp_od_clk_voltage); static DEVICE_ATTR(gpu_busy_percent, S_IRUGO, amdgpu_get_busy_percent, NULL); +static DEVICE_ATTR(pcie_bw, S_IRUGO, amdgpu_get_pcie_bw, NULL); static ssize_t amdgpu_hwmon_show_temp(struct device *dev, struct device_attribute *attr,@@ -2108,6 +2136,14 @@ int amdgpu_pm_sysfs_init(struct
amdgpu_device*adev)Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +4
-0"gpu_busy_level\n");return ret; } +/* PCIe Perf counters won't work on APU nodes */ +if (adev->flags & !AMD_IS_APU ) { + ret =device_create_file (adev->dev, &dev_attr_pcie_bw); +if (ret) {Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +4
-0+DRM_ERROR ("failed to create device file pcie_bw\n" ); +return ret; + } + } ret =amdgpu_debugfs_pm_init (adev);if (ret) { DRM_ERROR("Failed to register debugfs file fordpm!\n"); @@ -2147,6 +2183,8 @@ void amdgpu_pm_sysfs_fini(struct
amdgpu_device*adev)Quoted 7 lines
Quoted 7 lines
device_remove_file(adev->dev, &dev_attr_pp_od_clk_voltage); device_remove_file(adev->dev, &dev_attr_gpu_busy_percent);drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +2
-0+if (adev->flags & !AMD_IS_APU ) +device_remove_file (adev->dev, &dev_attr_pcie_bw); }Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct
Quoted 7 lines
void
amdgpu_pm_compute_clocks(struct amdgpu_device *adev)diff
--gita/drivers/gpu/drm/amd/amdgpu/cik.cb/drivers/gpu/drm/amd/amdgpu/cik.c
index 71c50d8..8681744 100644drivers/gpu/drm/amd/amdgpu/cik.c +0
-0@@ -1741,6 +1741,46 @@ static bool cik_need_full_reset(struct
amdgpu_device*adev)Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct amdgpu_device *adev)
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/cik.c +1
-0return true; } +static void cik_get_pcie_usage(struct amdgpu_device *adev, uint64_t*count0,
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct amdgpu_device *adev)
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/cik.c +8
-0+ uint64_t *count1) { +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp; + +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK,
EVENT0_SEL, 40);Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/cik.c +16
-0+ perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK , +EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct amdgpu_device *adev)
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/cik.c +8
-0+* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK); + cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK,
COUNTER0_UPPER);Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct · line 1781
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/cik.c +5
-0+ cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK , +COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 = RREG32_PCIE(ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<32);
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/cik.c +5
-0+ *count1 =RREG32_PCIE (ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of << +32 ); } +static const struct amdgpu_asic_funcs cik_asic_funcs = { .read_disabled_bios = &cik_read_disabled_bios, @@ -1756,6 +1796,7 @@ static const struct amdgpu_asic_funcs cik_asic_funcs = .invalidate_hdp = &cik_invalidate_hdp, .need_full_reset = &cik_need_full_reset, .init_doorbell_index = &legacy_doorbell_index_init, + .get_pcie_usage = &cik_get_pcie_usage, };Quoted 2 lines
Quoted 2 lines
static int
cik_common_early_init(void *handle)diff --gita/drivers/gpu/drm/amd/amdgpu/si.c
b/drivers/gpu/drm/amd/amdgpu/si.cQuoted 4 lines
drivers/gpu/drm/amd/amdgpu/si.c static void si_set_pcie_lanes(struct
Quoted 4 lines
index f8408f8..2b3eb0e 100644
drivers/gpu/drm/amd/amdgpu/si.c +0
-0@@ -1323,6 +1323,46 @@ static void si_set_pcie_lanes(struct
amdgpu_device*adev, int lanes)Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/si.c static void si_set_pcie_lanes(struct · line 1325
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/si.c +1
-0WREG32_PCIE_PORT (PCIE_LC_LINK_WIDTH_CNTL , link_width_cntl); } +static void si_get_pcie_usage(struct amdgpu_device *adev, uint64_t*count0,
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/si.c static void si_set_pcie_lanes(struct · line 1333
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/si.c +8
-0+ uint64_t *count1) { +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp; + +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK,
EVENT0_SEL, 40);Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/si.c +16
-0+ perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK , +EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/si.c static void si_set_pcie_lanes(struct · line 1357
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/si.c +8
-0+* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK); + cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK,
COUNTER0_UPPER);Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/si.c static void si_set_pcie_lanes(struct · line 1362
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/si.c +5
-0+ cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK , +COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 = RREG32_PCIE(ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<32);
Quoted 26 lines
Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/si.c +5
-1+ *count1 =RREG32_PCIE (ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of << +32 ); } +static const struct amdgpu_asic_funcs si_asic_funcs = { .read_disabled_bios = &si_read_disabled_bios, @@ -1339,6 +1379,7 @@ static const struct amdgpu_asic_funcs si_asic_funcs = .flush_hdp = &si_flush_hdp, .invalidate_hdp = &si_invalidate_hdp, .need_full_reset = &si_need_full_reset, + .get_pcie_usage = &si_get_pcie_usage, }; static uint32_t si_get_rev_id(struct amdgpu_device *adev) diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c
b/drivers/gpu/drm/amd/amdgpu/soc15.c
index 8849b74..afd8391 100644drivers/gpu/drm/amd/amdgpu/soc15.c +3
-0@@ -43,6 +43,9 @@#include "hdp/hdp_4_0_sh_mask.h" #include "smuio/smuio_9_0_offset.h" #include "smuio/smuio_9_0_sh_mask.h" +#include "nbio/nbio_7_0_default.h" +#include "nbio/nbio_7_0_sh_mask.h" +#include "nbio/nbio_7_0_smn.h" Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/soc15.c static bool soc15_need_full_reset(struct
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +0
-0#include "soc15.h" #include "soc15_common.h" @@ -601,6 +604,45 @@ static bool soc15_need_full_reset(struct
amdgpu_device*adev)Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/soc15.c static bool soc15_need_full_reset(struct amdgpu_device *adev)
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +1
-0/* change this when we implement soft reset */ return true; } +static void soc15_get_pcie_usage(struct amdgpu_device *adev,
uint64_t*count0,Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/soc15.c static bool soc15_need_full_reset(struct · line 615
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +8
-0+ uint64_t *count1) { +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp; + +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK,
EVENT0_SEL, 40);Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +16
-0+ perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK , +EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (smnPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (smnPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/soc15.c static bool soc15_need_full_reset(struct amdgpu_device *adev)
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +8
-0+* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (smnPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (smnPCIE_PERF_CNTL_TXCLK); + cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK,
COUNTER0_UPPER);Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/soc15.c static bool soc15_need_full_reset(struct · line 644
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +5
-0+ cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK , +COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK) | (cnt0_of<< 32);
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/soc15.c static bool soc15_need_full_reset(struct · line 645
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/soc15.c +1
-0+ *count1 = RREG32_PCIE(smnPCIE_PERF_COUNT1_TXCLK) | (cnt1_of<<
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/soc15.c static bool soc15_need_full_reset(struct · line 606
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +1
-1+32); } static const struct amdgpu_asic_funcs soc15_asic_funcs = { @@ -617,6 +659,7 @@ static const struct amdgpu_asic_funcs
soc15_asic_funcs=Quoted 14 lines
Quoted 14 lines
.invalidate_hdp =
&soc15_invalidate_hdp, .need_full_reset =&soc15_need_full_reset, .init_doorbell_index =&vega10_doorbell_index_init,drivers/gpu/drm/amd/amdgpu/soc15.c +3
-0+ .get_pcie_usage = &soc15_get_pcie_usage, }; static const struct amdgpu_asic_funcs vega20_asic_funcs = @@ -634,6 +677,7 @@ static const struct amdgpu_asic_funcs vega20_asic_funcs = .invalidate_hdp = &soc15_invalidate_hdp, .need_full_reset = &soc15_need_full_reset, .init_doorbell_index = &vega20_doorbell_index_init, + .get_pcie_usage = &soc15_get_pcie_usage, };Quoted 2 lines
Quoted 2 lines
static int
soc15_common_early_init(void *handle)diff --gita/drivers/gpu/drm/amd/amdgpu/vi.c
b/drivers/gpu/drm/amd/amdgpu/vi.cQuoted 4 lines
drivers/gpu/drm/amd/amdgpu/vi.c static bool vi_need_full_reset(struct
Quoted 4 lines
index 03e7be5..f785565 100644
drivers/gpu/drm/amd/amdgpu/vi.c +0
-0@@ -941,6 +941,46 @@ static bool vi_need_full_reset(struct
amdgpu_device*adev)Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/vi.c static bool vi_need_full_reset(struct · line 944
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/vi.c +1
-0} } +static void vi_get_pcie_usage(struct amdgpu_device *adev, uint64_t*count0,
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vi.c static bool vi_need_full_reset(struct · line 952
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vi.c +8
-0+ uint64_t *count1) { +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp; + +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK,
EVENT0_SEL, 40);Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/vi.c +16
-0+ perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK , +EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vi.c static bool vi_need_full_reset(struct · line 976
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vi.c +8
-0+* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK); + cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK,
COUNTER0_UPPER);
Quoted 23 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/vi.c static bool vi_need_full_reset(struct · line 981
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/vi.c +5
-0+ cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK , +COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 = RREG32_PCIE(ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<32);
Quoted 17 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/vi.c +3
-0+ *count1 =RREG32_PCIE (ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of << +32 ); } +static const struct amdgpu_asic_funcs vi_asic_funcs = { .read_disabled_bios = &vi_read_disabled_bios, @@ -956,6 +996,7@@ static const struct
amdgpu_asic_funcsvi_asic_funcs=
.invalidate_hdp =&vi_invalidate_hdp, .need_full_reset =&vi_need_full_reset, .init_doorbell_index =&legacy_doorbell_index_init,
+ .get_pcie_usage =&vi_get_pcie_usage,
};Quoted 1 line
#define
CZ_REV_BRISTOL(rev)\_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 115 lines · Kent
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 APUsSigned-off-by Kent Russell <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 38 +++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/cik.c | 41 +++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/si.c | 41 +++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/soc15.c | 44 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/vi.c | 41 +++++++++++++++++++++++++++++++ 6 files changed, 209 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +4
-0@@ -542,6 +542,9 @@ struct amdgpu_asic_funcs {bool (*need_full_reset)(struct amdgpu_device *adev);/* initialize doorbell layout for specific asic*/ void (*init_doorbell_index)(struct amdgpu_device *adev); +/* PCIe bandwidth usage */ +void (*get_pcie_usage)(struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1); };/* @@ -1045,6 +1048,7 @@ int emu_soc_asic_init(struct amdgpu_device *adev);#define amdgpu_asic_invalidate_hdp (adev, r) (adev)->asic_funcs->invalidate_hdp((adev), (r))#define amdgpu_asic_need_full_reset (adev) (adev)->asic_funcs->need_full_reset((adev))#define amdgpu_asic_init_doorbell_index (adev) (adev)->asic_funcs->init_doorbell_index((adev)) +#define amdgpu_asic_get_pcie_usage (adev, cnt0, cnt1) ((adev)->asic_funcs->get_pcie_usage((adev), (cnt0), (cnt1)))/* Common functions */ bool amdgpu_device_should_recover_gpu (struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +38
-0@@ -990,6 +990,33 @@ static ssize_t amdgpu_get_busy_percent(struct device *dev,return snprintf (buf,PAGE_SIZE ,"%d\n" , value); } +/** +* DOC: pcie_bw +* +* The amdgpu driver provides a sysfs API for reading how much data +* has been sent and received by the GPU in the last second through PCIe. +* The file pcie_bw is used for this. +* The Perf counters calculate this and return the number of sent and received +* messages, which we multiply by the maxsize of our PCIe packets (mps). +* Note that it is not possible to easily and quickly obtain the size of each +* packet transmitted, so we use the max payload size (mps) to estimate the +* PCIe bandwidth usage +*/ +static ssize_t amdgpu_get_pcie_bw (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct drm_device *ddev =dev_get_drvdata (dev); +struct amdgpu_device *adev = ddev->dev_private; +uint64_t mps =pcie_get_mps (adev->pdev); +uint64_t count0, count1; + +amdgpu_asic_get_pcie_usage (adev, &count0, &count1); +return snprintf (buf,PAGE_SIZE , +"Bytes received: %llu\nBytes sent: %llu\n" , + count0 * mps, count1 * mps); +} + static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR, amdgpu_get_dpm_state, amdgpu_set_dpm_state); static DEVICE_ATTR(power_dpm_force_performance_level, S_IRUGO | S_IWUSR, amdgpu_get_dpm_forced_performance_level,@@ -1025,6 +1052,7 @@ static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO | S_IWUSR, amdgpu_set_pp_od_clk_voltage); static DEVICE_ATTR(gpu_busy_percent, S_IRUGO, amdgpu_get_busy_percent, NULL); +static DEVICE_ATTR(pcie_bw, S_IRUGO, amdgpu_get_pcie_bw, NULL); static ssize_t amdgpu_hwmon_show_temp(struct device *dev, struct device_attribute *attr,@@ -2108,6 +2136,14 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev) "gpu_busy_level\n");return ret; } +/* PCIe Perf counters won't work on APU nodes */ +if (adev->flags & !AMD_IS_APU ) { + ret =device_create_file (adev->dev, &dev_attr_pcie_bw); +if (ret) { +DRM_ERROR ("failed to create device file pcie_bw\n" ); +return ret; + } + } ret =amdgpu_debugfs_pm_init (adev);if (ret) {DRM_ERROR ("Failed to register debugfs file for dpm!\n" );@@ -2147,6 +2183,8 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)device_remove_file (adev->dev, &dev_attr_pp_od_clk_voltage);device_remove_file (adev->dev, &dev_attr_gpu_busy_percent); +if (adev->flags & !AMD_IS_APU ) +device_remove_file (adev->dev, &dev_attr_pcie_bw); }void amdgpu_pm_compute_clocks (struct amdgpu_device *adev)drivers/gpu/drm/amd/amdgpu/cik.c +0
-0
drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct amdgpu_device *adev) · line 1749
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/cik.c +6
-0@@ -1741,6 +1741,46 @@ static bool cik_need_full_reset(struct amdgpu_device *adev)return true; } +static void cik_get_pcie_usage (struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1) +{ +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp;
We should probably return early here for APUs to avoid accidentally messing with registers that may be problematic or missing on APUs. Same for the other asic callbacks.
Alex
Quoted 242 lines
drivers/gpu/drm/amd/amdgpu/cik.c +35
-0+ +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT0_SEL ,40 ); + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: +* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK); + cnt0_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER0_UPPER ); + cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 =RREG32_PCIE (ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<32 ); + *count1 =RREG32_PCIE (ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of <<32 ); +} +static const struct amdgpu_asic_funcs cik_asic_funcs = { .read_disabled_bios = &cik_read_disabled_bios,@@ -1756,6 +1796,7 @@ static const struct amdgpu_asic_funcs cik_asic_funcs = .invalidate_hdp = &cik_invalidate_hdp, .need_full_reset = &cik_need_full_reset, .init_doorbell_index = &legacy_doorbell_index_init, + .get_pcie_usage = &cik_get_pcie_usage, };static int cik_common_early_init (void *handle)drivers/gpu/drm/amd/amdgpu/si.c +41
-0@@ -1323,6 +1323,46 @@ static void si_set_pcie_lanes(struct amdgpu_device *adev, int lanes)WREG32_PCIE_PORT (PCIE_LC_LINK_WIDTH_CNTL , link_width_cntl); } +static void si_get_pcie_usage (struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1) +{ +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp; + +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT0_SEL ,40 ); + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: +* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK); + cnt0_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER0_UPPER ); + cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 =RREG32_PCIE (ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<32 ); + *count1 =RREG32_PCIE (ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of <<32 ); +} +static const struct amdgpu_asic_funcs si_asic_funcs = { .read_disabled_bios = &si_read_disabled_bios,@@ -1339,6 +1379,7 @@ static const struct amdgpu_asic_funcs si_asic_funcs = .flush_hdp = &si_flush_hdp, .invalidate_hdp = &si_invalidate_hdp, .need_full_reset = &si_need_full_reset, + .get_pcie_usage = &si_get_pcie_usage, };static uint32_t si_get_rev_id (struct amdgpu_device *adev)drivers/gpu/drm/amd/amdgpu/soc15.c +44
-0@@ -43,6 +43,9 @@#include "hdp/hdp_4_0_sh_mask.h" #include "smuio/smuio_9_0_offset.h" #include "smuio/smuio_9_0_sh_mask.h" +#include "nbio/nbio_7_0_default.h" +#include "nbio/nbio_7_0_sh_mask.h" +#include "nbio/nbio_7_0_smn.h" #include "soc15.h" #include "soc15_common.h" @@ -601,6 +604,45 @@ static bool soc15_need_full_reset(struct amdgpu_device *adev)/* change this when we implement soft reset */ return true; } +static void soc15_get_pcie_usage (struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1) +{ +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp; + +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT0_SEL ,40 ); + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (smnPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (smnPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: +* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (smnPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (smnPCIE_PERF_CNTL_TXCLK); + cnt0_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER0_UPPER ); + cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 =RREG32_PCIE (smnPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<32 ); + *count1 =RREG32_PCIE (smnPCIE_PERF_COUNT1_TXCLK) | (cnt1_of <<32 ); +}static const struct amdgpu_asic_funcs soc15_asic_funcs = {@@ -617,6 +659,7 @@ static const struct amdgpu_asic_funcs soc15_asic_funcs = .invalidate_hdp = &soc15_invalidate_hdp, .need_full_reset = &soc15_need_full_reset, .init_doorbell_index = &vega10_doorbell_index_init, + .get_pcie_usage = &soc15_get_pcie_usage, }; static const struct amdgpu_asic_funcs vega20_asic_funcs =@@ -634,6 +677,7 @@ static const struct amdgpu_asic_funcs vega20_asic_funcs = .invalidate_hdp = &soc15_invalidate_hdp, .need_full_reset = &soc15_need_full_reset, .init_doorbell_index = &vega20_doorbell_index_init, + .get_pcie_usage = &soc15_get_pcie_usage, };static int soc15_common_early_init (void *handle)drivers/gpu/drm/amd/amdgpu/vi.c +41
-1@@ -941,6 +941,46 @@ static bool vi_need_full_reset(struct amdgpu_device *adev) } } +static void vi_get_pcie_usage (struct amdgpu_device *adev,uint64_t *count0, +uint64_t *count1) +{ +uint32_t perfctr =0 ; +uint64_t cnt0_of, cnt1_of; +int tmp; + +/* Set the 2 events that we wish to watch, defined above */ +/* Reg 40 is # received msgs, Reg 104 is # of posted requests sent */ + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT0_SEL ,40 ); + perfctr =REG_SET_FIELD (perfctr,PCIE_PERF_CNTL_TXCLK ,EVENT1_SEL ,104 ); + +/* Write to enable desired perf counters */ +WREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK, perfctr); +/* Zero out and enable the perf counters +* Write 0x5: +* Bit 0 = Start all counters(1) +* Bit 2 = Global counter reset enable(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000005 ); + +msleep (1000 ); + +/* Load the shadow and disable the perf counters +* Write 0x2: +* Bit 0 = Stop counters(0) +* Bit 1 = Load the shadow counters(1) +*/ +WREG32_PCIE (ixPCIE_PERF_COUNT_CNTL,0x00000002 ); + +/* Read register values to get any >32bit overflow */ + tmp =RREG32_PCIE (ixPCIE_PERF_CNTL_TXCLK); + cnt0_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER0_UPPER ); + cnt1_of =REG_GET_FIELD (tmp,PCIE_PERF_CNTL_TXCLK ,COUNTER1_UPPER ); + +/* Get the values and add the overflow */ + *count0 =RREG32_PCIE (ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<32 ); + *count1 =RREG32_PCIE (ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of <<32 ); +} +static const struct amdgpu_asic_funcs vi_asic_funcs = { .read_disabled_bios = &vi_read_disabled_bios,@@ -956,6 +996,7 @@ static const struct amdgpu_asic_funcs vi_asic_funcs = .invalidate_hdp = &vi_invalidate_hdp, .need_full_reset = &vi_need_full_reset, .init_doorbell_index = &legacy_doorbell_index_init, + .get_pcie_usage = &vi_get_pcie_usage, };#define CZ_REV_BRISTOL (rev) \ --2.7.4
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx