diff options
Diffstat (limited to 'mm/cma_debug.c')
-rw-r--r-- | mm/cma_debug.c | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/mm/cma_debug.c b/mm/cma_debug.c index 0b377536ccde..7621ee34daa0 100644 --- a/mm/cma_debug.c +++ b/mm/cma_debug.c | |||
@@ -30,9 +30,44 @@ static int cma_debugfs_get(void *data, u64 *val) | |||
30 | 30 | ||
31 | return 0; | 31 | return 0; |
32 | } | 32 | } |
33 | |||
34 | DEFINE_SIMPLE_ATTRIBUTE(cma_debugfs_fops, cma_debugfs_get, NULL, "%llu\n"); | 33 | DEFINE_SIMPLE_ATTRIBUTE(cma_debugfs_fops, cma_debugfs_get, NULL, "%llu\n"); |
35 | 34 | ||
35 | static int cma_used_get(void *data, u64 *val) | ||
36 | { | ||
37 | struct cma *cma = data; | ||
38 | unsigned long used; | ||
39 | |||
40 | mutex_lock(&cma->lock); | ||
41 | /* pages counter is smaller than sizeof(int) */ | ||
42 | used = bitmap_weight(cma->bitmap, (int)cma->count); | ||
43 | mutex_unlock(&cma->lock); | ||
44 | *val = (u64)used << cma->order_per_bit; | ||
45 | |||
46 | return 0; | ||
47 | } | ||
48 | DEFINE_SIMPLE_ATTRIBUTE(cma_used_fops, cma_used_get, NULL, "%llu\n"); | ||
49 | |||
50 | static int cma_maxchunk_get(void *data, u64 *val) | ||
51 | { | ||
52 | struct cma *cma = data; | ||
53 | unsigned long maxchunk = 0; | ||
54 | unsigned long start, end = 0; | ||
55 | |||
56 | mutex_lock(&cma->lock); | ||
57 | for (;;) { | ||
58 | start = find_next_zero_bit(cma->bitmap, cma->count, end); | ||
59 | if (start >= cma->count) | ||
60 | break; | ||
61 | end = find_next_bit(cma->bitmap, cma->count, start); | ||
62 | maxchunk = max(end - start, maxchunk); | ||
63 | } | ||
64 | mutex_unlock(&cma->lock); | ||
65 | *val = (u64)maxchunk << cma->order_per_bit; | ||
66 | |||
67 | return 0; | ||
68 | } | ||
69 | DEFINE_SIMPLE_ATTRIBUTE(cma_maxchunk_fops, cma_maxchunk_get, NULL, "%llu\n"); | ||
70 | |||
36 | static void cma_add_to_cma_mem_list(struct cma *cma, struct cma_mem *mem) | 71 | static void cma_add_to_cma_mem_list(struct cma *cma, struct cma_mem *mem) |
37 | { | 72 | { |
38 | spin_lock(&cma->mem_head_lock); | 73 | spin_lock(&cma->mem_head_lock); |
@@ -91,7 +126,6 @@ static int cma_free_write(void *data, u64 val) | |||
91 | 126 | ||
92 | return cma_free_mem(cma, pages); | 127 | return cma_free_mem(cma, pages); |
93 | } | 128 | } |
94 | |||
95 | DEFINE_SIMPLE_ATTRIBUTE(cma_free_fops, NULL, cma_free_write, "%llu\n"); | 129 | DEFINE_SIMPLE_ATTRIBUTE(cma_free_fops, NULL, cma_free_write, "%llu\n"); |
96 | 130 | ||
97 | static int cma_alloc_mem(struct cma *cma, int count) | 131 | static int cma_alloc_mem(struct cma *cma, int count) |
@@ -124,7 +158,6 @@ static int cma_alloc_write(void *data, u64 val) | |||
124 | 158 | ||
125 | return cma_alloc_mem(cma, pages); | 159 | return cma_alloc_mem(cma, pages); |
126 | } | 160 | } |
127 | |||
128 | DEFINE_SIMPLE_ATTRIBUTE(cma_alloc_fops, NULL, cma_alloc_write, "%llu\n"); | 161 | DEFINE_SIMPLE_ATTRIBUTE(cma_alloc_fops, NULL, cma_alloc_write, "%llu\n"); |
129 | 162 | ||
130 | static void cma_debugfs_add_one(struct cma *cma, int idx) | 163 | static void cma_debugfs_add_one(struct cma *cma, int idx) |
@@ -149,6 +182,8 @@ static void cma_debugfs_add_one(struct cma *cma, int idx) | |||
149 | &cma->count, &cma_debugfs_fops); | 182 | &cma->count, &cma_debugfs_fops); |
150 | debugfs_create_file("order_per_bit", S_IRUGO, tmp, | 183 | debugfs_create_file("order_per_bit", S_IRUGO, tmp, |
151 | &cma->order_per_bit, &cma_debugfs_fops); | 184 | &cma->order_per_bit, &cma_debugfs_fops); |
185 | debugfs_create_file("used", S_IRUGO, tmp, cma, &cma_used_fops); | ||
186 | debugfs_create_file("maxchunk", S_IRUGO, tmp, cma, &cma_maxchunk_fops); | ||
152 | 187 | ||
153 | u32s = DIV_ROUND_UP(cma_bitmap_maxno(cma), BITS_PER_BYTE * sizeof(u32)); | 188 | u32s = DIV_ROUND_UP(cma_bitmap_maxno(cma), BITS_PER_BYTE * sizeof(u32)); |
154 | debugfs_create_u32_array("bitmap", S_IRUGO, tmp, (u32*)cma->bitmap, u32s); | 189 | debugfs_create_u32_array("bitmap", S_IRUGO, tmp, (u32*)cma->bitmap, u32s); |