[pull] amdgpu drm-next-5.2

2019-04-10 Thread Alex Deucher
Hi Dave, Daniel,

More stuff for 5.2:
- Fixes for powerplay custom profiles
- DC bandwidth clean ups and fixes
- RAS fixes for vega20
- DC atomic resume fix
- Better plane handling in DC
- Freesync improvements
- Misc bug fixes and cleanups

The following changes since commit 5ebffda257731a11cf1db6c6142c82d5b30aec35:

  Merge commit 'refs/for-upstream/mali-dp' of git://linux-arm.org/linux-ld into 
drm-next (2019-04-03 13:44:40 +1000)

are available in the Git repository at:

  git://people.freedesktop.org/~agd5f/linux drm-next-5.2

for you to fetch changes up to fe6382cd69de98802455e77040c6e00d9e12cc47:

  drm/amd/display: fix is odm head pipe logic (2019-04-10 13:53:28 -0500)


Aidan Wood (1):
  drm/amd/display: Fix multi-thread writing to 1 state

Anthony Koo (2):
  drm/amd/display: init dc_config before rest of DC init
  drm/amd/display: disable link before changing link settings

Aric Cyr (1):
  drm/amd/display: 3.2.25

Christian König (3):
  drm/amdgpu: fix ATC handling for Ryzen
  drm/amdgpu: handle leaf PDEs as PTEs on Vega
  drm/amdgpu: provide the page fault queue to the VM code

Dmytro Laktyushkin (2):
  drm/amd/display: fix clk_mgr naming
  drm/amd/display: fix is odm head pipe logic

Emily Deng (1):
  drm/amdgpu: Correct the irq types' num of sdma

Eric Yang (1):
  drm/amd/display: fix underflow on boot

Evan Quan (1):
  drm/amd/powerplay: check for invalid profile mode before switching

Josip Pavic (1):
  drm/amd/display: remove min reduction for abm 2.2 level 3

Kent Russell (3):
  drm/amdgpu: Allow switching to CUSTOM profile on smu7 v2
  drm/amdgpu: Allow switching to CUSTOM profile on Vega10 v2
  drm/amdgpu: Allow switching to CUSTOM profile on Vega20

Kevin Wang (2):
  drm/amd/powerplay: optimization function of smu_update_table
  drm/amd/powerplay: simplify the code of [get|set]_activity_monitor_coeff

Leo Li (3):
  drm/amd/display: Fix "dc has no member named dml" compile error
  drm/amd/display: Recreate private_obj->state during S3 resume
  drm/amd/display: Clean up locking in dcn*_apply_ctx_for_surface()

Mario Kleiner (5):
  drm/amd/display: Update VRR state earlier in atomic_commit_tail.
  drm/amd/display: Prevent vblank irq disable while VRR is active. (v3)
  drm/amd/display: Rework vrr flip throttling for late vblank irq.
  drm/amd/display: In VRR mode, do DRM core vblank handling at end of 
vblank. (v2)
  drm/amd/display: Make pageflip event delivery compatible with VRR.

Murton Liu (1):
  drm/amd/display: HDR visual confirmation incorrectly reports black color

Nicholas Kazlauskas (7):
  drm/amd/display: Prevent cursor hotspot overflow for RV overlay planes
  drm/amd/display: Remove semicolon from to_dm_plane_state definition
  drm/amd/display: Initialize stream_update with memset
  drm/amd/display: Add debugfs entry for amdgpu_dm_visual_confirm
  drm/amd/display: Use plane->color_space for dpp if specified
  drm/amd/display: Set surface color space from DRM plane state
  drm/amd/display: Pass plane caps into amdgpu_dm_plane_init

Nikola Cornij (1):
  drm/amd/display: Calculate link bandwidth in a common function

SivapiriyanKumarasamy (2):
  drm/amd/display: fix dp_hdmi_max_pixel_clk units
  drm/amd/display: Call hwss.set_cursor_sdr_white_level, if available

Su Sung Chung (1):
  drm/amd/display: return correct dc_status for dcn10_validate_global

Wenjing Liu (2):
  drm/amd/display: use proper formula to calculate bandwidth from timing
  drm/amd/display: prefer preferred link cap over verified link settings

Yintian Tao (1):
  drm/amdgpu: support dpm level modification under virtualization v3

shaoyunl (3):
  drm/amdgpu: Adjust TMR address alignment as per HW requirement
  drm/amdgpu: Add preferred_domain check when determine XGMI state
  drm/amdgpu: Always enable memory sharing within same XGMI hive

xinhui pan (6):
  drm/amdgpu: Make default ras error type to none
  drm/amdgpu: Introduce another ras enable function
  drm/amdgpu: gfx use amdgpu_ras_feature_enable_on_boot
  drm/amdgpu: gmc use amdgpu_ras_feature_enable_on_boot
  drm/amdgpu: sdma use amdgpu_ras_feature_enable_on_boot
  drm/amdgpu: Add a check to avoid panic because of unexpected irqs

 drivers/gpu/drm/amd/amdgpu/amdgpu.h|   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c|  11 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c|   4 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h   |   4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c |  16 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c|   6 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c|  51 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h|   3 +
 

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)
>   }
>  }
> 
> +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)

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

2019-04-10 Thread Kuehling, Felix
How does forcing DPM levels work in SRIOV? Can clocks switch fast enough to 
allow different VFs have different clocks? If not, can one VF override the 
clocks used by another VF? In that case, wouldn't that violate the isolation 
between VFs?

Regards,
  Felix

