0001
0002 #ifndef __PERF_THREAD_H
0003 #define __PERF_THREAD_H
0004
0005 #include <linux/refcount.h>
0006 #include <linux/rbtree.h>
0007 #include <linux/list.h>
0008 #include <stdio.h>
0009 #include <unistd.h>
0010 #include <sys/types.h>
0011 #include "srccode.h"
0012 #include "symbol_conf.h"
0013 #include <strlist.h>
0014 #include <intlist.h>
0015 #include "rwsem.h"
0016 #include "event.h"
0017 #include "callchain.h"
0018
0019 struct addr_location;
0020 struct map;
0021 struct perf_record_namespaces;
0022 struct thread_stack;
0023 struct unwind_libunwind_ops;
0024
0025 struct lbr_stitch {
0026 struct list_head lists;
0027 struct list_head free_lists;
0028 struct perf_sample prev_sample;
0029 struct callchain_cursor_node *prev_lbr_cursor;
0030 };
0031
0032 struct thread {
0033 union {
0034 struct rb_node rb_node;
0035 struct list_head node;
0036 };
0037 struct maps *maps;
0038 pid_t pid_;
0039 pid_t tid;
0040 pid_t ppid;
0041 int cpu;
0042 int guest_cpu;
0043 refcount_t refcnt;
0044 bool comm_set;
0045 int comm_len;
0046 bool dead;
0047 struct list_head namespaces_list;
0048 struct rw_semaphore namespaces_lock;
0049 struct list_head comm_list;
0050 struct rw_semaphore comm_lock;
0051 u64 db_id;
0052
0053 void *priv;
0054 struct thread_stack *ts;
0055 struct nsinfo *nsinfo;
0056 struct srccode_state srccode_state;
0057 bool filter;
0058 int filter_entry_depth;
0059
0060
0061 bool lbr_stitch_enable;
0062 struct lbr_stitch *lbr_stitch;
0063 };
0064
0065 struct machine;
0066 struct namespaces;
0067 struct comm;
0068
0069 struct thread *thread__new(pid_t pid, pid_t tid);
0070 int thread__init_maps(struct thread *thread, struct machine *machine);
0071 void thread__delete(struct thread *thread);
0072
0073 struct thread *thread__get(struct thread *thread);
0074 void thread__put(struct thread *thread);
0075
0076 static inline void __thread__zput(struct thread **thread)
0077 {
0078 thread__put(*thread);
0079 *thread = NULL;
0080 }
0081
0082 #define thread__zput(thread) __thread__zput(&thread)
0083
0084 static inline void thread__exited(struct thread *thread)
0085 {
0086 thread->dead = true;
0087 }
0088
0089 struct namespaces *thread__namespaces(struct thread *thread);
0090 int thread__set_namespaces(struct thread *thread, u64 timestamp,
0091 struct perf_record_namespaces *event);
0092
0093 int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp,
0094 bool exec);
0095 static inline int thread__set_comm(struct thread *thread, const char *comm,
0096 u64 timestamp)
0097 {
0098 return __thread__set_comm(thread, comm, timestamp, false);
0099 }
0100
0101 int thread__set_comm_from_proc(struct thread *thread);
0102
0103 int thread__comm_len(struct thread *thread);
0104 struct comm *thread__comm(const struct thread *thread);
0105 struct comm *thread__exec_comm(const struct thread *thread);
0106 const char *thread__comm_str(struct thread *thread);
0107 int thread__insert_map(struct thread *thread, struct map *map);
0108 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone);
0109 size_t thread__fprintf(struct thread *thread, FILE *fp);
0110
0111 struct thread *thread__main_thread(struct machine *machine, struct thread *thread);
0112
0113 struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
0114 struct addr_location *al);
0115 struct map *thread__find_map_fb(struct thread *thread, u8 cpumode, u64 addr,
0116 struct addr_location *al);
0117
0118 struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode,
0119 u64 addr, struct addr_location *al);
0120 struct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode,
0121 u64 addr, struct addr_location *al);
0122
0123 void thread__find_cpumode_addr_location(struct thread *thread, u64 addr,
0124 struct addr_location *al);
0125
0126 int thread__memcpy(struct thread *thread, struct machine *machine,
0127 void *buf, u64 ip, int len, bool *is64bit);
0128
0129 static inline void *thread__priv(struct thread *thread)
0130 {
0131 return thread->priv;
0132 }
0133
0134 static inline void thread__set_priv(struct thread *thread, void *p)
0135 {
0136 thread->priv = p;
0137 }
0138
0139 static inline bool thread__is_filtered(struct thread *thread)
0140 {
0141 if (symbol_conf.comm_list &&
0142 !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) {
0143 return true;
0144 }
0145
0146 if (symbol_conf.pid_list &&
0147 !intlist__has_entry(symbol_conf.pid_list, thread->pid_)) {
0148 return true;
0149 }
0150
0151 if (symbol_conf.tid_list &&
0152 !intlist__has_entry(symbol_conf.tid_list, thread->tid)) {
0153 return true;
0154 }
0155
0156 return false;
0157 }
0158
0159 void thread__free_stitch_list(struct thread *thread);
0160
0161 #endif