Linux Audio

Check our new training course

Loading...
v5.4
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef __PERF_THREAD_H
  3#define __PERF_THREAD_H
  4
  5#include <linux/refcount.h>
  6#include <linux/rbtree.h>
  7#include <linux/list.h>
  8#include <stdio.h>
  9#include <unistd.h>
 10#include <sys/types.h>
 11#include "srccode.h"
 12#include "symbol_conf.h"
 13#include <strlist.h>
 14#include <intlist.h>
 15#include "rwsem.h"
 
 
 
 16
 17struct addr_location;
 18struct map;
 19struct perf_record_namespaces;
 20struct thread_stack;
 21struct unwind_libunwind_ops;
 22
 23struct thread {
 24	union {
 25		struct rb_node	 rb_node;
 26		struct list_head node;
 27	};
 28	struct map_groups	*mg;
 
 
 
 
 
 
 
 
 
 29	pid_t			pid_; /* Not all tools update this */
 
 30	pid_t			tid;
 
 31	pid_t			ppid;
 32	int			cpu;
 
 33	refcount_t		refcnt;
 
 
 
 
 
 
 34	bool			comm_set;
 35	int			comm_len;
 36	bool			dead; /* if set thread has exited */
 37	struct list_head	namespaces_list;
 38	struct rw_semaphore	namespaces_lock;
 39	struct list_head	comm_list;
 40	struct rw_semaphore	comm_lock;
 41	u64			db_id;
 42
 43	void			*priv;
 44	struct thread_stack	*ts;
 45	struct nsinfo		*nsinfo;
 46	struct srccode_state	srccode_state;
 47	bool			filter;
 48	int			filter_entry_depth;
 
 
 
 
 49};
 50
 51struct machine;
 52struct namespaces;
 53struct comm;
 54
 55struct thread *thread__new(pid_t pid, pid_t tid);
 56int thread__init_map_groups(struct thread *thread, struct machine *machine);
 57void thread__delete(struct thread *thread);
 58
 
 
 59struct thread *thread__get(struct thread *thread);
 60void thread__put(struct thread *thread);
 61
 62static inline void __thread__zput(struct thread **thread)
 63{
 64	thread__put(*thread);
 65	*thread = NULL;
 66}
 67
 68#define thread__zput(thread) __thread__zput(&thread)
 69
 70static inline void thread__exited(struct thread *thread)
 71{
 72	thread->dead = true;
 73}
 74
 75struct namespaces *thread__namespaces(struct thread *thread);
 76int thread__set_namespaces(struct thread *thread, u64 timestamp,
 77			   struct perf_record_namespaces *event);
 78
 79int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp,
 80		       bool exec);
 81static inline int thread__set_comm(struct thread *thread, const char *comm,
 82				   u64 timestamp)
 83{
 84	return __thread__set_comm(thread, comm, timestamp, false);
 85}
 86
 87int thread__set_comm_from_proc(struct thread *thread);
 88
 89int thread__comm_len(struct thread *thread);
 90struct comm *thread__comm(const struct thread *thread);
 91struct comm *thread__exec_comm(const struct thread *thread);
 92const char *thread__comm_str(struct thread *thread);
 93int thread__insert_map(struct thread *thread, struct map *map);
 94int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone);
 95size_t thread__fprintf(struct thread *thread, FILE *fp);
 96
 97struct thread *thread__main_thread(struct machine *machine, struct thread *thread);
 98
 99struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
100			     struct addr_location *al);
101struct map *thread__find_map_fb(struct thread *thread, u8 cpumode, u64 addr,
102				struct addr_location *al);
103
104struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode,
105				   u64 addr, struct addr_location *al);
106struct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode,
107				      u64 addr, struct addr_location *al);
108
109void thread__find_cpumode_addr_location(struct thread *thread, u64 addr,
110					struct addr_location *al);
111
112int thread__memcpy(struct thread *thread, struct machine *machine,
113		   void *buf, u64 ip, int len, bool *is64bit);
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115static inline void *thread__priv(struct thread *thread)
116{
117	return thread->priv;
118}
119
120static inline void thread__set_priv(struct thread *thread, void *p)
121{
122	thread->priv = p;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123}
124
125static inline bool thread__is_filtered(struct thread *thread)
126{
127	if (symbol_conf.comm_list &&
128	    !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) {
129		return true;
130	}
131
132	if (symbol_conf.pid_list &&
133	    !intlist__has_entry(symbol_conf.pid_list, thread->pid_)) {
134		return true;
135	}
136
137	if (symbol_conf.tid_list &&
138	    !intlist__has_entry(symbol_conf.tid_list, thread->tid)) {
139		return true;
140	}
141
142	return false;
143}
 
 
 
 
 
