<!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-27 14:11, Alex Deucher
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CADnq5_MyXm+G3n=n9o8NJiHR9BtFZkN9+FSS1r3MkUvaPnzh7g@mail.gmail.com">
      <pre class="moz-quote-pre" wrap="">On Fri, Nov 3, 2023 at 9:22 AM James Zhu <a class="moz-txt-link-rfc2396E" href="mailto:James.Zhu@amd.com"><James.Zhu@amd.com></a> wrote:
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">
From: David Yat Sin <a class="moz-txt-link-rfc2396E" href="mailto:david.yatsin@amd.com"><david.yatsin@amd.com></a>

Add pc sampling support in kfd_ioctl.

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>
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
For any new IOCTL interfaces, please provide a link to the user mode
code branch which uses it in the patch description.
</pre>
    </blockquote>
    <span style="white-space: pre-wrap">[JZ] will add, Thanks!</span><br>
    <blockquote type="cite" cite="mid:CADnq5_MyXm+G3n=n9o8NJiHR9BtFZkN9+FSS1r3MkUvaPnzh7g@mail.gmail.com">
      <pre class="moz-quote-pre" wrap="">
Thanks,

Alex

</pre>
    </blockquote>
    <blockquote type="cite" cite="mid:CADnq5_MyXm+G3n=n9o8NJiHR9BtFZkN9+FSS1r3MkUvaPnzh7g@mail.gmail.com">
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">---
 include/uapi/linux/kfd_ioctl.h | 57 +++++++++++++++++++++++++++++++++-
 1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
index f0ed68974c54..5202e29c9560 100644
--- a/include/uapi/linux/kfd_ioctl.h
+++ b/include/uapi/linux/kfd_ioctl.h
@@ -1446,6 +1446,58 @@ struct kfd_ioctl_dbg_trap_args {
        };
 };

+/**
+ * kfd_ioctl_pc_sample_op - PC Sampling ioctl operations
+ *
+ * @KFD_IOCTL_PCS_OP_QUERY_CAPABILITIES: Query device PC Sampling capabilities
+ * @KFD_IOCTL_PCS_OP_CREATE:             Register this process with a per-device PC sampler instance
+ * @KFD_IOCTL_PCS_OP_DESTROY:            Unregister from a previously registered PC sampler instance
+ * @KFD_IOCTL_PCS_OP_START:              Process begins taking samples from a previously registered PC sampler instance
+ * @KFD_IOCTL_PCS_OP_STOP:               Process stops taking samples from a previously registered PC sampler instance
+ */
+enum kfd_ioctl_pc_sample_op {
+       KFD_IOCTL_PCS_OP_QUERY_CAPABILITIES,
+       KFD_IOCTL_PCS_OP_CREATE,
+       KFD_IOCTL_PCS_OP_DESTROY,
+       KFD_IOCTL_PCS_OP_START,
+       KFD_IOCTL_PCS_OP_STOP,
+};
+
+/* Values have to be a power of 2*/
+#define KFD_IOCTL_PCS_FLAG_POWER_OF_2 0x00000001
+
+enum kfd_ioctl_pc_sample_method {
+       KFD_IOCTL_PCS_METHOD_HOSTTRAP = 1,
+       KFD_IOCTL_PCS_METHOD_STOCHASTIC,
+};
+
+enum kfd_ioctl_pc_sample_type {
+       KFD_IOCTL_PCS_TYPE_TIME_US,
+       KFD_IOCTL_PCS_TYPE_CLOCK_CYCLES,
+       KFD_IOCTL_PCS_TYPE_INSTRUCTIONS
+};
+
+struct kfd_pc_sample_info {
+       __u64 value;         /* [IN] if PCS_TYPE_INTERVAL_US: sample interval in us
+                             * if PCS_TYPE_CLOCK_CYCLES: sample interval in graphics core clk cycles
+                             * if PCS_TYPE_INSTRUCTIONS: sample interval in instructions issued by
+                             * graphics compute units
+                             */
+       __u64 value_min;     /* [OUT] */
+       __u64 value_max;     /* [OUT] */
+       __u64 flags;         /* [OUT] indicate potential restrictions e.g FLAG_POWER_OF_2 */
+       __u32 method;        /* [IN/OUT] kfd_ioctl_pc_sample_method */
+       __u32 type;          /* [IN/OUT] kfd_ioctl_pc_sample_type */
+};
+
+struct kfd_ioctl_pc_sample_args {
+       __u64 sample_info_ptr;   /* array of kfd_pc_sample_info */
+       __u32 num_sample_info;
+       __u32 op;                /* kfd_ioctl_pc_sample_op */
+       __u32 gpu_id;
+       __u32 trace_id;
+};
+
 #define AMDKFD_IOCTL_BASE 'K'
 #define AMDKFD_IO(nr)                  _IO(AMDKFD_IOCTL_BASE, nr)
 #define AMDKFD_IOR(nr, type)           _IOR(AMDKFD_IOCTL_BASE, nr, type)
@@ -1566,7 +1618,10 @@ struct kfd_ioctl_dbg_trap_args {
 #define AMDKFD_IOC_DBG_TRAP                    \
                AMDKFD_IOWR(0x26, struct kfd_ioctl_dbg_trap_args)

+#define AMDKFD_IOC_PC_SAMPLE           \
+               AMDKFD_IOWR(0x27, struct kfd_ioctl_pc_sample_args)
+
 #define AMDKFD_COMMAND_START           0x01
-#define AMDKFD_COMMAND_END             0x27
+#define AMDKFD_COMMAND_END             0x28

 #endif
--
2.25.1

</pre>
      </blockquote>
    </blockquote>
  </body>
</html>