<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 2023-11-10 14:07, Yat Sin, David
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:DM6PR12MB50211E7128EDF3D5D6067B9295AEA@DM6PR12MB5021.namprd12.prod.outlook.com">
      <pre class="moz-quote-pre" wrap="">[AMD Official Use Only - General]

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">-----Original Message-----
From: Zhu, James <a class="moz-txt-link-rfc2396E" href="mailto:James.Zhu@amd.com"><James.Zhu@amd.com></a>
Sent: Friday, November 3, 2023 9:12 AM
To: <a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>
Cc: Kuehling, Felix <a class="moz-txt-link-rfc2396E" href="mailto:Felix.Kuehling@amd.com"><Felix.Kuehling@amd.com></a>; Greathouse, Joseph
<a class="moz-txt-link-rfc2396E" href="mailto:Joseph.Greathouse@amd.com"><Joseph.Greathouse@amd.com></a>; Yat Sin, David <a class="moz-txt-link-rfc2396E" href="mailto:David.YatSin@amd.com"><David.YatSin@amd.com></a>; Zhu,
James <a class="moz-txt-link-rfc2396E" href="mailto:James.Zhu@amd.com"><James.Zhu@amd.com></a>
Subject: [PATCH 19/24] drm/amdkfd: enable pc sampling stop

Enable pc sampling stop.

Signed-off-by: James Zhu <a class="moz-txt-link-rfc2396E" href="mailto:James.Zhu@amd.com"><James.Zhu@amd.com></a>
---
 drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 28 +++++++++++++++++--
-
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h        |  2 ++
 2 files changed, 27 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 33d003ca0093..2c4ac5b4cc4b 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c
@@ -108,10 +108,32 @@ static int kfd_pc_sample_start(struct
kfd_process_device *pdd,
      return 0;
 }

-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);
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">For the START/STOP/DESTROY ioctls, I think we can hold pdd->dev->pcs_data.mutex through the whole IOCTL. Then we would not have to deal with the intermediate states where the START/STOP/DESTROY are happening at the same time.</pre>
    </blockquote>
    [JZ] <span style="white-space: pre-wrap">pdd->dev->pcs_data.mutex</span>
    is per device, not per process. In the future, also it will share
    protection within different pc sampling methods on the same devices.
    So I don't think a bigger lock here is good idea.<br>
    <blockquote type="cite" cite="mid:DM6PR12MB50211E7128EDF3D5D6067B9295AEA@DM6PR12MB5021.namprd12.prod.outlook.com">
      <pre class="moz-quote-pre" wrap="">

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">+     pdd->dev->pcs_data.hosttrap_entry.base.active_count--;
+     if (!pdd->dev->pcs_data.hosttrap_entry.base.active_count) {
+             WRITE_ONCE(pdd->dev-
</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">pcs_data.hosttrap_entry.base.stop_enable, true);
</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">+             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-
</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">pcs_data.hosttrap_entry.base.pc_sample_info.method,
</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">+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-
</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">pcs_data.hosttrap_entry.base.stop_enable, false);
</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">+             mutex_unlock(&pdd->dev->pcs_data.mutex);
+     }
+
+     return 0;
 }

 static int kfd_pc_sample_create(struct kfd_process_device *pdd, @@ -251,7
+273,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 613910e0d440..badaa4d68cc4 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -259,6 +259,8 @@ 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
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
    </blockquote>
  </body>
</html>