RE: [PATCH] drm/amdgpu: support dpm level modification under virtualization v3

2019-04-10 Thread Quan, Evan
Reviewed-by: Evan Quan 

> -Original Message-
> From: amd-gfx  On Behalf Of
> Yintian Tao
> Sent: Wednesday, April 10, 2019 10:26 PM
> To: amd-gfx@lists.freedesktop.org
> Cc: Tao, Yintian 
> Subject: [PATCH] drm/amdgpu: support dpm level modification under
> virtualization v3
> 
> Under vega10 virtualuzation, smu ip block will not be added.
> Therefore, we need add pp clk query and force dpm level function at
> amdgpu_virt_ops to support the feature.
> 
> v2: add get_pp_clk existence check and use kzalloc to allocate buf
> 
> v3: return -ENOMEM for allocation failure and correct the coding style
> 
> Change-Id: I713419c57b854082f6f739f1d32a055c7115e620
> Signed-off-by: Yintian Tao 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c|  4 ++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 15 ++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 49
> +++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   | 11 +
>  drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c  | 78
> ++
>  drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h  |  6 +++
>  7 files changed, 164 insertions(+)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 3ff8899..bb0fd5a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -2486,6 +2486,7 @@ int amdgpu_device_init(struct amdgpu_device
> *adev,
>   mutex_init(>virt.vf_errors.lock);
>   hash_init(adev->mn_hash);
>   mutex_init(>lock_reset);
> + mutex_init(>virt.dpm_mutex);
> 
>   amdgpu_device_check_arguments(adev);
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 6190495..29ec28f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -727,6 +727,10 @@ static int amdgpu_info_ioctl(struct drm_device *dev,
> void *data, struct drm_file
>   if (adev->pm.dpm_enabled) {
>   dev_info.max_engine_clock =
> amdgpu_dpm_get_sclk(adev, false) * 10;
>   dev_info.max_memory_clock =
> amdgpu_dpm_get_mclk(adev, false) * 10;
> + } else if (amdgpu_sriov_vf(adev) &&
> amdgim_is_hwperf(adev) &&
> +adev->virt.ops->get_pp_clk) {
> + dev_info.max_engine_clock =
> amdgpu_virt_get_sclk(adev, false) * 10;
> + dev_info.max_memory_clock =
> amdgpu_virt_get_mclk(adev, false) * 10;
>   } else {
>   dev_info.max_engine_clock = adev-
> >clock.default_sclk * 10;
>   dev_info.max_memory_clock = adev-
> >clock.default_mclk * 10; diff --git
> a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> index 5540259..0162d1e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> @@ -380,6 +380,17 @@ static ssize_t
> amdgpu_set_dpm_forced_performance_level(struct device *dev,
>   goto fail;
>   }
> 
> +if (amdgpu_sriov_vf(adev)) {
> +if (amdgim_is_hwperf(adev) &&
> +adev->virt.ops->force_dpm_level) {
> +mutex_lock(>pm.mutex);
> +adev->virt.ops->force_dpm_level(adev, level);
> +mutex_unlock(>pm.mutex);
> +return count;
> +} else
> +return -EINVAL;
> +}
> +
>   if (current_level == level)
>   return count;
> 
> @@ -843,6 +854,10 @@ static ssize_t amdgpu_get_pp_dpm_sclk(struct
> device *dev,
>   struct drm_device *ddev = dev_get_drvdata(dev);
>   struct amdgpu_device *adev = ddev->dev_private;
> 
> + if (amdgpu_sriov_vf(adev) && amdgim_is_hwperf(adev) &&
> + adev->virt.ops->get_pp_clk)
> + return adev->virt.ops->get_pp_clk(adev, PP_SCLK, buf);
> +
>   if (is_support_sw_smu(adev))
>   return smu_print_clk_levels(>smu, PP_SCLK, buf);
>   else if (adev->powerplay.pp_funcs->print_clock_levels)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> index 462a04e..7e7f9ed 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> @@ -375,4 +375,53 @@ void amdgpu_virt_init_data_exchange(struct
> amdgpu_device *adev)
>   }
>  }
> 
> 

RE: [PATCH] drm/amdgpu: support dpm level modification under virtualization v3

2019-04-10 Thread Tao, Yintian
Hi Alex

Many thanks for your review.

Best Regards
Yintian Tao

-Original Message-
From: Alex Deucher  
Sent: Wednesday, April 10, 2019 11:32 PM
To: Tao, Yintian 
Cc: amd-gfx list 
Subject: Re: [PATCH] drm/amdgpu: support dpm level modification under 
virtualization v3

On Wed, Apr 10, 2019 at 10:25 AM Yintian Tao  wrote:
>
> Under vega10 virtualuzation, smu ip block will not be added.
> Therefore, we need add pp clk query and force dpm level function at 
> amdgpu_virt_ops to support the feature.
>
> v2: add get_pp_clk existence check and use kzalloc to allocate buf
>
> v3: return -ENOMEM for allocation failure and correct the coding style
>
> Change-Id: I713419c57b854082f6f739f1d32a055c7115e620
> Signed-off-by: Yintian Tao 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c|  4 ++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 15 ++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 49 +++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   | 11 +
>  drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c  | 78 
> ++
>  drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h  |  6 +++
>  7 files changed, 164 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 3ff8899..bb0fd5a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -2486,6 +2486,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
> mutex_init(>virt.vf_errors.lock);
> hash_init(adev->mn_hash);
> mutex_init(>lock_reset);
> +   mutex_init(>virt.dpm_mutex);
>
> amdgpu_device_check_arguments(adev);
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 6190495..29ec28f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -727,6 +727,10 @@ static int amdgpu_info_ioctl(struct drm_device *dev, 
> void *data, struct drm_file
> if (adev->pm.dpm_enabled) {
> dev_info.max_engine_clock = amdgpu_dpm_get_sclk(adev, 
> false) * 10;
> dev_info.max_memory_clock = 
> amdgpu_dpm_get_mclk(adev, false) * 10;
> +   } else if (amdgpu_sriov_vf(adev) && amdgim_is_hwperf(adev) &&
> +  adev->virt.ops->get_pp_clk) {
> +   dev_info.max_engine_clock = 
> amdgpu_virt_get_sclk(adev, false) * 10;
> +   dev_info.max_memory_clock = 
> + amdgpu_virt_get_mclk(adev, false) * 10;
> } else {
> dev_info.max_engine_clock = adev->clock.default_sclk 
> * 10;
> dev_info.max_memory_clock = 
> adev->clock.default_mclk * 10; diff --git 
> a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> index 5540259..0162d1e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> @@ -380,6 +380,17 @@ static ssize_t 
> amdgpu_set_dpm_forced_performance_level(struct device *dev,
> goto fail;
> }
>
> +if (amdgpu_sriov_vf(adev)) {
> +if (amdgim_is_hwperf(adev) &&
> +adev->virt.ops->force_dpm_level) {
> +mutex_lock(>pm.mutex);
> +adev->virt.ops->force_dpm_level(adev, level);
> +mutex_unlock(>pm.mutex);
> +return count;
> +} else
> +return -EINVAL;

Coding style.  If any clause as parens, all should.  E.g., this should be :

} else {
return -EINVAL;
}

With that fixed, this patch is:
Reviewed-by: Alex Deucher 

> +}
> +
> if (current_level == level)
> return count;
>
> @@ -843,6 +854,10 @@ static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
> struct drm_device *ddev = dev_get_drvdata(dev);
> struct amdgpu_device *adev = ddev->dev_private;
>
> +   if (amdgpu_sriov_vf(adev) && amdgim_is_hwperf(adev) &&
> +   adev->virt.ops->get_pp_clk)
> +   return adev->virt.ops->get_pp_clk(adev, PP_SCLK, buf);
> +
> if (is_support_sw_smu(adev))
> return smu_print_clk_levels(>smu, PP_SCLK, buf);
> else if (adev->powerplay.pp_funcs->print_clock_levels)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> inde

Re: [PATCH] drm/amdgpu: support dpm level modification under virtualization v3

2019-04-10 Thread Alex Deucher
On Wed, Apr 10, 2019 at 10:25 AM Yintian Tao  wrote:
>
> Under vega10 virtualuzation, smu ip block will not be added.
> Therefore, we need add pp clk query and force dpm level function
> at amdgpu_virt_ops to support the feature.
>
> v2: add get_pp_clk existence check and use kzalloc to allocate buf
>
> v3: return -ENOMEM for allocation failure and correct the coding style
>
> Change-Id: I713419c57b854082f6f739f1d32a055c7115e620
> Signed-off-by: Yintian Tao 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c|  4 ++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 15 ++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 49 +++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   | 11 +
>  drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c  | 78 
> ++
>  drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h  |  6 +++
>  7 files changed, 164 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 3ff8899..bb0fd5a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -2486,6 +2486,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
> mutex_init(>virt.vf_errors.lock);
> hash_init(adev->mn_hash);
> mutex_init(>lock_reset);
> +   mutex_init(>virt.dpm_mutex);
>
> amdgpu_device_check_arguments(adev);
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 6190495..29ec28f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -727,6 +727,10 @@ static int amdgpu_info_ioctl(struct drm_device *dev, 
> void *data, struct drm_file
> if (adev->pm.dpm_enabled) {
> dev_info.max_engine_clock = amdgpu_dpm_get_sclk(adev, 
> false) * 10;
> dev_info.max_memory_clock = amdgpu_dpm_get_mclk(adev, 
> false) * 10;
> +   } else if (amdgpu_sriov_vf(adev) && amdgim_is_hwperf(adev) &&
> +  adev->virt.ops->get_pp_clk) {
> +   dev_info.max_engine_clock = 
> amdgpu_virt_get_sclk(adev, false) * 10;
> +   dev_info.max_memory_clock = 
> amdgpu_virt_get_mclk(adev, false) * 10;
> } else {
> dev_info.max_engine_clock = adev->clock.default_sclk 
> * 10;
> dev_info.max_memory_clock = adev->clock.default_mclk 
> * 10;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> index 5540259..0162d1e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> @@ -380,6 +380,17 @@ static ssize_t 
> amdgpu_set_dpm_forced_performance_level(struct device *dev,
> goto fail;
> }
>
> +if (amdgpu_sriov_vf(adev)) {
> +if (amdgim_is_hwperf(adev) &&
> +adev->virt.ops->force_dpm_level) {
> +mutex_lock(>pm.mutex);
> +adev->virt.ops->force_dpm_level(adev, level);
> +mutex_unlock(>pm.mutex);
> +return count;
> +} else
> +return -EINVAL;

Coding style.  If any clause as parens, all should.  E.g., this should be :

} else {
return -EINVAL;
}

With that fixed, this patch is:
Reviewed-by: Alex Deucher 

> +}
> +
> if (current_level == level)
> return count;
>
> @@ -843,6 +854,10 @@ static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
> struct drm_device *ddev = dev_get_drvdata(dev);
> struct amdgpu_device *adev = ddev->dev_private;
>
> +   if (amdgpu_sriov_vf(adev) && amdgim_is_hwperf(adev) &&
> +   adev->virt.ops->get_pp_clk)
> +   return adev->virt.ops->get_pp_clk(adev, PP_SCLK, buf);
> +
> if (is_support_sw_smu(adev))
> return smu_print_clk_levels(>smu, PP_SCLK, buf);
> else if (adev->powerplay.pp_funcs->print_clock_levels)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> index 462a04e..7e7f9ed 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> @@ -375,4 +375,53 @@ void amdgpu_virt_init_data_exchange(struct amdgpu_device 
> *adev)
> }
>  }
>
> +static uint32_t parse_clk(char *buf, bool min)
> +{
> +char *ptr = buf;
> +uint32_t clk = 0;
> +
> +do {
> +ptr = strchr(ptr, ':');
> +if (!ptr)
> +break;
> +ptr+=2;
> +clk = simple_strtoul(ptr, NULL, 10);
> +} while (!min);
> +
> +return clk * 100;
> +}
> +
> +uint32_t amdgpu_virt_get_sclk(struct amdgpu_device *adev, bool lowest)
> +{

[PATCH] drm/amdgpu: support dpm level modification under virtualization v3

2019-04-10 Thread Yintian Tao
Under vega10 virtualuzation, smu ip block will not be added.
Therefore, we need add pp clk query and force dpm level function
at amdgpu_virt_ops to support the feature.

v2: add get_pp_clk existence check and use kzalloc to allocate buf

v3: return -ENOMEM for allocation failure and correct the coding style

Change-Id: I713419c57b854082f6f739f1d32a055c7115e620
Signed-off-by: Yintian Tao 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c|  4 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 15 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 49 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   | 11 +
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c  | 78 ++
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h  |  6 +++
 7 files changed, 164 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 3ff8899..bb0fd5a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -2486,6 +2486,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
mutex_init(>virt.vf_errors.lock);
hash_init(adev->mn_hash);
mutex_init(>lock_reset);
+   mutex_init(>virt.dpm_mutex);
 
amdgpu_device_check_arguments(adev);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 6190495..29ec28f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -727,6 +727,10 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void 
*data, struct drm_file
if (adev->pm.dpm_enabled) {
dev_info.max_engine_clock = amdgpu_dpm_get_sclk(adev, 
false) * 10;
dev_info.max_memory_clock = amdgpu_dpm_get_mclk(adev, 
false) * 10;
+   } else if (amdgpu_sriov_vf(adev) && amdgim_is_hwperf(adev) &&
+  adev->virt.ops->get_pp_clk) {
+   dev_info.max_engine_clock = amdgpu_virt_get_sclk(adev, 
false) * 10;
+   dev_info.max_memory_clock = amdgpu_virt_get_mclk(adev, 
false) * 10;
} else {
dev_info.max_engine_clock = adev->clock.default_sclk * 
10;
dev_info.max_memory_clock = adev->clock.default_mclk * 
10;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 5540259..0162d1e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -380,6 +380,17 @@ static ssize_t 
amdgpu_set_dpm_forced_performance_level(struct device *dev,
goto fail;
}
 
+if (amdgpu_sriov_vf(adev)) {
+if (amdgim_is_hwperf(adev) &&
+adev->virt.ops->force_dpm_level) {
+mutex_lock(>pm.mutex);
+adev->virt.ops->force_dpm_level(adev, level);
+mutex_unlock(>pm.mutex);
+return count;
+} else
+return -EINVAL;
+}
+
if (current_level == level)
return count;
 
@@ -843,6 +854,10 @@ static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
struct drm_device *ddev = dev_get_drvdata(dev);
struct amdgpu_device *adev = ddev->dev_private;
 
+   if (amdgpu_sriov_vf(adev) && amdgim_is_hwperf(adev) &&
+   adev->virt.ops->get_pp_clk)
+   return adev->virt.ops->get_pp_clk(adev, PP_SCLK, buf);
+
if (is_support_sw_smu(adev))
return smu_print_clk_levels(>smu, PP_SCLK, buf);
else if (adev->powerplay.pp_funcs->print_clock_levels)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index 462a04e..7e7f9ed 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -375,4 +375,53 @@ void amdgpu_virt_init_data_exchange(struct amdgpu_device 
*adev)
}
 }
 
+static uint32_t parse_clk(char *buf, bool min)
+{
+char *ptr = buf;
+uint32_t clk = 0;
+
+do {
+ptr = strchr(ptr, ':');
+if (!ptr)
+break;
+ptr+=2;
+clk = simple_strtoul(ptr, NULL, 10);
+} while (!min);
+
+return clk * 100;
+}
+
+uint32_t amdgpu_virt_get_sclk(struct amdgpu_device *adev, bool lowest)
+{
+   char *buf = NULL;
+   uint32_t clk = 0;
+
+   buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
+   adev->virt.ops->get_pp_clk(adev, PP_SCLK, buf);
+   clk = parse_clk(buf, lowest);
+
+   kfree(buf);
+
+   return clk;
+}
+
+uint32_t amdgpu_virt_get_mclk(struct amdgpu_device *adev, bool lowest)
+{
+   char *buf = NULL;
+   uint32_t clk = 0;
+
+   buf =