Linux 5.1.15
[linux/fpc-iii.git] / tools / perf / util / thread.h
blobcf8375c017a03a1b5e8ba273d8b7d2e24a503c3d
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_THREAD_H
3 #define __PERF_THREAD_H
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"
17 struct addr_location;
18 struct map;
19 struct namespaces_event;
20 struct thread_stack;
21 struct unwind_libunwind_ops;
23 struct thread {
24 union {
25 struct rb_node rb_node;
26 struct list_head node;
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;
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;
55 struct machine;
56 struct namespaces;
57 struct comm;
59 struct thread *thread__new(pid_t pid, pid_t tid);
60 int thread__init_map_groups(struct thread *thread, struct machine *machine);
61 void thread__delete(struct thread *thread);
63 struct thread *thread__get(struct thread *thread);
64 void thread__put(struct thread *thread);
66 static inline void __thread__zput(struct thread **thread)
68 thread__put(*thread);
69 *thread = NULL;
72 #define thread__zput(thread) __thread__zput(&thread)
74 static inline void thread__exited(struct thread *thread)
76 thread->dead = true;
79 struct namespaces *thread__namespaces(const struct thread *thread);
80 int thread__set_namespaces(struct thread *thread, u64 timestamp,
81 struct namespaces_event *event);
83 int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp,
84 bool exec);
85 static inline int thread__set_comm(struct thread *thread, const char *comm,
86 u64 timestamp)
88 return __thread__set_comm(thread, comm, timestamp, false);
91 int thread__set_comm_from_proc(struct thread *thread);
93 int thread__comm_len(struct thread *thread);
94 struct comm *thread__comm(const struct thread *thread);
95 struct comm *thread__exec_comm(const struct thread *thread);
96 const char *thread__comm_str(const struct thread *thread);
97 int thread__insert_map(struct thread *thread, struct map *map);
98 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone);
99 size_t thread__fprintf(struct thread *thread, FILE *fp);
101 struct thread *thread__main_thread(struct machine *machine, struct thread *thread);
103 struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
104 struct addr_location *al);
105 struct map *thread__find_map_fb(struct thread *thread, u8 cpumode, u64 addr,
106 struct addr_location *al);
108 struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode,
109 u64 addr, struct addr_location *al);
110 struct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode,
111 u64 addr, struct addr_location *al);
113 void thread__find_cpumode_addr_location(struct thread *thread, u64 addr,
114 struct addr_location *al);
116 int thread__memcpy(struct thread *thread, struct machine *machine,
117 void *buf, u64 ip, int len, bool *is64bit);
119 static inline void *thread__priv(struct thread *thread)
121 return thread->priv;
124 static inline void thread__set_priv(struct thread *thread, void *p)
126 thread->priv = p;
129 static inline bool thread__is_filtered(struct thread *thread)
131 if (symbol_conf.comm_list &&
132 !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) {
133 return true;
136 if (symbol_conf.pid_list &&
137 !intlist__has_entry(symbol_conf.pid_list, thread->pid_)) {
138 return true;
141 if (symbol_conf.tid_list &&
142 !intlist__has_entry(symbol_conf.tid_list, thread->tid)) {
143 return true;
146 return false;
149 #endif /* __PERF_THREAD_H */