<!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-12-12 19:55, Yat Sin, David
wrote:<br>
</div>
<blockquote type="cite" cite="mid:DM6PR12MB5021CAF710E26D085BBCD92F958DA@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: Thursday, December 7, 2023 5:54 PM
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 v2 03/23] drm/amdkfd: enable pc sampling query
From: David Yat Sin <a class="moz-txt-link-rfc2396E" href="mailto:david.yatsin@amd.com"><david.yatsin@amd.com></a>
Enable pc sampling to query system capability.
Co-developed-by: James Zhu <a class="moz-txt-link-rfc2396E" href="mailto:James.Zhu@amd.com"><James.Zhu@amd.com></a>
Signed-off-by: James Zhu <a class="moz-txt-link-rfc2396E" href="mailto:James.Zhu@amd.com"><James.Zhu@amd.com></a>
Signed-off-by: David Yat Sin <a class="moz-txt-link-rfc2396E" href="mailto:david.yatsin@amd.com"><david.yatsin@amd.com></a>
---
drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c | 54
+++++++++++++++++++-
1 file changed, 53 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c
b/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c
index a7e78ff42d07..49fecbc7013e 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_pc_sampling.c
@@ -25,10 +25,62 @@
#include "amdgpu_amdkfd.h"
#include "kfd_pc_sampling.h"
+struct supported_pc_sample_info {
+ uint32_t ip_version;
+ const struct kfd_pc_sample_info *sample_info; };
+
+const struct kfd_pc_sample_info sample_info_hosttrap_9_0_0 = {
+ 0, 1, ~0ULL, 0, KFD_IOCTL_PCS_METHOD_HOSTTRAP,
+KFD_IOCTL_PCS_TYPE_TIME_US };
+
+struct supported_pc_sample_info supported_formats[] = {
+ { IP_VERSION(9, 4, 1), &sample_info_hosttrap_9_0_0 },
+ { IP_VERSION(9, 4, 2), &sample_info_hosttrap_9_0_0 }, };
+
static int kfd_pc_sample_query_cap(struct kfd_process_device *pdd,
struct kfd_ioctl_pc_sample_args
__user *user_args) {
- return -EINVAL;
+ uint64_t sample_offset;
+ int num_method = 0;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(supported_formats); i++)
+ if (KFD_GC_VERSION(pdd->dev) ==
supported_formats[i].ip_version)
+ num_method++;
+
+ if (!num_method) {
+ pr_debug("PC Sampling not supported on GC_HWIP:0x%x.",
+ pdd->dev->adev->ip_versions[GC_HWIP][0]);
+ return -EOPNOTSUPP;
+ }
+
+ if (!user_args->sample_info_ptr) {
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">Should be:
if (!user_args->sample_info_ptr || !user_args->num_sample_info) {
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">+ user_args->num_sample_info = num_method;
+ return 0;
+ }
+
+ if (user_args->num_sample_info < num_method) {
+ user_args->num_sample_info = num_method;
+ pr_debug("Sample info buffer is not large enough, "
+ "ASIC requires space for %d kfd_pc_sample_info
entries.", num_method);
+ return -ENOSPC;
+ }
+
+ sample_offset = user_args->sample_info_ptr;
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
If there is another active PC Sampling session that is active, I thought we were planning to have code to
return a reduced list with only the methods that are compatible with the current active session. Did we
decide to drop this behavior?</pre>
</blockquote>
[JZ] Do we have design changed here? I though we allow sharing the
same<span style="white-space: pre-wrap"> active PC Sampling session between multiple processes.</span>
<blockquote type="cite" cite="mid:DM6PR12MB5021CAF710E26D085BBCD92F958DA@DM6PR12MB5021.namprd12.prod.outlook.com">
<pre class="moz-quote-pre" wrap="">
Regards,
David
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">+ for (i = 0; i < ARRAY_SIZE(supported_formats); i++) {
+ if (KFD_GC_VERSION(pdd->dev) ==
supported_formats[i].ip_version) {
+ int ret = copy_to_user((void __user *) sample_offset,
+ supported_formats[i].sample_info,
sizeof(struct kfd_pc_sample_info));
+ if (ret) {
+ pr_debug("Failed to copy PC sampling info to
user.");
+ return -EFAULT;
+ }
+ sample_offset += sizeof(struct kfd_pc_sample_info);
+ }
+ }
+
+ return 0;
}
static int kfd_pc_sample_start(struct kfd_process_device *pdd)
--
2.25.1
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
</pre>
</blockquote>
</body>
</html>