Adjustments to _PR3 detection
Subsystems (2)
cover Adjustments to _PR3 detection
As part of reviewing a recent issue with BOCO I looked more closely at what we're doing for _PR3 detection.
We used to look at the immediate link partner of the GPU PCIe device to detect _PR3. This was wrong because dGPUs have internal PCIe switches and those switches won't have _PR3.
So I changed it a few years back to look at the root port. This worked correctly for some common cases, but I realized that if you have a bridge between (for example a B650) then you might end up in the wrong power state for either of these cases:
* Bridge supports _PR3 but CPU root port doesn't
* CPU root port supports _PR3 but bridge doesn't
Both of those cases could lead to actually using the wrong power management for the dGPU.
So this series adjusts the detection to look at the link partner of the first PCIe device "outside of the dGPU" instead of the root port.
Mario Limonciello (2):
drm/amd: Add dedicated helper for amdgpu_device_find_parent() drm/amd: Adjust _PR3 detection
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 51 +++++++++++----------- 1 file changed, 25 insertions(+), 26 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 drm/amd: Add dedicated helper for amdgpu_device_find_parent()
There are a few cases that code walks up the topology to find the link partner of the integrated switch in a dGPU. Split this out to a helper and call in all places.
This does have a functional change that amdgpu_device_gpu_bandwidth() doesn't cache the internal link but only the parent.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 44 +++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +23 -21
@@ -1913,6 +1913,19 @@ static void amdgpu_uid_fini(struct amdgpu_device *adev) adev->uid_info =NULL ; } +static struct pci_dev *amdgpu_device_find_parent (struct amdgpu_device *adev) +{ +struct pci_dev *parent = adev->pdev; + +/* skip upstream/downstream switches internal to dGPU */ +while ((parent =pci_upstream_bridge (parent))) { +if (parent->vendor ==PCI_VENDOR_ID_ATI ) +continue ; + } + +return parent; +} +/** * amdgpu_device_ip_early_init - run early init for hardware IPs *
@@ -5913,8 +5926,6 @@ static void amdgpu_device_partner_bandwidth(struct amdgpu_device *adev, enum pci_bus_speed *speed, enum pcie_link_width *width) { - struct pci_dev *parent = adev->pdev; -if (!speed || !width)return ;
@@ -5922,13 +5933,11 @@ static void amdgpu_device_partner_bandwidth(struct amdgpu_device *adev, *width =PCIE_LNK_WIDTH_UNKNOWN ;if (amdgpu_device_pcie_dynamic_switching_supported (adev)) { -while ((parent =pci_upstream_bridge (parent))) { -/* skip upstream/downstream switches internal to dGPU*/ -if (parent->vendor ==PCI_VENDOR_ID_ATI ) -continue ; +struct pci_dev *parent =amdgpu_device_find_parent (adev); + +if (parent) { *speed =pcie_get_speed_cap (parent); *width =pcie_get_width_cap (parent); -break ; } }else {/* use the current speeds rather than max if switching is not supported */
@@ -5955,22 +5964,15 @@ static void amdgpu_device_gpu_bandwidth(struct amdgpu_device *adev,if (!speed || !width)return ; - parent =pci_upstream_bridge (parent); -if (parent && parent->vendor ==PCI_VENDOR_ID_ATI ) { -/* use the upstream/downstream switches internal to dGPU */ +/* use the device itself */ + *speed =pcie_get_speed_cap (adev->pdev); + *width =pcie_get_width_cap (adev->pdev); + +/* use the link outside the device */ + parent =amdgpu_device_find_parent (adev); +if (parent) { *speed =pcie_get_speed_cap (parent); *width =pcie_get_width_cap (parent); -while ((parent =pci_upstream_bridge (parent))) { -if (parent->vendor ==PCI_VENDOR_ID_ATI ) { -/* use the upstream/downstream switches internal to dGPU */ - *speed =pcie_get_speed_cap (parent); - *width =pcie_get_width_cap (parent); - } - } - }else { -/* use the device itself */ - *speed =pcie_get_speed_cap (adev->pdev); - *width =pcie_get_width_cap (adev->pdev); } }
Signature · 1 line
2.43.0
Re: [PATCH 1/2] drm/amd: Add dedicated helper for amdgpu_device_find_parent()
Hi Mario,
(re-sending to the list)
Note that this breaks PCIe info reported to userspace via drm_amdgpu_info_device. Previously it reported the PCIe info corresponding to what the GPU uses such that the maximum available PCIe bandwidth could be calculated. Now it reports the PCIe info supported by the host PCIe. E.g. on a card with gen 4 and 8 lanes, it reports gen 5 and 16 lanes.
Userspace depends on correct numbers to make performance decisions.
Marek
Quoted 96 lines · Mario Limonciello
There are a few cases that code walks up the topology to find the link partner of the integrated switch in a dGPU. Split this out to a helper and call in all places.
This does have a functional change that
amdgpu_device_gpu_bandwidth()doesn't cache the internal link but only the parent.Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 44 +++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +23
-22@@ -1913,6 +1913,19 @@ static void amdgpu_uid_fini(struct amdgpu_device *adev) adev->uid_info =NULL ; } +static struct pci_dev *amdgpu_device_find_parent (struct amdgpu_device *adev) +{ +struct pci_dev *parent = adev->pdev; + +/* skip upstream/downstream switches internal to dGPU */ +while ((parent =pci_upstream_bridge (parent))) { +if (parent->vendor ==PCI_VENDOR_ID_ATI ) +continue ; + } + +return parent; +} +/** * amdgpu_device_ip_early_init - run early init for hardware IPs * @@ -5913,8 +5926,6 @@ static void amdgpu_device_partner_bandwidth(struct amdgpu_device *adev, enum pci_bus_speed *speed, enum pcie_link_width *width) { - struct pci_dev *parent = adev->pdev; -if (!speed || !width)return ;@@ -5922,13 +5933,11 @@ static void amdgpu_device_partner_bandwidth(struct amdgpu_device *adev, *width =PCIE_LNK_WIDTH_UNKNOWN ;if (amdgpu_device_pcie_dynamic_switching_supported (adev)) { -while ((parent =pci_upstream_bridge (parent))) { -/* skip upstream/downstream switches internal to dGPU*/ -if (parent->vendor ==PCI_VENDOR_ID_ATI ) -continue ; +struct pci_dev *parent =amdgpu_device_find_parent (adev); + +if (parent) { *speed =pcie_get_speed_cap (parent); *width =pcie_get_width_cap (parent); -break ; } }else {/* use the current speeds rather than max if switching is not supported */ @@ -5955,22 +5964,15 @@ static void amdgpu_device_gpu_bandwidth(struct amdgpu_device *adev,if (!speed || !width)return ; - parent =pci_upstream_bridge (parent); -if (parent && parent->vendor ==PCI_VENDOR_ID_ATI ) { -/* use the upstream/downstream switches internal to dGPU */ +/* use the device itself */ + *speed =pcie_get_speed_cap (adev->pdev); + *width =pcie_get_width_cap (adev->pdev); + +/* use the link outside the device */ + parent =amdgpu_device_find_parent (adev); +if (parent) { *speed =pcie_get_speed_cap (parent); *width =pcie_get_width_cap (parent); -while ((parent =pci_upstream_bridge (parent))) { -if (parent->vendor ==PCI_VENDOR_ID_ATI ) { -/* use the upstream/downstream switches internal to dGPU */ - *speed =pcie_get_speed_cap (parent); - *width =pcie_get_width_cap (parent); - } - } - }else { -/* use the device itself */ - *speed =pcie_get_speed_cap (adev->pdev); - *width =pcie_get_width_cap (adev->pdev); } } --2.43.0
Re: [PATCH 1/2] drm/amd: Add dedicated helper for amdgpu_device_find_parent()
In reply to Mario LimoncielloQuoted 65 lines · Mario Limonciello
There are a few cases that code walks up the topology to find the link partner of the integrated switch in a dGPU. Split this out to a helper and call in all places.
This does have a functional change that
amdgpu_device_gpu_bandwidth()doesn't cache the internal link but only the parent.Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 44 +++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +16
-7@@ -1913,6 +1913,19 @@ static void amdgpu_uid_fini(struct amdgpu_device *adev) adev->uid_info =NULL ; } +static struct pci_dev *amdgpu_device_find_parent (struct amdgpu_device *adev) +{ +struct pci_dev *parent = adev->pdev; + +/* skip upstream/downstream switches internal to dGPU */ +while ((parent =pci_upstream_bridge (parent))) { +if (parent->vendor ==PCI_VENDOR_ID_ATI ) +continue ; + } + +return parent; +} +/** * amdgpu_device_ip_early_init - run early init for hardware IPs * @@ -5913,8 +5926,6 @@ static void amdgpu_device_partner_bandwidth(struct amdgpu_device *adev, enum pci_bus_speed *speed, enum pcie_link_width *width) { - struct pci_dev *parent = adev->pdev; -if (!speed || !width)return ;@@ -5922,13 +5933,11 @@ static void amdgpu_device_partner_bandwidth(struct amdgpu_device *adev, *width =PCIE_LNK_WIDTH_UNKNOWN ;if (amdgpu_device_pcie_dynamic_switching_supported (adev)) { -while ((parent =pci_upstream_bridge (parent))) { -/* skip upstream/downstream switches internal to dGPU*/ -if (parent->vendor ==PCI_VENDOR_ID_ATI ) -continue ; +struct pci_dev *parent =amdgpu_device_find_parent (adev); + +if (parent) { *speed =pcie_get_speed_cap (parent); *width =pcie_get_width_cap (parent); -break ; } }else {/* use the current speeds rather than max if switching is not supported */ @@ -5955,22 +5964,15 @@ static void amdgpu_device_gpu_bandwidth(struct amdgpu_device *adev,if (!speed || !width)return ;
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_device_gpu_bandwidth(struct amdgpu_device *adev, · line 5972
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6
-3- parent =pci_upstream_bridge (parent); -if (parent && parent->vendor ==PCI_VENDOR_ID_ATI ) { -/* use the upstream/downstream switches internal to dGPU */ +/* use the device itself */ + *speed =pcie_get_speed_cap (adev->pdev); + *width =pcie_get_width_cap (adev->pdev); + +/* use the link outside the device */ + parent =amdgpu_device_find_parent (adev);
This is for GPU device's bandwidth and not the parent device. Suggest to cache both pdevs separately as link_dev (device which is connected to actual physical link) and link_partner (the other end of link) one-time during init. That will avoid confusion.
Thanks,
Lijo
Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-11+if (parent) { *speed =pcie_get_speed_cap (parent); *width =pcie_get_width_cap (parent); -while ((parent =pci_upstream_bridge (parent))) { -if (parent->vendor ==PCI_VENDOR_ID_ATI ) { -/* use the upstream/downstream switches internal to dGPU */ - *speed =pcie_get_speed_cap (parent); - *width =pcie_get_width_cap (parent); - } - } - }else { -/* use the device itself */ - *speed =pcie_get_speed_cap (adev->pdev); - *width =pcie_get_width_cap (adev->pdev); } }
Re: [PATCH 1/2] drm/amd: Add dedicated helper for amdgpu_device_find_parent()
+Christian (re-sending for the list)
Quoted 106 lines · Lijo
Quoted 65 lines · Mario Limonciello
There are a few cases that code walks up the topology to find the link partner of the integrated switch in a dGPU. Split this out to a helper and call in all places.
This does have a functional change that
amdgpu_device_gpu_bandwidth()doesn't cache the internal link but only the parent.Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 44 +++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +16
-7@@ -1913,6 +1913,19 @@ static void amdgpu_uid_fini(struct amdgpu_device *adev) adev->uid_info =NULL ; } +static struct pci_dev *amdgpu_device_find_parent (struct amdgpu_device *adev) +{ +struct pci_dev *parent = adev->pdev; + +/* skip upstream/downstream switches internal to dGPU */ +while ((parent =pci_upstream_bridge (parent))) { +if (parent->vendor ==PCI_VENDOR_ID_ATI ) +continue ; + } + +return parent; +} +/** * amdgpu_device_ip_early_init - run early init for hardware IPs * @@ -5913,8 +5926,6 @@ static void amdgpu_device_partner_bandwidth(struct amdgpu_device *adev, enum pci_bus_speed *speed, enum pcie_link_width *width) { - struct pci_dev *parent = adev->pdev; -if (!speed || !width)return ;@@ -5922,13 +5933,11 @@ static void amdgpu_device_partner_bandwidth(struct amdgpu_device *adev, *width =PCIE_LNK_WIDTH_UNKNOWN ;if (amdgpu_device_pcie_dynamic_switching_supported (adev)) { -while ((parent =pci_upstream_bridge (parent))) { -/* skip upstream/downstream switches internal to dGPU*/ -if (parent->vendor ==PCI_VENDOR_ID_ATI ) -continue ; +struct pci_dev *parent =amdgpu_device_find_parent (adev); + +if (parent) { *speed =pcie_get_speed_cap (parent); *width =pcie_get_width_cap (parent); -break ; } }else {/* use the current speeds rather than max if switching is not supported */ @@ -5955,22 +5964,15 @@ static void amdgpu_device_gpu_bandwidth(struct amdgpu_device *adev,if (!speed || !width)return ;drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_device_gpu_bandwidth(struct amdgpu_device *adev, · line 5972
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6
-3- parent =pci_upstream_bridge (parent); -if (parent && parent->vendor ==PCI_VENDOR_ID_ATI ) { -/* use the upstream/downstream switches internal to dGPU */ +/* use the device itself */ + *speed =pcie_get_speed_cap (adev->pdev); + *width =pcie_get_width_cap (adev->pdev); + +/* use the link outside the device */ + parent =amdgpu_device_find_parent (adev);This is for GPU device's bandwidth and not the parent device. Suggest to cache both pdevs separately as
link_dev(device which is connected to actual physical link) andlink_partner(the other end of link) one-time during init. That will avoid confusion.Thanks,
LijoQuoted 17 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-11+if (parent) { *speed =pcie_get_speed_cap (parent); *width =pcie_get_width_cap (parent); -while ((parent =pci_upstream_bridge (parent))) { -if (parent->vendor ==PCI_VENDOR_ID_ATI ) { -/* use the upstream/downstream switches internal to dGPU */ - *speed =pcie_get_speed_cap (parent); - *width =pcie_get_width_cap (parent); - } - } - }else { -/* use the device itself */ - *speed =pcie_get_speed_cap (adev->pdev); - *width =pcie_get_width_cap (adev->pdev); } }
PATCH 2/2 drm/amd: Adjust _PR3 detection
In reply to Mario Limonciello_PR3 detection was changed in commit 134b8c5d8674e ("drm/amd: Fix detection of _PR3 on the PCIe root port") to look at the root port of the topology containing the GPU. This however was too far because it ignored whether or not all the intermediary bridges could power off the device. The original design in commit b10c1c5b3a4e3 ("drm/amdgpu:
add check for ACPI power resources") was too narrow because it matched the switches internal to the GPU.
Use the goldilocks approach and look for the first bridge outside of the GPU and check for _PR3 on that device.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -5
@@ -1939,7 +1939,6 @@ static struct pci_dev *amdgpu_device_find_parent(struct amdgpu_device *adev)static int amdgpu_device_ip_early_init (struct amdgpu_device *adev) {struct amdgpu_ip_block *ip_block; -struct pci_dev *parent;bool total, skip_bios;uint32_t bios_flags;int i, r;
@@ -2026,10 +2025,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev) !dev_is_removable(&adev->pdev->dev)) adev->flags |=AMD_IS_PX ; -if (!(adev->flags &AMD_IS_APU )) { - parent =pcie_find_root_port (adev->pdev); - adev->has_pr3 = parent ?pci_pr3_present (parent) : false; - } +if (!(adev->flags &AMD_IS_APU )) + adev->has_pr3 =pci_pr3_present (amdgpu_device_find_parent (adev)); adev->pm.pp_feature = amdgpu_pp_feature_mask;if (amdgpu_sriov_vf (adev) || sched_policy ==KFD_SCHED_POLICY_NO_HWS )
Signature · 1 line
2.43.0
Re: [PATCH 2/2] drm/amd: Adjust _PR3 detection
Quoted 9 lines · Mario Limonciello
_PR3detection was changed in commit134b8c5d8674e("drm/amd: Fix detection of_PR3on the PCIe root port") to look at the root port of the topology containing the GPU. This however was too far because it ignored whether or not all the intermediary bridges could power off the device. The original design in commitb10c1c5b3a4e3("drm/amdgpu:
add check for ACPI power resources") was too narrow because it matched the switches internal to the GPU.
Quoted 5 lines
Use the goldilocks approach and look for the first bridge outside of the GPU and check for
_PR3on that device.Fixes 134b8c5d8674e ("drm/amd: Fix detection of _PR3 on the PCIe root port")Signed-off-by Mario Limonciello <[email protected]>
Series is:
Quoted 32 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-6@@ -1939,7 +1939,6 @@ static struct pci_dev *amdgpu_device_find_parent(struct amdgpu_device *adev)static int amdgpu_device_ip_early_init (struct amdgpu_device *adev) {struct amdgpu_ip_block *ip_block; -struct pci_dev *parent;bool total, skip_bios;uint32_t bios_flags;int i, r;@@ -2026,10 +2025,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev) !dev_is_removable(&adev->pdev->dev)) adev->flags |=AMD_IS_PX ; -if (!(adev->flags &AMD_IS_APU )) { - parent =pcie_find_root_port (adev->pdev); - adev->has_pr3 = parent ?pci_pr3_present (parent) : false; - } +if (!(adev->flags &AMD_IS_APU )) + adev->has_pr3 =pci_pr3_present (amdgpu_device_find_parent (adev)); adev->pm.pp_feature = amdgpu_pp_feature_mask;if (amdgpu_sriov_vf (adev) || sched_policy ==KFD_SCHED_POLICY_NO_HWS ) --2.43.0