Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 1 | #ifndef __PERF_MAP_H |
| 2 | #define __PERF_MAP_H |
| 3 | |
| 4 | #include <linux/compiler.h> |
| 5 | #include <linux/list.h> |
| 6 | #include <linux/rbtree.h> |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame] | 7 | #include <stdio.h> |
| 8 | #include "types.h" |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 9 | |
| 10 | enum map_type { |
| 11 | MAP__FUNCTION = 0, |
| 12 | MAP__VARIABLE, |
| 13 | }; |
| 14 | |
| 15 | #define MAP__NR_TYPES (MAP__VARIABLE + 1) |
| 16 | |
Arnaldo Carvalho de Melo | 3846df2 | 2010-02-22 16:15:39 -0300 | [diff] [blame] | 17 | extern const char *map_type__name[MAP__NR_TYPES]; |
| 18 | |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 19 | struct dso; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 20 | struct ref_reloc_sym; |
| 21 | struct map_groups; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame^] | 22 | struct kernel_info; |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 23 | |
| 24 | struct map { |
| 25 | union { |
| 26 | struct rb_node rb_node; |
| 27 | struct list_head node; |
| 28 | }; |
| 29 | u64 start; |
| 30 | u64 end; |
| 31 | enum map_type type; |
| 32 | u64 pgoff; |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 33 | |
| 34 | /* ip -> dso rip */ |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 35 | u64 (*map_ip)(struct map *, u64); |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 36 | /* dso rip -> ip */ |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 37 | u64 (*unmap_ip)(struct map *, u64); |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 38 | |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 39 | struct dso *dso; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame^] | 40 | struct map_groups *groups; |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 41 | }; |
| 42 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 43 | struct kmap { |
| 44 | struct ref_reloc_sym *ref_reloc_sym; |
| 45 | struct map_groups *kmaps; |
| 46 | }; |
| 47 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame^] | 48 | struct map_groups { |
| 49 | struct rb_root maps[MAP__NR_TYPES]; |
| 50 | struct list_head removed_maps[MAP__NR_TYPES]; |
| 51 | struct kernel_info *this_kerninfo; |
| 52 | }; |
| 53 | |
| 54 | /* Native host kernel uses -1 as pid index in kernel_info */ |
| 55 | #define HOST_KERNEL_ID (-1) |
| 56 | #define DEFAULT_GUEST_KERNEL_ID (0) |
| 57 | |
| 58 | struct kernel_info { |
| 59 | struct rb_node rb_node; |
| 60 | pid_t pid; |
| 61 | char *root_dir; |
| 62 | struct list_head dsos__user; |
| 63 | struct list_head dsos__kernel; |
| 64 | struct map_groups kmaps; |
| 65 | struct map *vmlinux_maps[MAP__NR_TYPES]; |
| 66 | }; |
| 67 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 68 | static inline struct kmap *map__kmap(struct map *self) |
| 69 | { |
| 70 | return (struct kmap *)(self + 1); |
| 71 | } |
| 72 | |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 73 | static inline u64 map__map_ip(struct map *map, u64 ip) |
| 74 | { |
| 75 | return ip - map->start + map->pgoff; |
| 76 | } |
| 77 | |
| 78 | static inline u64 map__unmap_ip(struct map *map, u64 ip) |
| 79 | { |
| 80 | return ip + map->start - map->pgoff; |
| 81 | } |
| 82 | |
| 83 | static inline u64 identity__map_ip(struct map *map __used, u64 ip) |
| 84 | { |
| 85 | return ip; |
| 86 | } |
| 87 | |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 88 | |
Kirill Smelkov | ee11b90 | 2010-02-07 11:46:15 -0200 | [diff] [blame] | 89 | /* rip/ip <-> addr suitable for passing to `objdump --start-address=` */ |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 90 | u64 map__rip_2objdump(struct map *map, u64 rip); |
Kirill Smelkov | ee11b90 | 2010-02-07 11:46:15 -0200 | [diff] [blame] | 91 | u64 map__objdump_2ip(struct map *map, u64 addr); |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 92 | |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 93 | struct symbol; |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 94 | |
| 95 | typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym); |
| 96 | |
| 97 | void map__init(struct map *self, enum map_type type, |
| 98 | u64 start, u64 end, u64 pgoff, struct dso *dso); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame^] | 99 | struct map *map__new(struct list_head *dsos__list, u64 start, u64 len, |
| 100 | u64 pgoff, u32 pid, char *filename, |
Arnaldo Carvalho de Melo | b177f63 | 2010-03-25 19:58:57 -0300 | [diff] [blame] | 101 | enum map_type type, char *cwd, int cwdlen); |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 102 | void map__delete(struct map *self); |
| 103 | struct map *map__clone(struct map *self); |
| 104 | int map__overlap(struct map *l, struct map *r); |
| 105 | size_t map__fprintf(struct map *self, FILE *fp); |
| 106 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 107 | int map__load(struct map *self, symbol_filter_t filter); |
| 108 | struct symbol *map__find_symbol(struct map *self, |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 109 | u64 addr, symbol_filter_t filter); |
| 110 | struct symbol *map__find_symbol_by_name(struct map *self, const char *name, |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 111 | symbol_filter_t filter); |
| 112 | void map__fixup_start(struct map *self); |
| 113 | void map__fixup_end(struct map *self); |
| 114 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 115 | void map__reloc_vmlinux(struct map *self); |
| 116 | |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame] | 117 | size_t __map_groups__fprintf_maps(struct map_groups *self, |
Arnaldo Carvalho de Melo | c6e718f | 2010-03-26 12:11:06 -0300 | [diff] [blame] | 118 | enum map_type type, int verbose, FILE *fp); |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame] | 119 | void maps__insert(struct rb_root *maps, struct map *map); |
| 120 | struct map *maps__find(struct rb_root *maps, u64 addr); |
| 121 | void map_groups__init(struct map_groups *self); |
Arnaldo Carvalho de Melo | c6e718f | 2010-03-26 12:11:06 -0300 | [diff] [blame] | 122 | int map_groups__clone(struct map_groups *self, |
| 123 | struct map_groups *parent, enum map_type type); |
| 124 | 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); |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame] | 126 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame^] | 127 | struct kernel_info *add_new_kernel_info(struct rb_root *kerninfo_root, |
| 128 | pid_t pid, const char *root_dir); |
| 129 | struct kernel_info *kerninfo__find(struct rb_root *kerninfo_root, pid_t pid); |
| 130 | struct kernel_info *kerninfo__findnew(struct rb_root *kerninfo_root, pid_t pid); |
| 131 | struct kernel_info *kerninfo__findhost(struct rb_root *kerninfo_root); |
| 132 | char *kern_mmap_name(struct kernel_info *kerninfo, char *buff); |
| 133 | |
| 134 | /* |
| 135 | * Default guest kernel is defined by parameter --guestkallsyms |
| 136 | * and --guestmodules |
| 137 | */ |
| 138 | static inline int is_default_guest(struct kernel_info *kerninfo) |
| 139 | { |
| 140 | if (!kerninfo) |
| 141 | return 0; |
| 142 | return kerninfo->pid == DEFAULT_GUEST_KERNEL_ID; |
| 143 | } |
| 144 | |
| 145 | static inline int is_host_kernel(struct kernel_info *kerninfo) |
| 146 | { |
| 147 | if (!kerninfo) |
| 148 | return 0; |
| 149 | return kerninfo->pid == HOST_KERNEL_ID; |
| 150 | } |
| 151 | |
| 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 | |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame] | 157 | static inline void map_groups__insert(struct map_groups *self, struct map *map) |
| 158 | { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame^] | 159 | maps__insert(&self->maps[map->type], map); |
| 160 | map->groups = self; |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | static inline struct map *map_groups__find(struct map_groups *self, |
| 164 | enum map_type type, u64 addr) |
| 165 | { |
| 166 | return maps__find(&self->maps[type], addr); |
| 167 | } |
| 168 | |
| 169 | struct symbol *map_groups__find_symbol(struct map_groups *self, |
| 170 | enum map_type type, u64 addr, |
Arnaldo Carvalho de Melo | 7e5e1b1 | 2010-03-26 12:30:40 -0300 | [diff] [blame] | 171 | struct map **mapp, |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame] | 172 | symbol_filter_t filter); |
| 173 | |
Arnaldo Carvalho de Melo | 7e5e1b1 | 2010-03-26 12:30:40 -0300 | [diff] [blame] | 174 | struct symbol *map_groups__find_symbol_by_name(struct map_groups *self, |
| 175 | enum map_type type, |
| 176 | const char *name, |
| 177 | struct map **mapp, |
| 178 | symbol_filter_t filter); |
| 179 | |
| 180 | static inline |
| 181 | struct symbol *map_groups__find_function(struct map_groups *self, u64 addr, |
| 182 | struct map **mapp, symbol_filter_t filter) |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame] | 183 | { |
Arnaldo Carvalho de Melo | 7e5e1b1 | 2010-03-26 12:30:40 -0300 | [diff] [blame] | 184 | return map_groups__find_symbol(self, MAP__FUNCTION, addr, mapp, filter); |
| 185 | } |
| 186 | |
| 187 | static inline |
| 188 | struct symbol *map_groups__find_function_by_name(struct map_groups *self, |
| 189 | const char *name, struct map **mapp, |
| 190 | symbol_filter_t filter) |
| 191 | { |
| 192 | return map_groups__find_symbol_by_name(self, MAP__FUNCTION, name, mapp, filter); |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame] | 193 | } |
| 194 | |
Arnaldo Carvalho de Melo | c6e718f | 2010-03-26 12:11:06 -0300 | [diff] [blame] | 195 | int map_groups__fixup_overlappings(struct map_groups *self, struct map *map, |
| 196 | int verbose, FILE *fp); |
| 197 | |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame] | 198 | struct map *map_groups__find_by_name(struct map_groups *self, |
| 199 | enum map_type type, const char *name); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame^] | 200 | struct map *map_groups__new_module(struct map_groups *self, |
| 201 | u64 start, |
| 202 | const char *filename, |
| 203 | struct kernel_info *kerninfo); |
| 204 | |
Arnaldo Carvalho de Melo | c6e718f | 2010-03-26 12:11:06 -0300 | [diff] [blame] | 205 | void map_groups__flush(struct map_groups *self); |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame] | 206 | |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 207 | #endif /* __PERF_MAP_H */ |