Commit 75ae84c8 authored by Philip Yang's avatar Philip Yang Committed by Alex Deucher

drm/amdkfd: add helper function for kfd sysfs create

No functionality change. Modify kfd_sysfs_create_file to use kobject as
parameter, so it becomes common helper function to remove duplicate code
and will simplify new kfd sysfs file create in future.

Move pr_warn to helper function if sysfs file create failed. Set helper
function as void return because caller doesn't use the helper function
return value.
Signed-off-by: default avatarPhilip Yang <Philip.Yang@amd.com>
Reviewed-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent ff4b601a
...@@ -484,34 +484,31 @@ int kfd_procfs_add_queue(struct queue *q) ...@@ -484,34 +484,31 @@ int kfd_procfs_add_queue(struct queue *q)
return 0; return 0;
} }
static int kfd_sysfs_create_file(struct kfd_process *p, struct attribute *attr, static void kfd_sysfs_create_file(struct kobject *kobj, struct attribute *attr,
char *name) char *name)
{ {
int ret = 0; int ret;
if (!p || !attr || !name) if (!kobj || !attr || !name)
return -EINVAL; return;
attr->name = name; attr->name = name;
attr->mode = KFD_SYSFS_FILE_MODE; attr->mode = KFD_SYSFS_FILE_MODE;
sysfs_attr_init(attr); sysfs_attr_init(attr);
ret = sysfs_create_file(p->kobj, attr); ret = sysfs_create_file(kobj, attr);
if (ret)
return ret; pr_warn("Create sysfs %s/%s failed %d", kobj->name, name, ret);
} }
static int kfd_procfs_add_sysfs_stats(struct kfd_process *p) static void kfd_procfs_add_sysfs_stats(struct kfd_process *p)
{ {
int ret = 0; int ret;
int i; int i;
char stats_dir_filename[MAX_SYSFS_FILENAME_LEN]; char stats_dir_filename[MAX_SYSFS_FILENAME_LEN];
if (!p) if (!p || !p->kobj)
return -EINVAL; return;
if (!p->kobj)
return -EFAULT;
/* /*
* Create sysfs files for each GPU: * Create sysfs files for each GPU:
...@@ -521,15 +518,14 @@ static int kfd_procfs_add_sysfs_stats(struct kfd_process *p) ...@@ -521,15 +518,14 @@ static int kfd_procfs_add_sysfs_stats(struct kfd_process *p)
*/ */
for (i = 0; i < p->n_pdds; i++) { for (i = 0; i < p->n_pdds; i++) {
struct kfd_process_device *pdd = p->pdds[i]; struct kfd_process_device *pdd = p->pdds[i];
struct kobject *kobj_stats;
snprintf(stats_dir_filename, MAX_SYSFS_FILENAME_LEN, snprintf(stats_dir_filename, MAX_SYSFS_FILENAME_LEN,
"stats_%u", pdd->dev->id); "stats_%u", pdd->dev->id);
kobj_stats = kfd_alloc_struct(kobj_stats); pdd->kobj_stats = kfd_alloc_struct(pdd->kobj_stats);
if (!kobj_stats) if (!pdd->kobj_stats)
return -ENOMEM; return;
ret = kobject_init_and_add(kobj_stats, ret = kobject_init_and_add(pdd->kobj_stats,
&procfs_stats_type, &procfs_stats_type,
p->kobj, p->kobj,
stats_dir_filename); stats_dir_filename);
...@@ -537,47 +533,28 @@ static int kfd_procfs_add_sysfs_stats(struct kfd_process *p) ...@@ -537,47 +533,28 @@ static int kfd_procfs_add_sysfs_stats(struct kfd_process *p)
if (ret) { if (ret) {
pr_warn("Creating KFD proc/stats_%s folder failed", pr_warn("Creating KFD proc/stats_%s folder failed",
stats_dir_filename); stats_dir_filename);
kobject_put(kobj_stats); kobject_put(pdd->kobj_stats);
goto err; pdd->kobj_stats = NULL;
return;
} }
pdd->kobj_stats = kobj_stats; kfd_sysfs_create_file(pdd->kobj_stats, &pdd->attr_evict,
pdd->attr_evict.name = "evicted_ms"; "evicted_ms");
pdd->attr_evict.mode = KFD_SYSFS_FILE_MODE;
sysfs_attr_init(&pdd->attr_evict);
ret = sysfs_create_file(kobj_stats, &pdd->attr_evict);
if (ret)
pr_warn("Creating eviction stats for gpuid %d failed",
(int)pdd->dev->id);
/* Add sysfs file to report compute unit occupancy */ /* Add sysfs file to report compute unit occupancy */
if (pdd->dev->kfd2kgd->get_cu_occupancy != NULL) { if (pdd->dev->kfd2kgd->get_cu_occupancy)
pdd->attr_cu_occupancy.name = "cu_occupancy"; kfd_sysfs_create_file(pdd->kobj_stats,
pdd->attr_cu_occupancy.mode = KFD_SYSFS_FILE_MODE; &pdd->attr_cu_occupancy,
sysfs_attr_init(&pdd->attr_cu_occupancy); "cu_occupancy");
ret = sysfs_create_file(kobj_stats,
&pdd->attr_cu_occupancy);
if (ret)
pr_warn("Creating %s failed for gpuid: %d",
pdd->attr_cu_occupancy.name,
(int)pdd->dev->id);
}
} }
err:
return ret;
} }
static int kfd_procfs_add_sysfs_files(struct kfd_process *p) static void kfd_procfs_add_sysfs_files(struct kfd_process *p)
{ {
int ret = 0;
int i; int i;
if (!p) if (!p || !p->kobj)
return -EINVAL; return;
if (!p->kobj)
return -EFAULT;
/* /*
* Create sysfs files for each GPU: * Create sysfs files for each GPU:
...@@ -589,20 +566,14 @@ static int kfd_procfs_add_sysfs_files(struct kfd_process *p) ...@@ -589,20 +566,14 @@ static int kfd_procfs_add_sysfs_files(struct kfd_process *p)
snprintf(pdd->vram_filename, MAX_SYSFS_FILENAME_LEN, "vram_%u", snprintf(pdd->vram_filename, MAX_SYSFS_FILENAME_LEN, "vram_%u",
pdd->dev->id); pdd->dev->id);
ret = kfd_sysfs_create_file(p, &pdd->attr_vram, pdd->vram_filename); kfd_sysfs_create_file(p->kobj, &pdd->attr_vram,
if (ret) pdd->vram_filename);
pr_warn("Creating vram usage for gpu id %d failed",
(int)pdd->dev->id);
snprintf(pdd->sdma_filename, MAX_SYSFS_FILENAME_LEN, "sdma_%u", snprintf(pdd->sdma_filename, MAX_SYSFS_FILENAME_LEN, "sdma_%u",
pdd->dev->id); pdd->dev->id);
ret = kfd_sysfs_create_file(p, &pdd->attr_sdma, pdd->sdma_filename); kfd_sysfs_create_file(p->kobj, &pdd->attr_sdma,
if (ret) pdd->sdma_filename);
pr_warn("Creating sdma usage for gpu id %d failed",
(int)pdd->dev->id);
} }
return ret;
} }
void kfd_procfs_del_queue(struct queue *q) void kfd_procfs_del_queue(struct queue *q)
...@@ -800,28 +771,16 @@ struct kfd_process *kfd_create_process(struct file *filep) ...@@ -800,28 +771,16 @@ struct kfd_process *kfd_create_process(struct file *filep)
goto out; goto out;
} }
process->attr_pasid.name = "pasid"; kfd_sysfs_create_file(process->kobj, &process->attr_pasid,
process->attr_pasid.mode = KFD_SYSFS_FILE_MODE; "pasid");
sysfs_attr_init(&process->attr_pasid);
ret = sysfs_create_file(process->kobj, &process->attr_pasid);
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_queues = kobject_create_and_add("queues",
process->kobj); process->kobj);
if (!process->kobj_queues) if (!process->kobj_queues)
pr_warn("Creating KFD proc/queues folder failed"); pr_warn("Creating KFD proc/queues folder failed");
ret = kfd_procfs_add_sysfs_stats(process); kfd_procfs_add_sysfs_stats(process);
if (ret) kfd_procfs_add_sysfs_files(process);
pr_warn("Creating sysfs stats dir for pid %d failed",
(int)process->lead_thread->pid);
ret = kfd_procfs_add_sysfs_files(process);
if (ret)
pr_warn("Creating sysfs usage file for pid %d failed",
(int)process->lead_thread->pid);
} }
out: out:
if (!IS_ERR(process)) if (!IS_ERR(process))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment