aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/map.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/map.h')
-rw-r--r--tools/perf/util/map.h86
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
10enum map_type { 11enum map_type {
@@ -19,7 +20,7 @@ extern const char *map_type__name[MAP__NR_TYPES];
19struct dso; 20struct dso;
20struct ref_reloc_sym; 21struct ref_reloc_sym;
21struct map_groups; 22struct map_groups;
22struct kernel_info; 23struct machine;
23 24
24struct map { 25struct 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
48struct map_groups { 50struct 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
58struct kernel_info { 60struct 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
70static inline
71struct map *machine__kernel_map(struct machine *self, enum map_type type)
72{
73 return self->vmlinux_maps[type];
74}
75
68static inline struct kmap *map__kmap(struct map *self) 76static 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,
124size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp); 132size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp);
125size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp); 133size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp);
126 134
127struct kernel_info *add_new_kernel_info(struct rb_root *kerninfo_root, 135typedef void (*machine__process_t)(struct machine *self, void *data);
128 pid_t pid, const char *root_dir); 136
129struct kernel_info *kerninfo__find(struct rb_root *kerninfo_root, pid_t pid); 137void machines__process(struct rb_root *self, machine__process_t process, void *data);
130struct kernel_info *kerninfo__findnew(struct rb_root *kerninfo_root, pid_t pid); 138struct machine *machines__add(struct rb_root *self, pid_t pid,
131struct kernel_info *kerninfo__findhost(struct rb_root *kerninfo_root); 139 const char *root_dir);
132char *kern_mmap_name(struct kernel_info *kerninfo, char *buff); 140struct machine *machines__find_host(struct rb_root *self);
141struct machine *machines__find(struct rb_root *self, pid_t pid);
142struct machine *machines__findnew(struct rb_root *self, pid_t pid);
143char *machine__mmap_name(struct machine *self, char *bf, size_t size);
144int 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 */
138static inline int is_default_guest(struct kernel_info *kerninfo) 150static 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
145static inline int is_host_kernel(struct kernel_info *kerninfo) 155static 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
152typedef void (*process_kernel_info)(struct kernel_info *kerninfo, void *data);
153void kerninfo__process_allkernels(struct rb_root *kerninfo_root,
154 process_kernel_info process,
155 void *data);
156
157static inline void map_groups__insert(struct map_groups *self, struct map *map) 160static 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
180static inline 183static inline
181struct symbol *map_groups__find_function(struct map_groups *self, u64 addr, 184struct 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
192static inline
193struct 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
187static inline 200static inline
@@ -197,10 +210,7 @@ int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
197 210
198struct map *map_groups__find_by_name(struct map_groups *self, 211struct 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);
200struct map *map_groups__new_module(struct map_groups *self, 213struct 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
205void map_groups__flush(struct map_groups *self); 215void map_groups__flush(struct map_groups *self);
206 216