144
145#endif	/* __PERF_THREAD_H */
v6.8
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef __PERF_THREAD_H
  3#define __PERF_THREAD_H
  4
  5#include <linux/refcount.h>
  6#include <linux/rbtree.h>
  7#include <linux/list.h>
  8#include <stdio.h>
  9#include <unistd.h>
 10#include <sys/types.h>
 11#include "srccode.h"
 12#include "symbol_conf.h"
 13#include <strlist.h>
 14#include <intlist.h>
 15#include "rwsem.h"
 16#include "event.h"
 17#include "callchain.h"
 18#include <internal/rc_check.h>
 19
 20struct addr_location;
 21struct map;
 22struct perf_record_namespaces;
 23struct thread_stack;
 24struct unwind_libunwind_ops;
 25
 26struct lbr_stitch {
 27	struct list_head		lists;
 28	struct list_head		free_lists;
 29	struct perf_sample		prev_sample;
 30	struct callchain_cursor_node	*prev_lbr_cursor;
 31};
 32
 33struct thread_rb_node {
 34	struct rb_node rb_node;
 35	struct thread *thread;
 36};
 37
 38DECLARE_RC_STRUCT(thread) {
 39	/** @maps: mmaps associated with this thread. */
 40	struct maps		*maps;
 41	pid_t			pid_; /* Not all tools update this */
 42	/** @tid: thread ID number unique to a machine. */
 43	pid_t			tid;
 44	/** @ppid: parent process of the process this thread belongs to. */
 45	pid_t			ppid;
 46	int			cpu;
 47	int			guest_cpu; /* For QEMU thread */
 48	refcount_t		refcnt;
 49	/**
 50	 * @exited: Has the thread had an exit event. Such threads are usually
 51	 * removed from the machine's threads but some events/tools require
 52	 * access to dead threads.
 53	 */
 54	bool			exited;
 55	bool			comm_set;
 56	int			comm_len;
 
 57	struct list_head	namespaces_list;
 58	struct rw_semaphore	namespaces_lock;
 59	struct list_head	comm_list;
 60	struct rw_semaphore	comm_lock;
 61	u64			db_id;
 62
 63	void			*priv;
 64	struct thread_stack	*ts;
 65	struct nsinfo		*nsinfo;
 66	struct srccode_state	srccode_state;
 67	bool			filter;
 68	int			filter_entry_depth;
 69
 70	/* LBR call stack stitch */
 71	bool			lbr_stitch_enable;
 72	struct lbr_stitch	*lbr_stitch;
 73};
 74
 75struct machine;
 76struct namespaces;
 77struct comm;
 78
 79struct thread *thread__new(pid_t pid, pid_t tid);
 80int thread__init_maps(struct thread *thread, struct machine *machine);
 81void thread__delete(struct thread *thread);
 82
 83void thread__set_priv_destructor(void (*destructor)(void *priv));
 84
 85struct thread *thread__get(struct thread *thread);
 86void thread__put(struct thread *thread);
 87
 88static inline void __thread__zput(struct thread **thread)
 89{
 90	thread__put(*thread);
 91	*thread = NULL;
 92}
 93
 94#define thread__zput(thread) __thread__zput(&thread)
 95
 
 
 
 
 
 96struct namespaces *thread__namespaces(struct thread *thread);
 97int thread__set_namespaces(struct thread *thread, u64 timestamp,
 98			   struct perf_record_namespaces *event);
 99
