diff options
author | Ankit Goyal <layog@google.com> | 2021-07-13 17:21:51 +0800 |
---|---|---|
committer | Ankit Goyal <layog@google.com> | 2021-07-21 21:26:08 +0800 |
commit | 620019f26cee4f69c33fc0861a7975f50b7ce8b3 (patch) | |
tree | 35f557f1998a07f4eb35f05390250d8a3e91f63e /mali_kbase/context | |
parent | ced6904b8892e23333566105d5266515532a9c2c (diff) | |
download | gpu-620019f26cee4f69c33fc0861a7975f50b7ce8b3.tar.gz |
mali_kbase: platform: Add per-process and global sysfs nodes for GPU mem usage
Bug: 191966412
Signed-off-by: Ankit Goyal <layog@google.com>
Change-Id: Id47feadaf9da7ef8e22494ab64e6263d7f87213c
Diffstat (limited to 'mali_kbase/context')
-rw-r--r-- | mali_kbase/context/mali_kbase_context.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/mali_kbase/context/mali_kbase_context.c b/mali_kbase/context/mali_kbase_context.c index 914f43e..3779b37 100644 --- a/mali_kbase/context/mali_kbase_context.c +++ b/mali_kbase/context/mali_kbase_context.c @@ -32,6 +32,48 @@ #include <mmu/mali_kbase_mmu.h> #include <context/mali_kbase_context_internal.h> +#define to_kprcs(kobj) container_of(kobj, struct kbase_process, kobj) + +static void kbase_kprcs_release(struct kobject *kobj) +{ + // Nothing to release +} + +static ssize_t total_gpu_mem_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) +{ + struct kbase_process *kprcs = to_kprcs(kobj); + if (WARN_ON(!kprcs)) + return 0; + + return sysfs_emit(buf, "%lu\n", + (unsigned long) kprcs->total_gpu_pages << PAGE_SHIFT); +} +static struct kobj_attribute total_gpu_mem_attr = __ATTR_RO(total_gpu_mem); + +static ssize_t dma_buf_gpu_mem_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) +{ + struct kbase_process *kprcs = to_kprcs(kobj); + if (WARN_ON(!kprcs)) + return 0; + + return sysfs_emit(buf, "%lu\n", + (unsigned long) kprcs->dma_buf_pages << PAGE_SHIFT); +} +static struct kobj_attribute dma_buf_gpu_mem_attr = __ATTR_RO(dma_buf_gpu_mem); + +static struct attribute *kprcs_attrs[] = { + &total_gpu_mem_attr.attr, + &dma_buf_gpu_mem_attr.attr, + NULL +}; +ATTRIBUTE_GROUPS(kprcs); + +static struct kobj_type kprcs_ktype = { + .release = kbase_kprcs_release, + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = kprcs_groups, +}; + /** * find_process_node - Used to traverse the process rb_tree to find if * process exists already in process rb_tree. @@ -100,6 +142,10 @@ static int kbase_insert_kctx_to_process(struct kbase_context *kctx) kprcs->dma_buf_root = RB_ROOT; kprcs->total_gpu_pages = 0; kprcs->dma_buf_pages = 0; + WARN_ON(kobject_init_and_add( + &kprcs->kobj, &kprcs_ktype, + kctx->kbdev->proc_sysfs_node, + "%d", tgid)); while (*new) { struct kbase_process *prcs_node; @@ -238,6 +284,8 @@ static void kbase_remove_kctx_from_process(struct kbase_context *kctx) */ WARN_ON(kprcs->total_gpu_pages); WARN_ON(!RB_EMPTY_ROOT(&kprcs->dma_buf_root)); + kobject_del(&kprcs->kobj); + kobject_put(&kprcs->kobj); kfree(kprcs); } } |