~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/mm/cma_sysfs.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * CMA SysFS Interface
  4  *
  5  * Copyright (c) 2021 Minchan Kim <minchan@kernel.org>
  6  */
  7 
  8 #include <linux/cma.h>
  9 #include <linux/kernel.h>
 10 #include <linux/slab.h>
 11 
 12 #include "cma.h"
 13 
 14 #define CMA_ATTR_RO(_name) \
 15         static struct kobj_attribute _name##_attr = __ATTR_RO(_name)
 16 
 17 void cma_sysfs_account_success_pages(struct cma *cma, unsigned long nr_pages)
 18 {
 19         atomic64_add(nr_pages, &cma->nr_pages_succeeded);
 20 }
 21 
 22 void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages)
 23 {
 24         atomic64_add(nr_pages, &cma->nr_pages_failed);
 25 }
 26 
 27 void cma_sysfs_account_release_pages(struct cma *cma, unsigned long nr_pages)
 28 {
 29         atomic64_add(nr_pages, &cma->nr_pages_released);
 30 }
 31 
 32 static inline struct cma *cma_from_kobj(struct kobject *kobj)
 33 {
 34         return container_of(kobj, struct cma_kobject, kobj)->cma;
 35 }
 36 
 37 static ssize_t alloc_pages_success_show(struct kobject *kobj,
 38                                         struct kobj_attribute *attr, char *buf)
 39 {
 40         struct cma *cma = cma_from_kobj(kobj);
 41 
 42         return sysfs_emit(buf, "%llu\n",
 43                           atomic64_read(&cma->nr_pages_succeeded));
 44 }
 45 CMA_ATTR_RO(alloc_pages_success);
 46 
 47 static ssize_t alloc_pages_fail_show(struct kobject *kobj,
 48                                      struct kobj_attribute *attr, char *buf)
 49 {
 50         struct cma *cma = cma_from_kobj(kobj);
 51 
 52         return sysfs_emit(buf, "%llu\n", atomic64_read(&cma->nr_pages_failed));
 53 }
 54 CMA_ATTR_RO(alloc_pages_fail);
 55 
 56 static ssize_t release_pages_success_show(struct kobject *kobj,
 57                                           struct kobj_attribute *attr, char *buf)
 58 {
 59         struct cma *cma = cma_from_kobj(kobj);
 60 
 61         return sysfs_emit(buf, "%llu\n", atomic64_read(&cma->nr_pages_released));
 62 }
 63 CMA_ATTR_RO(release_pages_success);
 64 
 65 static void cma_kobj_release(struct kobject *kobj)
 66 {
 67         struct cma *cma = cma_from_kobj(kobj);
 68         struct cma_kobject *cma_kobj = cma->cma_kobj;
 69 
 70         kfree(cma_kobj);
 71         cma->cma_kobj = NULL;
 72 }
 73 
 74 static struct attribute *cma_attrs[] = {
 75         &alloc_pages_success_attr.attr,
 76         &alloc_pages_fail_attr.attr,
 77         &release_pages_success_attr.attr,
 78         NULL,
 79 };
 80 ATTRIBUTE_GROUPS(cma);
 81 
 82 static const struct kobj_type cma_ktype = {
 83         .release = cma_kobj_release,
 84         .sysfs_ops = &kobj_sysfs_ops,
 85         .default_groups = cma_groups,
 86 };
 87 
 88 static int __init cma_sysfs_init(void)
 89 {
 90         struct kobject *cma_kobj_root;
 91         struct cma_kobject *cma_kobj;
 92         struct cma *cma;
 93         int i, err;
 94 
 95         cma_kobj_root = kobject_create_and_add("cma", mm_kobj);
 96         if (!cma_kobj_root)
 97                 return -ENOMEM;
 98 
 99         for (i = 0; i < cma_area_count; i++) {
100                 cma_kobj = kzalloc(sizeof(*cma_kobj), GFP_KERNEL);
101                 if (!cma_kobj) {
102                         err = -ENOMEM;
103                         goto out;
104                 }
105 
106                 cma = &cma_areas[i];
107                 cma->cma_kobj = cma_kobj;
108                 cma_kobj->cma = cma;
109                 err = kobject_init_and_add(&cma_kobj->kobj, &cma_ktype,
110                                            cma_kobj_root, "%s", cma->name);
111                 if (err) {
112                         kobject_put(&cma_kobj->kobj);
113                         goto out;
114                 }
115         }
116 
117         return 0;
118 out:
119         while (--i >= 0) {
120                 cma = &cma_areas[i];
121                 kobject_put(&cma->cma_kobj->kobj);
122         }
123         kobject_put(cma_kobj_root);
124 
125         return err;
126 }
127 subsys_initcall(cma_sysfs_init);
128 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php