Blame view

tools/perf/util/machine.h 8.8 KB
9d2f8e22f   Arnaldo Carvalho de Melo   perf machine: Int...
1
2
3
4
  #ifndef __PERF_MACHINE_H
  #define __PERF_MACHINE_H
  
  #include <sys/types.h>
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
5
6
  #include <linux/rbtree.h>
  #include "map.h"
8fa7d87f9   Waiman Long   perf symbols: Enc...
7
  #include "dso.h"
58d925dce   Arnaldo Carvalho de Melo   perf machine: Int...
8
  #include "event.h"
9d2f8e22f   Arnaldo Carvalho de Melo   perf machine: Int...
9

b21484f1a   Greg Price   perf report/top: ...
10
  struct addr_location;
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
11
12
13
14
  struct branch_stack;
  struct perf_evsel;
  struct perf_sample;
  struct symbol;
9d2f8e22f   Arnaldo Carvalho de Melo   perf machine: Int...
15
  struct thread;
b0a7d1a0c   Arnaldo Carvalho de Melo   perf machine: Car...
16
  union perf_event;
9d2f8e22f   Arnaldo Carvalho de Melo   perf machine: Int...
17

69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
18
19
20
  /* Native host kernel uses -1 as pid index in machine */
  #define	HOST_KERNEL_ID			(-1)
  #define	DEFAULT_GUEST_KERNEL_ID		(0)
5512cf24b   Adrian Hunter   perf machine: Set...
21
  extern const char *ref_reloc_sym_names[];
d027b6400   Adrian Hunter   perf machine: Fix...
22
  struct vdso_info;
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
23
24
25
26
  struct machine {
  	struct rb_node	  rb_node;
  	pid_t		  pid;
  	u16		  id_hdr_size;
cfe1c4140   Adrian Hunter   perf machine: Add...
27
  	bool		  comm_exec;
caf8a0d04   Arnaldo Carvalho de Melo   perf trace: Warn ...
28
  	bool		  kptr_restrict_warned;
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
29
30
  	char		  *root_dir;
  	struct rb_root	  threads;
b91fc39f4   Arnaldo Carvalho de Melo   perf machine: Pro...
31
  	pthread_rwlock_t  threads_lock;
d2c110344   Arnaldo Carvalho de Melo   perf machine: Int...
32
  	unsigned int	  nr_threads;
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
33
34
  	struct list_head  dead_threads;
  	struct thread	  *last_match;
d027b6400   Adrian Hunter   perf machine: Fix...
35
  	struct vdso_info  *vdso_info;
4cde998d2   Arnaldo Carvalho de Melo   perf machine: Add...
36
  	struct perf_env   *env;
3d39ac538   Arnaldo Carvalho de Melo   perf machine: No ...
37
  	struct dsos	  dsos;
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
38
39
  	struct map_groups kmaps;
  	struct map	  *vmlinux_maps[MAP__NR_TYPES];
fbe2af45f   Adrian Hunter   perf tools: Add m...
40
  	u64		  kernel_start;
b9d266baa   Adrian Hunter   perf machine: Add...
41
  	pid_t		  *current_tid;
0db15b1e8   Adrian Hunter   perf tools: Add f...
42
43
44
45
  	union { /* Tool specific area */
  		void	  *priv;
  		u64	  db_id;
  	};
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
46
47
48
  };
  
  static inline
a5e813c68   Arnaldo Carvalho de Melo   perf machine: Add...
49
  struct map *__machine__kernel_map(struct machine *machine, enum map_type type)
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
50
51
52
  {
  	return machine->vmlinux_maps[type];
  }
a5e813c68   Arnaldo Carvalho de Melo   perf machine: Add...
53
54
55
56
57
  static inline
  struct map *machine__kernel_map(struct machine *machine)
  {
  	return __machine__kernel_map(machine, MAP__FUNCTION);
  }
fbe2af45f   Adrian Hunter   perf tools: Add m...
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  int machine__get_kernel_start(struct machine *machine);
  
  static inline u64 machine__kernel_start(struct machine *machine)
  {
  	if (!machine->kernel_start)
  		machine__get_kernel_start(machine);
  	return machine->kernel_start;
  }
  
  static inline bool machine__kernel_ip(struct machine *machine, u64 ip)
  {
  	u64 kernel_start = machine__kernel_start(machine);
  
  	return ip >= kernel_start;
  }
