1
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 namespaces_event;
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_;
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;
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#ifdef HAVE_LIBUNWIND_SUPPORT
48 void *addr_space;
49 struct unwind_libunwind_ops *unwind_libunwind_ops;
50#endif
51 bool filter;
52 int filter_entry_depth;
53};
54
55struct machine;
56struct namespaces;
57struct comm;
58
59struct thread *thread__new(pid_t pid, pid_t tid);
60int thread__init_map_groups(struct thread *thread, struct machine *machine);
61void thread__delete(struct thread *thread);
62
63struct thread *thread__get(struct thread *thread);
64void thread__put(struct thread *thread);
65
66static inline void __thread__zput(struct thread **thread)
67{
68 thread__put(*thread);
69 *thread = NULL;
70}
71
72#define thread__zput(thread) __thread__zput(&thread)
73
74static inline void thread__exited(struct thread *thread)
75{
76 thread->dead = true;
77}
78
79struct namespaces *thread__namespaces(struct thread *thread);
80int thread__set_namespaces(struct thread *thread, u64 timestamp,
81 struct namespaces_event *event);
82
83int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp,
84 bool exec);
85static inline int thread__set_comm(struct thread *thread, const char *comm,
86 u64 timestamp)
87{
88 return __thread__set_comm(thread, comm, timestamp, false);
89}
90
91int thread__set_comm_from_proc(struct thread *thread);
92
93int thread__comm_len(struct thread *thread);
94struct comm *thread__comm(const struct thread *thread);
95struct comm *thread__exec_comm(const struct thread *thread);
96const char *thread__comm_str(struct thread *thread);
97int thread__insert_map(struct thread *thread, struct map *map);
98int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone);
99size_t thread__fprintf(struct thread *thread, FILE *fp);
100
101struct thread *thread__main_thread(struct machine *machine, struct thread *thread);
102
103struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
104 struct addr_location *al);
105struct map *thread__find_map_fb(struct thread *thread, u8 cpumode, u64 addr,
106 struct addr_location *al);
107
108struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode,
109 u64 addr, struct addr_location *al);
110struct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode,
111 u64 addr, struct addr_location *al);
112
113void thread__find_cpumode_addr_location(struct thread *thread, u64 addr,
114 struct addr_location *al);
115
116int thread__memcpy(struct thread *thread, struct machine *machine,
117 void *buf, u64 ip, int len, bool *is64bit);
118
119static inline void *thread__priv(struct thread *thread)
120{
121 return thread->priv;
122}
123
124static inline void thread__set_priv(struct thread *thread, void *p)
125{
126 thread->priv = p;
127}
128
129static inline bool thread__is_filtered(struct thread *thread)
130{
131 if (symbol_conf.comm_list &&
132 !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) {
133 return true;
134 }
135
136 if (symbol_conf.pid_list &&
137 !intlist__has_entry(symbol_conf.pid_list, thread->pid_)) {
138 return true;
139 }
140
141 if (symbol_conf.tid_list &&
142 !intlist__has_entry(symbol_conf.tid_list, thread->tid)) {
143 return true;
144 }
145
146 return false;
147}
148
149#endif
150