Enable pc sampling stop.

Signed-off-by: James Zhu <james....@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 28 +++++++++++++++++---
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h        |  4 +++
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c
index 18fe06d712c5..29a6f9f40f83 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c
@@ -88,10 +88,32 @@ static int kfd_pc_sample_start(struct kfd_process_device 
*pdd)
        return -EINVAL;
 }
 
-static int kfd_pc_sample_stop(struct kfd_process_device *pdd)
+static int kfd_pc_sample_stop(struct kfd_process_device *pdd,
+                                       struct pc_sampling_entry *pcs_entry)
 {
-       return -EINVAL;
+       bool pc_sampling_stop = false;
+
+       pcs_entry->enabled = false;
+       mutex_lock(&pdd->dev->pcs_data.mutex);
+       pdd->dev->pcs_data.hosttrap_entry.base.active_count--;
+       if (!pdd->dev->pcs_data.hosttrap_entry.base.active_count) {
+               WRITE_ONCE(pdd->dev->pcs_data.hosttrap_entry.base.stop_enable, 
true);
+               pc_sampling_stop = true;
+       }
+       mutex_unlock(&pdd->dev->pcs_data.mutex);
 
+       if (pc_sampling_stop) {
+               kfd_process_set_trap_pc_sampling_flag(&pdd->qpd,
+                       
pdd->dev->pcs_data.hosttrap_entry.base.pc_sample_info.method, false);
+
+               mutex_lock(&pdd->dev->pcs_data.mutex);
+               pdd->dev->pcs_data.hosttrap_entry.base.target_simd = 0;
+               pdd->dev->pcs_data.hosttrap_entry.base.target_wave_slot = 0;
+               WRITE_ONCE(pdd->dev->pcs_data.hosttrap_entry.base.stop_enable, 
false);
+               mutex_unlock(&pdd->dev->pcs_data.mutex);
+       }
+
+       return 0;
 }
 
 static int kfd_pc_sample_create(struct kfd_process_device *pdd,
@@ -233,7 +255,7 @@ int kfd_pc_sample(struct kfd_process_device *pdd,
                if (!pcs_entry->enabled)
                        return -EALREADY;
                else
-                       return kfd_pc_sample_stop(pdd);
+                       return kfd_pc_sample_stop(pdd, pcs_entry);
        }
 
        return -EINVAL;
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h 
b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
index b9a36891d099..0839a0ca3099 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -271,6 +271,10 @@ struct kfd_dev;
 
 struct kfd_dev_pc_sampling_data {
        uint32_t use_count;         /* Num of PC sampling sessions */
+       uint32_t active_count;      /* Num of active sessions */
+       uint32_t target_simd;       /* target simd for trap */
+       uint32_t target_wave_slot;  /* target wave slot for trap */
+       bool stop_enable;           /* pc sampling stop in process */
        struct idr pc_sampling_idr;
        struct kfd_pc_sample_info pc_sample_info;
 };
-- 
2.25.1

Reply via email to