d75e6097e   Jiri Olsa   perf machine: Fac...
73
74
  struct thread *machine__find_thread(struct machine *machine, pid_t pid,
  				    pid_t tid);
cfe1c4140   Adrian Hunter   perf machine: Add...
75
76
  struct comm *machine__thread_exec_comm(struct machine *machine,
  				       struct thread *thread);
9d2f8e22f   Arnaldo Carvalho de Melo   perf machine: Int...
77

162f0befd   Frederic Weisbecker   perf tools: Add t...
78
79
80
81
82
83
84
85
  int machine__process_comm_event(struct machine *machine, union perf_event *event,
  				struct perf_sample *sample);
  int machine__process_exit_event(struct machine *machine, union perf_event *event,
  				struct perf_sample *sample);
  int machine__process_fork_event(struct machine *machine, union perf_event *event,
  				struct perf_sample *sample);
  int machine__process_lost_event(struct machine *machine, union perf_event *event,
  				struct perf_sample *sample);
c4937a91e   Kan Liang   perf tools: handl...
86
87
  int machine__process_lost_samples_event(struct machine *machine, union perf_event *event,
  					struct perf_sample *sample);
4a96f7a02   Adrian Hunter   perf tools: Add s...
88
89
  int machine__process_aux_event(struct machine *machine,
  			       union perf_event *event);
0ad21f686   Adrian Hunter   perf tools: Add s...
90
91
  int machine__process_itrace_start_event(struct machine *machine,
  					union perf_event *event);
b8f8eb84f   Arnaldo Carvalho de Melo   perf tools: Remov...
92
  int machine__process_switch_event(struct machine *machine,
0286039f7   Adrian Hunter   perf tools: Add n...
93
  				  union perf_event *event);
f3b3614a2   Hari Bathini   perf tools: Add P...
94
95
96
  int machine__process_namespaces_event(struct machine *machine,
  				      union perf_event *event,
  				      struct perf_sample *sample);
162f0befd   Frederic Weisbecker   perf tools: Add t...
97
98
99
100
101
102
  int machine__process_mmap_event(struct machine *machine, union perf_event *event,
  				struct perf_sample *sample);
  int machine__process_mmap2_event(struct machine *machine, union perf_event *event,
  				 struct perf_sample *sample);
  int machine__process_event(struct machine *machine, union perf_event *event,
  				struct perf_sample *sample);
b0a7d1a0c   Arnaldo Carvalho de Melo   perf machine: Car...
103

69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
104
  typedef void (*machine__process_t)(struct machine *machine, void *data);
876650e6c   Arnaldo Carvalho de Melo   perf machine: Int...
105
106
107
108
109
110
111
112
113
114
  struct machines {
  	struct machine host;
  	struct rb_root guests;
  };
  
  void machines__init(struct machines *machines);
  void machines__exit(struct machines *machines);
  
  void machines__process_guests(struct machines *machines,
  			      machine__process_t process, void *data);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
115

876650e6c   Arnaldo Carvalho de Melo   perf machine: Int...
116
  struct machine *machines__add(struct machines *machines, pid_t pid,
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
117
  			      const char *root_dir);
876650e6c   Arnaldo Carvalho de Melo   perf machine: Int...
118
119
120
  struct machine *machines__find_host(struct machines *machines);
  struct machine *machines__find(struct machines *machines, pid_t pid);
  struct machine *machines__findnew(struct machines *machines, pid_t pid);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
121

876650e6c   Arnaldo Carvalho de Melo   perf machine: Int...
122
  void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
123
  char *machine__mmap_name(struct machine *machine, char *bf, size_t size);
cfe1c4140   Adrian Hunter   perf machine: Add...
124
  void machines__set_comm_exec(struct machines *machines, bool comm_exec);
611a5ce8a   Adrian Hunter   perf machine: Add...
125

8fb598e5a   David Ahern   perf trace: Fix c...
126
  struct machine *machine__new_host(void);
7d132caaf   Arnaldo Carvalho de Melo   perf machine: Add...
127
  struct machine *machine__new_kallsyms(void);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
128
129
  int machine__init(struct machine *machine, const char *root_dir, pid_t pid);
  void machine__exit(struct machine *machine);
