blob: 30d38d634e091db990cb3003c9f399ae9b22957a [file] [log] [blame]
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -02001#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 Melo4b8cf842010-03-25 19:58:58 -03007#include <stdio.h>
8#include "types.h"
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -02009
10enum map_type {
11 MAP__FUNCTION = 0,
12 MAP__VARIABLE,
13};
14
15#define MAP__NR_TYPES (MAP__VARIABLE + 1)
16
Arnaldo Carvalho de Melo3846df22010-02-22 16:15:39 -030017extern const char *map_type__name[MAP__NR_TYPES];
18
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020019struct dso;
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -020020struct ref_reloc_sym;
21struct map_groups;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +080022struct kernel_info;
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020023
24struct 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 Smelkov7a2b6202010-02-03 16:52:07 -020033
34 /* ip -> dso rip */
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020035 u64 (*map_ip)(struct map *, u64);
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020036 /* dso rip -> ip */
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020037 u64 (*unmap_ip)(struct map *, u64);
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020038
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020039 struct dso *dso;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +080040 struct map_groups *groups;
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020041};
42
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -020043struct kmap {
44 struct ref_reloc_sym *ref_reloc_sym;
45 struct map_groups *kmaps;
46};
47
Zhang, Yanmina1645ce2010-04-19 13:32:50 +080048struct 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
58struct 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 Melo9de89fe2010-02-03 16:52:00 -020068static inline struct kmap *map__kmap(struct map *self)
69{
70 return (struct kmap *)(self + 1);
71}
72
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020073static inline u64 map__map_ip(struct map *map, u64 ip)
74{
75 return ip - map->start + map->pgoff;
76}
77
78static inline u64 map__unmap_ip(struct map *map, u64 ip)
79{
80 return ip + map->start - map->pgoff;
81}
82
83static inline u64 identity__map_ip(struct map *map __used, u64 ip)
84{
85 return ip;
86}
87
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020088
Kirill Smelkovee11b902010-02-07 11:46:15 -020089/* rip/ip <-> addr suitable for passing to `objdump --start-address=` */
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020090u64 map__rip_2objdump(struct map *map, u64 rip);
Kirill Smelkovee11b902010-02-07 11:46:15 -020091u64 map__objdump_2ip(struct map *map, u64 addr);
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020092
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020093struct symbol;
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020094
95typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);
96
97void map__init(struct map *self, enum map_type type,
98 u64 start, u64 end, u64 pgoff, struct dso *dso);
Zhang, Yanmina1645ce2010-04-19 13:32:50 +080099struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,
100 u64 pgoff, u32 pid, char *filename,
Arnaldo Carvalho de Melob177f632010-03-25 19:58:57 -0300101 enum map_type type, char *cwd, int cwdlen);
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -0200102void map__delete(struct map *self);
103struct map *map__clone(struct map *self);
104int map__overlap(struct map *l, struct map *r);
105size_t map__fprintf(struct map *self, FILE *fp);
106
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -0200107int map__load(struct map *self, symbol_filter_t filter);
108struct symbol *map__find_symbol(struct map *self,
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -0200109 u64 addr, symbol_filter_t filter);
110struct symbol *map__find_symbol_by_name(struct map *self, const char *name,
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -0200111 symbol_filter_t filter);
112void map__fixup_start(struct map *self);
113void map__fixup_end(struct map *self);
114
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -0200115void map__reloc_vmlinux(struct map *self);
116
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300117size_t __map_groups__fprintf_maps(struct map_groups *self,
Arnaldo Carvalho de Meloc6e718f2010-03-26 12:11:06 -0300118 enum map_type type, int verbose, FILE *fp);
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300119void maps__insert(struct rb_root *maps, struct map *map);
120struct map *maps__find(struct rb_root *maps, u64 addr);
121void map_groups__init(struct map_groups *self);
Arnaldo Carvalho de Meloc6e718f2010-03-26 12:11:06 -0300122int map_groups__clone(struct map_groups *self,
123 struct map_groups *parent, enum map_type type);
124size_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);
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300126
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800127struct kernel_info *add_new_kernel_info(struct rb_root *kerninfo_root,
128 pid_t pid, const char *root_dir);
129struct kernel_info *kerninfo__find(struct rb_root *kerninfo_root, pid_t pid);
130struct kernel_info *kerninfo__findnew(struct rb_root *kerninfo_root, pid_t pid);
131struct kernel_info *kerninfo__findhost(struct rb_root *kerninfo_root);
132char *kern_mmap_name(struct kernel_info *kerninfo, char *buff);
133
134/*
135 * Default guest kernel is defined by parameter --guestkallsyms
136 * and --guestmodules
137 */
138static 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
145static 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
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
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300157static inline void map_groups__insert(struct map_groups *self, struct map *map)
158{
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800159 maps__insert(&self->maps[map->type], map);
160 map->groups = self;
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300161}
162
163static 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
169struct symbol *map_groups__find_symbol(struct map_groups *self,
170 enum map_type type, u64 addr,
Arnaldo Carvalho de Melo7e5e1b12010-03-26 12:30:40 -0300171 struct map **mapp,
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300172 symbol_filter_t filter);
173
Arnaldo Carvalho de Melo7e5e1b12010-03-26 12:30:40 -0300174struct 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
180static inline
181struct symbol *map_groups__find_function(struct map_groups *self, u64 addr,
182 struct map **mapp, symbol_filter_t filter)
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300183{
Arnaldo Carvalho de Melo7e5e1b12010-03-26 12:30:40 -0300184 return map_groups__find_symbol(self, MAP__FUNCTION, addr, mapp, filter);
185}
186
187static inline
188struct 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 Melo4b8cf842010-03-25 19:58:58 -0300193}
194
Arnaldo Carvalho de Meloc6e718f2010-03-26 12:11:06 -0300195int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
196 int verbose, FILE *fp);
197
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300198struct map *map_groups__find_by_name(struct map_groups *self,
199 enum map_type type, const char *name);
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800200struct 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 Meloc6e718f2010-03-26 12:11:06 -0300205void map_groups__flush(struct map_groups *self);
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300206
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -0200207#endif /* __PERF_MAP_H */