diff options
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/kmem_priv.h')
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/kmem_priv.h | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/kmem_priv.h b/drivers/gpu/nvgpu/common/linux/kmem_priv.h new file mode 100644 index 00000000..5e38ad5d --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/kmem_priv.h | |||
@@ -0,0 +1,90 @@ | |||
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 <linux/rbtree.h> | ||
21 | |||
22 | #define __pstat(s, fmt, msg...) \ | ||
23 | do { \ | ||
24 | if (s) \ | ||
25 | seq_printf(s, fmt, ##msg); \ | ||
26 | else \ | ||
27 | pr_info(fmt, ##msg); \ | ||
28 | } while (0) | ||
29 | |||
30 | #define MAX_STACK_TRACE 20 | ||
31 | |||
32 | /* | ||
33 | * Linux specific version of the nvgpu_kmem_cache struct. This type is | ||
34 | * completely opaque to the rest of the driver. | ||
35 | */ | ||
36 | struct nvgpu_kmem_cache { | ||
37 | struct gk20a *g; | ||
38 | struct kmem_cache *cache; | ||
39 | |||
40 | /* | ||
41 | * Memory to hold the kmem_cache unique name. Only necessary on our | ||
42 | * k3.10 kernel when not using the SLUB allocator but it's easier to | ||
43 | * just carry this on to newer kernels. | ||
44 | */ | ||
45 | char name[128]; | ||
46 | }; | ||
47 | |||
48 | #ifdef CONFIG_NVGPU_TRACK_MEM_USAGE | ||
49 | |||
50 | struct nvgpu_mem_alloc { | ||
51 | struct nvgpu_mem_alloc_tracker *owner; | ||
52 | |||
53 | void *ip; | ||
54 | #ifdef __NVGPU_SAVE_KALLOC_STACK_TRACES | ||
55 | unsigned long stack[MAX_STACK_TRACE]; | ||
56 | int stack_length; | ||
57 | #endif | ||
58 | |||
59 | u64 addr; | ||
60 | |||
61 | unsigned long size; | ||
62 | unsigned long real_size; | ||
63 | |||
64 | /* Ugh - linux specific. Will need to be abstracted. */ | ||
65 | struct rb_node allocs_entry; | ||
66 | }; | ||
67 | |||
68 | /* | ||
69 | * Linux specific tracking of vmalloc, kmalloc, etc. | ||
70 | */ | ||
71 | struct nvgpu_mem_alloc_tracker { | ||
72 | const char *name; | ||
73 | struct nvgpu_kmem_cache *allocs_cache; | ||
74 | struct rb_root allocs; | ||
75 | struct mutex lock; | ||
76 | |||
77 | u64 bytes_alloced; | ||
78 | u64 bytes_freed; | ||
79 | u64 bytes_alloced_real; | ||
80 | u64 bytes_freed_real; | ||
81 | u64 nr_allocs; | ||
82 | u64 nr_frees; | ||
83 | |||
84 | unsigned long min_alloc; | ||
85 | unsigned long max_alloc; | ||
86 | }; | ||
87 | |||
88 | #endif /* CONFIG_NVGPU_TRACK_MEM_USAGE */ | ||
89 | |||
90 | #endif /* __KMEM_PRIV_H__ */ | ||