Skip to contentSkip to conversation

drm/amdgpu: Add NBIO SMN headers

PATCH In review Russell, Kent 3 participants 8 messages Jan 4, 2019 – Jan 8, 2019 5 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu: Add NBIO SMN headers

We need these offsets for PCIE perf counters, so include them as well as the the previously-used defines from the nbio_*.c files

Change-Id I0e090e5b5b97359a67b28952f069ff6e603edf10
---
 drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c             |  6 +--
 drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c             |  6 +--
 drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c             |  6 +--
 .../drm/amd/include/asic_reg/nbio/nbio_6_1_smn.h   | 58 ++++++++++++++++++++++
 .../drm/amd/include/asic_reg/nbio/nbio_7_0_smn.h   | 55 ++++++++++++++++++++
 .../drm/amd/include/asic_reg/nbio/nbio_7_4_0_smn.h | 53 ++++++++++++++++++++
 6 files changed, 169 insertions(+), 15 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_6_1_smn.h
 create mode 100644 drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_7_0_smn.h
 create mode 100644 drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_7_4_0_smn.h
drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c +1 -5
index accdedd..1965756 100644
@@ -27,13 +27,9 @@
 #include "nbio/nbio_6_1_default.h"
 #include "nbio/nbio_6_1_offset.h"
 #include "nbio/nbio_6_1_sh_mask.h"
+#include "nbio/nbio_6_1_smn.h"
 #include "vega10_enum.h"
 
-#define smnCPM_CONTROL                                                                                  0x11180460
-#define smnPCIE_CNTL2                                                                                   0x11180070
-#define smnPCIE_CONFIG_CNTL                                                                             0x11180044
-#define smnPCIE_CI_CNTL                                                                                 0x11180080
-
 static u32 nbio_v6_1_get_rev_id(struct amdgpu_device *adev)
 {
         u32 tmp = RREG32_SOC15(NBIO, 0, mmRCC_DEV0_EPF0_STRAP0);
drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c +1 -5
index df34dc7..f718fe2 100644
@@ -27,13 +27,9 @@
 #include "nbio/nbio_7_0_default.h"
 #include "nbio/nbio_7_0_offset.h"
 #include "nbio/nbio_7_0_sh_mask.h"
+#include "nbio/nbio_7_0_smn.h"
 #include "vega10_enum.h"
 
-#define smnNBIF_MGCG_CTRL_LCLK	0x1013a05c
-
-#define smnCPM_CONTROL                                                                                  0x11180460
-#define smnPCIE_CNTL2                                                                                   0x11180070
-
 static u32 nbio_v7_0_get_rev_id(struct amdgpu_device *adev)
 {
         u32 tmp = RREG32_SOC15(NBIO, 0, mmRCC_DEV0_EPF0_STRAP0);
drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c +1 -5
index 4cd31a2..c402727 100644
@@ -26,12 +26,8 @@
 
 #include "nbio/nbio_7_4_offset.h"
 #include "nbio/nbio_7_4_sh_mask.h"
+#include "nbio/nbio_7_4_0_smn.h"
 
-#define smnNBIF_MGCG_CTRL_LCLK	0x1013a21c
-
-#define smnCPM_CONTROL                                                                                  0x11180460
-#define smnPCIE_CNTL2                                                                                   0x11180070
-#define smnPCIE_CI_CNTL                                                                                 0x11180080
 
 static u32 nbio_v7_4_get_rev_id(struct amdgpu_device *adev)
 {
drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_6_1_smn.h new file +58 -0

58 lines not on this page · raw message

drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_7_0_smn.h new file +55 -0

55 lines not on this page · raw message

drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_7_4_0_smn.h new file +53 -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): 1546605277-21243-1-git-send-email-kent.russell-5C7GfCeVMHo@public.gmane.org

#2 lore raw

PATCH 2/2 drm/amdgpu: Add sysfs file for PCIe usage

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.

Change-Id I6c82fe1cb17726825736512990fa64f5c1489861
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h    |  4 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 31 ++++++++++++++++++++++++
 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, 202 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
index e1b2c64..512b124 100644
@@ -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 +31 -0
index 1f61ed9..051307e 100644
@@ -990,6 +990,30 @@ 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 size of our PCIe packets (mps).
+ */
+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 +1049,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,
@@ -2105,6 +2130,11 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
 				"gpu_busy_level\n");
 		return ret;
 	}
+	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");
@@ -2141,6 +2171,7 @@ 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);
+	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): 1546605277-21243-2-git-send-email-kent.russell-5C7GfCeVMHo@public.gmane.org

#4 lore raw

Re: [PATCH 2/2] drm/amdgpu: Add sysfs file for PCIe usage

