diff options
Diffstat (limited to 'tools/perf/util/map.h')
-rw-r--r-- | tools/perf/util/map.h | 86 |
1 files changed, 48 insertions, 38 deletions
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 30d38d634e09..f39134512829 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <linux/list.h> | 5 | #include <linux/list.h> |
6 | #include <linux/rbtree.h> | 6 | #include <linux/rbtree.h> |
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | #include <stdbool.h> | ||
8 | #include "types.h" | 9 | #include "types.h" |
9 | 10 | ||
10 | enum map_type { | 11 | enum map_type { |
@@ -19,7 +20,7 @@ extern const char *map_type__name[MAP__NR_TYPES]; | |||
19 | struct dso; | 20 | struct dso; |
20 | struct ref_reloc_sym; | 21 | struct ref_reloc_sym; |
21 | struct map_groups; | 22 | struct map_groups; |
22 | struct kernel_info; | 23 | struct machine; |
23 | 24 | ||
24 | struct map { | 25 | struct map { |
25 | union { | 26 | union { |
@@ -29,6 +30,7 @@ struct map { | |||
29 | u64 start; | 30 | u64 start; |
30 | u64 end; | 31 | u64 end; |
31 | enum map_type type; | 32 | enum map_type type; |
33 | u32 priv; | ||
32 | u64 pgoff; | 34 | u64 pgoff; |
33 | 35 | ||
34 | /* ip -> dso rip */ | 36 | /* ip -> dso rip */ |
@@ -46,25 +48,31 @@ struct kmap { | |||
46 | }; | 48 | }; |
47 | 49 | ||
48 | struct map_groups { | 50 | struct map_groups { |
49 | struct rb_root maps[MAP__NR_TYPES]; | 51 | struct rb_root maps[MAP__NR_TYPES]; |
50 | struct list_head removed_maps[MAP__NR_TYPES]; | 52 | struct list_head removed_maps[MAP__NR_TYPES]; |
51 | struct kernel_info *this_kerninfo; | 53 | struct machine *machine; |
52 | }; | 54 | }; |
53 | 55 | ||
54 | /* Native host kernel uses -1 as pid index in kernel_info */ | 56 | /* Native host kernel uses -1 as pid index in machine */ |
55 | #define HOST_KERNEL_ID (-1) | 57 | #define HOST_KERNEL_ID (-1) |
56 | #define DEFAULT_GUEST_KERNEL_ID (0) | 58 | #define DEFAULT_GUEST_KERNEL_ID (0) |
57 | 59 | ||
58 | struct kernel_info { | 60 | struct machine { |
59 | struct rb_node rb_node; | 61 | struct rb_node rb_node; |
60 | pid_t pid; | 62 | pid_t pid; |
61 | char *root_dir; | 63 | char *root_dir; |
62 | struct list_head dsos__user; | 64 | struct list_head user_dsos; |
63 | struct list_head dsos__kernel; | 65 | struct list_head kernel_dsos; |
64 | struct map_groups kmaps; | 66 | struct map_groups kmaps; |
65 | struct map *vmlinux_maps[MAP__NR_TYPES]; | 67 | struct map *vmlinux_maps[MAP__NR_TYPES]; |
66 | }; | 68 | }; |
67 | 69 | ||
70 | static inline | ||
71 | struct map *machine__kernel_map(struct machine *self, enum map_type type) | ||
72 | { | ||
73 | return self->vmlinux_maps[type]; | ||
74 | } | ||
75 | |||
68 | static inline struct kmap *map__kmap(struct map *self) | 76 | static inline struct kmap *map__kmap(struct map *self) |
69 | { | 77 | { |
70 | return (struct kmap *)(self + 1); | 78 | return (struct kmap *)(self + 1); |
@@ -124,36 +132,31 @@ int map_groups__clone(struct map_groups *self, | |||
124 | size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp); | 132 | size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp); |
125 | size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp); | 133 | size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp); |
126 | 134 | ||
127 | struct kernel_info *add_new_kernel_info(struct rb_root *kerninfo_root, | 135 | typedef void (*machine__process_t)(struct machine *self, void *data); |
128 | pid_t pid, const char *root_dir); | 136 | |
129 | struct kernel_info *kerninfo__find(struct rb_root *kerninfo_root, pid_t pid); | 137 | void machines__process(struct rb_root *self, machine__process_t process, void *data); |
130 | struct kernel_info *kerninfo__findnew(struct rb_root *kerninfo_root, pid_t pid); | 138 | struct machine *machines__add(struct rb_root *self, pid_t pid, |
131 | struct kernel_info *kerninfo__findhost(struct rb_root *kerninfo_root); | 139 | const char *root_dir); |
132 | char *kern_mmap_name(struct kernel_info *kerninfo, char *buff); | 140 | struct machine *machines__find_host(struct rb_root *self); |
141 | struct machine *machines__find(struct rb_root *self, pid_t pid); | ||
142 | struct machine *machines__findnew(struct rb_root *self, pid_t pid); | ||
143 | char *machine__mmap_name(struct machine *self, char *bf, size_t size); | ||
144 | int machine__init(struct machine *self, const char *root_dir, pid_t pid); | ||
133 | 145 | ||
134 | /* | 146 | /* |
135 | * Default guest kernel is defined by parameter --guestkallsyms | 147 | * Default guest kernel is defined by parameter --guestkallsyms |
136 | * and --guestmodules | 148 | * and --guestmodules |
137 | */ | 149 | */ |
138 | static inline int is_default_guest(struct kernel_info *kerninfo) | 150 | static inline bool machine__is_default_guest(struct machine *self) |
139 | { | 151 | { |
140 | if (!kerninfo) | 152 | return self ? self->pid == DEFAULT_GUEST_KERNEL_ID : false; |
141 | return 0; | ||
142 | return kerninfo->pid == DEFAULT_GUEST_KERNEL_ID; | ||
143 | } | 153 | } |
144 | 154 | ||
145 | static inline int is_host_kernel(struct kernel_info *kerninfo) | 155 | static inline bool machine__is_host(struct machine *self) |
146 | { | 156 | { |
147 | if (!kerninfo) | 157 | return self ? self->pid == HOST_KERNEL_ID : false; |
148 | return 0; | ||
149 | return kerninfo->pid == HOST_KERNEL_ID; | ||
150 | } | 158 | } |
151 | 159 | ||
152 | typedef void (*process_kernel_info)(struct kernel_info *kerninfo, void *data); | ||
153 | void kerninfo__process_allkernels(struct rb_root *kerninfo_root, | ||
154 | process_kernel_info process, | ||
155 | void *data); | ||
156 | |||
157 | static inline void map_groups__insert(struct map_groups *self, struct map *map) | 160 | static inline void map_groups__insert(struct map_groups *self, struct map *map) |
158 | { | 161 | { |
159 | maps__insert(&self->maps[map->type], map); | 162 | maps__insert(&self->maps[map->type], map); |
@@ -178,10 +181,20 @@ struct symbol *map_groups__find_symbol_by_name(struct map_groups *self, | |||
178 | symbol_filter_t filter); | 181 | symbol_filter_t filter); |
179 | 182 | ||
180 | static inline | 183 | static inline |
181 | struct symbol *map_groups__find_function(struct map_groups *self, u64 addr, | 184 | struct symbol *machine__find_kernel_symbol(struct machine *self, |
182 | struct map **mapp, symbol_filter_t filter) | 185 | enum map_type type, u64 addr, |
186 | struct map **mapp, | ||
187 | symbol_filter_t filter) | ||
188 | { | ||
189 | return map_groups__find_symbol(&self->kmaps, type, addr, mapp, filter); | ||
190 | } | ||
191 | |||
192 | static inline | ||
193 | struct symbol *machine__find_kernel_function(struct machine *self, u64 addr, | ||
194 | struct map **mapp, | ||
195 | symbol_filter_t filter) | ||
183 | { | 196 | { |
184 | return map_groups__find_symbol(self, MAP__FUNCTION, addr, mapp, filter); | 197 | return machine__find_kernel_symbol(self, MAP__FUNCTION, addr, mapp, filter); |
185 | } | 198 | } |
186 | 199 | ||
187 | static inline | 200 | static inline |
@@ -197,10 +210,7 @@ int map_groups__fixup_overlappings(struct map_groups *self, struct map *map, | |||
197 | 210 | ||
198 | struct map *map_groups__find_by_name(struct map_groups *self, | 211 | struct map *map_groups__find_by_name(struct map_groups *self, |
199 | enum map_type type, const char *name); | 212 | enum map_type type, const char *name); |
200 | struct map *map_groups__new_module(struct map_groups *self, | 213 | struct map *machine__new_module(struct machine *self, u64 start, const char *filename); |
201 | u64 start, | ||
202 | const char *filename, | ||
203 | struct kernel_info *kerninfo); | ||
204 | 214 | ||
205 | void map_groups__flush(struct map_groups *self); | 215 | void map_groups__flush(struct map_groups *self); |
206 | 216 | ||