100int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp,
101		       bool exec);
102static inline int thread__set_comm(struct thread *thread, const char *comm,
103				   u64 timestamp)
104{
105	return __thread__set_comm(thread, comm, timestamp, false);
106}
107
108int thread__set_comm_from_proc(struct thread *thread);
109
110int thread__comm_len(struct thread *thread);
111struct comm *thread__comm(struct thread *thread);
112struct comm *thread__exec_comm(struct thread *thread);
113const char *thread__comm_str(struct thread *thread);
114int thread__insert_map(struct thread *thread, struct map *map);
115int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone);
116size_t thread__fprintf(struct thread *thread, FILE *fp);
117
118struct thread *thread__main_thread(struct machine *machine, struct thread *thread);
119
120struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
121			     struct addr_location *al);
122struct map *thread__find_map_fb(struct thread *thread, u8 cpumode, u64 addr,
123				struct addr_location *al);
124
125struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode,
126				   u64 addr, struct addr_location *al);
127struct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode,
128				      u64 addr, struct addr_location *al);
129
130void thread__find_cpumode_addr_location(struct thread *thread, u64 addr,
131					struct addr_location *al);
132
133int thread__memcpy(struct thread *thread, struct machine *machine,
134		   void *buf, u64 ip, int len, bool *is64bit);
135
136static inline struct maps *thread__maps(struct thread *thread)
137{
138	return RC_CHK_ACCESS(thread)->maps;
139}
140
141static inline void thread__set_maps(struct thread *thread, struct maps *maps)
142{
143	RC_CHK_ACCESS(thread)->maps = maps;
144}
145
146static inline pid_t thread__pid(const struct thread *thread)
147{
148	return RC_CHK_ACCESS(thread)->pid_;
149}
150
151static inline void thread__set_pid(struct thread *thread, pid_t pid_)
152{
153	RC_CHK_ACCESS(thread)->pid_ = pid_;
154}
155
156static inline pid_t thread__tid(const struct thread *thread)
157{
158	return RC_CHK_ACCESS(thread)->tid;
159}
160
161static inline void thread__set_tid(struct thread *thread, pid_t tid)
162{
163	RC_CHK_ACCESS(thread)->tid = tid;
164}
165
166static inline pid_t thread__ppid(const struct thread *thread)
167{
168	return RC_CHK_ACCESS(thread)->ppid;
169}
170
171static inline void thread__set_ppid(struct thread *thread, pid_t ppid)
172{
173	RC_CHK_ACCESS(thread)->ppid = ppid;
174}
175
176static inline int thread__cpu(const struct thread *thread)
177{
178	return RC_CHK_ACCESS(thread)->cpu;
179}
180
181static inline void thread__set_cpu(struct thread *thread, int cpu)
182{
183	RC_CHK_ACCESS(thread)->cpu = cpu;
184}
185
186static inline int thread__guest_cpu(const struct thread *thread)
187{
188	return RC_CHK_ACCESS(thread)->guest_cpu;
189}
190
191static inline void thread__set_guest_cpu(struct thread *thread, int guest_cpu)
192{
193	RC_CHK_ACCESS(thread)->guest_cpu = guest_cpu;
194}
195
196static inline refcount_t *thread__refcnt(struct thread *thread)
197{
198	return &RC_CHK_ACCESS(thread)->refcnt;
199}
200
201static inline void thread__set_exited(struct thread *thread, bool exited)
202{
203	RC_CHK_ACCESS(thread)->exited = exited;
204}
205
206static inline bool thread__comm_set(const struct thread *thread)
207{
208	return RC_CHK_ACCESS(thread)->comm_set;
209}
210
211static inline void thread__set_comm_set(struct thread *thread, bool set)
212{
213	RC_CHK_ACCESS(thread)->comm_set = set;
214}
215
216static inline int thread__var_comm_len(const struct thread *thread)
217{
218	return RC_CHK_ACCESS(thread)->comm_len;
219}
220
221static inline void thread__set_comm_len(struct thread *thread, int len)
222{
223	RC_CHK_ACCESS(thread)->comm_len = len;
224}
225
226static inline struct list_head *thread__namespaces_list(struct thread *thread)
227{
228	return &RC_CHK_ACCESS(thread)->namespaces_list;
229}
230
231static inline int thread__namespaces_list_empty(const struct thread *thread)
232{
233	return list_empty(&RC_CHK_ACCESS(thread)->namespaces_list);
234}
235
236static inline struct rw_semaphore *thread__namespaces_lock(struct thread *thread)
237{
238	return &RC_CHK_ACCESS(thread)->namespaces_lock;
239}
240
241static inline struct list_head *thread__comm_list(struct thread *thread)
242{
243	return &RC_CHK_ACCESS(thread)->comm_list;
244}
245
246static inline struct rw_semaphore *thread__comm_lock(struct thread *thread)
247{
248	return &RC_CHK_ACCESS(thread)->comm_lock;
249}
250
251static inline u64 thread__db_id(const struct thread *thread)
252{
253	return RC_CHK_ACCESS(thread)->db_id;
254}
255
256static inline void thread__set_db_id(struct thread *thread, u64 db_id)
257{
258	RC_CHK_ACCESS(thread)->db_id = db_id;
259}
260
261static inline void *thread__priv(struct thread *thread)
262{
263	return RC_CHK_ACCESS(thread)->priv;
264}
265
266static inline void thread__set_priv(struct thread *thread, void *p)
267{
268	RC_CHK_ACCESS(thread)->priv = p;
269}
270
271static inline struct thread_stack *thread__ts(struct thread *thread)
272{
273	return RC_CHK_ACCESS(thread)->ts;
274}
275
276static inline void thread__set_ts(struct thread *thread, struct thread_stack *ts)
277{
278	RC_CHK_ACCESS(thread)->ts = ts;
279}
280
281static inline struct nsinfo *thread__nsinfo(struct thread *thread)
282{
283	return RC_CHK_ACCESS(thread)->nsinfo;
284}
285
286static inline struct srccode_state *thread__srccode_state(struct thread *thread)
287{
288	return &RC_CHK_ACCESS(thread)->srccode_state;
289}
290
291static inline bool thread__filter(const struct thread *thread)
292{
293	return RC_CHK_ACCESS(thread)->filter;
294}
295
296static inline void thread__set_filter(struct thread *thread, bool filter)
297{
298	RC_CHK_ACCESS(thread)->filter = filter;
299}
300
301static inline int thread__filter_entry_depth(const struct thread *thread)
302{
303	return RC_CHK_ACCESS(thread)->filter_entry_depth;
304}
305
306static inline void thread__set_filter_entry_depth(struct thread *thread, int depth)
307{
308	RC_CHK_ACCESS(thread)->filter_entry_depth = depth;
309}
310
311static inline bool thread__lbr_stitch_enable(const struct thread *thread)
312{
313	return RC_CHK_ACCESS(thread)->lbr_stitch_enable;
314}
315
316static inline void thread__set_lbr_stitch_enable(struct thread *thread, bool en)
317{
318	RC_CHK_ACCESS(thread)->lbr_stitch_enable = en;
319}
320
321static inline struct lbr_stitch	*thread__lbr_stitch(struct thread *thread)
322{
323	return RC_CHK_ACCESS(thread)->lbr_stitch;
324}
325
326static inline void thread__set_lbr_stitch(struct thread *thread, struct lbr_stitch *lbrs)
327{
328	RC_CHK_ACCESS(thread)->lbr_stitch = lbrs;
329}
330
331static inline bool thread__is_filtered(struct thread *thread)
332{
333	if (symbol_conf.comm_list &&
334	    !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) {
335		return true;
336	}
337
338	if (symbol_conf.pid_list &&
339	    !intlist__has_entry(symbol_conf.pid_list, thread__pid(thread))) {
340		return true;
341	}
342
343	if (symbol_conf.tid_list &&
344	    !intlist__has_entry(symbol_conf.tid_list, thread__tid(thread))) {
345		return true;
346	}
347
348	return false;
349}
350
351void thread__free_stitch_list(struct thread *thread);
352
353void thread__resolve(struct thread *thread, struct addr_location *al,
354		     struct perf_sample *sample);
355
356#endif	/* __PERF_THREAD_H */