Quoted 82 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.

Change-Id I6c82fe1cb17726825736512990fa64f5c1489861
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h    |  4 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 31 ++++++++++++++++++++++++
 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, 202 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
index e1b2c64..512b124 100644
@@ -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 +25 -0
index 1f61ed9..051307e 100644
@@ -990,6 +990,30 @@ 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 size of our PCIe packets (mps).
+ */
+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 +1049,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,

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c int amdgpu_pm_sysfs_init(struct amdgpu_device *adev) · line 2137

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +5 -0
@@ -2105,6 +2130,11 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
                                "gpu_busy_level\n");
                return ret;
        }
+       ret = device_create_file(adev->dev, &dev_attr_pcie_bw);
+       if (ret) {
+               DRM_ERROR("failed to create device file pcie_bw\n");
+               return ret;
+       }

Should this file be added for APUs too or just dGPUs?

Quoted 48 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -0
        ret = amdgpu_debugfs_pm_init(adev);
        if (ret) {
                DRM_ERROR("Failed to register debugfs file for dpm!\n");
@@ -2141,6 +2171,7 @@ 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);
+       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 +29 -0
index 71c50d8..8681744 100644
@@ -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);

drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct amdgpu_device *adev) · line 1782

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/cik.c +10 -0
+
+       /* 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);
+}

Does this work properly on APUs as well or just dGPUs? Same comment for VI and SOC15.

Thanks,

Alex

Quoted 209 lines
drivers/gpu/drm/amd/amdgpu/cik.c +2 -0
+
 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
index f8408f8..2b3eb0e 100644
@@ -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
index 8849b74..afd8391 100644
@@ -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
index 03e7be5..f785565 100644
@@ -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

A message that is not in the archive (sent off-list or not yet received): CADnq5_NMdjhix4tXe93=cy3DT2x8vZrA6ZH5htiHzg_J=Y_Qpw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#6 lore raw

RE: [PATCH 2/2] drm/amdgpu: Add sysfs file for PCIe usage

Did you mean on APU+dGPU, or just straight APU? The file currently returns 0s on my Carrizo. The event values are the same on CZ as they are for the dGPU ASICs, so it might just be that it's not supported since it's not going through the physical PCIe bus on the board. I have tested it on Fiji/Vega10/Vega20 successfully, and they all give reasonable values, at least. But I don't have access to Raven to see if it just returns 0s like CZ does. Would you prefer that the sysfs file only be added for dGPUs, to save confusion and wasted sysfs files that return no useful information?

Kent

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Friday, January 04, 2019 11:22 AM
To: Russell, Kent <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu: Add sysfs file for PCIe usage

Quoted 87 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.

Change-Id I6c82fe1cb17726825736512990fa64f5c1489861
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h    |  4 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 31 ++++++++++++++++++++++++
 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, 202 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
index e1b2c64..512b124 100644
@@ -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))

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)))
 
 /* Common functions */
 bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev); 
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +25 -0
index 1f61ed9..051307e 100644
@@ -990,6 +990,30 @@ 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 size of our PCIe packets (mps).
+ */
+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 +1049,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, 

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c int amdgpu_pm_sysfs_init(struct amdgpu_device *adev) · line 2137

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +5 -0
@@ -2105,6 +2130,11 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
                                "gpu_busy_level\n");
                return ret;
        }
+       ret = device_create_file(adev->dev, &dev_attr_pcie_bw);
+       if (ret) {
+               DRM_ERROR("failed to create device file pcie_bw\n");
+               return ret;
+       }

Should this file be added for APUs too or just dGPUs?

Quoted 49 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0 -0
        ret = amdgpu_debugfs_pm_init(adev);
        if (ret) {
                DRM_ERROR("Failed to register debugfs file for 

dpm!\n"); @@ -2141,6 +2171,7 @@ 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);

+ device_remove_file(adev->dev, &dev_attr_pcie_bw);
}

void amdgpu_pm_compute_clocks(struct amdgpu_device *adev) diff --git
a/drivers/gpu/drm/amd/amdgpu/cik.c b/drivers/gpu/drm/amd/amdgpu/cik.c index 71c50d8..8681744 100644

drivers/gpu/drm/amd/amdgpu/cik.c +30 -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);
+

drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct amdgpu_device *adev) · line 1783

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/cik.c +10 -0
+       /* 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); }

Does this work properly on APUs as well or just dGPUs? Same comment for VI and SOC15.

Thanks,

Alex

Quoted 204 lines
drivers/gpu/drm/amd/amdgpu/cik.c +3 -0
+
 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) diff --git 

a/drivers/gpu/drm/amd/amdgpu/si.c b/drivers/gpu/drm/amd/amdgpu/si.c index f8408f8..2b3eb0e 100644

drivers/gpu/drm/amd/amdgpu/si.c +43 -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) diff --git 

a/drivers/gpu/drm/amd/amdgpu/soc15.c
b/drivers/gpu/drm/amd/amdgpu/soc15.c
index 8849b74..afd8391 100644

drivers/gpu/drm/amd/amdgpu/soc15.c +47 -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) diff --git 

a/drivers/gpu/drm/amd/amdgpu/vi.c b/drivers/gpu/drm/amd/amdgpu/vi.c index 03e7be5..f785565 100644

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 8 lines

#define CZ_REV_BRISTOL(rev) \
--
2.7.4

_______________________________________________
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): BN6PR12MB161862CF953F235037326C0185890-/b2+HYfkarRqaFUXYJa4HgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#8 lore raw

Re: [PATCH 2/2] drm/amdgpu: Add sysfs file for PCIe usage

Quoted 3 lines · Kent

Did you mean on APU+dGPU, or just straight APU? The file currently returns 0s on my Carrizo. The event values are the same on CZ as they are for the dGPU ASICs, so it might just be that it's not supported since it's not going through the physical PCIe bus on the board. I have tested it on Fiji/Vega10/Vega20 successfully, and they all give reasonable values, at least. But I don't have access to Raven to see if it just returns 0s like CZ does. Would you prefer that the sysfs file only be added for dGPUs, to save confusion and wasted sysfs files that return no useful information?

On APUs. If the registers don't exist or don't do anything on APUs, then let's just not expose the file. Otherwise, it just leads to confusion.

Alex

Quoted 379 lines

Kent

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Friday, January 04, 2019 11:22 AM
To: Russell, Kent <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu: Add sysfs file for PCIe usage

Quoted 87 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.

Change-Id I6c82fe1cb17726825736512990fa64f5c1489861
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h    |  4 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 31 ++++++++++++++++++++++++
 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, 202 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
index e1b2c64..512b124 100644
@@ -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))

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)))
 
 /* Common functions */
 bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +25 -0
index 1f61ed9..051307e 100644
@@ -990,6 +990,30 @@ 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 size of our PCIe packets (mps).
+ */
+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 +1049,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,

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c int amdgpu_pm_sysfs_init(struct amdgpu_device *adev) · line 2137

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +5 -0
@@ -2105,6 +2130,11 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
                                "gpu_busy_level\n");
                return ret;
        }
+       ret = device_create_file(adev->dev, &dev_attr_pcie_bw);
+       if (ret) {
+               DRM_ERROR("failed to create device file pcie_bw\n");
+               return ret;
+       }

Should this file be added for APUs too or just dGPUs?

Quoted 49 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0 -0
        ret = amdgpu_debugfs_pm_init(adev);
        if (ret) {
                DRM_ERROR("Failed to register debugfs file for

dpm!\n"); @@ -2141,6 +2171,7 @@ 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);

+ device_remove_file(adev->dev, &dev_attr_pcie_bw);
}

void amdgpu_pm_compute_clocks(struct amdgpu_device *adev) diff --git
a/drivers/gpu/drm/amd/amdgpu/cik.c b/drivers/gpu/drm/amd/amdgpu/cik.c index 71c50d8..8681744 100644

drivers/gpu/drm/amd/amdgpu/cik.c +30 -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);
+

drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct amdgpu_device *adev) · line 1783

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/cik.c +10 -0
+       /* 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); }

Does this work properly on APUs as well or just dGPUs? Same comment for VI and SOC15.

Thanks,

Alex

Quoted 204 lines
drivers/gpu/drm/amd/amdgpu/cik.c +3 -0
+
 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) diff --git

a/drivers/gpu/drm/amd/amdgpu/si.c b/drivers/gpu/drm/amd/amdgpu/si.c index f8408f8..2b3eb0e 100644

drivers/gpu/drm/amd/amdgpu/si.c +43 -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) diff --git

a/drivers/gpu/drm/amd/amdgpu/soc15.c
b/drivers/gpu/drm/amd/amdgpu/soc15.c
index 8849b74..afd8391 100644

drivers/gpu/drm/amd/amdgpu/soc15.c +47 -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) diff --git

a/drivers/gpu/drm/amd/amdgpu/vi.c b/drivers/gpu/drm/amd/amdgpu/vi.c index 03e7be5..f785565 100644

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 8 lines
Quoted 8 lines

#define CZ_REV_BRISTOL(rev) \
--
2.7.4

_______________________________________________
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

#9 lore raw

Re: [PATCH 2/2] drm/amdgpu: Add sysfs file for PCIe usage

In reply to a message not in the archive
Quoted 57 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.

Change-Id I6c82fe1cb17726825736512990fa64f5c1489861
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h    |  4 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 31 ++++++++++++++++++++++++
 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, 202 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
index e1b2c64..512b124 100644
@@ -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 +12 -0
index 1f61ed9..051307e 100644
@@ -990,6 +990,30 @@ 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 size of our PCIe packets (mps).
+ */
+static ssize_t amdgpu_get_pcie_bw(struct device *dev,
+		struct device_attribute *attr,
+		char *buf)

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c static ssize_t amdgpu_get_busy_percent(struct device *dev, · line 1014

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +10 -0
+{
+	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);

This quietly assumes that all transfers use the maximum payload size.

We should either state the assumption or report the count rather than a number in bytes.

Regards,
  Felix

Quoted 279 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +9 -0
+}
+
 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 +1049,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,
