diff options
Diffstat (limited to 'include/os/linux/kmem_priv.h')
-rw-r--r-- | include/os/linux/kmem_priv.h | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/include/os/linux/kmem_priv.h b/include/os/linux/kmem_priv.h new file mode 100644 index 0000000..a41762a --- /dev/null +++ b/include/os/linux/kmem_priv.h | |||
@@ -0,0 +1,105 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #ifndef __KMEM_PRIV_H__ | ||
18 | #define __KMEM_PRIV_H__ | ||
19 | |||
20 | #include <nvgpu/rbtree.h> | ||
21 | #include <nvgpu/lock.h> | ||
22 | |||
23 | struct seq_file; | ||
24 | |||
25 | #define __pstat(s, fmt, msg...) \ | ||
26 | do { \ | ||
27 | if (s) \ | ||
28 | seq_printf(s, fmt, ##msg); \ | ||
29 | else \ | ||
30 | pr_info(fmt, ##msg); \ | ||
31 | } while (0) | ||
32 | |||
33 | #define MAX_STACK_TRACE 20 | ||
34 | |||
35 | /* | ||
36 | * Linux specific version of the nvgpu_kmem_cache struct. This type is | ||
37 | * completely opaque to the rest of the driver. | ||
38 | */ | ||
39 | struct nvgpu_kmem_cache { | ||
40 | struct gk20a *g; | ||
41 | struct kmem_cache *cache; | ||
42 | |||
43 | /* | ||
44 | * Memory to hold the kmem_cache unique name. Only necessary on our | ||
45 | * k3.10 kernel when not using the SLUB allocator but it's easier to | ||
46 | * just carry this on to newer kernels. | ||
47 | */ | ||
48 | char name[128]; | ||
49 | }; | ||
50 | |||
51 | #ifdef CONFIG_NVGPU_TRACK_MEM_USAGE | ||
52 | |||
53 | struct nvgpu_mem_alloc { | ||
54 | struct nvgpu_mem_alloc_tracker *owner; | ||
55 | |||
56 | void *ip; | ||
57 | #ifdef __NVGPU_SAVE_KALLOC_STACK_TRACES | ||
58 | unsigned long stack[MAX_STACK_TRACE]; | ||
59 | int stack_length; | ||
60 | #endif | ||
61 | |||
62 | u64 addr; | ||
63 | |||
64 | unsigned long size; | ||
65 | unsigned long real_size; | ||
66 | |||
67 | struct nvgpu_rbtree_node allocs_entry; | ||
68 | }; | ||
69 | |||
70 | static inline struct nvgpu_mem_alloc * | ||
71 | nvgpu_mem_alloc_from_rbtree_node(struct nvgpu_rbtree_node *node) | ||
72 | { | ||
73 | return (struct nvgpu_mem_alloc *) | ||
74 | ((uintptr_t)node - offsetof(struct nvgpu_mem_alloc, allocs_entry)); | ||
75 | }; | ||
76 | |||
77 | /* | ||
78 | * Linux specific tracking of vmalloc, kmalloc, etc. | ||
79 | */ | ||
80 | struct nvgpu_mem_alloc_tracker { | ||
81 | const char *name; | ||
82 | struct nvgpu_kmem_cache *allocs_cache; | ||
83 | struct nvgpu_rbtree_node *allocs; | ||
84 | struct nvgpu_mutex lock; | ||
85 | |||
86 | u64 bytes_alloced; | ||
87 | u64 bytes_freed; | ||
88 | u64 bytes_alloced_real; | ||
89 | u64 bytes_freed_real; | ||
90 | u64 nr_allocs; | ||
91 | u64 nr_frees; | ||
92 | |||
93 | unsigned long min_alloc; | ||
94 | unsigned long max_alloc; | ||
95 | }; | ||
96 | |||
97 | void nvgpu_lock_tracker(struct nvgpu_mem_alloc_tracker *tracker); | ||
98 | void nvgpu_unlock_tracker(struct nvgpu_mem_alloc_tracker *tracker); | ||
99 | |||
100 | void kmem_print_mem_alloc(struct gk20a *g, | ||
101 | struct nvgpu_mem_alloc *alloc, | ||
102 | struct seq_file *s); | ||
103 | #endif /* CONFIG_NVGPU_TRACK_MEM_USAGE */ | ||
104 | |||
105 | #endif /* __KMEM_PRIV_H__ */ | ||