3f067dcab   Arnaldo Carvalho de Melo   perf machine: Mov...
130
  void machine__delete_threads(struct machine *machine);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
131
  void machine__delete(struct machine *machine);
5e78c69b7   He Kuang   perf buildid-list...
132
  void machine__remove_thread(struct machine *machine, struct thread *th);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
133

644f2df29   Arnaldo Carvalho de Melo   perf tools: Short...
134
135
  struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
  					   struct addr_location *al);
e80faac04   Arnaldo Carvalho de Melo   perf tools: Short...
136
137
  struct mem_info *sample__resolve_mem(struct perf_sample *sample,
  				     struct addr_location *al);
91d7b2de3   Arnaldo Carvalho de Melo   perf callchain: S...
138
139
  
  struct callchain_cursor;
cc8b7c2bf   Arnaldo Carvalho de Melo   perf thread: Adop...
140
  int thread__resolve_callchain(struct thread *thread,
91d7b2de3   Arnaldo Carvalho de Melo   perf callchain: S...
141
  			      struct callchain_cursor *cursor,
cc8b7c2bf   Arnaldo Carvalho de Melo   perf thread: Adop...
142
143
144
145
146
  			      struct perf_evsel *evsel,
  			      struct perf_sample *sample,
  			      struct symbol **parent,
  			      struct addr_location *root_al,
  			      int max_stack);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
147
148
149
150
151
152
153
154
155
156
157
158
159
160
  
  /*
   * Default guest kernel is defined by parameter --guestkallsyms
   * and --guestmodules
   */
  static inline bool machine__is_default_guest(struct machine *machine)
  {
  	return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false;
  }
  
  static inline bool machine__is_host(struct machine *machine)
  {
  	return machine ? machine->pid == HOST_KERNEL_ID : false;
  }
b91fc39f4   Arnaldo Carvalho de Melo   perf machine: Pro...
161
162
  struct thread *__machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid);
  struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
163

aa7cc2ae5   Arnaldo Carvalho de Melo   perf machine: Int...
164
  struct dso *machine__findnew_dso(struct machine *machine, const char *filename);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
165
166
167
168
169
  size_t machine__fprintf(struct machine *machine, FILE *fp);
  
  static inline
  struct symbol *machine__find_kernel_symbol(struct machine *machine,
  					   enum map_type type, u64 addr,
be39db9f2   Arnaldo Carvalho de Melo   perf symbols: Rem...
170
  					   struct map **mapp)
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
171
  {
be39db9f2   Arnaldo Carvalho de Melo   perf symbols: Rem...
172
  	return map_groups__find_symbol(&machine->kmaps, type, addr, mapp);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
173
174
175
  }
  
  static inline
8acd3da03   Arnaldo Carvalho de Melo   perf machine: Int...
176
177
  struct symbol *machine__find_kernel_symbol_by_name(struct machine *machine,
  						   enum map_type type, const char *name,
be39db9f2   Arnaldo Carvalho de Melo   perf symbols: Rem...
178
  						   struct map **mapp)
8acd3da03   Arnaldo Carvalho de Melo   perf machine: Int...
179
  {
be39db9f2   Arnaldo Carvalho de Melo   perf symbols: Rem...
180
  	return map_groups__find_symbol_by_name(&machine->kmaps, type, name, mapp);
8acd3da03   Arnaldo Carvalho de Melo   perf machine: Int...
181
182
183
  }
  
  static inline
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
184
  struct symbol *machine__find_kernel_function(struct machine *machine, u64 addr,
be39db9f2   Arnaldo Carvalho de Melo   perf symbols: Rem...
185
  					     struct map **mapp)
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
186
187
  {
  	return machine__find_kernel_symbol(machine, MAP__FUNCTION, addr,
be39db9f2   Arnaldo Carvalho de Melo   perf symbols: Rem...
188
  					   mapp);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
189
190
191
192
193
  }
  
  static inline
  struct symbol *machine__find_kernel_function_by_name(struct machine *machine,
  						     const char *name,
be39db9f2   Arnaldo Carvalho de Melo   perf symbols: Rem...
194
  						     struct map **mapp)
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
195
  {
be39db9f2   Arnaldo Carvalho de Melo   perf symbols: Rem...
196
  	return map_groups__find_function_by_name(&machine->kmaps, name, mapp);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
197
  }