@@ -2105,6 +2130,11 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
 				"gpu_busy_level\n");
 		return ret;
 	}
+	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");
@@ -2141,6 +2171,7 @@ 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);
+	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
index 71c50d8..8681744 100644
@@ -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
index f8408f8..2b3eb0e 100644
@@ -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
index 8849b74..afd8391 100644
@@ -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
index 03e7be5..f785565 100644
@@ -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): fa9a3c57-6ed0-8aed-3d76-17beda5e0e22-5C7GfCeVMHo@public.gmane.org

#11 lore raw

RE: [PATCH 2/2] drm/amdgpu: Add sysfs file for PCIe usage

Quoted 92 lines

-----Original Message-----
From: Kuehling, Felix
Sent: Monday, January 07, 2019 2:54 PM
To: Russell, Kent <[email protected]>; [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu: Add sysfs file for PCIe usage

Quoted 9 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.

Change-Id I6c82fe1cb17726825736512990fa64f5c1489861
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h    |  4 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 31

++++++++++++++++++++++++

Quoted 1 line
 drivers/gpu/drm/amd/amdgpu/cik.c       | 41

+++++++++++++++++++++++++++++++

Quoted 1 line
 drivers/gpu/drm/amd/amdgpu/si.c        | 41

+++++++++++++++++++++++++++++++

Quoted 1 line
 drivers/gpu/drm/amd/amdgpu/soc15.c     | 44

++++++++++++++++++++++++++++++++++

Quoted 1 line
 drivers/gpu/drm/amd/amdgpu/vi.c        | 41

+++++++++++++++++++++++++++++++

drivers/gpu/drm/amd/amdgpu/amdgpu.h struct amdgpu_asic_funcs { · line 546

Quoted 13 lines
 6 files changed, 202 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
index e1b2c64..512b124 100644
@@ -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,

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c static ssize_t amdgpu_get_busy_percent(struct

Quoted 22 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))
#define amdgpu_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)))
 
 /* Common functions */
 bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0 -0
index 1f61ed9..051307e 100644
@@ -990,6 +990,30 @@ static ssize_t amdgpu_get_busy_percent(struct

device *dev,

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +13 -0
 	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 size of our PCIe packets (mps).
+ */
+static ssize_t amdgpu_get_pcie_bw(struct device *dev,
+		struct device_attribute *attr,
+		char *buf)

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c static ssize_t amdgpu_get_busy_percent(struct device *dev, · line 1014

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +10 -0
+{
+	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);

This quietly assumes that all transfers use the maximum payload size.

Quoted 5 lines

We should either state the assumption or report the count rather than a number in bytes.

Regards,
  Felix

Agreed, I have expanded upon the comment to clarify this in the upcoming v2 patch

Quoted 320 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +2 -0
+}
+
 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,

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0 -0
 		   amdgpu_get_dpm_forced_performance_level,
@@ -1025,6 +1049,7 @@ static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO

| S_IWUSR,

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO | S_IWUSR,

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -0
 		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, @@ -2105,6

+2130,11 @@ int

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c int amdgpu_pm_sysfs_init(struct amdgpu_device *adev) · line 2140

Quoted 12 lines

amdgpu_pm_sysfs_init(struct amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +5 -0
 				"gpu_busy_level\n");
 		return ret;
 	}
+	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");

@@ -2141,6

Quoted 9 lines

+2171,7 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +1 -0
 	device_remove_file(adev->dev,
 			&dev_attr_pp_od_clk_voltage);
 	device_remove_file(adev->dev, &dev_attr_gpu_busy_percent);
+	device_remove_file(adev->dev, &dev_attr_pcie_bw);
 }
 
 void amdgpu_pm_compute_clocks(struct amdgpu_device *adev) diff --git

a/drivers/gpu/drm/amd/amdgpu/cik.c

b/drivers/gpu/drm/amd/amdgpu/cik.c

drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct

Quoted 4 lines

index 71c50d8..8681744 100644

drivers/gpu/drm/amd/amdgpu/cik.c +0 -0
@@ -1741,6 +1741,46 @@ static bool cik_need_full_reset(struct

amdgpu_device *adev)

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 -0
 	return true;
 }
 
+static void cik_get_pcie_usage(struct amdgpu_device *adev, uint64_t

*count0,

drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct amdgpu_device *adev)

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/cik.c +9 -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);

drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct · line 1754

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/cik.c +1 -0
+	perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK,

EVENT1_SEL,

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/cik.c +13 -0
+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);
+

drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/cik.c +10 -0
+	/* 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);

drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct · line 1778

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/cik.c +1 -0
+	cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK,

COUNTER1_UPPER);

drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct amdgpu_device *adev)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/cik.c +3 -0
+
+	/* Get the values and add the overflow */
+	*count0 = RREG32_PCIE(ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<

32);

drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct · line 1782

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/cik.c +1 -0
+	*count1 = RREG32_PCIE(ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of <<

32); }

drivers/gpu/drm/amd/amdgpu/cik.c static bool cik_need_full_reset(struct · line 1785

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/cik.c +1 -0
+
 static const struct amdgpu_asic_funcs cik_asic_funcs =  {
 	.read_disabled_bios = &cik_read_disabled_bios, @@ -1756,6 +1796,7

@@

Quoted 9 lines

static const struct amdgpu_asic_funcs cik_asic_funcs =

drivers/gpu/drm/amd/amdgpu/cik.c +1 -0
 	.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) diff --git

a/drivers/gpu/drm/amd/amdgpu/si.c

b/drivers/gpu/drm/amd/amdgpu/si.c

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)

drivers/gpu/drm/amd/amdgpu/si.c static void si_set_pcie_lanes(struct amdgpu_device *adev, int lanes) · line 1323

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/si.c +0 -0
 	WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);

}

