All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: refactoring the runtime pm mode detection code
@ 2024-03-29  8:28 Ma Jun
  2024-04-02  3:43 ` Ma, Jun
  2024-04-02  4:16 ` Lazar, Lijo
  0 siblings, 2 replies; 4+ messages in thread
From: Ma Jun @ 2024-03-29  8:28 UTC (permalink / raw)
  To: amd-gfx; +Cc: Kenneth.Feng, Alexander.Deucher, kevinyang.wang, lijo.lazar,
	Ma Jun

refactor the code of runtime pm mode detection to support
amdgpu_runtime_pm =2 and 1 two cases

Signed-off-by: Ma Jun <Jun.Ma2@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 68 ++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    | 48 +--------------
 3 files changed, 70 insertions(+), 47 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 3723235f5818..4358d8c630b2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1408,6 +1408,7 @@ bool amdgpu_device_supports_px(struct drm_device *dev);
 bool amdgpu_device_supports_boco(struct drm_device *dev);
 bool amdgpu_device_supports_smart_shift(struct drm_device *dev);
 int amdgpu_device_supports_baco(struct drm_device *dev);
+void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev);
 bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
 				      struct amdgpu_device *peer_adev);
 int amdgpu_device_baco_enter(struct drm_device *dev);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 410f878462bc..ca117f2666bc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -350,6 +350,74 @@ int amdgpu_device_supports_baco(struct drm_device *dev)
 	return amdgpu_asic_supports_baco(adev);
 }
 
