Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

amdkfd: identify a secondary kfd process by its id

This commit introduces a new id field for
struct kfd process, which helps identify
a kfd process among multiple contexts that
all belong to a single user space program.

The sysfs entry of a secondary kfd process
is placed under the sysfs entry folder of
its primary kfd process.

The naming format of the sysfs entry of a secondary
kfd process is "context_%u" where %u is the context id.

Signed-off-by: Zhu Lingshan <lingshan.zhu@amd.com>
Reviewed-by: Felix Kuehling <felix.kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Zhu Lingshan and committed by
Alex Deucher
fac682a1 1707d576

+80 -3
+5
drivers/gpu/drm/amd/amdkfd/kfd_priv.h
··· 1020 1020 1021 1021 /*kfd context id */ 1022 1022 u16 context_id; 1023 + 1024 + /* The primary kfd_process allocating IDs for its secondary kfd_process, 0 for primary kfd_process */ 1025 + struct ida id_table; 1026 + 1023 1027 }; 1024 1028 1025 1029 #define KFD_PROCESS_TABLE_SIZE 8 /* bits: 256 entries */ 1026 1030 #define KFD_CONTEXT_ID_PRIMARY 0xFFFF 1031 + #define KFD_CONTEXT_ID_MIN 0 1027 1032 1028 1033 extern DECLARE_HASHTABLE(kfd_processes_table, KFD_PROCESS_TABLE_SIZE); 1029 1034 extern struct srcu_struct kfd_processes_srcu;
+75 -3
drivers/gpu/drm/amd/amdkfd/kfd_process.c
··· 827 827 828 828 int kfd_create_process_sysfs(struct kfd_process *process) 829 829 { 830 + struct kfd_process *primary_process; 830 831 int ret; 831 832 832 833 if (process->kobj) { ··· 840 839 pr_warn("Creating procfs kobject failed"); 841 840 return -ENOMEM; 842 841 } 843 - ret = kobject_init_and_add(process->kobj, &procfs_type, 844 - procfs.kobj, "%d", 845 - (int)process->lead_thread->pid); 842 + 843 + if (process->context_id == KFD_CONTEXT_ID_PRIMARY) 844 + ret = kobject_init_and_add(process->kobj, &procfs_type, 845 + procfs.kobj, "%d", 846 + (int)process->lead_thread->pid); 847 + else { 848 + primary_process = kfd_lookup_process_by_mm(process->lead_thread->mm); 849 + if (!primary_process) 850 + return -ESRCH; 851 + 852 + ret = kobject_init_and_add(process->kobj, &procfs_type, 853 + primary_process->kobj, "context_%u", 854 + process->context_id); 855 + kfd_unref_process(primary_process); 856 + } 857 + 846 858 if (ret) { 847 859 pr_warn("Creating procfs pid directory failed"); 848 860 kobject_put(process->kobj); ··· 875 861 kfd_procfs_add_sysfs_counters(process); 876 862 877 863 return 0; 864 + } 865 + 866 + static int kfd_process_alloc_id(struct kfd_process *process) 867 + { 868 + int ret; 869 + struct kfd_process *primary_process; 870 + 871 + /* already assign 0xFFFF when create */ 872 + if (process->context_id == KFD_CONTEXT_ID_PRIMARY) 873 + return 0; 874 + 875 + primary_process = kfd_lookup_process_by_mm(process->lead_thread->mm); 876 + if (!primary_process) 877 + return -ESRCH; 878 + 879 + /* id range: KFD_CONTEXT_ID_MIN to 0xFFFE */ 880 + ret = ida_alloc_range(&primary_process->id_table, KFD_CONTEXT_ID_MIN, 881 + KFD_CONTEXT_ID_PRIMARY - 1, GFP_KERNEL); 882 + if (ret < 0) 883 + goto out; 884 + 885 + process->context_id = ret; 886 + ret = 0; 887 + 888 + out: 889 + kfd_unref_process(primary_process); 890 + 891 + return ret; 892 + } 893 + 894 + static void kfd_process_free_id(struct kfd_process *process) 895 + { 896 + struct kfd_process *primary_process; 897 + 898 + if (process->context_id != KFD_CONTEXT_ID_PRIMARY) 899 + return; 900 + 901 + primary_process = kfd_lookup_process_by_mm(process->lead_thread->mm); 902 + if (!primary_process) 903 + return; 904 + 905 + ida_free(&primary_process->id_table, process->context_id); 906 + 907 + kfd_unref_process(primary_process); 878 908 } 879 909 880 910 struct kfd_process *kfd_create_process(struct task_struct *thread) ··· 1248 1190 ef = rcu_access_pointer(p->ef); 1249 1191 if (ef) 1250 1192 dma_fence_signal(ef); 1193 + 1194 + if (p->context_id != KFD_CONTEXT_ID_PRIMARY) 1195 + kfd_process_free_id(p); 1196 + else 1197 + ida_destroy(&p->id_table); 1251 1198 1252 1199 kfd_process_remove_sysfs(p); 1253 1200 kfd_debugfs_remove_process(p); ··· 1668 1605 goto err_register_notifier; 1669 1606 } 1670 1607 BUG_ON(mn != &process->mmu_notifier); 1608 + ida_init(&process->id_table); 1609 + } 1610 + 1611 + err = kfd_process_alloc_id(process); 1612 + if (err) { 1613 + pr_err("Creating kfd process: failed to alloc an id\n"); 1614 + goto err_alloc_id; 1671 1615 } 1672 1616 1673 1617 kfd_unref_process(process); ··· 1684 1614 1685 1615 return process; 1686 1616 1617 + err_alloc_id: 1618 + kfd_process_free_id(process); 1687 1619 err_register_notifier: 1688 1620 hash_del_rcu(&process->kfd_processes); 1689 1621 svm_range_list_fini(process);