• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <linux/kobject.h>
2 #include <linux/sysfs.h>
3 #include <linux/gcma.h>
4 #include "gcma_sysfs.h"
5 
6 extern struct kobject *vendor_mm_kobj;
7 static struct kobject gcma_kobj;
8 
9 static atomic64_t gcma_stats[NUM_OF_GCMA_STAT];
10 
gcma_stat_inc(enum gcma_stat_type type)11 void gcma_stat_inc(enum gcma_stat_type type)
12 {
13 	atomic64_inc(&gcma_stats[type]);
14 }
15 
gcma_stat_dec(enum gcma_stat_type type)16 void gcma_stat_dec(enum gcma_stat_type type)
17 {
18 	atomic64_dec(&gcma_stats[type]);
19 }
20 
gcma_stat_add(enum gcma_stat_type type,unsigned long delta)21 void gcma_stat_add(enum gcma_stat_type type, unsigned long delta)
22 {
23 	atomic64_add(delta, &gcma_stats[type]);
24 }
25 
gcma_stat_sub(enum gcma_stat_type type,unsigned long delta)26 void gcma_stat_sub(enum gcma_stat_type type, unsigned long delta)
27 {
28 	atomic64_sub(delta, &gcma_stats[type]);
29 }
30 
gcma_stat_get(enum gcma_stat_type type)31 u64 gcma_stat_get(enum gcma_stat_type type)
32 {
33 	return (u64)atomic64_read(&gcma_stats[type]);
34 }
35 EXPORT_SYMBOL_GPL(gcma_stat_get);
36 
37 /*
38  * This all compiles without CONFIG_SYSFS, but is a waste of space.
39  */
40 
41 #define GCMA_ATTR_RO(_name) \
42 	static struct kobj_attribute _name##_attr = __ATTR_RO(_name)
43 
allocated_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)44 static ssize_t allocated_show(struct kobject *kobj,
45 		struct kobj_attribute *attr, char *buf)
46 {
47 	return sysfs_emit(buf, "%llu\n", (u64)atomic64_read(&gcma_stats[ALLOCATED_PAGE]));
48 }
49 GCMA_ATTR_RO(allocated);
50 
stored_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)51 static ssize_t stored_show(struct kobject *kobj,
52 		struct kobj_attribute *attr, char *buf)
53 {
54 	return sysfs_emit(buf, "%llu\n", (u64)atomic64_read(&gcma_stats[STORED_PAGE]));
55 }
56 GCMA_ATTR_RO(stored);
57 
loaded_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)58 static ssize_t loaded_show(struct kobject *kobj,
59 		struct kobj_attribute *attr, char *buf)
60 {
61 	return sysfs_emit(buf, "%llu\n", (u64)atomic64_read(&gcma_stats[LOADED_PAGE]));
62 }
63 GCMA_ATTR_RO(loaded);
64 
evicted_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)65 static ssize_t evicted_show(struct kobject *kobj,
66 		struct kobj_attribute *attr, char *buf)
67 {
68 	return sysfs_emit(buf, "%llu\n", (u64)atomic64_read(&gcma_stats[EVICTED_PAGE]));
69 }
70 GCMA_ATTR_RO(evicted);
71 
cached_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)72 static ssize_t cached_show(struct kobject *kobj,
73 		struct kobj_attribute *attr, char *buf)
74 {
75 	return sysfs_emit(buf, "%llu\n", (u64)atomic64_read(&gcma_stats[CACHED_PAGE]));
76 }
77 GCMA_ATTR_RO(cached);
78 
discarded_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)79 static ssize_t discarded_show(struct kobject *kobj,
80 		struct kobj_attribute *attr, char *buf)
81 {
82 	return sysfs_emit(buf, "%llu\n", (u64)atomic64_read(&gcma_stats[DISCARDED_PAGE]));
83 }
84 GCMA_ATTR_RO(discarded);
85 
total_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)86 static ssize_t total_show(struct kobject *kobj,
87 		struct kobj_attribute *attr, char *buf)
88 {
89 	return sysfs_emit(buf, "%llu\n", (u64)atomic64_read(&gcma_stats[TOTAL_PAGE]));
90 }
91 GCMA_ATTR_RO(total);
92 
93 static struct attribute *gcma_attrs[] = {
94 	&allocated_attr.attr,
95 	&stored_attr.attr,
96 	&loaded_attr.attr,
97 	&evicted_attr.attr,
98 	&cached_attr.attr,
99 	&discarded_attr.attr,
100 	&total_attr.attr,
101 	NULL,
102 };
103 ATTRIBUTE_GROUPS(gcma);
104 
gcma_kobj_release(struct kobject * obj)105 static void gcma_kobj_release(struct kobject *obj)
106 {
107 	/* Never released the static objects */
108 }
109 
110 static struct kobj_type gcma_ktype = {
111 	.release = gcma_kobj_release,
112 	.sysfs_ops = &kobj_sysfs_ops,
113 	.default_groups = gcma_groups,
114 };
115 
gcma_sysfs_init(void)116 static int __init gcma_sysfs_init(void)
117 {
118 	return kobject_init_and_add(&gcma_kobj, &gcma_ktype, mm_kobj, "gcma");
119 }
120 subsys_initcall(gcma_sysfs_init);
121