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 <unistd.h> 9 #include <sys/types.h> 10 #include "symbol.h" 11 #include "map.h" 12 #include <strlist.h> 13 #include <intlist.h> 14 #include "rwsem.h" 15 16 struct namespaces_event; 17 struct thread_stack; 18 struct unwind_libunwind_ops; 19 20 struct thread { 21 union { 22 struct rb_node rb_node; 23 struct list_head node; 24 }; 25 struct map_groups *mg; 26 pid_t pid_; /* Not all tools update this */ 27 pid_t tid; 28 pid_t ppid; 29 int cpu; 30 refcount_t refcnt; 31 bool comm_set; 32 int comm_len; 33 bool dead; /* if set thread has exited */ 34 struct list_head namespaces_list; 35 struct rw_semaphore namespaces_lock; 36 struct list_head comm_list; 37 struct rw_semaphore comm_lock; 38 u64 db_id; 39 40 void *priv; 41 struct thread_stack *ts; 42 struct nsinfo *nsinfo; 43 struct srccode_state srccode_state; 44 #ifdef HAVE_LIBUNWIND_SUPPORT 45 void *addr_space; 46 struct unwind_libunwind_ops *unwind_libunwind_ops; 47 #endif 48 bool filter; 49 int filter_entry_depth; 50 }; 51 52 struct machine; 53 struct namespaces; 54 struct comm; 55 56 struct thread *thread__new(pid_t pid, pid_t tid); 57 int thread__init_map_groups(struct thread *thread, struct machine *machine); 58 void thread__delete(struct thread *thread); 59 60 struct thread *thread__get(struct thread *thread); 61 void thread__put(struct thread *thread); 62 63 static inline void __thread__zput(struct thread **thread) 64 { 65 thread__put(*thread); 66 *thread = NULL; 67 } 68 69 #define thread__zput(thread) __thread__zput(&thread) 70 71 static inline void thread__exited(struct thread *thread) 72 { 73 thread->dead = true; 74 } 75 76 struct namespaces *thread__namespaces(const struct thread *thread); 77 int thread__set_namespaces(struct thread *thread, u64 timestamp, 78 struct namespaces_event *event); 79 80 int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp, 81 bool exec); 82 static inline int thread__set_comm(struct thread *thread, const char *comm, 83 u64 timestamp) 84 { 85 return __thread__set_comm(thread, comm, timestamp, false); 86 } 87 88 int thread__set_comm_from_proc(struct thread *thread); 89 90 int thread__comm_len(struct thread *thread); 91 struct comm *thread__comm(const struct thread *thread); 92 struct comm *thread__exec_comm(const struct thread *thread); 93 const char *thread__comm_str(const struct thread *thread); 94 int thread__insert_map(struct thread *thread, struct map *map); 95 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone); 96 size_t thread__fprintf(struct thread *thread, FILE *fp); 97 98 struct thread *thread__main_thread(struct machine *machine, struct thread *thread); 99 100 struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr, 101 struct addr_location *al); 102 struct map *thread__find_map_fb(struct thread *thread, u8 cpumode, u64 addr, 103 struct addr_location *al); 104 105 struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode, 106 u64 addr, struct addr_location *al); 107 struct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode, 108 u64 addr, struct addr_location *al); 109 110 void thread__find_cpumode_addr_location(struct thread *thread, u64 addr, 111 struct addr_location *al); 112 113 static inline void *thread__priv(struct thread *thread) 114 { 115 return thread->priv; 116 } 117 118 static inline void thread__set_priv(struct thread *thread, void *p) 119 { 120 thread->priv = p; 121 } 122 123 static inline bool thread__is_filtered(struct thread *thread) 124 { 125 if (symbol_conf.comm_list && 126 !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) { 127 return true; 128 } 129 130 if (symbol_conf.pid_list && 131 !intlist__has_entry(symbol_conf.pid_list, thread->pid_)) { 132 return true; 133 } 134 135 if (symbol_conf.tid_list && 136 !intlist__has_entry(symbol_conf.tid_list, thread->tid)) { 137 return true; 138 } 139 140 return false; 141 } 142 143 #endif /* __PERF_THREAD_H */ 144