drivers/gpu/drm/amd/amdgpu/si.c static void si_set_pcie_lanes(struct · line 1324

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/si.c +1 -0
+static void si_get_pcie_usage(struct amdgpu_device *adev, uint64_t

*count0,

drivers/gpu/drm/amd/amdgpu/si.c static void si_set_pcie_lanes(struct · line 1333

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/si.c +9 -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);

drivers/gpu/drm/amd/amdgpu/si.c static void si_set_pcie_lanes(struct · line 1334

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/si.c +1 -0
+	perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK,

EVENT1_SEL,

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/si.c +13 -0
+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);
+

drivers/gpu/drm/amd/amdgpu/si.c static void si_set_pcie_lanes(struct · line 1357

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/si.c +10 -0
+	/* 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);

drivers/gpu/drm/amd/amdgpu/si.c static void si_set_pcie_lanes(struct · line 1358

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/si.c +1 -0
+	cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK,

COUNTER1_UPPER);

drivers/gpu/drm/amd/amdgpu/si.c static void si_set_pcie_lanes(struct · line 1361

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/si.c +3 -0
+
+	/* Get the values and add the overflow */
+	*count0 = RREG32_PCIE(ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<

32);

drivers/gpu/drm/amd/amdgpu/si.c static void si_set_pcie_lanes(struct · line 1362

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/si.c +1 -0
+	*count1 = RREG32_PCIE(ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of <<

32); }

drivers/gpu/drm/amd/amdgpu/si.c static void si_set_pcie_lanes(struct · line 1365

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/si.c +1 -0
+
 static const struct amdgpu_asic_funcs si_asic_funcs =  {
 	.read_disabled_bios = &si_read_disabled_bios, @@ -1339,6 +1379,7

@@

drivers/gpu/drm/amd/amdgpu/soc15.c static bool soc15_need_full_reset(struct

Quoted 24 lines

static const struct amdgpu_asic_funcs si_asic_funcs =

drivers/gpu/drm/amd/amdgpu/si.c +1 -0
 	.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 100644

drivers/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"
 
 #include "soc15.h"
 #include "soc15_common.h"
@@ -601,6 +604,45 @@ static bool soc15_need_full_reset(struct

amdgpu_device *adev)

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,

drivers/gpu/drm/amd/amdgpu/soc15.c static bool soc15_need_full_reset(struct · line 616

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +9 -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);

drivers/gpu/drm/amd/amdgpu/soc15.c static bool soc15_need_full_reset(struct · line 617

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/soc15.c +1 -0
+	perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK,

EVENT1_SEL,

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +13 -0
+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);
+

drivers/gpu/drm/amd/amdgpu/soc15.c static bool soc15_need_full_reset(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +10 -0
+	/* 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);

drivers/gpu/drm/amd/amdgpu/soc15.c static bool soc15_need_full_reset(struct · line 641

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/soc15.c +1 -0
+	cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK,

COUNTER1_UPPER);

drivers/gpu/drm/amd/amdgpu/soc15.c static bool soc15_need_full_reset(struct · line 644

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +3 -0
+
+	/* Get the values and add the overflow */
+	*count0 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK) | (cnt0_of

<< 32);

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

<< 32);

Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +5 -0
+}
 
 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) diff --git
Quoted 1 line

a/drivers/gpu/drm/amd/amdgpu/vi.c

b/drivers/gpu/drm/amd/amdgpu/vi.c

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)

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,

drivers/gpu/drm/amd/amdgpu/vi.c static bool vi_need_full_reset(struct · line 953

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/vi.c +9 -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);

drivers/gpu/drm/amd/amdgpu/vi.c static bool vi_need_full_reset(struct · line 954

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/vi.c +1 -0
+	perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK,

EVENT1_SEL,

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/vi.c +13 -0
+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);
+

drivers/gpu/drm/amd/amdgpu/vi.c static bool vi_need_full_reset(struct · line 977

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/vi.c +10 -0
+	/* 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);

drivers/gpu/drm/amd/amdgpu/vi.c static bool vi_need_full_reset(struct · line 978

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/vi.c +1 -0
+	cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK,

COUNTER1_UPPER);

drivers/gpu/drm/amd/amdgpu/vi.c static bool vi_need_full_reset(struct · line 981

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/vi.c +3 -0
+
+	/* Get the values and add the overflow */
+	*count0 = RREG32_PCIE(ixPCIE_PERF_COUNT0_TXCLK) | (cnt0_of <<

32);

drivers/gpu/drm/amd/amdgpu/vi.c static bool vi_need_full_reset(struct · line 982

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/vi.c +1 -0
+	*count1 = RREG32_PCIE(ixPCIE_PERF_COUNT1_TXCLK) | (cnt1_of <<

32); }

drivers/gpu/drm/amd/amdgpu/vi.c static bool vi_need_full_reset(struct · line 985

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/vi.c +1 -0
+
 static const struct amdgpu_asic_funcs vi_asic_funcs =  {
 	.read_disabled_bios = &vi_read_disabled_bios, @@ -956,6 +996,7

@@

Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/vi.c static const struct amdgpu_asic_funcs vi_asic_funcs = · line 1002

Quoted 8 lines

static const struct amdgpu_asic_funcs vi_asic_funcs =

drivers/gpu/drm/amd/amdgpu/vi.c +1 -0
 	.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

Reviewed-by
#12 lore raw
In reply to a message not in the archive
Quoted 61 lines · Kent

We need these offsets for PCIE perf counters, so include them as well as the the previously-used defines from the nbio_*.c files

Change-Id I0e090e5b5b97359a67b28952f069ff6e603edf10
---
 drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c             |  6 +--
 drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c             |  6 +--
 drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c             |  6 +--
 .../drm/amd/include/asic_reg/nbio/nbio_6_1_smn.h   | 58 ++++++++++++++++++++++
 .../drm/amd/include/asic_reg/nbio/nbio_7_0_smn.h   | 55 ++++++++++++++++++++
 .../drm/amd/include/asic_reg/nbio/nbio_7_4_0_smn.h | 53 ++++++++++++++++++++
 6 files changed, 169 insertions(+), 15 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_6_1_smn.h
 create mode 100644 drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_7_0_smn.h
 create mode 100644 drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_7_4_0_smn.h
drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c +1 -5
index accdedd..1965756 100644
@@ -27,13 +27,9 @@
 #include "nbio/nbio_6_1_default.h"
 #include "nbio/nbio_6_1_offset.h"
 #include "nbio/nbio_6_1_sh_mask.h"
+#include "nbio/nbio_6_1_smn.h"
 #include "vega10_enum.h"
 
-#define smnCPM_CONTROL                                                                                  0x11180460
-#define smnPCIE_CNTL2                                                                                   0x11180070
-#define smnPCIE_CONFIG_CNTL                                                                             0x11180044
-#define smnPCIE_CI_CNTL                                                                                 0x11180080
-
 static u32 nbio_v6_1_get_rev_id(struct amdgpu_device *adev)
 {
         u32 tmp = RREG32_SOC15(NBIO, 0, mmRCC_DEV0_EPF0_STRAP0);
drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c +1 -5
index df34dc7..f718fe2 100644
@@ -27,13 +27,9 @@
 #include "nbio/nbio_7_0_default.h"
 #include "nbio/nbio_7_0_offset.h"
 #include "nbio/nbio_7_0_sh_mask.h"
+#include "nbio/nbio_7_0_smn.h"
 #include "vega10_enum.h"
 
-#define smnNBIF_MGCG_CTRL_LCLK 0x1013a05c
-
-#define smnCPM_CONTROL                                                                                  0x11180460
-#define smnPCIE_CNTL2                                                                                   0x11180070
-
 static u32 nbio_v7_0_get_rev_id(struct amdgpu_device *adev)
 {
         u32 tmp = RREG32_SOC15(NBIO, 0, mmRCC_DEV0_EPF0_STRAP0);
drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c +0 -0
index 4cd31a2..c402727 100644

drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c line 30

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c +1 -1
@@ -26,12 +26,8 @@
 
 #include "nbio/nbio_7_4_offset.h"
 #include "nbio/nbio_7_4_sh_mask.h"
+#include "nbio/nbio_7_4_0_smn.h"
 
-#define smnNBIF_MGCG_CTRL_LCLK 0x1013a21c

I think technically the smnNBIF registers should be in the nbif_*_smn.h headers so maybe leave that here. Same comment on other IP revisions. Either way:

Quoted 194 lines
drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c +0 -4
-
-#define smnCPM_CONTROL                                                                                  0x11180460
-#define smnPCIE_CNTL2                                                                                   0x11180070
-#define smnPCIE_CI_CNTL                                                                                 0x11180080
 
 static u32 nbio_v7_4_get_rev_id(struct amdgpu_device *adev)
 {
drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_6_1_smn.h new file +58 -0
new file mode 100644
index 0000000..8c75669
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2019  Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _nbio_6_1_SMN_HEADER
+#define _nbio_6_1_SMN_HEADER
+
+
+#define smnCPM_CONTROL                                 0x11180460
+#define smnPCIE_CNTL2                                  0x11180070
+#define smnPCIE_CONFIG_CNTL                            0x11180044
+#define smnPCIE_CI_CNTL                                        0x11180080
+
+
+#define smnPCIE_PERF_COUNT_CNTL                                0x11180200
+#define smnPCIE_PERF_CNTL_TXCLK                                0x11180204
+#define smnPCIE_PERF_COUNT0_TXCLK                      0x11180208
+#define smnPCIE_PERF_COUNT1_TXCLK                      0x1118020c
+#define smnPCIE_PERF_CNTL_MST_R_CLK                    0x11180210
+#define smnPCIE_PERF_COUNT0_MST_R_CLK                  0x11180214
+#define smnPCIE_PERF_COUNT1_MST_R_CLK                  0x11180218
+#define smnPCIE_PERF_CNTL_MST_C_CLK                    0x1118021c
+#define smnPCIE_PERF_COUNT0_MST_C_CLK                  0x11180220
+#define smnPCIE_PERF_COUNT1_MST_C_CLK                  0x11180224
+#define smnPCIE_PERF_CNTL_SLV_R_CLK                    0x11180228
+#define smnPCIE_PERF_COUNT0_SLV_R_CLK                  0x1118022c
+#define smnPCIE_PERF_COUNT1_SLV_R_CLK                  0x11180230
+#define smnPCIE_PERF_CNTL_SLV_S_C_CLK                  0x11180234
+#define smnPCIE_PERF_COUNT0_SLV_S_C_CLK                        0x11180238
+#define smnPCIE_PERF_COUNT1_SLV_S_C_CLK                        0x1118023c
+#define smnPCIE_PERF_CNTL_SLV_NS_C_CLK                 0x11180240
+#define smnPCIE_PERF_COUNT0_SLV_NS_C_CLK               0x11180244
+#define smnPCIE_PERF_COUNT1_SLV_NS_C_CLK               0x11180248
+#define smnPCIE_PERF_CNTL_EVENT0_PORT_SEL              0x1118024c
+#define smnPCIE_PERF_CNTL_EVENT1_PORT_SEL              0x11180250
+#define smnPCIE_PERF_CNTL_TXCLK2                       0x11180254
+#define smnPCIE_PERF_COUNT0_TXCLK2                     0x11180258
+#define smnPCIE_PERF_COUNT1_TXCLK2                     0x1118025c
+
+#endif // _nbio_6_1_SMN_HEADER
+
drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_7_0_smn.h new file +55 -0
new file mode 100644
index 0000000..3ffd221
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2019  Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _nbio_7_0_SMN_HEADER
+#define _nbio_7_0_SMN_HEADER
+
+
+#define smnNBIF_MGCG_CTRL_LCLK                         0x1013a05c
+#define smnCPM_CONTROL                                 0x11180460
+#define smnPCIE_CNTL2                                  0x11180070
+
+#define smnPCIE_PERF_COUNT_CNTL                                0x11180200
+#define smnPCIE_PERF_CNTL_TXCLK                                0x11180204
+#define smnPCIE_PERF_COUNT0_TXCLK                      0x11180208
+#define smnPCIE_PERF_COUNT1_TXCLK                      0x1118020c
+#define smnPCIE_PERF_CNTL_MST_R_CLK                    0x11180210
+#define smnPCIE_PERF_COUNT0_MST_R_CLK                  0x11180214
+#define smnPCIE_PERF_COUNT1_MST_R_CLK                  0x11180218
+#define smnPCIE_PERF_CNTL_MST_C_CLK                    0x1118021c
+#define smnPCIE_PERF_COUNT0_MST_C_CLK                  0x11180220
+#define smnPCIE_PERF_COUNT1_MST_C_CLK                  0x11180224
+#define smnPCIE_PERF_CNTL_SLV_R_CLK                    0x11180228
+#define smnPCIE_PERF_COUNT0_SLV_R_CLK                  0x1118022c
+#define smnPCIE_PERF_COUNT1_SLV_R_CLK                  0x11180230
+#define smnPCIE_PERF_CNTL_SLV_S_C_CLK                  0x11180234
+#define smnPCIE_PERF_COUNT0_SLV_S_C_CLK                        0x11180238
+#define smnPCIE_PERF_COUNT1_SLV_S_C_CLK                        0x1118023c
+#define smnPCIE_PERF_CNTL_SLV_NS_C_CLK                 0x11180240
+#define smnPCIE_PERF_COUNT0_SLV_NS_C_CLK               0x11180244
+#define smnPCIE_PERF_COUNT1_SLV_NS_C_CLK               0x11180248
+#define smnPCIE_PERF_CNTL_EVENT0_PORT_SEL              0x1118024c
+#define smnPCIE_PERF_CNTL_EVENT1_PORT_SEL              0x11180250
+#define smnPCIE_PERF_CNTL_TXCLK2                       0x11180254
+#define smnPCIE_PERF_COUNT0_TXCLK2                     0x11180258
+#define smnPCIE_PERF_COUNT1_TXCLK2                     0x1118025c
+
+#endif // _nbio_7_0_SMN_HEADER
drivers/gpu/drm/amd/include/asic_reg/nbio/nbio_7_4_0_smn.h new file +53 -1
new file mode 100644
index 0000000..c1457d8
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2019  Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _nbio_7_4_0_SMN_HEADER
+#define _nbio_7_4_0_SMN_HEADER
+
+
+#define smnNBIF_MGCG_CTRL_LCLK                         0x1013a21c
+#define smnCPM_CONTROL                                 0x11180460
+#define smnPCIE_CNTL2                                  0x11180070
+#define smnPCIE_CI_CNTL                                        0x11180080
+
+#define smnPCIE_PERF_COUNT_CNTL                                0x11180200
+#define smnPCIE_PERF_CNTL_TXCLK1                       0x11180204
+#define smnPCIE_PERF_COUNT0_TXCLK1                     0x11180208
+#define smnPCIE_PERF_COUNT1_TXCLK1                     0x1118020c
+#define smnPCIE_PERF_CNTL_TXCLK2                       0x11180210
+#define smnPCIE_PERF_COUNT0_TXCLK2                     0x11180214
+#define smnPCIE_PERF_COUNT1_TXCLK2                     0x11180218
+#define smnPCIE_PERF_CNTL_TXCLK3                       0x1118021c
+#define smnPCIE_PERF_COUNT0_TXCLK3                     0x11180220
+#define smnPCIE_PERF_COUNT1_TXCLK3                     0x11180224
+#define smnPCIE_PERF_CNTL_TXCLK4                       0x11180228
+#define smnPCIE_PERF_COUNT0_TXCLK4                     0x1118022c
+#define smnPCIE_PERF_COUNT1_TXCLK4                     0x11180230
+#define smnPCIE_PERF_CNTL_SCLK1                                0x11180234
+#define smnPCIE_PERF_COUNT0_SCLK1                      0x11180238
+#define smnPCIE_PERF_COUNT1_SCLK1                      0x1118023c
+#define smnPCIE_PERF_CNTL_SCLK2                                0x11180240
+#define smnPCIE_PERF_COUNT0_SCLK2                      0x11180244
+#define smnPCIE_PERF_COUNT1_SCLK2                      0x11180248
+#define smnPCIE_PERF_CNTL_EVENT_LC_PORT_SEL            0x1118024c
+#define smnPCIE_PERF_CNTL_EVENT_CI_PORT_SEL            0x11180250
+
+#endif // _nbio_7_4_0_SMN_HEADER
--

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