Merge tag 'v3.10.55' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / kmem_mon.h
1 #ifndef __KMEM_MON_H__
2 #define __KMEM_MON_H__
3
4 #include <linux/sched.h>
5
6 #ifdef CONFIG_MTPROF_KMEM
7
8 #ifndef TRUE
9 /** @def TRUE Logical value of true. */
10 #define TRUE 1
11 #endif
12
13 #ifndef FALSE
14 /** @def FALSE Logical value of false. */
15 #define FALSE 0
16 #endif
17
18 /* TODO: relationship amoung differnent definations */
19 #define MAX_PROCESS_NUM (16*1024) /* MAX PID defined by linux: 32 *1024 - 1 */
20 #define MAX_KMEM_MON_NUM (20*1024)
21 #define MAX_ADDR_TABLE (64*1024) /* NOTICE: for the hash */
22 #define MAX_CALLER_TABLE (80*1024)
23 #define MAX_FAIL_PARAMETER 256
24 #define MAX_MEM_CLASS_NUM 64
25 #define MAX_CMD_LINE 64
26 #define MAX_PID_LEN 6 /* because 16*1024 = 16384 */
27 #define MAX_ADDR_IDX (16*1024) /* 14 */
28 #define ADDR_SHIFT 14
29
30 typedef enum {
31 KMEM_MON_TYPE_KMALLOC = 0, /* kmalloc() or kfree(). */
32 KMEM_MON_TYPE_KMEM_CACHE, /* kmem_cache_*(). */
33 KMEM_MON_TYPE_PAGES, /* __get_free_pages() and friends. */
34 KMEM_MON_TYPE_PMEM,
35 KMEM_MON_TYPE_M4U,
36 KMEM_MON_TYPE_VMALLOC,
37 KMEM_MON_TYPE_ASHMEM,
38 KMEM_MON_TYPE_KMALLOCWRAPPER,
39 } MEM_CLASS_T;
40
41 typedef struct mem_class_info_struct {
42 MEM_CLASS_T mem_class;
43
44 int index[MAX_KMEM_MON_NUM];
45 } mem_class_info_t;
46
47 /* TODO: keep caller backtrace */
48 typedef struct caller_info_struct {
49 unsigned long caller_addr;
50 int bytes_req, bytes_alloc;
51 int bytes_free;
52 int freq_alloc, freq_free;
53 int pid;
54 MEM_CLASS_T mem_class;
55 int next_node;
56 } caller_info_t;
57
58 /* NOTICE: if the node is not used, caller_hash == 0 */
59 typedef struct addr_info_struct {
60 unsigned long addr;
61 int caller_hash;
62 int next;
63 } addr_info_t;
64
65 typedef struct process_info_struct {
66 pid_t pid;
67 pid_t tgid;
68 char cmdline[MAX_CMD_LINE];
69 char comm[TASK_COMM_LEN]; /* executable name excluding path
70 - access with [gs]et_task_comm (which lock
71 it with task_lock())
72 - initialized normally by setup_new_exec */
73 int start_idx; /* ->kmalloc->pem... */
74 /* TODO: use an array to arrage all mem nodes */
75 } process_info_t;
76
77 /* ========================================================================== */
78 /**
79 * @struct kmem_info_struct
80 *
81 * @brief keep information for kernel memory monitoring
82 *
83 */
84 /**
85 * @typedef kmem_mon_info_t
86 * @brief Type definition for the kmem_mon_info_struct.
87 */
88 typedef struct mem_info_struct {
89 MEM_CLASS_T mem_class;
90
91 /* these information should be kept in caller table */
92 size_t total_bytes_req;
93 size_t total_bytes_alloc;
94
95 size_t total_bytes_free;
96
97 int alloc_freq;
98 int free_freq;
99
100 int peak_every_req; /* peak size of a single requirment */
101 unsigned long peak_caller; /* code position' */
102 /* ends */
103
104 /* TODO: allocation failures */
105 #if 0
106 int fail_freq;
107 unsigned long fail_caller;
108 char last_fail_parameter[MAX_FAIL_PARAMETER]; /* only record the latest failure's paramter */
109 #endif
110 int caller_start_idx;
111 int next_mem_node;
112 /* */
113 /* TODO: additional info for different memory class */
114 /* */
115 } mem_info_t;
116
117 #endif /* #ifdef CONFIG_MTPROF_KMEM */
118
119 extern void kmem_mon_kmalloc(unsigned long caller, const void *addr, int bytes_req,
120 int bytes_alloc);
121 extern void kmem_mon_kfree(unsigned long caller, const void *addr);
122 extern void kmem_mon_pmem_alloc(int req, int alloc);
123 extern void kmem_mon_pmem_free(int size);
124 extern void kmem_mon_m4u_alloc(int req, int alloc);
125 extern void kmem_mon_m4u_dealloc(const unsigned int addr, const unsigned int req_size);
126 extern void kmem_mon_vmalloc(unsigned long caller, const void *addr, int bytes_req,
127 int bytes_alloc);
128 extern void kmem_mon_vfree(int size);
129 extern void kmem_mon_ashmem_mmap(int size);
130 extern void kmem_mon_ashmem_release(int size);
131 extern void kmem_mon_kmallocwrapper(unsigned long caller, int size);
132 /* extern void kmem_mon_kmallocwrapper(unsigned long caller, const void *addr, int bytes_req, int bytes_alloc); */
133 extern void kmem_mon_kfreewrapper(const void *addr);
134 extern void kmem_mon_kmem_cache_alloc(unsigned long caller, const void *addr, size_t bytes_req,
135 size_t bytes_alloc);
136 extern void kmem_mon_kmem_cache_free(unsigned long caller, const void *addr);
137
138 #endif /* __KMEM_MON_H__ */