18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef __PERF_THREAD_H 38c2ecf20Sopenharmony_ci#define __PERF_THREAD_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/refcount.h> 68c2ecf20Sopenharmony_ci#include <linux/rbtree.h> 78c2ecf20Sopenharmony_ci#include <linux/list.h> 88c2ecf20Sopenharmony_ci#include <stdio.h> 98c2ecf20Sopenharmony_ci#include <unistd.h> 108c2ecf20Sopenharmony_ci#include <sys/types.h> 118c2ecf20Sopenharmony_ci#include "srccode.h" 128c2ecf20Sopenharmony_ci#include "symbol_conf.h" 138c2ecf20Sopenharmony_ci#include <strlist.h> 148c2ecf20Sopenharmony_ci#include <intlist.h> 158c2ecf20Sopenharmony_ci#include "rwsem.h" 168c2ecf20Sopenharmony_ci#include "event.h" 178c2ecf20Sopenharmony_ci#include "callchain.h" 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cistruct addr_location; 208c2ecf20Sopenharmony_cistruct map; 218c2ecf20Sopenharmony_cistruct perf_record_namespaces; 228c2ecf20Sopenharmony_cistruct thread_stack; 238c2ecf20Sopenharmony_cistruct unwind_libunwind_ops; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cistruct lbr_stitch { 268c2ecf20Sopenharmony_ci struct list_head lists; 278c2ecf20Sopenharmony_ci struct list_head free_lists; 288c2ecf20Sopenharmony_ci struct perf_sample prev_sample; 298c2ecf20Sopenharmony_ci struct callchain_cursor_node *prev_lbr_cursor; 308c2ecf20Sopenharmony_ci}; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_cistruct thread { 338c2ecf20Sopenharmony_ci union { 348c2ecf20Sopenharmony_ci struct rb_node rb_node; 358c2ecf20Sopenharmony_ci struct list_head node; 368c2ecf20Sopenharmony_ci }; 378c2ecf20Sopenharmony_ci struct maps *maps; 388c2ecf20Sopenharmony_ci pid_t pid_; /* Not all tools update this */ 398c2ecf20Sopenharmony_ci pid_t tid; 408c2ecf20Sopenharmony_ci pid_t ppid; 418c2ecf20Sopenharmony_ci int cpu; 428c2ecf20Sopenharmony_ci refcount_t refcnt; 438c2ecf20Sopenharmony_ci bool comm_set; 448c2ecf20Sopenharmony_ci int comm_len; 458c2ecf20Sopenharmony_ci bool dead; /* if set thread has exited */ 468c2ecf20Sopenharmony_ci struct list_head namespaces_list; 478c2ecf20Sopenharmony_ci struct rw_semaphore namespaces_lock; 488c2ecf20Sopenharmony_ci struct list_head comm_list; 498c2ecf20Sopenharmony_ci struct rw_semaphore comm_lock; 508c2ecf20Sopenharmony_ci u64 db_id; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci void *priv; 538c2ecf20Sopenharmony_ci struct thread_stack *ts; 548c2ecf20Sopenharmony_ci struct nsinfo *nsinfo; 558c2ecf20Sopenharmony_ci struct srccode_state srccode_state; 568c2ecf20Sopenharmony_ci bool filter; 578c2ecf20Sopenharmony_ci int filter_entry_depth; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci /* LBR call stack stitch */ 608c2ecf20Sopenharmony_ci bool lbr_stitch_enable; 618c2ecf20Sopenharmony_ci struct lbr_stitch *lbr_stitch; 628c2ecf20Sopenharmony_ci}; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistruct machine; 658c2ecf20Sopenharmony_cistruct namespaces; 668c2ecf20Sopenharmony_cistruct comm; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistruct thread *thread__new(pid_t pid, pid_t tid); 698c2ecf20Sopenharmony_ciint thread__init_maps(struct thread *thread, struct machine *machine); 708c2ecf20Sopenharmony_civoid thread__delete(struct thread *thread); 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistruct thread *thread__get(struct thread *thread); 738c2ecf20Sopenharmony_civoid thread__put(struct thread *thread); 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistatic inline void __thread__zput(struct thread **thread) 768c2ecf20Sopenharmony_ci{ 778c2ecf20Sopenharmony_ci thread__put(*thread); 788c2ecf20Sopenharmony_ci *thread = NULL; 798c2ecf20Sopenharmony_ci} 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci#define thread__zput(thread) __thread__zput(&thread) 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistatic inline void thread__exited(struct thread *thread) 848c2ecf20Sopenharmony_ci{ 858c2ecf20Sopenharmony_ci thread->dead = true; 868c2ecf20Sopenharmony_ci} 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_cistruct namespaces *thread__namespaces(struct thread *thread); 898c2ecf20Sopenharmony_ciint thread__set_namespaces(struct thread *thread, u64 timestamp, 908c2ecf20Sopenharmony_ci struct perf_record_namespaces *event); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ciint __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp, 938c2ecf20Sopenharmony_ci bool exec); 948c2ecf20Sopenharmony_cistatic inline int thread__set_comm(struct thread *thread, const char *comm, 958c2ecf20Sopenharmony_ci u64 timestamp) 968c2ecf20Sopenharmony_ci{ 978c2ecf20Sopenharmony_ci return __thread__set_comm(thread, comm, timestamp, false); 988c2ecf20Sopenharmony_ci} 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ciint thread__set_comm_from_proc(struct thread *thread); 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ciint thread__comm_len(struct thread *thread); 1038c2ecf20Sopenharmony_cistruct comm *thread__comm(const struct thread *thread); 1048c2ecf20Sopenharmony_cistruct comm *thread__exec_comm(const struct thread *thread); 1058c2ecf20Sopenharmony_ciconst char *thread__comm_str(struct thread *thread); 1068c2ecf20Sopenharmony_ciint thread__insert_map(struct thread *thread, struct map *map); 1078c2ecf20Sopenharmony_ciint thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone); 1088c2ecf20Sopenharmony_cisize_t thread__fprintf(struct thread *thread, FILE *fp); 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_cistruct thread *thread__main_thread(struct machine *machine, struct thread *thread); 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_cistruct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr, 1138c2ecf20Sopenharmony_ci struct addr_location *al); 1148c2ecf20Sopenharmony_cistruct map *thread__find_map_fb(struct thread *thread, u8 cpumode, u64 addr, 1158c2ecf20Sopenharmony_ci struct addr_location *al); 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_cistruct symbol *thread__find_symbol(struct thread *thread, u8 cpumode, 1188c2ecf20Sopenharmony_ci u64 addr, struct addr_location *al); 1198c2ecf20Sopenharmony_cistruct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode, 1208c2ecf20Sopenharmony_ci u64 addr, struct addr_location *al); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_civoid thread__find_cpumode_addr_location(struct thread *thread, u64 addr, 1238c2ecf20Sopenharmony_ci struct addr_location *al); 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ciint thread__memcpy(struct thread *thread, struct machine *machine, 1268c2ecf20Sopenharmony_ci void *buf, u64 ip, int len, bool *is64bit); 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cistatic inline void *thread__priv(struct thread *thread) 1298c2ecf20Sopenharmony_ci{ 1308c2ecf20Sopenharmony_ci return thread->priv; 1318c2ecf20Sopenharmony_ci} 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_cistatic inline void thread__set_priv(struct thread *thread, void *p) 1348c2ecf20Sopenharmony_ci{ 1358c2ecf20Sopenharmony_ci thread->priv = p; 1368c2ecf20Sopenharmony_ci} 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_cistatic inline bool thread__is_filtered(struct thread *thread) 1398c2ecf20Sopenharmony_ci{ 1408c2ecf20Sopenharmony_ci if (symbol_conf.comm_list && 1418c2ecf20Sopenharmony_ci !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) { 1428c2ecf20Sopenharmony_ci return true; 1438c2ecf20Sopenharmony_ci } 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci if (symbol_conf.pid_list && 1468c2ecf20Sopenharmony_ci !intlist__has_entry(symbol_conf.pid_list, thread->pid_)) { 1478c2ecf20Sopenharmony_ci return true; 1488c2ecf20Sopenharmony_ci } 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci if (symbol_conf.tid_list && 1518c2ecf20Sopenharmony_ci !intlist__has_entry(symbol_conf.tid_list, thread->tid)) { 1528c2ecf20Sopenharmony_ci return true; 1538c2ecf20Sopenharmony_ci } 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci return false; 1568c2ecf20Sopenharmony_ci} 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_civoid thread__free_stitch_list(struct thread *thread); 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci#endif /* __PERF_THREAD_H */ 161