+void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev)
+{
+	struct drm_device *dev;
+	int bamaco_support = 0;
+
+	dev = adev_to_drm(adev);
+
+	adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
+	bamaco_support = amdgpu_device_supports_baco(dev);
+
+	if (amdgpu_runtime_pm == 2) {
+		if (bamaco_support == (BACO_SUPPORT | MACO_SUPPORT)) {
+			adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
+			dev_info(adev->dev, "Forcing BAMACO for runtime pm\n");
+		} else if (bamaco_support == BACO_SUPPORT) {
+			adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
+			dev_info(adev->dev, "Forcing BACO for runtime pm\n");
+		}
+	} else if (amdgpu_runtime_pm == 1) {
+		if (bamaco_support == BACO_SUPPORT) {
+			adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
+			dev_info(adev->dev, "Forcing BACO for runtime pm\n");
+		}
+	} else if (amdgpu_runtime_pm == -1 || amdgpu_runtime_pm == -2) {
+		if (amdgpu_device_supports_px(dev)) { /* enable PX as runtime mode */
+			adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
+			dev_info(adev->dev, "Using ATPX for runtime pm\n");
+		} else if (amdgpu_device_supports_boco(dev)) { /* enable boco as runtime mode */
+			adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
+			dev_info(adev->dev, "Using BOCO for runtime pm\n");
+		} else {
+			if (!bamaco_support)
+				goto no_runtime_pm;
+
+			switch (adev->asic_type) {
+			case CHIP_VEGA20:
+			case CHIP_ARCTURUS:
+				/* BACO are not supported on vega20 and arctrus */
+				break;
+			case CHIP_VEGA10:
+				/* enable BACO as runpm mode if noretry=0 */
+				if (!adev->gmc.noretry)
+					adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
+				break;
+			default:
+				/* enable BACO as runpm mode on CI+ */
+				adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
+				break;
+			}
+
+			if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) {
+				if (bamaco_support & MACO_SUPPORT) {
+					adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
+					dev_info(adev->dev, "Using BAMACO for runtime pm\n");
+				} else {
+					dev_info(adev->dev, "Using BACO for runtime pm\n");
+				}
+			}
+		}
+
+	} else {
+		dev_info(adev->dev, "runtime pm is manually disabled\n");
+	}
+
+no_runtime_pm:
+	if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
+		dev_info(adev->dev, "NO pm mode for runtime pm\n");
+}
 /**
  * amdgpu_device_supports_smart_shift - Is the device dGPU with
  * smart shift support
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 5d1b084eb631..924baf58e322 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -133,7 +133,6 @@ void amdgpu_register_gpu_instance(struct amdgpu_device *adev)
 int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
 {
 	struct drm_device *dev;
-	int bamaco_support = 0;
 	int r, acpi_status;
 
 	dev = adev_to_drm(adev);
@@ -150,52 +149,7 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
 		goto out;
 	}
 
-	adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
-	if (amdgpu_device_supports_px(dev) &&
-	    (amdgpu_runtime_pm != 0)) { /* enable PX as runtime mode */
-		adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
-		dev_info(adev->dev, "Using ATPX for runtime pm\n");
-	} else if (amdgpu_device_supports_boco(dev) &&
-		   (amdgpu_runtime_pm != 0)) { /* enable boco as runtime mode */
-		adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
-		dev_info(adev->dev, "Using BOCO for runtime pm\n");
-	} else if (amdgpu_runtime_pm != 0) {
-		bamaco_support = amdgpu_device_supports_baco(dev);
-
-		if (!bamaco_support)
-			goto no_runtime_pm;
-
-		switch (adev->asic_type) {
-		case CHIP_VEGA20:
-		case CHIP_ARCTURUS:
-			/* enable BACO as runpm mode if runpm=1 */
-			if (amdgpu_runtime_pm > 0)
-				adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
-			break;
-		case CHIP_VEGA10:
-			/* enable BACO as runpm mode if noretry=0 */
-			if (!adev->gmc.noretry)
-				adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
-			break;
-		default:
-			/* enable BACO as runpm mode on CI+ */
-			adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
-			break;
-		}
-
-		if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) {
-			if (bamaco_support & MACO_SUPPORT) {
-				adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
-				dev_info(adev->dev, "Using BAMACO for runtime pm\n");
-			} else {
-				dev_info(adev->dev, "Using BACO for runtime pm\n");
-			}
-		}
-	}
-
-no_runtime_pm:
-	if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
-		dev_info(adev->dev, "NO pm mode for runtime pm\n");
+	amdgpu_device_detect_runtime_pm_mode(adev);
 
 	/* Call ACPI methods: require modeset init
 	 * but failure is not fatal
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/amdgpu: refactoring the runtime pm mode detection code
  2024-03-29  8:28 [PATCH] drm/amdgpu: refactoring the runtime pm mode detection code Ma Jun
@ 2024-04-02  3:43 ` Ma, Jun
  2024-04-02  4:07   ` Wang, Yang(Kevin)
  2024-04-02  4:16 ` Lazar, Lijo
  1 sibling, 1 reply; 4+ messages in thread
From: Ma, Jun @ 2024-04-02  3:43 UTC (permalink / raw)
  To: Ma Jun, amd-gfx
  Cc: majun, Kenneth.Feng, Alexander.Deucher, kevinyang.wang,
	lijo.lazar

ping...

Regards,
Ma Jun

On 3/29/2024 4:28 PM, Ma Jun wrote:
> refactor the code of runtime pm mode detection to support
> amdgpu_runtime_pm =2 and 1 two cases
> 
> Signed-off-by: Ma Jun <Jun.Ma2@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 68 ++++++++++++++++++++++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    | 48 +--------------
>  3 files changed, 70 insertions(+), 47 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 3723235f5818..4358d8c630b2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1408,6 +1408,7 @@ bool amdgpu_device_supports_px(struct drm_device *dev);
>  bool amdgpu_device_supports_boco(struct drm_device *dev);
>  bool amdgpu_device_supports_smart_shift(struct drm_device *dev);
>  int amdgpu_device_supports_baco(struct drm_device *dev);
> +void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev);
>  bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
>  				      struct amdgpu_device *peer_adev);
>  int amdgpu_device_baco_enter(struct drm_device *dev);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 410f878462bc..ca117f2666bc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -350,6 +350,74 @@ int amdgpu_device_supports_baco(struct drm_device *dev)
>  	return amdgpu_asic_supports_baco(adev);
>  }
>  
> +void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev)
> +{
> +	struct drm_device *dev;
> +	int bamaco_support = 0;
> +
> +	dev = adev_to_drm(adev);
> +
> +	adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
> +	bamaco_support = amdgpu_device_supports_baco(dev);
> +
> +	if (amdgpu_runtime_pm == 2) {
> +		if (bamaco_support == (BACO_SUPPORT | MACO_SUPPORT)) {
> +			adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
> +			dev_info(adev->dev, "Forcing BAMACO for runtime pm\n");
> +		} else if (bamaco_support == BACO_SUPPORT) {
> +			adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> +			dev_info(adev->dev, "Forcing BACO for runtime pm\n");
> +		}
> +	} else if (amdgpu_runtime_pm == 1) {
> +		if (bamaco_support == BACO_SUPPORT) {
> +			adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> +			dev_info(adev->dev, "Forcing BACO for runtime pm\n");
> +		}
> +	} else if (amdgpu_runtime_pm == -1 || amdgpu_runtime_pm == -2) {
> +		if (amdgpu_device_supports_px(dev)) { /* enable PX as runtime mode */
> +			adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
> +			dev_info(adev->dev, "Using ATPX for runtime pm\n");
> +		} else if (amdgpu_device_supports_boco(dev)) { /* enable boco as runtime mode */
> +			adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
> +			dev_info(adev->dev, "Using BOCO for runtime pm\n");
> +		} else {
> +			if (!bamaco_support)
> +				goto no_runtime_pm;
> +
> +			switch (adev->asic_type) {
> +			case CHIP_VEGA20:
> +			case CHIP_ARCTURUS:
> +				/* BACO are not supported on vega20 and arctrus */
> +				break;
> +			case CHIP_VEGA10:
> +				/* enable BACO as runpm mode if noretry=0 */
> +				if (!adev->gmc.noretry)
> +					adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> +				break;
> +			default:
> +				/* enable BACO as runpm mode on CI+ */
> +				adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> +				break;
> +			}
> +
> +			if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) {
> +				if (bamaco_support & MACO_SUPPORT) {
> +					adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
> +					dev_info(adev->dev, "Using BAMACO for runtime pm\n");
> +				} else {
> +					dev_info(adev->dev, "Using BACO for runtime pm\n");
> +				}
> +			}
> +		}
> +
> +	} else {
> +		dev_info(adev->dev, "runtime pm is manually disabled\n");
> +	}
> +
> +no_runtime_pm:
> +	if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
> +		dev_info(adev->dev, "NO pm mode for runtime pm\n");
> +}
>  /**
>   * amdgpu_device_supports_smart_shift - Is the device dGPU with
>   * smart shift support
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 5d1b084eb631..924baf58e322 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -133,7 +133,6 @@ void amdgpu_register_gpu_instance(struct amdgpu_device *adev)
>  int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
>  {
>  	struct drm_device *dev;
> -	int bamaco_support = 0;
>  	int r, acpi_status;
>  
>  	dev = adev_to_drm(adev);
> @@ -150,52 +149,7 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
>  		goto out;
>  	}
>  
> -	adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
> -	if (amdgpu_device_supports_px(dev) &&
> -	    (amdgpu_runtime_pm != 0)) { /* enable PX as runtime mode */
> -		adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
> -		dev_info(adev->dev, "Using ATPX for runtime pm\n");
> -	} else if (amdgpu_device_supports_boco(dev) &&
> -		   (amdgpu_runtime_pm != 0)) { /* enable boco as runtime mode */
> -		adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
> -		dev_info(adev->dev, "Using BOCO for runtime pm\n");
> -	} else if (amdgpu_runtime_pm != 0) {
> -		bamaco_support = amdgpu_device_supports_baco(dev);
> -
> -		if (!bamaco_support)
> -			goto no_runtime_pm;
> -
> -		switch (adev->asic_type) {
> -		case CHIP_VEGA20:
> -		case CHIP_ARCTURUS:
> -			/* enable BACO as runpm mode if runpm=1 */
> -			if (amdgpu_runtime_pm > 0)
> -				adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> -			break;
> -		case CHIP_VEGA10:
> -			/* enable BACO as runpm mode if noretry=0 */
> -			if (!adev->gmc.noretry)
> -				adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> -			break;
> -		default:
> -			/* enable BACO as runpm mode on CI+ */
> -			adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> -			break;
> -		}
> -
> -		if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) {
> -			if (bamaco_support & MACO_SUPPORT) {
> -				adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
> -				dev_info(adev->dev, "Using BAMACO for runtime pm\n");
> -			} else {
> -				dev_info(adev->dev, "Using BACO for runtime pm\n");
> -			}
> -		}
> -	}
> -
> -no_runtime_pm:
> -	if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
> -		dev_info(adev->dev, "NO pm mode for runtime pm\n");
> +	amdgpu_device_detect_runtime_pm_mode(adev);
>  
>  	/* Call ACPI methods: require modeset init
>  	 * but failure is not fatal

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] drm/amdgpu: refactoring the runtime pm mode detection code
  2024-04-02  3:43 ` Ma, Jun
@ 2024-04-02  4:07   ` Wang, Yang(Kevin)
  0 siblings, 0 replies; 4+ messages in thread
From: Wang, Yang(Kevin) @ 2024-04-02  4:07 UTC (permalink / raw)
  To: Ma, Jun, amd-gfx@lists.freedesktop.org
  Cc: Feng, Kenneth, Deucher, Alexander, Lazar, Lijo

[AMD Official Use Only - General]

-----Original Message-----
From: Ma, Jun <Jun.Ma2@amd.com>
Sent: Tuesday, April 2, 2024 11:44 AM
To: Ma, Jun <Jun.Ma2@amd.com>; amd-gfx@lists.freedesktop.org
Cc: Ma, Jun <Jun.Ma2@amd.com>; Feng, Kenneth <Kenneth.Feng@amd.com>; Deucher, Alexander <Alexander.Deucher@amd.com>; Wang, Yang(Kevin) <KevinYang.Wang@amd.com>; Lazar, Lijo <Lijo.Lazar@amd.com>
Subject: Re: [PATCH] drm/amdgpu: refactoring the runtime pm mode detection code

ping...

Regards,
Ma Jun

On 3/29/2024 4:28 PM, Ma Jun wrote:
> refactor the code of runtime pm mode detection to support
> amdgpu_runtime_pm =2 and 1 two cases
>
> Signed-off-by: Ma Jun <Jun.Ma2@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 68 ++++++++++++++++++++++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    | 48 +--------------
>  3 files changed, 70 insertions(+), 47 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 3723235f5818..4358d8c630b2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1408,6 +1408,7 @@ bool amdgpu_device_supports_px(struct drm_device
> *dev);  bool amdgpu_device_supports_boco(struct drm_device *dev);
> bool amdgpu_device_supports_smart_shift(struct drm_device *dev);  int
> amdgpu_device_supports_baco(struct drm_device *dev);
> +void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device
> +*adev);
>  bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
>                                     struct amdgpu_device *peer_adev);  int
> amdgpu_device_baco_enter(struct drm_device *dev); diff --git
> a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 410f878462bc..ca117f2666bc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -350,6 +350,74 @@ int amdgpu_device_supports_baco(struct drm_device *dev)
>       return amdgpu_asic_supports_baco(adev);  }
>
> +void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev)
> +{
> +     struct drm_device *dev;
> +     int bamaco_support = 0;
> +
> +     dev = adev_to_drm(adev);
> +
> +     adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
> +     bamaco_support = amdgpu_device_supports_baco(dev);
> +
> +     if (amdgpu_runtime_pm == 2) {
> +             if (bamaco_support == (BACO_SUPPORT | MACO_SUPPORT)) {
> +                     adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
> +                     dev_info(adev->dev, "Forcing BAMACO for runtime pm\n");
> +             } else if (bamaco_support == BACO_SUPPORT) {
> +                     adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> +                     dev_info(adev->dev, "Forcing BACO for runtime pm\n");
> +             }
> +     } else if (amdgpu_runtime_pm == 1) {
> +             if (bamaco_support == BACO_SUPPORT) {
> +                     adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> +                     dev_info(adev->dev, "Forcing BACO for runtime pm\n");
> +             }
> +     } else if (amdgpu_runtime_pm == -1 || amdgpu_runtime_pm == -2) {
> +             if (amdgpu_device_supports_px(dev)) { /* enable PX as runtime mode */
> +                     adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
> +                     dev_info(adev->dev, "Using ATPX for runtime pm\n");
> +             } else if (amdgpu_device_supports_boco(dev)) { /* enable boco as runtime mode */
> +                     adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
> +                     dev_info(adev->dev, "Using BOCO for runtime pm\n");
> +             } else {
> +                     if (!bamaco_support)
> +                             goto no_runtime_pm;
> +
> +                     switch (adev->asic_type) {
> +                     case CHIP_VEGA20:
> +                     case CHIP_ARCTURUS:
> +                             /* BACO are not supported on vega20 and arctrus */
> +                             break;
> +                     case CHIP_VEGA10:
> +                             /* enable BACO as runpm mode if noretry=0 */
> +                             if (!adev->gmc.noretry)
> +                                     adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> +                             break;
> +                     default:
> +                             /* enable BACO as runpm mode on CI+ */
> +                             adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> +                             break;
> +                     }
> +
> +                     if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) {
> +                             if (bamaco_support & MACO_SUPPORT) {
> +                                     adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
> +                                     dev_info(adev->dev, "Using BAMACO for runtime pm\n");
> +                             } else {
> +                                     dev_info(adev->dev, "Using BACO for runtime pm\n");
> +                             }
> +                     }
> +             }
> +
> +     } else {
> +             dev_info(adev->dev, "runtime pm is manually disabled\n");
> +     }

