mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lizhi Hou <lizhi.hou@amd.com>
To: Max Zhen <max.zhen@amd.com>, <ogabbay@kernel.org>,
	<quic_jhugo@quicinc.com>, <dri-devel@lists.freedesktop.org>,
	<mario.limonciello@amd.com>, <karol.wachowski@linux.intel.com>
Cc: <linux-kernel@vger.kernel.org>, <sonal.santan@amd.com>
Subject: Re: [PATCH V1] accel/amdxdna: Expose NPU device busy time via DRM fdinfo
Date: Wed, 14 Oct 2026 09:21:42 -0700	[thread overview]
Message-ID: <6df59031-1f6a-ab1d-16a3-4525727ba644@amd.com> (raw)
In-Reply-To: <9a73a766-55f6-386f-0ec2-2ca3f4a987db@amd.com>

Applied to drm-misc-next

On 10/13/26 10:02, Lizhi Hou wrote:
>
> On 10/12/26 11:08, Max Zhen wrote:
>> Expose NPU device engine busy time through DRM fdinfo to enable
>> standardized userspace monitoring and profiling.
>>
>> Add support for reporting per-engine busy time in nanoseconds
>> via fdinfo using the "drm-engine-<driver-name>" key. The value
>
> It should be "drm-engine-npu" key here. I will change it when I merge.
>
> Lizhi
>
>> reflects the accumulated NPU device execution time for a given
>> process, allowing userspace tools to observe NPU device
>> utilization without driver-specific ioctls.
>>
>> Signed-off-by: Max Zhen <max.zhen@amd.com>
>> ---
>>   Documentation/accel/amdxdna/amdnpu.rst  |  1 +
>>   drivers/accel/amdxdna/aie.c             | 39 +++++++++++++++++++++++++
>>   drivers/accel/amdxdna/aie.h             |  4 +++
>>   drivers/accel/amdxdna/aie2_ctx.c        |  6 ++++
>>   drivers/accel/amdxdna/amdxdna_pci_drv.c |  6 ++++
>>   drivers/accel/amdxdna/amdxdna_pci_drv.h |  9 ++++++
>>   6 files changed, 65 insertions(+)
>>
>> diff --git a/Documentation/accel/amdxdna/amdnpu.rst 
>> b/Documentation/accel/amdxdna/amdnpu.rst
>> index 064973bf4893..d72af1b51ccf 100644
>> --- a/Documentation/accel/amdxdna/amdnpu.rst
>> +++ b/Documentation/accel/amdxdna/amdnpu.rst
>> @@ -289,6 +289,7 @@ Example of the output showing the implemented key 
>> value pairs:
>>           drm-driver:    amdxdna_accel_driver
>>           drm-client-id:    3219
>>           drm-pdev:    0000:c5:00.1
>> +        drm-engine-npu: 14003870 ns
>>           amdxdna_accel_driver-heap-alloc:    60 KiB
>>           amdxdna_accel_driver-internal-alloc:    67588 KiB
>>           amdxdna_accel_driver-external-alloc:    0
>> diff --git a/drivers/accel/amdxdna/aie.c b/drivers/accel/amdxdna/aie.c
>> index dd6f36f222c7..bf8eb66baab8 100644
>> --- a/drivers/accel/amdxdna/aie.c
>> +++ b/drivers/accel/amdxdna/aie.c
>> @@ -118,6 +118,45 @@ void amdxdna_vbnv_init(struct amdxdna_dev *xdna)
>>       amdxdna_update_vbnv(xdna, info->rev_vbnv_tbl, rev);
>>   }
>>   +void amdxdna_io_stats_job_start(struct amdxdna_client *client)
>> +{
>> +    int depth;
>> +
>> +    guard(spinlock)(&client->io_stats.lock);
>> +
>> +    depth = client->io_stats.job_depth++;
>> +    if (!depth)
>> +        client->io_stats.start_time = ktime_get_ns();
>> +}
>> +
>> +void amdxdna_io_stats_job_done(struct amdxdna_client *client)
>> +{
>> +    u64 busy_ns;
>> +    int depth;
>> +
>> +    guard(spinlock)(&client->io_stats.lock);
>> +
>> +    depth = --client->io_stats.job_depth;
>> +    if (!depth) {
>> +        busy_ns = ktime_get_ns() - client->io_stats.start_time;
>> +        client->io_stats.start_time = 0;
>> +        client->io_stats.busy_time += busy_ns;
>> +    }
>> +}
>> +
>> +u64 amdxdna_io_stats_busy_time_ns(struct amdxdna_client *client)
>> +{
>> +    u64 busy_ns;
>> +
>> +    guard(spinlock)(&client->io_stats.lock);
>> +
>> +    busy_ns = client->io_stats.busy_time;
>> +    if (client->io_stats.job_depth)
>> +        busy_ns += ktime_get_ns() - client->io_stats.start_time;
>> +
>> +    return busy_ns;
>> +}
>> +
>>   int amdxdna_get_metadata(struct aie_device *aie,
>>                struct amdxdna_client *client,
>>                struct amdxdna_drm_get_info *args)
>> diff --git a/drivers/accel/amdxdna/aie.h b/drivers/accel/amdxdna/aie.h
>> index 0483d582b7f8..1fc5ddfe696a 100644
>> --- a/drivers/accel/amdxdna/aie.h
>> +++ b/drivers/accel/amdxdna/aie.h
>> @@ -117,4 +117,8 @@ void aie_smu_fini(struct smu_device *smu);
>>   int aie_smu_set_clocks(struct smu_device *smu, u32 *npuclk, u32 
>> *hclk);
>>   int aie_smu_set_dpm(struct smu_device *smu, u32 dpm_level);
>>   +void amdxdna_io_stats_job_start(struct amdxdna_client *client);
>> +void amdxdna_io_stats_job_done(struct amdxdna_client *client);
>> +u64 amdxdna_io_stats_busy_time_ns(struct amdxdna_client *client);
>> +
>>   #endif /* _AIE_H_ */
>> diff --git a/drivers/accel/amdxdna/aie2_ctx.c 
>> b/drivers/accel/amdxdna/aie2_ctx.c
>> index d927c8c9d557..9c6b7353cbe9 100644
>> --- a/drivers/accel/amdxdna/aie2_ctx.c
>> +++ b/drivers/accel/amdxdna/aie2_ctx.c
>> @@ -290,6 +290,7 @@ aie2_sched_resp_handler(void *handle, void 
>> __iomem *data, size_t size)
>>       int ret = 0;
>>       u32 status;
>>   +    amdxdna_io_stats_job_done(job->hwctx->client);
>>       cmd_abo = job->cmd_bo;
>>         if (unlikely(job->job_timeout)) {
>> @@ -322,6 +323,8 @@ aie2_sched_drvcmd_resp_handler(void *handle, void 
>> __iomem *data, size_t size)
>>       struct amdxdna_sched_job *job = handle;
>>       int ret = 0;
>>   +    amdxdna_io_stats_job_done(job->hwctx->client);
>> +
>>       if (unlikely(!data || size != sizeof(u32))) {
>>           job->drv_cmd->result = U32_MAX;
>>           ret = -EINVAL;
>> @@ -344,6 +347,7 @@ aie2_sched_cmdlist_resp_handler(void *handle, 
>> void __iomem *data, size_t size)
>>       u32 cmd_status;
>>       int ret = 0;
>>   +    amdxdna_io_stats_job_done(job->hwctx->client);
>>       cmd_abo = job->cmd_bo;
>>         if (unlikely(job->job_timeout)) {
>> @@ -405,6 +409,7 @@ aie2_sched_job_run(struct drm_sched_job *sched_job)
>>       kref_get(&job->refcnt);
>>       fence = dma_fence_get(job->fence);
>>   +    amdxdna_io_stats_job_start(job->hwctx->client);
>>       if (job->drv_cmd) {
>>           switch (job->drv_cmd->opcode) {
>>           case SYNC_DEBUG_BO:
>> @@ -432,6 +437,7 @@ aie2_sched_job_run(struct drm_sched_job *sched_job)
>>     out:
>>       if (ret) {
>> +        amdxdna_io_stats_job_done(job->hwctx->client);
>>           dma_fence_put(job->fence);
>>           aie2_job_put(job);
>>           mmput(job->mm);
>> diff --git a/drivers/accel/amdxdna/amdxdna_pci_drv.c 
>> b/drivers/accel/amdxdna/amdxdna_pci_drv.c
>> index bb339e641416..67a02d6b7f97 100644
>> --- a/drivers/accel/amdxdna/amdxdna_pci_drv.c
>> +++ b/drivers/accel/amdxdna/amdxdna_pci_drv.c
>> @@ -14,6 +14,7 @@
>>   #include <linux/iommu.h>
>>   #include <linux/pci.h>
>>   +#include "aie.h"
>>   #include "amdxdna_cbuf.h"
>>   #include "amdxdna_ctx.h"
>>   #include "amdxdna_debugfs.h"
>> @@ -151,6 +152,8 @@ static int amdxdna_drm_open(struct drm_device 
>> *ddev, struct drm_file *filp)
>>       filp->driver_priv = client;
>>       client->filp = filp;
>>   +    spin_lock_init(&client->io_stats.lock);
>> +
>>       XDNA_DBG(xdna, "pid %d opened", client->pid);
>>       return 0;
>>   @@ -287,6 +290,9 @@ static void amdxdna_show_fdinfo(struct 
>> drm_printer *p, struct drm_file *filp)
>>       size_t heap_usage, external_usage, internal_usage;
>>       char *drv_name = filp->minor->dev->driver->name;
>>   +    drm_printf(p, "drm-engine-npu:\t%llu ns\n",
>> +           amdxdna_io_stats_busy_time_ns(client));
>> +
>>       mutex_lock(&client->mm_lock);
>>         heap_usage = client->heap_usage;
>> diff --git a/drivers/accel/amdxdna/amdxdna_pci_drv.h 
>> b/drivers/accel/amdxdna/amdxdna_pci_drv.h
>> index a997d27a504d..510356a31532 100644
>> --- a/drivers/accel/amdxdna/amdxdna_pci_drv.h
>> +++ b/drivers/accel/amdxdna/amdxdna_pci_drv.h
>> @@ -143,6 +143,13 @@ struct amdxdna_device_id {
>>       const struct amdxdna_dev_info *dev_info;
>>   };
>>   +struct amdxdna_io_stats {
>> +    spinlock_t            lock; /* protect io stats */
>> +    int                job_depth;
>> +    u64                start_time;
>> +    u64                busy_time;
>> +};
>> +
>>   /*
>>    * struct amdxdna_client - amdxdna client
>>    * A per fd data structure for managing context and other user 
>> process stuffs.
>> @@ -169,6 +176,8 @@ struct amdxdna_client {
>>       size_t                heap_usage;
>>       size_t                total_bo_usage;
>>       size_t                total_int_bo_usage;
>> +
>> +    struct amdxdna_io_stats        io_stats;
>>   };
>>     #define amdxdna_for_each_hwctx(client, hwctx_id, entry)        \

      reply	other threads:[~2026-10-14 16:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 18:08 Max Zhen
2026-10-13 16:44 ` Lizhi Hou
2026-10-13 17:02 ` Lizhi Hou
2026-10-14 16:21   ` Lizhi Hou [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6df59031-1f6a-ab1d-16a3-4525727ba644@amd.com \
    --to=lizhi.hou@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=karol.wachowski@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=max.zhen@amd.com \
    --cc=ogabbay@kernel.org \
    --cc=quic_jhugo@quicinc.com \
    --cc=sonal.santan@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®