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