[kevin]:

Better to use switch...case instead of if..else to make code clean for above code.
Anyway, Reviewed-by: Yang Wang <kevinyang.wang@amd.com>

Best Regards,
Kevin
> +
> +no_runtime_pm:
> +     if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
> +             dev_info(adev->dev, "NO pm mode for runtime pm\n"); }
>  /**
>   * amdgpu_device_supports_smart_shift - Is the device dGPU with
>   * smart shift support
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 5d1b084eb631..924baf58e322 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -133,7 +133,6 @@ void amdgpu_register_gpu_instance(struct
> amdgpu_device *adev)  int amdgpu_driver_load_kms(struct amdgpu_device
> *adev, unsigned long flags)  {
>       struct drm_device *dev;
> -     int bamaco_support = 0;
>       int r, acpi_status;
>
>       dev = adev_to_drm(adev);
> @@ -150,52 +149,7 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
>               goto out;
>       }
>
> -     adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
> -     if (amdgpu_device_supports_px(dev) &&
> -         (amdgpu_runtime_pm != 0)) { /* enable PX as runtime mode */
> -             adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
> -             dev_info(adev->dev, "Using ATPX for runtime pm\n");
> -     } else if (amdgpu_device_supports_boco(dev) &&
> -                (amdgpu_runtime_pm != 0)) { /* enable boco as runtime mode */
> -             adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
> -             dev_info(adev->dev, "Using BOCO for runtime pm\n");
> -     } else if (amdgpu_runtime_pm != 0) {
> -             bamaco_support = amdgpu_device_supports_baco(dev);
> -
> -             if (!bamaco_support)
> -                     goto no_runtime_pm;
> -
> -             switch (adev->asic_type) {
> -             case CHIP_VEGA20:
> -             case CHIP_ARCTURUS:
> -                     /* enable BACO as runpm mode if runpm=1 */
> -                     if (amdgpu_runtime_pm > 0)
> -                             adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> -                     break;
> -             case CHIP_VEGA10:
> -                     /* enable BACO as runpm mode if noretry=0 */
> -                     if (!adev->gmc.noretry)
> -                             adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> -                     break;
> -             default:
> -                     /* enable BACO as runpm mode on CI+ */
> -                     adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> -                     break;
> -             }
> -
> -             if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) {
> -                     if (bamaco_support & MACO_SUPPORT) {
> -                             adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
> -                             dev_info(adev->dev, "Using BAMACO for runtime pm\n");
> -                     } else {
> -                             dev_info(adev->dev, "Using BACO for runtime pm\n");
> -                     }
> -             }
> -     }
> -
> -no_runtime_pm:
> -     if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
> -             dev_info(adev->dev, "NO pm mode for runtime pm\n");
> +     amdgpu_device_detect_runtime_pm_mode(adev);
>
>       /* Call ACPI methods: require modeset init
>        * but failure is not fatal

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/amdgpu: refactoring the runtime pm mode detection code
  2024-03-29  8:28 [PATCH] drm/amdgpu: refactoring the runtime pm mode detection code Ma Jun
  2024-04-02  3:43 ` Ma, Jun
@ 2024-04-02  4:16 ` Lazar, Lijo
  1 sibling, 0 replies; 4+ messages in thread
From: Lazar, Lijo @ 2024-04-02  4:16 UTC (permalink / raw)
  To: Ma Jun, amd-gfx; +Cc: Kenneth.Feng, Alexander.Deucher, kevinyang.wang



On 3/29/2024 1:58 PM, Ma Jun wrote:
> refactor the code of runtime pm mode detection to support
> amdgpu_runtime_pm =2 and 1 two cases
> 
> Signed-off-by: Ma Jun <Jun.Ma2@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 68 ++++++++++++++++++++++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    | 48 +--------------
>  3 files changed, 70 insertions(+), 47 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 3723235f5818..4358d8c630b2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1408,6 +1408,7 @@ bool amdgpu_device_supports_px(struct drm_device *dev);
>  bool amdgpu_device_supports_boco(struct drm_device *dev);
>  bool amdgpu_device_supports_smart_shift(struct drm_device *dev);
>  int amdgpu_device_supports_baco(struct drm_device *dev);
> +void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev);
>  bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
>  				      struct amdgpu_device *peer_adev);
>  int amdgpu_device_baco_enter(struct drm_device *dev);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 410f878462bc..ca117f2666bc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -350,6 +350,74 @@ int amdgpu_device_supports_baco(struct drm_device *dev)
>  	return amdgpu_asic_supports_baco(adev);
>  }
>  
> +void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev)
> +{
> +	struct drm_device *dev;
> +	int bamaco_support = 0;

This initialization is not required.
> +
> +	dev = adev_to_drm(adev);
> +
> +	adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
> +	bamaco_support = amdgpu_device_supports_baco(dev);
> +
> +	if (amdgpu_runtime_pm == 2) {
> +		if (bamaco_support == (BACO_SUPPORT | MACO_SUPPORT)) {

Better to check only if MACO is supported as that's the user preference.

> +			adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
> +			dev_info(adev->dev, "Forcing BAMACO for runtime pm\n");
> +		} else if (bamaco_support == BACO_SUPPORT) {
> +			adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> +			dev_info(adev->dev, "Forcing BACO for runtime pm\n");

Maybe change this so that user doesn't get confused - "Requested mode
BAMACO not available, fallback to use BACO"

> +		}
> +	} else if (amdgpu_runtime_pm == 1) {
> +		if (bamaco_support == BACO_SUPPORT) {

Use & instead of ==. This could also mean SOC supports both MACO and
BACO, but user prefers BACO for runpm.

> +			adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> +			dev_info(adev->dev, "Forcing BACO for runtime pm\n");
> +		}
> +	} else if (amdgpu_runtime_pm == -1 || amdgpu_runtime_pm == -2) {
> +		if (amdgpu_device_supports_px(dev)) { /* enable PX as runtime mode */
> +			adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
> +			dev_info(adev->dev, "Using ATPX for runtime pm\n");
> +		} else if (amdgpu_device_supports_boco(dev)) { /* enable boco as runtime mode */
> +			adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
> +			dev_info(adev->dev, "Using BOCO for runtime pm\n");
> +		} else {
> +			if (!bamaco_support)
> +				goto no_runtime_pm;
> +
> +			switch (adev->asic_type) {
> +			case CHIP_VEGA20:
> +			case CHIP_ARCTURUS:
> +				/* BACO are not supported on vega20 and arctrus */
> +				break;
> +			case CHIP_VEGA10:
> +				/* enable BACO as runpm mode if noretry=0 */
> +				if (!adev->gmc.noretry)
> +					adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> +				break;
> +			default:
> +				/* enable BACO as runpm mode on CI+ */
> +				adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> +				break;
> +			}
> +
> +			if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) {
> +				if (bamaco_support & MACO_SUPPORT) {
> +					adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
> +					dev_info(adev->dev, "Using BAMACO for runtime pm\n");
> +				} else {
> +					dev_info(adev->dev, "Using BACO for runtime pm\n");
> +				}
> +			}
> +		}
> +
> +	} else {
> +		dev_info(adev->dev, "runtime pm is manually disabled\n");
> +	}
> +
> +no_runtime_pm:
> +	if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
> +		dev_info(adev->dev, "NO pm mode for runtime pm\n");