9f2de3154   Arnaldo Carvalho de Melo   perf machine: Fix...
198
199
  struct map *machine__findnew_module_map(struct machine *machine, u64 start,
  					const char *filename);
203d8a4aa   Song Shan Gong   perf s390: Fix 's...
200
  int arch__fix_module_text_start(u64 *start, const char *name);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
201

e02092b9a   Arnaldo Carvalho de Melo   perf symbols: All...
202
  int __machine__load_kallsyms(struct machine *machine, const char *filename,
be39db9f2   Arnaldo Carvalho de Melo   perf symbols: Rem...
203
  			     enum map_type type, bool no_kcore);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
204
  int machine__load_kallsyms(struct machine *machine, const char *filename,
be39db9f2   Arnaldo Carvalho de Melo   perf symbols: Rem...
205
206
  			   enum map_type type);
  int machine__load_vmlinux_path(struct machine *machine, enum map_type type);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
207

417c2ff68   Arnaldo Carvalho de Melo   perf symbols: Gen...
208
209
  size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
  				     bool (skip)(struct dso *dso, int parm), int parm);
876650e6c   Arnaldo Carvalho de Melo   perf machine: Int...
210
211
  size_t machines__fprintf_dsos(struct machines *machines, FILE *fp);
  size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
417c2ff68   Arnaldo Carvalho de Melo   perf symbols: Gen...
212
  				     bool (skip)(struct dso *dso, int parm), int parm);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
213
214
215
216
  
  void machine__destroy_kernel_maps(struct machine *machine);
  int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
  int machine__create_kernel_maps(struct machine *machine);
876650e6c   Arnaldo Carvalho de Melo   perf machine: Int...
217
218
219
  int machines__create_kernel_maps(struct machines *machines, pid_t pid);
  int machines__create_guest_kernel_maps(struct machines *machines);
  void machines__destroy_kernel_maps(struct machines *machines);
69d2591a8   Arnaldo Carvalho de Melo   perf machine: Mov...
220
221
  
  size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
35feee19f   David Ahern   perf machine: Add...
222
223
224
  int machine__for_each_thread(struct machine *machine,
  			     int (*fn)(struct thread *thread, void *p),
  			     void *priv);
a5499b371   Adrian Hunter   perf tools: Ensur...
225
226
227
  int machines__for_each_thread(struct machines *machines,
  			      int (*fn)(struct thread *thread, void *p),
  			      void *priv);
35feee19f   David Ahern   perf machine: Add...
228

a33fbd56e   Arnaldo Carvalho de Melo   perf machine: Sim...
229
  int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool,
602ad878d   Arnaldo Carvalho de Melo   perf target: Shor...
230
  				  struct target *target, struct thread_map *threads,
9d9cad763   Kan Liang   perf tools: Confi...
231
232
  				  perf_event__handler_t process, bool data_mmap,
  				  unsigned int proc_map_timeout);
a33fbd56e   Arnaldo Carvalho de Melo   perf machine: Sim...
233
  static inline
602ad878d   Arnaldo Carvalho de Melo   perf target: Shor...
234
  int machine__synthesize_threads(struct machine *machine, struct target *target,
9d9cad763   Kan Liang   perf tools: Confi...
235
236
  				struct thread_map *threads, bool data_mmap,
  				unsigned int proc_map_timeout)
a33fbd56e   Arnaldo Carvalho de Melo   perf machine: Sim...
237
238
  {
  	return __machine__synthesize_threads(machine, NULL, target, threads,
9d9cad763   Kan Liang   perf tools: Confi...
239
240
  					     perf_event__process, data_mmap,
  					     proc_map_timeout);
a33fbd56e   Arnaldo Carvalho de Melo   perf machine: Sim...
241
  }
b9d266baa   Adrian Hunter   perf machine: Add...
242
243
244
  pid_t machine__get_current_tid(struct machine *machine, int cpu);
  int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
  			     pid_t tid);
c3168b0db   Arnaldo Carvalho de Melo   perf symbols: Pro...
245
246
247
248
  /*
   * For use with libtraceevent's pevent_set_function_resolver()
   */
  char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, char **modp);
b9d266baa   Adrian Hunter   perf machine: Add...
249

9d2f8e22f   Arnaldo Carvalho de Melo   perf machine: Int...
250
  #endif /* __PERF_MACHINE_H */