-Original Message-
From: amd-gfx  On Behalf Of Yintian Tao
Sent: Tuesday, April 9, 2019 11:18
To: amd-gfx@lists.freedesktop.org
Cc: Tao, Yintian 
Subject: [PATCH] drm/amdgpu: support dpm level modification under virtualization

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.

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|  3 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 15 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 33 +
 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, 147 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..1353955 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -727,6 +727,9 @@ 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)) {
+   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..ae4b2a1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -375,4 +375,37 @@ 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[512] = {0};
+
+adev->virt.ops->get_pp_clk(adev, PP_SCLK, buf);
+
+return parse_clk(buf, lowest);
+}
+
+uint32_t amdgpu_virt_get_mclk(struct 

[pull] amdgpu, amdkfd drm-fixes-5.1

2019-04-10 Thread Alex Deucher
Hi Dave, Daniel,

A few fixes for 5.1:
- Cursor fixes
- Add missing picasso pci id to KFD
- XGMI fix
- Shadow buffer handling fix for GPU reset

The following changes since commit d939f44d4a7f910755165458da20407d2139f581:

  drm/amdgpu: remove unnecessary rlc reset function on gfx9 (2019-04-02 
16:23:16 -0500)

are available in the Git repository at:

  git://people.freedesktop.org/~agd5f/linux drm-fixes-5.1

for you to fetch changes up to bd13b2b874eceb4677cd26eebdc5f45cc52fa400:

  drm/amd/display: Fix negative cursor pos programming (v2) (2019-04-08 
10:33:40 -0500)


Alex Deucher (1):
  drm/amdkfd: Add picasso pci id

Nicholas Kazlauskas (1):
  drm/amd/display: Fix negative cursor pos programming (v2)

shaoyunl (1):
  drm/amdgpu: Adjust IB test timeout for XGMI configuration

tiancyin (1):
  drm/amd/display: fix cursor black issue

wentalou (1):
  drm/amdgpu: amdgpu_device_recover_vram always failed if only one node in 
shadow_list

 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 13 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c|  3 +++
 drivers/gpu/drm/amd/amdkfd/kfd_device.c   |  1 +
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  1 +
 drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hubp.c | 23 ++-
 5 files changed, 16 insertions(+), 25 deletions(-)
___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Re: How to get useful information other than "the whole system locks up"?

2019-04-10 Thread Braiam
On Sat, Apr 6, 2019 at 3:25 PM Braiam  wrote:

>
> At this point I decided that the system isn't going to recover, so I
> tried to soft-reboot it, but it only ended locked and had to hard
> reboot.
>
> I've found this bug[1] that seems related, user watching videos. I
> will try removing vaapi and check if that improves anything.
>
> [1]: https://bugs.freedesktop.org/show_bug.cgi?id=106547
>

Removing libva didn't help. Lock ups still occur frequently.

A new symptom is that video doesn't need to be visible on the display
for the lockup to occur. -rc4 didn't improve the situation either.
Lockups are still instantaneous, I haven't had another one where the
gpu doesn't drag all the system.

-- 
Braiam
___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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
> 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, ':');
> +   

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)
> +{

Re: [PATCH 3/3] drm/amdgpu: Avoid HW reset if guilty job already signaled.

2019-04-10 Thread Koenig, Christian
Am 10.04.19 um 17:05 schrieb Grodzovsky, Andrey:
> On 4/10/19 10:41 AM, Christian König wrote:
>> Am 10.04.19 um 16:28 schrieb Grodzovsky, Andrey:
>>> On 4/10/19 10:06 AM, Christian König wrote:
 Am 09.04.19 um 18:42 schrieb Grodzovsky, Andrey:
> On 4/9/19 10:50 AM, Christian König wrote:
>> Am 08.04.19 um 18:08 schrieb Andrey Grodzovsky:
>>> Also reject TDRs if another one already running.
>>>
>>> Signed-off-by: Andrey Grodzovsky 
>>> ---
>>>      drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 94
>>> +-
>>>      1 file changed, 67 insertions(+), 27 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>>> index aabd043..4446892 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>>> @@ -3327,10 +3327,12 @@ bool amdgpu_device_should_recover_gpu(struct
>>> amdgpu_device *adev)
>>>        static int amdgpu_device_pre_asic_reset(struct amdgpu_device
>>> *adev,
>>>      struct amdgpu_job *job,
>>> -    bool *need_full_reset_arg)
>>> +    bool *need_full_reset_arg,
>>> +    bool *job_signaled)
>>>      {
>>>      int i, r = 0;
>>>      bool need_full_reset  = *need_full_reset_arg;
>>> +    struct amdgpu_ring *job_ring = job ?
>>> to_amdgpu_ring(job->base.sched) : NULL;
>>>        /* block all schedulers and reset given job's ring */
>>>      for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
>>> @@ -3341,6 +3343,17 @@ static int
>>> amdgpu_device_pre_asic_reset(struct
>>> amdgpu_device *adev,
>>>        drm_sched_stop(>sched, >base);
>>>      +    /*
>>> + * Must check guilty signal here since after this point
>>> all old
>>> + * HW fences are force signaled.
>>> + *
>>> + * job->base holds a reference to parent fence
>>> + */
>>> +    if (job_signaled && job && ring == job_ring &&
>>> +    job->base.s_fence->parent &&
>>> + dma_fence_is_signaled(job->base.s_fence->parent))
>>> +    *job_signaled = true;
>>> +
>> That won't work correctly. See when the guilty job is not on the
>> first
>> scheduler, you would already have force completed some before getting
>> here.
>>
>> Better to stop all schedulers first and then do the check.
>>
>> Christian.
> What do you mean by first scheduler ? There is one scheduler object
> per
> ring so I am not clear what 'first' means here.
 Well for example if the guilty job is from a compute ring the we have
 already force signaled the gfx ring here.

 Same is true for other devices in the same hive, so it would probably
 be a good idea to move the force signaling and the IP reset somewhere
 else and this check up a layer.

 Christian.
>>> Let me see if I understand you correctly - you want to AVOID ANY force
>>> signaling in case we are not going to HW reset and so you want to have
>>> the check if guilty is signaled BEFORE any ring fences are force
>>> signaled. Correct ?
>> Correct.
>>
>> Basically we should do the following:
>> 1. Stop all schedulers to make sure that nothing is going on.
>> 2. Check the guilty job once more to make sure that it hasn't signaled
>> in the meantime.
>> 3. Start our reset procedure, with force complete, soft reset
>> eventually hard reset etc etc..
>> 4. Resubmit all not yet completed jobs.
>> 5. Start the schedulers again.
>>
>> Christian.
>
> Why not just always ensure the guilty  job's ring is always checked
> first  and then do the rest of the rings - inside
> amdgpu_device_pre_asic_reset. Seems to me like a much smaller change
> with less impact to current code structure.

Well we want to make sure that nothing else is touching the hardware any 
more before we start with the reset procedure.

To be more precise force completing one ring could make some other 
scheduler think that it could go ahead and scheduler another job 
(because for example some hw resource (VMID?) now became available).

Not sure if that is currently a problem, but I still think the GPU reset 
code is still rather badly designed and we should rather make larger 
code changes than smaller.

Christian.

>
> Andrey
>
>
>>> Andrey
>>>
> Andrey
>
>
>>>      /* after all hw jobs are reset, hw fence is
>>> meaningless, so
>>> force_completion */
>>>      amdgpu_fence_driver_force_completion(ring);
>>>      }
>>> @@ -3358,7 +3371,8 @@ static int amdgpu_device_pre_asic_reset(struct
>>> amdgpu_device *adev,
>>>          -    if (!amdgpu_sriov_vf(adev)) {
>>> +    /* Don't suspend on bare metal if we are not going to HW reset
>>> the ASIC */
>>> 

Re: [PATCH 3/3] drm/amdgpu: Avoid HW reset if guilty job already signaled.

2019-04-10 Thread Grodzovsky, Andrey

On 4/10/19 10:41 AM, Christian König wrote:
> Am 10.04.19 um 16:28 schrieb Grodzovsky, Andrey:
>> On 4/10/19 10:06 AM, Christian König wrote:
>>> Am 09.04.19 um 18:42 schrieb Grodzovsky, Andrey:
 On 4/9/19 10:50 AM, Christian König wrote:
> Am 08.04.19 um 18:08 schrieb Andrey Grodzovsky:
>> Also reject TDRs if another one already running.
>>
>> Signed-off-by: Andrey Grodzovsky 
>> ---
>>     drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 94
>> +-
>>     1 file changed, 67 insertions(+), 27 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>> index aabd043..4446892 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>> @@ -3327,10 +3327,12 @@ bool amdgpu_device_should_recover_gpu(struct
>> amdgpu_device *adev)
>>       static int amdgpu_device_pre_asic_reset(struct amdgpu_device
>> *adev,
>>     struct amdgpu_job *job,
>> -    bool *need_full_reset_arg)
>> +    bool *need_full_reset_arg,
>> +    bool *job_signaled)
>>     {
>>     int i, r = 0;
>>     bool need_full_reset  = *need_full_reset_arg;
>> +    struct amdgpu_ring *job_ring = job ?
>> to_amdgpu_ring(job->base.sched) : NULL;
>>       /* block all schedulers and reset given job's ring */
>>     for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
>> @@ -3341,6 +3343,17 @@ static int 
>> amdgpu_device_pre_asic_reset(struct
>> amdgpu_device *adev,
>>       drm_sched_stop(>sched, >base);
>>     +    /*
>> + * Must check guilty signal here since after this point
>> all old
>> + * HW fences are force signaled.
>> + *
>> + * job->base holds a reference to parent fence
>> + */
>> +    if (job_signaled && job && ring == job_ring &&
>> +    job->base.s_fence->parent &&
>> + dma_fence_is_signaled(job->base.s_fence->parent))
>> +    *job_signaled = true;
>> +
> That won't work correctly. See when the guilty job is not on the 
> first
> scheduler, you would already have force completed some before getting
> here.
>
> Better to stop all schedulers first and then do the check.
>
> Christian.
 What do you mean by first scheduler ? There is one scheduler object 
 per
 ring so I am not clear what 'first' means here.
>>> Well for example if the guilty job is from a compute ring the we have
>>> already force signaled the gfx ring here.
>>>
>>> Same is true for other devices in the same hive, so it would probably
>>> be a good idea to move the force signaling and the IP reset somewhere
>>> else and this check up a layer.
>>>
>>> Christian.
>>
>> Let me see if I understand you correctly - you want to AVOID ANY force
>> signaling in case we are not going to HW reset and so you want to have
>> the check if guilty is signaled BEFORE any ring fences are force
>> signaled. Correct ?
>
> Correct.
>
> Basically we should do the following:
> 1. Stop all schedulers to make sure that nothing is going on.
> 2. Check the guilty job once more to make sure that it hasn't signaled 
> in the meantime.
> 3. Start our reset procedure, with force complete, soft reset 
> eventually hard reset etc etc..
> 4. Resubmit all not yet completed jobs.
> 5. Start the schedulers again.
>
> Christian.


Why not just always ensure the guilty  job's ring is always checked 
first  and then do the rest of the rings - inside 
amdgpu_device_pre_asic_reset. Seems to me like a much smaller change 
with less impact to current code structure.

Andrey


>
>>
>> Andrey
>>
 Andrey


>>     /* after all hw jobs are reset, hw fence is 
>> meaningless, so
>> force_completion */
>>     amdgpu_fence_driver_force_completion(ring);
>>     }
>> @@ -3358,7 +3371,8 @@ static int amdgpu_device_pre_asic_reset(struct
>> amdgpu_device *adev,
>>         -    if (!amdgpu_sriov_vf(adev)) {
>> +    /* Don't suspend on bare metal if we are not going to HW reset
>> the ASIC */
>> +    if (!amdgpu_sriov_vf(adev) && !(*job_signaled)) {
>>       if (!need_full_reset)
>>     need_full_reset =
>> amdgpu_device_ip_need_full_reset(adev);
>> @@ -3495,7 +3509,7 @@ static int amdgpu_do_asic_reset(struct
>> amdgpu_hive_info *hive,
>>     return r;
>>     }
>>     -static void amdgpu_device_post_asic_reset(struct amdgpu_device
>> *adev)
>> +static void amdgpu_device_post_asic_reset(struct amdgpu_device
>> *adev, bool job_signaled)
>>     {
>>     int i;
>>     @@ -3505,7 +3519,8 @@ static void
>> amdgpu_device_post_asic_reset(struct amdgpu_device *adev)
>>    

Re: [PATCH 3/3] drm/amdgpu: Avoid HW reset if guilty job already signaled.

2019-04-10 Thread Christian König

Am 10.04.19 um 16:28 schrieb Grodzovsky, Andrey:

On 4/10/19 10:06 AM, Christian König wrote:

Am 09.04.19 um 18:42 schrieb Grodzovsky, Andrey:

On 4/9/19 10:50 AM, Christian König wrote:

Am 08.04.19 um 18:08 schrieb Andrey Grodzovsky:

Also reject TDRs if another one already running.

Signed-off-by: Andrey Grodzovsky 
---
    drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 94
+-
    1 file changed, 67 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index aabd043..4446892 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -3327,10 +3327,12 @@ bool amdgpu_device_should_recover_gpu(struct
amdgpu_device *adev)
      static int amdgpu_device_pre_asic_reset(struct amdgpu_device
*adev,
    struct amdgpu_job *job,
-    bool *need_full_reset_arg)
+    bool *need_full_reset_arg,
+    bool *job_signaled)
    {
    int i, r = 0;
    bool need_full_reset  = *need_full_reset_arg;
+    struct amdgpu_ring *job_ring = job ?
to_amdgpu_ring(job->base.sched) : NULL;
      /* block all schedulers and reset given job's ring */
    for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
@@ -3341,6 +3343,17 @@ static int amdgpu_device_pre_asic_reset(struct
amdgpu_device *adev,
      drm_sched_stop(>sched, >base);
    +    /*
+ * Must check guilty signal here since after this point
all old
+ * HW fences are force signaled.
+ *
+ * job->base holds a reference to parent fence
+ */
+    if (job_signaled && job && ring == job_ring &&
+    job->base.s_fence->parent &&
+ dma_fence_is_signaled(job->base.s_fence->parent))
+    *job_signaled = true;
+

That won't work correctly. See when the guilty job is not on the first
scheduler, you would already have force completed some before getting
here.

Better to stop all schedulers first and then do the check.

Christian.

What do you mean by first scheduler ? There is one scheduler object per
ring so I am not clear what 'first' means here.

Well for example if the guilty job is from a compute ring the we have
already force signaled the gfx ring here.

Same is true for other devices in the same hive, so it would probably
be a good idea to move the force signaling and the IP reset somewhere
else and this check up a layer.

Christian.


Let me see if I understand you correctly - you want to AVOID ANY force
signaling in case we are not going to HW reset and so you want to have
the check if guilty is signaled BEFORE any ring fences are force
signaled. Correct ?


Correct.

Basically we should do the following:
1. Stop all schedulers to make sure that nothing is going on.
2. Check the guilty job once more to make sure that it hasn't signaled 
in the meantime.
3. Start our reset procedure, with force complete, soft reset eventually 
hard reset etc etc..

4. Resubmit all not yet completed jobs.
5. Start the schedulers again.

Christian.



Andrey


Andrey



    /* after all hw jobs are reset, hw fence is meaningless, so
force_completion */
    amdgpu_fence_driver_force_completion(ring);
    }
@@ -3358,7 +3371,8 @@ static int amdgpu_device_pre_asic_reset(struct
amdgpu_device *adev,
        -    if (!amdgpu_sriov_vf(adev)) {
+    /* Don't suspend on bare metal if we are not going to HW reset
the ASIC */
+    if (!amdgpu_sriov_vf(adev) && !(*job_signaled)) {
      if (!need_full_reset)
    need_full_reset =
amdgpu_device_ip_need_full_reset(adev);
@@ -3495,7 +3509,7 @@ static int amdgpu_do_asic_reset(struct
amdgpu_hive_info *hive,
    return r;
    }
    -static void amdgpu_device_post_asic_reset(struct amdgpu_device
*adev)
+static void amdgpu_device_post_asic_reset(struct amdgpu_device
*adev, bool job_signaled)
    {
    int i;
    @@ -3505,7 +3519,8 @@ static void
amdgpu_device_post_asic_reset(struct amdgpu_device *adev)
    if (!ring || !ring->sched.thread)
    continue;
    -    if (!adev->asic_reset_res)
+    /* No point to resubmit jobs if we didn't HW reset*/
+    if (!adev->asic_reset_res && !job_signaled)
    drm_sched_resubmit_jobs(>sched);
      drm_sched_start(>sched, !adev->asic_reset_res);
@@ -3518,14 +3533,21 @@ static void
amdgpu_device_post_asic_reset(struct amdgpu_device *adev)
    adev->asic_reset_res = 0;
    }
    -static void amdgpu_device_lock_adev(struct amdgpu_device *adev)
+static bool amdgpu_device_lock_adev(struct amdgpu_device *adev, bool
trylock)
    {
-    mutex_lock(>lock_reset);
+    if (trylock) {
+    if (!mutex_trylock(>lock_reset))
+    return false;
+    } else
+    mutex_lock(>lock_reset);
+
    atomic_inc(>gpu_reset_counter);
    adev->in_gpu_reset = 1;
    /* Block kfd: SRIOV would do it separately */
    if 

Re: [PATCH 3/3] drm/amdgpu: Avoid HW reset if guilty job already signaled.

2019-04-10 Thread Grodzovsky, Andrey

On 4/10/19 10:06 AM, Christian König wrote:
> Am 09.04.19 um 18:42 schrieb Grodzovsky, Andrey:
>> On 4/9/19 10:50 AM, Christian König wrote:
>>> Am 08.04.19 um 18:08 schrieb Andrey Grodzovsky:
 Also reject TDRs if another one already running.

 Signed-off-by: Andrey Grodzovsky 
 ---
    drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 94
 +-
    1 file changed, 67 insertions(+), 27 deletions(-)

 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
 b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
 index aabd043..4446892 100644
 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
 +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
 @@ -3327,10 +3327,12 @@ bool amdgpu_device_should_recover_gpu(struct
 amdgpu_device *adev)
      static int amdgpu_device_pre_asic_reset(struct amdgpu_device 
 *adev,
    struct amdgpu_job *job,
 -    bool *need_full_reset_arg)
 +    bool *need_full_reset_arg,
 +    bool *job_signaled)
    {
    int i, r = 0;
    bool need_full_reset  = *need_full_reset_arg;
 +    struct amdgpu_ring *job_ring = job ?
 to_amdgpu_ring(job->base.sched) : NULL;
      /* block all schedulers and reset given job's ring */
    for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
 @@ -3341,6 +3343,17 @@ static int amdgpu_device_pre_asic_reset(struct
 amdgpu_device *adev,
      drm_sched_stop(>sched, >base);
    +    /*
 + * Must check guilty signal here since after this point 
 all old
 + * HW fences are force signaled.
 + *
 + * job->base holds a reference to parent fence
 + */
 +    if (job_signaled && job && ring == job_ring &&
 +    job->base.s_fence->parent &&
 + dma_fence_is_signaled(job->base.s_fence->parent))
 +    *job_signaled = true;
 +
>>> That won't work correctly. See when the guilty job is not on the first
>>> scheduler, you would already have force completed some before getting
>>> here.
>>>
>>> Better to stop all schedulers first and then do the check.
>>>
>>> Christian.
>>
>> What do you mean by first scheduler ? There is one scheduler object per
>> ring so I am not clear what 'first' means here.
>
> Well for example if the guilty job is from a compute ring the we have 
> already force signaled the gfx ring here.
>
> Same is true for other devices in the same hive, so it would probably 
> be a good idea to move the force signaling and the IP reset somewhere 
> else and this check up a layer.
>
> Christian.


Let me see if I understand you correctly - you want to AVOID ANY force 
signaling in case we are not going to HW reset and so you want to have 
the check if guilty is signaled BEFORE any ring fences are force 
signaled. Correct ?

Andrey

>
>>
>> Andrey
>>
>>
    /* after all hw jobs are reset, hw fence is meaningless, so
 force_completion */
    amdgpu_fence_driver_force_completion(ring);
    }
 @@ -3358,7 +3371,8 @@ static int amdgpu_device_pre_asic_reset(struct
 amdgpu_device *adev,
        -    if (!amdgpu_sriov_vf(adev)) {
 +    /* Don't suspend on bare metal if we are not going to HW reset
 the ASIC */
 +    if (!amdgpu_sriov_vf(adev) && !(*job_signaled)) {
      if (!need_full_reset)
    need_full_reset = 
 amdgpu_device_ip_need_full_reset(adev);
 @@ -3495,7 +3509,7 @@ static int amdgpu_do_asic_reset(struct
 amdgpu_hive_info *hive,
    return r;
    }
    -static void amdgpu_device_post_asic_reset(struct amdgpu_device 
 *adev)
 +static void amdgpu_device_post_asic_reset(struct amdgpu_device
 *adev, bool job_signaled)
    {
    int i;
    @@ -3505,7 +3519,8 @@ static void
 amdgpu_device_post_asic_reset(struct amdgpu_device *adev)
    if (!ring || !ring->sched.thread)
    continue;
    -    if (!adev->asic_reset_res)
 +    /* No point to resubmit jobs if we didn't HW reset*/
 +    if (!adev->asic_reset_res && !job_signaled)
    drm_sched_resubmit_jobs(>sched);
      drm_sched_start(>sched, !adev->asic_reset_res);
 @@ -3518,14 +3533,21 @@ static void
 amdgpu_device_post_asic_reset(struct amdgpu_device *adev)
    adev->asic_reset_res = 0;
    }
    -static void amdgpu_device_lock_adev(struct amdgpu_device *adev)
 +static bool amdgpu_device_lock_adev(struct amdgpu_device *adev, bool
 trylock)
    {
 -    mutex_lock(>lock_reset);
 +    if (trylock) {
 +    if (!mutex_trylock(>lock_reset))
 +    return false;
 +    } else
 +    mutex_lock(>lock_reset);
 +
    atomic_inc(>gpu_reset_counter);
    adev->in_gpu_reset = 1;
    /* 

[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 = 

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

2019-04-10 Thread Tao, Yintian
Hi  Christian

Many thanks for your review. I will correct the patch by v3

Best Regards
Yintian Tao

-Original Message-
From: Christian König  
Sent: Wednesday, April 10, 2019 10:02 PM
To: Tao, Yintian ; amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu: support dpm level modification under 
virtualization v2

Am 10.04.19 um 15:02 schrieb 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
>
> 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..efdb6b7 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 

Re: [PATCH 3/3] drm/amdgpu: Avoid HW reset if guilty job already signaled.

2019-04-10 Thread Christian König

Am 09.04.19 um 18:42 schrieb Grodzovsky, Andrey:

On 4/9/19 10:50 AM, Christian König wrote:

Am 08.04.19 um 18:08 schrieb Andrey Grodzovsky:

Also reject TDRs if another one already running.

Signed-off-by: Andrey Grodzovsky 
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 94
+-
   1 file changed, 67 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index aabd043..4446892 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -3327,10 +3327,12 @@ bool amdgpu_device_should_recover_gpu(struct
amdgpu_device *adev)
     static int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,
   struct amdgpu_job *job,
-    bool *need_full_reset_arg)
+    bool *need_full_reset_arg,
+    bool *job_signaled)
   {
   int i, r = 0;
   bool need_full_reset  = *need_full_reset_arg;
+    struct amdgpu_ring *job_ring = job ?
to_amdgpu_ring(job->base.sched) : NULL;
     /* block all schedulers and reset given job's ring */
   for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
@@ -3341,6 +3343,17 @@ static int amdgpu_device_pre_asic_reset(struct
amdgpu_device *adev,
     drm_sched_stop(>sched, >base);
   +    /*
+ * Must check guilty signal here since after this point all old
+ * HW fences are force signaled.
+ *
+ * job->base holds a reference to parent fence
+ */
+    if (job_signaled && job && ring == job_ring &&
+    job->base.s_fence->parent &&
+ dma_fence_is_signaled(job->base.s_fence->parent))
+    *job_signaled = true;
+

That won't work correctly. See when the guilty job is not on the first
scheduler, you would already have force completed some before getting
here.

Better to stop all schedulers first and then do the check.

Christian.


What do you mean by first scheduler ? There is one scheduler object per
ring so I am not clear what 'first' means here.


Well for example if the guilty job is from a compute ring the we have 
already force signaled the gfx ring here.


Same is true for other devices in the same hive, so it would probably be 
a good idea to move the force signaling and the IP reset somewhere else 
and this check up a layer.


Christian.



Andrey



   /* after all hw jobs are reset, hw fence is meaningless, so
force_completion */
   amdgpu_fence_driver_force_completion(ring);
   }
@@ -3358,7 +3371,8 @@ static int amdgpu_device_pre_asic_reset(struct
amdgpu_device *adev,
       -    if (!amdgpu_sriov_vf(adev)) {
+    /* Don't suspend on bare metal if we are not going to HW reset
the ASIC */
+    if (!amdgpu_sriov_vf(adev) && !(*job_signaled)) {
     if (!need_full_reset)
   need_full_reset = amdgpu_device_ip_need_full_reset(adev);
@@ -3495,7 +3509,7 @@ static int amdgpu_do_asic_reset(struct
amdgpu_hive_info *hive,
   return r;
   }
   -static void amdgpu_device_post_asic_reset(struct amdgpu_device *adev)
+static void amdgpu_device_post_asic_reset(struct amdgpu_device
*adev, bool job_signaled)
   {
   int i;
   @@ -3505,7 +3519,8 @@ static void
amdgpu_device_post_asic_reset(struct amdgpu_device *adev)
   if (!ring || !ring->sched.thread)
   continue;
   -    if (!adev->asic_reset_res)
+    /* No point to resubmit jobs if we didn't HW reset*/
+    if (!adev->asic_reset_res && !job_signaled)
   drm_sched_resubmit_jobs(>sched);
     drm_sched_start(>sched, !adev->asic_reset_res);
@@ -3518,14 +3533,21 @@ static void
amdgpu_device_post_asic_reset(struct amdgpu_device *adev)
   adev->asic_reset_res = 0;
   }
   -static void amdgpu_device_lock_adev(struct amdgpu_device *adev)
+static bool amdgpu_device_lock_adev(struct amdgpu_device *adev, bool
trylock)
   {
-    mutex_lock(>lock_reset);
+    if (trylock) {
+    if (!mutex_trylock(>lock_reset))
+    return false;
+    } else
+    mutex_lock(>lock_reset);
+
   atomic_inc(>gpu_reset_counter);
   adev->in_gpu_reset = 1;
   /* Block kfd: SRIOV would do it separately */
   if (!amdgpu_sriov_vf(adev))
   amdgpu_amdkfd_pre_reset(adev);
+
+    return true;
   }
     static void amdgpu_device_unlock_adev(struct amdgpu_device *adev)
@@ -3555,29 +3577,44 @@ int amdgpu_device_gpu_recover(struct
amdgpu_device *adev,
   {
   int r;
   struct amdgpu_hive_info *hive = NULL;
-    bool need_full_reset = false;
   struct amdgpu_device *tmp_adev = NULL;
   struct list_head device_list, *device_list_handle =  NULL;
+    bool xgmi_topology_present, need_full_reset, job_signaled;
   +    need_full_reset = job_signaled = false;
   INIT_LIST_HEAD(_list);
     dev_info(adev->dev, "GPU reset begin!\n");
   +    hive = amdgpu_get_xgmi_hive(adev, 0);
+    xgmi_topology_present = hive &&

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

2019-04-10 Thread Christian König

Am 10.04.19 um 15:02 schrieb 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

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..efdb6b7 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 (NULL == buf)


According to coding style rules that should be "if (!buf)".


+   return -EINVAL;


Please return -ENOMEM here.


+
+adev->virt.ops->get_pp_clk(adev, PP_SCLK, buf);
+clk = parse_clk(buf, lowest);


Looks like you are using spaces instead of tabs here.


+
+   kfree(buf);
+
+   return clk;
+}
+
+uint32_t 

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

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

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..efdb6b7 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 (NULL == buf)
+   return -EINVAL;
+
+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 = kzalloc(PAGE_SIZE, GFP_KERNEL);
+   if (NULL == buf)
+   

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

2019-04-10 Thread Tao, Yintian
Hi  Christian


Many thanks.

The reason is that the reserved buffer for pf2vf communication is allocated 
from visible VRAM and the allocation granularity from it is page size at 
amdgpu_ttm_fw_reserve_vram_init.


Best Regards
Yintian Tao


-Original Message-
From: Koenig, Christian  
Sent: Wednesday, April 10, 2019 8:23 PM
To: Tao, Yintian ; Quan, Evan ; 
amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu: support dpm level modification under 
virtualization

Hi Yintian,

yeah, kzalloc would obvious work.

But why do you need such a large buffer in the first place?

Rule of thumb is that each function should not use more than 1KB of stack, 
otherwise the compiler will raise a warning.

Christian.

Am 10.04.19 um 14:09 schrieb Tao, Yintian:
> Hi  Christian
>
>
> Thanks for your review. May I use the kzalloc to allocate the memory for the 
> buffer to avoid the stack problem you said?
>
> Because hypervisor driver will transfer the message through this page size 
> memory.
>
> Best Regards
> Yintian Tao
>
> -Original Message-
> From: Christian König 
> Sent: Wednesday, April 10, 2019 6:32 PM
> To: Quan, Evan ; Tao, Yintian 
> ; amd-gfx@lists.freedesktop.org
> Subject: Re: [PATCH] drm/amdgpu: support dpm level modification under 
> virtualization
>
> Am 10.04.19 um 11:58 schrieb Quan, Evan:
>>> -Original Message-
>>> From: amd-gfx  On Behalf Of 
>>> Yintian Tao
>>> Sent: 2019年4月9日 23:18
>>> To: amd-gfx@lists.freedesktop.org
>>> Cc: Tao, Yintian 
>>> Subject: [PATCH] drm/amdgpu: support dpm level modification under 
>>> virtualization
>>>
>>> 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.
>>>
>>> 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|  3 ++
>>>drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 15 ++
>>>drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 33 +
>>>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, 147 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..1353955 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
>>> @@ -727,6 +727,9 @@ 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)) {
>>> +   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 = 

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

2019-04-10 Thread Koenig, Christian
Hi Yintian,

yeah, kzalloc would obvious work.

But why do you need such a large buffer in the first place?

Rule of thumb is that each function should not use more than 1KB of 
stack, otherwise the compiler will raise a warning.

Christian.

Am 10.04.19 um 14:09 schrieb Tao, Yintian:
> Hi  Christian
>
>
> Thanks for your review. May I use the kzalloc to allocate the memory for the 
> buffer to avoid the stack problem you said?
>
> Because hypervisor driver will transfer the message through this page size 
> memory.
>
> Best Regards
> Yintian Tao
>
> -Original Message-
> From: Christian König 
> Sent: Wednesday, April 10, 2019 6:32 PM
> To: Quan, Evan ; Tao, Yintian ; 
> amd-gfx@lists.freedesktop.org
> Subject: Re: [PATCH] drm/amdgpu: support dpm level modification under 
> virtualization
>
> Am 10.04.19 um 11:58 schrieb Quan, Evan:
>>> -Original Message-
>>> From: amd-gfx  On Behalf Of
>>> Yintian Tao
>>> Sent: 2019年4月9日 23:18
>>> To: amd-gfx@lists.freedesktop.org
>>> Cc: Tao, Yintian 
>>> Subject: [PATCH] drm/amdgpu: support dpm level modification under
>>> virtualization
>>>
>>> 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.
>>>
>>> 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|  3 ++
>>>drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 15 ++
>>>drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 33 +
>>>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, 147 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..1353955 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
>>> @@ -727,6 +727,9 @@ 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)) {
>>> +   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
>>> 

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

2019-04-10 Thread Tao, Yintian
Hi  Christian


Thanks for your review. May I use the kzalloc to allocate the memory for the 
buffer to avoid the stack problem you said?

Because hypervisor driver will transfer the message through this page size 
memory.

Best Regards
Yintian Tao

-Original Message-
From: Christian König  
Sent: Wednesday, April 10, 2019 6:32 PM
To: Quan, Evan ; Tao, Yintian ; 
amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu: support dpm level modification under 
virtualization

Am 10.04.19 um 11:58 schrieb Quan, Evan:
>
>> -Original Message-
>> From: amd-gfx  On Behalf Of 
>> Yintian Tao
>> Sent: 2019年4月9日 23:18
>> To: amd-gfx@lists.freedesktop.org
>> Cc: Tao, Yintian 
>> Subject: [PATCH] drm/amdgpu: support dpm level modification under 
>> virtualization
>>
>> 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.
>>
>> 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|  3 ++
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 15 ++
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 33 +
>>   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, 147 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..1353955 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
>> @@ -727,6 +727,9 @@ 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)) {
>> +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..ae4b2a1 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
>> @@ -375,4 +375,37 @@ 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;
>> +
>> +

RE: [PATCH] drm/ttm: fix incrementing the page pointer for huge pages

2019-04-10 Thread Huang, Ray
> -Original Message-
> From: amd-gfx [mailto:amd-gfx-boun...@lists.freedesktop.org] On Behalf
> Of Christian K?nig
> Sent: Wednesday, April 10, 2019 5:46 PM
> To: amd-gfx@lists.freedesktop.org
> Subject: [PATCH] drm/ttm: fix incrementing the page pointer for huge pages
> 
> When we increment the counter we need to increment the pointer as well.
> 
> Signed-off-by: Christian König 
> Fixes: e16858a7e6e7 drm/ttm: fix start page for huge page check in
> ttm_put_pages()

Acked-by: Huang Rui 

> ---
>  drivers/gpu/drm/ttm/ttm_page_alloc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c
> b/drivers/gpu/drm/ttm/ttm_page_alloc.c
> index c74147f0cbe3..627f8dc91d0e 100644
> --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
> +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
> @@ -733,7 +733,7 @@ static void ttm_put_pages(struct page **pages,
> unsigned npages, int flags,
>   if (!(flags & TTM_PAGE_FLAG_DMA32) &&
>   (npages - i) >= HPAGE_PMD_NR) {
>   for (j = 1; j < HPAGE_PMD_NR; ++j)
> - if (p++ != pages[i + j])
> + if (++p != pages[i + j])
>   break;
> 
>   if (j == HPAGE_PMD_NR)
> @@ -768,7 +768,7 @@ static void ttm_put_pages(struct page **pages,
> unsigned npages, int flags,
>   break;
> 
>   for (j = 1; j < HPAGE_PMD_NR; ++j)
> - if (p++ != pages[i + j])
> + if (++p != pages[i + j])
>   break;
> 
>   if (j != HPAGE_PMD_NR)
> --
> 2.17.1
> 
> ___
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

2019-04-10 Thread Christian König

Am 10.04.19 um 11:58 schrieb Quan, Evan:



-Original Message-
From: amd-gfx  On Behalf Of
Yintian Tao
Sent: 2019年4月9日 23:18
To: amd-gfx@lists.freedesktop.org
Cc: Tao, Yintian 
Subject: [PATCH] drm/amdgpu: support dpm level modification under
virtualization

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.

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|  3 ++
  drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 15 ++
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 33 +
  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, 147 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..1353955 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -727,6 +727,9 @@ 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)) {
+   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..ae4b2a1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -375,4 +375,37 @@ 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[512] = {0};

[Quan, Evan] In  xgpu_ai_get_pp_clk, the max  buffer size seems PAGE_SIZE. 
Maybe this should be aligned with that.


Well at least on the stack that would be a really bad idea. Where have 
you seen that?


Saying so 512 is a bit large as well and additional to that please stop 
initializing things with "{0}", use memset for that.


Christian.


+
+adev->virt.ops->get_pp_clk(adev, 

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

2019-04-10 Thread Tao, Yintian
Hi  Evan 

Many thanks for your review.

I will submit v2 patch according to your comments.

Best Regards
Yintian Tao

-Original Message-
From: amd-gfx  On Behalf Of Quan, Evan
Sent: Wednesday, April 10, 2019 5:58 PM
To: Tao, Yintian ; amd-gfx@lists.freedesktop.org
Cc: Tao, Yintian 
Subject: RE: [PATCH] drm/amdgpu: support dpm level modification under 
virtualization



> -Original Message-
> From: amd-gfx  On Behalf Of 
> Yintian Tao
> Sent: 2019年4月9日 23:18
> To: amd-gfx@lists.freedesktop.org
> Cc: Tao, Yintian 
> Subject: [PATCH] drm/amdgpu: support dpm level modification under 
> virtualization
> 
> 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.
> 
> 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|  3 ++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 15 ++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 33 +
>  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, 147 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..1353955 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -727,6 +727,9 @@ 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)) {
> + 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..ae4b2a1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> @@ -375,4 +375,37 @@ 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);
> +
> +

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

2019-04-10 Thread Quan, Evan


> -Original Message-
> From: amd-gfx  On Behalf Of
> Yintian Tao
> Sent: 2019年4月9日 23:18
> To: amd-gfx@lists.freedesktop.org
> Cc: Tao, Yintian 
> Subject: [PATCH] drm/amdgpu: support dpm level modification under
> virtualization
> 
> 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.
> 
> 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|  3 ++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 15 ++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 33 +
>  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, 147 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..1353955 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -727,6 +727,9 @@ 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)) {
> + 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..ae4b2a1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> @@ -375,4 +375,37 @@ 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[512] = {0};
[Quan, Evan] In  xgpu_ai_get_pp_clk, the max  buffer size seems PAGE_SIZE. 
Maybe this should be aligned with that.
> +
> +adev->virt.ops->get_pp_clk(adev, PP_SCLK, buf);
[Quan, Evan] Better to check existence of adev->virt.ops->get_pp_clk 

[PATCH] drm/ttm: fix incrementing the page pointer for huge pages

2019-04-10 Thread Christian König
When we increment the counter we need to increment the pointer as well.

Signed-off-by: Christian König 
Fixes: e16858a7e6e7 drm/ttm: fix start page for huge page check in 
ttm_put_pages()
---
 drivers/gpu/drm/ttm/ttm_page_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c 
b/drivers/gpu/drm/ttm/ttm_page_alloc.c
index c74147f0cbe3..627f8dc91d0e 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -733,7 +733,7 @@ static void ttm_put_pages(struct page **pages, unsigned 
npages, int flags,
if (!(flags & TTM_PAGE_FLAG_DMA32) &&
(npages - i) >= HPAGE_PMD_NR) {
for (j = 1; j < HPAGE_PMD_NR; ++j)
-   if (p++ != pages[i + j])
+   if (++p != pages[i + j])
break;
 
if (j == HPAGE_PMD_NR)
@@ -768,7 +768,7 @@ static void ttm_put_pages(struct page **pages, unsigned 
npages, int flags,
break;
 
for (j = 1; j < HPAGE_PMD_NR; ++j)
-   if (p++ != pages[i + j])
+   if (++p != pages[i + j])
break;
 
if (j != HPAGE_PMD_NR)
-- 
2.17.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

2019-04-10 Thread Tao, Yintian
Hi  Christian

Many thanks. I got it.

Hi  Alex

Can you help review on it? Many thanks in advance.


Best Regards
Yintian Tao

-Original Message-
From: Koenig, Christian  
Sent: Wednesday, April 10, 2019 4:44 PM
To: Tao, Yintian 
Cc: amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu: support dpm level modification under 
virtualization

Hi Yintian,

sorry but this is power management and that is not something I'm very familiar 
with.

I can only say that at least on first glance the coding style looks good to me 
:)

Probably best to wait for Alex to wake up.

Regards,
Christian.

Am 10.04.19 um 10:38 schrieb Tao, Yintian:
> Ping
>
>
> Hi Christian
>
>
> Can you help have review on it? Thanks in advance.
>
> Best Regards
> Yintian Tao
>
> -Original Message-
> From: amd-gfx  On Behalf Of 
> Yintian Tao
> Sent: Tuesday, April 09, 2019 11:18 PM
> To: amd-gfx@lists.freedesktop.org
> Cc: Tao, Yintian 
> Subject: [PATCH] drm/amdgpu: support dpm level modification under 
> virtualization
>
> 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.
>
> 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|  3 ++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 15 ++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 33 +
>   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, 147 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..1353955 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -727,6 +727,9 @@ 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)) {
> + 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..ae4b2a1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> @@ -375,4 +375,37 @@ void 

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

2019-04-10 Thread Koenig, Christian
Hi Yintian,

sorry but this is power management and that is not something I'm very 
familiar with.

I can only say that at least on first glance the coding style looks good 
to me :)

Probably best to wait for Alex to wake up.

Regards,
Christian.

Am 10.04.19 um 10:38 schrieb Tao, Yintian:
> Ping
>
>
> Hi Christian
>
>
> Can you help have review on it? Thanks in advance.
>
> Best Regards
> Yintian Tao
>
> -Original Message-
> From: amd-gfx  On Behalf Of Yintian Tao
> Sent: Tuesday, April 09, 2019 11:18 PM
> To: amd-gfx@lists.freedesktop.org
> Cc: Tao, Yintian 
> Subject: [PATCH] drm/amdgpu: support dpm level modification under 
> virtualization
>
> 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.
>
> 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|  3 ++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 15 ++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 33 +
>   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, 147 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..1353955 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -727,6 +727,9 @@ 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)) {
> + 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..ae4b2a1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> @@ -375,4 +375,37 @@ 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 = 

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

2019-04-10 Thread Tao, Yintian
Ping


Hi Christian 


Can you help have review on it? Thanks in advance.

Best Regards
Yintian Tao

-Original Message-
From: amd-gfx  On Behalf Of Yintian Tao
Sent: Tuesday, April 09, 2019 11:18 PM
To: amd-gfx@lists.freedesktop.org
Cc: Tao, Yintian 
Subject: [PATCH] drm/amdgpu: support dpm level modification under virtualization

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.

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|  3 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 15 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 33 +
 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, 147 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..1353955 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -727,6 +727,9 @@ 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)) {
+   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..ae4b2a1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -375,4 +375,37 @@ 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[512] = {0};
+
+adev->virt.ops->get_pp_clk(adev, PP_SCLK, buf);
+
+return parse_clk(buf, lowest);
+}
+
+uint32_t amdgpu_virt_get_mclk(struct amdgpu_device *adev, bool lowest) 
+{
+char buf[512] = {0};
+
+adev->virt.ops->get_pp_clk(adev, PP_MCLK, buf);
+
+return parse_clk(buf,