[PATCH 4/9] amdkfd: Introduce kfd_create_process_sysfs as a separate function
Zhu Lingshan
lingshan.zhu at amd.com
Fri Jul 25 02:43:11 UTC 2025
KFD creates sysfs entries for a kfd_process in
function kfd_create_process when creating it.
This commit extracts the code creating sysfs
entries to a separate function because it
would be invoked in other code path like
creating secondary kfd contexts (kfd_process).
Signed-off-by: Zhu Lingshan <lingshan.zhu at amd.com>
---
drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 1 +
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 66 +++++++++++++++---------
2 files changed, 42 insertions(+), 25 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
index 8149ce0639c0..bf4a8972e3bf 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -1040,6 +1040,7 @@ int kfd_process_create_wq(void);
void kfd_process_destroy_wq(void);
void kfd_cleanup_processes(void);
struct kfd_process *kfd_create_process(struct task_struct *thread);
+int kfd_create_process_sysfs(struct kfd_process *process);
struct kfd_process *kfd_get_process(const struct task_struct *task);
struct kfd_process *kfd_lookup_process_by_pasid(u32 pasid,
struct kfd_process_device **pdd);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index 3f4ac9122203..d8535cd47850 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -825,6 +825,44 @@ static void kfd_process_device_destroy_ib_mem(struct kfd_process_device *pdd)
kfd_process_free_gpuvm(qpd->ib_mem, pdd, &qpd->ib_kaddr);
}
+int kfd_create_process_sysfs(struct kfd_process *process)
+{
+ int ret;
+
+ if (process->kobj) {
+ pr_warn("kobject already exsists for the kfd_process\n");
+ return -EINVAL;
+ }
+
+ process->kobj = kfd_alloc_struct(process->kobj);
+ if (!process->kobj) {
+ pr_warn("Creating procfs kobject failed");
+ return -ENOMEM;
+ }
+ ret = kobject_init_and_add(process->kobj, &procfs_type,
+ procfs.kobj, "%d",
+ (int)process->lead_thread->pid);
+ if (ret) {
+ pr_warn("Creating procfs pid directory failed");
+ kobject_put(process->kobj);
+ return ret;
+ }
+
+ kfd_sysfs_create_file(process->kobj, &process->attr_pasid,
+ "pasid");
+
+ process->kobj_queues = kobject_create_and_add("queues",
+ process->kobj);
+ if (!process->kobj_queues)
+ pr_warn("Creating KFD proc/queues folder failed");
+
+ kfd_procfs_add_sysfs_stats(process);
+ kfd_procfs_add_sysfs_files(process);
+ kfd_procfs_add_sysfs_counters(process);
+
+ return 0;
+}
+
struct kfd_process *kfd_create_process(struct task_struct *thread)
{
struct kfd_process *process;
@@ -874,31 +912,9 @@ struct kfd_process *kfd_create_process(struct task_struct *thread)
if (!procfs.kobj)
goto out;
- process->kobj = kfd_alloc_struct(process->kobj);
- if (!process->kobj) {
- pr_warn("Creating procfs kobject failed");
- goto out;
- }
- ret = kobject_init_and_add(process->kobj, &procfs_type,
- procfs.kobj, "%d",
- (int)process->lead_thread->pid);
- if (ret) {
- pr_warn("Creating procfs pid directory failed");
- kobject_put(process->kobj);
- goto out;
- }
-
- kfd_sysfs_create_file(process->kobj, &process->attr_pasid,
- "pasid");
-
- process->kobj_queues = kobject_create_and_add("queues",
- process->kobj);
- if (!process->kobj_queues)
- pr_warn("Creating KFD proc/queues folder failed");
-
- kfd_procfs_add_sysfs_stats(process);
- kfd_procfs_add_sysfs_files(process);
- kfd_procfs_add_sysfs_counters(process);
+ ret = kfd_create_process_sysfs(process);
+ if (ret)
+ pr_warn("Failed to create sysfs entry for the kfd_process");
kfd_debugfs_add_process(process);
--
2.47.1
More information about the amd-gfx
mailing list