Maybe put this differently - "Runtime PM not available"

Thanks,
Lijo

> +}
>  /**
>   * amdgpu_device_supports_smart_shift - Is the device dGPU with
>   * smart shift support
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 5d1b084eb631..924baf58e322 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -133,7 +133,6 @@ void amdgpu_register_gpu_instance(struct amdgpu_device *adev)
>  int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
>  {
>  	struct drm_device *dev;
> -	int bamaco_support = 0;
>  	int r, acpi_status;
>  
>  	dev = adev_to_drm(adev);
> @@ -150,52 +149,7 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
>  		goto out;
>  	}
>  
> -	adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
> -	if (amdgpu_device_supports_px(dev) &&
> -	    (amdgpu_runtime_pm != 0)) { /* enable PX as runtime mode */
> -		adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
> -		dev_info(adev->dev, "Using ATPX for runtime pm\n");
> -	} else if (amdgpu_device_supports_boco(dev) &&
> -		   (amdgpu_runtime_pm != 0)) { /* enable boco as runtime mode */
> -		adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
> -		dev_info(adev->dev, "Using BOCO for runtime pm\n");
> -	} else if (amdgpu_runtime_pm != 0) {
> -		bamaco_support = amdgpu_device_supports_baco(dev);
> -
> -		if (!bamaco_support)
> -			goto no_runtime_pm;
> -
> -		switch (adev->asic_type) {
> -		case CHIP_VEGA20:
> -		case CHIP_ARCTURUS:
> -			/* enable BACO as runpm mode if runpm=1 */
> -			if (amdgpu_runtime_pm > 0)
> -				adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> -			break;
> -		case CHIP_VEGA10:
> -			/* enable BACO as runpm mode if noretry=0 */
> -			if (!adev->gmc.noretry)
> -				adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> -			break;
> -		default:
> -			/* enable BACO as runpm mode on CI+ */
> -			adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
> -			break;
> -		}
> -
> -		if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) {
> -			if (bamaco_support & MACO_SUPPORT) {
> -				adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
> -				dev_info(adev->dev, "Using BAMACO for runtime pm\n");
> -			} else {
> -				dev_info(adev->dev, "Using BACO for runtime pm\n");
> -			}
> -		}
> -	}
> -
> -no_runtime_pm:
> -	if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
> -		dev_info(adev->dev, "NO pm mode for runtime pm\n");
> +	amdgpu_device_detect_runtime_pm_mode(adev);
>  
>  	/* Call ACPI methods: require modeset init
>  	 * but failure is not fatal

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-02  4:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-29  8:28 [PATCH] drm/amdgpu: refactoring the runtime pm mode detection code Ma Jun
2024-04-02  3:43 ` Ma, Jun
2024-04-02  4:07   ` Wang, Yang(Kevin)
2024-04-02  4:16 ` Lazar, Lijo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.