All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felix Kuehling <felix.kuehling@amd.com>
To: Amber Lin <Amber.Lin@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v3] drm/amdkfd: Add queue information to sysfs
Date: Tue, 4 Feb 2020 16:13:46 -0500	[thread overview]
Message-ID: <0492fc83-2d69-ab3f-ab4d-18a7bd9d4ac4@amd.com> (raw)
In-Reply-To: <1580751448-3759-1-git-send-email-Amber.Lin@amd.com>

On 2020-02-03 12:37 p.m., Amber Lin wrote:
> Provide compute queues information in sysfs under /sys/class/kfd/kfd/proc.
> The format is /sys/class/kfd/kfd/proc/<pid>/queues/<queue id>/XX where
> XX are size, type, and gpuid three files to represent queue size, queue
> type, and the GPU this queue uses. <queue id> folder and files underneath
> are generated when a queue is created. They are removed when the queue is
> destroyed.
>
> Signed-off-by: Amber Lin <Amber.Lin@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>


> ---
>   drivers/gpu/drm/amd/amdkfd/kfd_priv.h              |  7 ++
>   drivers/gpu/drm/amd/amdkfd/kfd_process.c           | 90 ++++++++++++++++++++++
>   .../gpu/drm/amd/amdkfd/kfd_process_queue_manager.c |  2 +
>   3 files changed, 99 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> index c0b0def..f805f55 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> @@ -41,6 +41,7 @@
>   #include <drm/drm_drv.h>
>   #include <drm/drm_device.h>
>   #include <kgd_kfd_interface.h>
> +#include <linux/swap.h>
>   
>   #include "amd_shared.h"
>   
> @@ -503,6 +504,9 @@ struct queue {
>   	struct kfd_process	*process;
>   	struct kfd_dev		*device;
>   	void *gws;
> +
> +	/* procfs */
> +	struct kobject kobj;
>   };
>   
>   /*
> @@ -730,6 +734,7 @@ struct kfd_process {
>   
>   	/* Kobj for our procfs */
>   	struct kobject *kobj;
> +	struct kobject *kobj_queues;
>   	struct attribute attr_pasid;
>   };
>   
> @@ -836,6 +841,8 @@ extern struct device *kfd_device;
>   /* KFD's procfs */
>   void kfd_procfs_init(void);
>   void kfd_procfs_shutdown(void);
> +int kfd_procfs_add_queue(struct queue *q);
> +void kfd_procfs_del_queue(struct queue *q);
>   
>   /* Topology */
>   int kfd_topology_init(void);
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> index 25b90f7..98dcbb9 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> @@ -132,6 +132,88 @@ void kfd_procfs_shutdown(void)
>   	}
>   }
>   
> +static ssize_t kfd_procfs_queue_show(struct kobject *kobj,
> +				     struct attribute *attr, char *buffer)
> +{
> +	struct queue *q = container_of(kobj, struct queue, kobj);
> +
> +	if (!strcmp(attr->name, "size"))
> +		return snprintf(buffer, PAGE_SIZE, "%llu",
> +				q->properties.queue_size);
> +	else if (!strcmp(attr->name, "type"))
> +		return snprintf(buffer, PAGE_SIZE, "%d", q->properties.type);
> +	else if (!strcmp(attr->name, "gpuid"))
> +		return snprintf(buffer, PAGE_SIZE, "%u", q->device->id);
> +	else
> +		pr_err("Invalid attribute");
> +
> +	return 0;
> +}
> +
> +static struct attribute attr_queue_size = {
> +	.name = "size",
> +	.mode = KFD_SYSFS_FILE_MODE
> +};
> +
> +static struct attribute attr_queue_type = {
> +	.name = "type",
> +	.mode = KFD_SYSFS_FILE_MODE
> +};
> +
> +static struct attribute attr_queue_gpuid = {
> +	.name = "gpuid",
> +	.mode = KFD_SYSFS_FILE_MODE
> +};
> +
> +static struct attribute *procfs_queue_attrs[] = {
> +	&attr_queue_size,
> +	&attr_queue_type,
> +	&attr_queue_gpuid,
> +	NULL
> +};
> +
> +static const struct sysfs_ops procfs_queue_ops = {
> +	.show = kfd_procfs_queue_show,
> +};
> +
> +static struct kobj_type procfs_queue_type = {
> +	.sysfs_ops = &procfs_queue_ops,
> +	.default_attrs = procfs_queue_attrs,
> +};
> +
> +int kfd_procfs_add_queue(struct queue *q)
> +{
> +	struct kfd_process *proc;
> +	int ret;
> +
> +	if (!q || !q->process)
> +		return -EINVAL;
> +	proc = q->process;
> +
> +	/* Create proc/<pid>/queues/<queue id> folder */
> +	if (!proc->kobj_queues)
> +		return -EFAULT;
> +	ret = kobject_init_and_add(&q->kobj, &procfs_queue_type,
> +			proc->kobj_queues, "%u", q->properties.queue_id);
> +	if (ret < 0) {
> +		pr_warn("Creating proc/<pid>/queues/%u failed",
> +			q->properties.queue_id);
> +		kobject_put(&q->kobj);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +void kfd_procfs_del_queue(struct queue *q)
> +{
> +	if (!q)
> +		return;
> +
> +	kobject_del(&q->kobj);
> +	kobject_put(&q->kobj);
> +}
> +
>   int kfd_process_create_wq(void)
>   {
>   	if (!kfd_process_wq)
> @@ -323,6 +405,11 @@ struct kfd_process *kfd_create_process(struct file *filep)
>   		if (ret)
>   			pr_warn("Creating pasid for pid %d failed",
>   					(int)process->lead_thread->pid);
> +
> +		process->kobj_queues = kobject_create_and_add("queues",
> +							process->kobj);
> +		if (!process->kobj_queues)
> +			pr_warn("Creating KFD proc/queues folder failed");
>   	}
>   out:
>   	if (!IS_ERR(process))
> @@ -457,6 +544,9 @@ static void kfd_process_wq_release(struct work_struct *work)
>   	/* Remove the procfs files */
>   	if (p->kobj) {
>   		sysfs_remove_file(p->kobj, &p->attr_pasid);
> +		kobject_del(p->kobj_queues);
> +		kobject_put(p->kobj_queues);
> +		p->kobj_queues = NULL;
>   		kobject_del(p->kobj);
>   		kobject_put(p->kobj);
>   		p->kobj = NULL;
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> index 8fa856e..cb1ca11 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> @@ -322,6 +322,7 @@ int pqm_create_queue(struct process_queue_manager *pqm,
>   
>   	if (q) {
>   		pr_debug("PQM done creating queue\n");
> +		kfd_procfs_add_queue(q);
>   		print_queue_properties(&q->properties);
>   	}
>   
> @@ -378,6 +379,7 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid)
>   	}
>   
>   	if (pqn->q) {
> +		kfd_procfs_del_queue(pqn->q);
>   		dqm = pqn->q->device->dqm;
>   		retval = dqm->ops.destroy_queue(dqm, &pdd->qpd, pqn->q);
>   		if (retval) {
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

      reply	other threads:[~2020-02-04 21:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-03 17:37 [PATCH v3] drm/amdkfd: Add queue information to sysfs Amber Lin
2020-02-04 21:13 ` Felix Kuehling [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=0492fc83-2d69-ab3f-ab4d-18a7bd9d4ac4@amd.com \
    --to=felix.kuehling@amd.com \
    --cc=Amber.Lin@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.