blob: b066fb30d203da8eb87ace26fb3998b4a1ee3fad [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
John Kacur8b40f522009-09-24 18:02:18 +02002#ifndef __PERF_THREAD_H
3#define __PERF_THREAD_H
4
Elena Reshetovae34f5b12017-02-21 17:35:02 +02005#include <linux/refcount.h>
Frederic Weisbecker6baa0a5a2009-08-14 12:21:53 +02006#include <linux/rbtree.h>
Frederic Weisbecker1902efe2013-09-11 16:56:44 +02007#include <linux/list.h>
Arnaldo Carvalho de Meloe22c1c72019-01-28 00:07:40 +01008#include <stdio.h>
Frederic Weisbecker6baa0a5a2009-08-14 12:21:53 +02009#include <unistd.h>
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -030010#include <sys/types.h>
Arnaldo Carvalho de Melo4fed0722019-01-27 11:31:39 +010011#include "srccode.h"
Arnaldo Carvalho de Meloe22c1c72019-01-28 00:07:40 +010012#include "symbol_conf.h"
David Ahern1f3878c2013-11-18 13:32:47 -070013#include <strlist.h>
David Aherne03eaa42015-03-24 09:52:41 -060014#include <intlist.h>
Kan Liangb32ee9e2017-09-29 07:47:52 -070015#include "rwsem.h"
Kan Liang9c6c3f42020-03-19 13:25:10 -070016#include "event.h"
Kan Liang7f1d3932020-03-19 13:25:11 -070017#include "callchain.h"
Frederic Weisbecker6baa0a5a2009-08-14 12:21:53 +020018
Arnaldo Carvalho de Meloe22c1c72019-01-28 00:07:40 +010019struct addr_location;
20struct map;
Arnaldo Carvalho de Melo69d81f02019-08-26 19:02:31 -030021struct perf_record_namespaces;
Adrian Hunter00447cc2014-10-30 16:09:42 +020022struct thread_stack;
He Kuangf83c0412016-06-03 03:33:12 +000023struct unwind_libunwind_ops;
Adrian Hunter00447cc2014-10-30 16:09:42 +020024
Kan Liang9c6c3f42020-03-19 13:25:10 -070025struct lbr_stitch {
Kan Liangff165622020-03-19 13:25:12 -070026 struct list_head lists;
27 struct list_head free_lists;
Kan Liang9c6c3f42020-03-19 13:25:10 -070028 struct perf_sample prev_sample;
Kan Liang7f1d3932020-03-19 13:25:11 -070029 struct callchain_cursor_node *prev_lbr_cursor;
Kan Liang9c6c3f42020-03-19 13:25:10 -070030};
31
Arnaldo Carvalho de Melo9958e1f2009-12-11 14:50:36 -020032struct thread {
Arnaldo Carvalho de Melo720a3ae2010-06-17 08:37:44 -030033 union {
34 struct rb_node rb_node;
35 struct list_head node;
36 };
Arnaldo Carvalho de Melofe87797d2019-11-25 22:07:43 -030037 struct maps *maps;
Adrian Hunter99d725f2013-08-26 16:00:19 +030038 pid_t pid_; /* Not all tools update this */
Adrian Hunter38051232013-07-04 16:20:31 +030039 pid_t tid;
David Ahern70c57ef2013-05-25 22:47:10 -060040 pid_t ppid;
Adrian Hunterbf49c352014-07-22 16:17:24 +030041 int cpu;
Elena Reshetovae34f5b12017-02-21 17:35:02 +020042 refcount_t refcnt;
Arnaldo Carvalho de Melofaa5c5c2010-02-19 23:02:07 -020043 bool comm_set;
Arnaldo Carvalho de Melo86066062015-05-15 17:29:56 -030044 int comm_len;
David Ahern236a3bb2013-08-14 08:49:27 -060045 bool dead; /* if set thread has exited */
Hari Bathinif3b36142017-03-08 02:11:43 +053046 struct list_head namespaces_list;
Kan Liangb32ee9e2017-09-29 07:47:52 -070047 struct rw_semaphore namespaces_lock;
Frederic Weisbecker1902efe2013-09-11 16:56:44 +020048 struct list_head comm_list;
Kan Liangb32ee9e2017-09-29 07:47:52 -070049 struct rw_semaphore comm_lock;
Adrian Hunter0db15b12014-10-23 13:45:13 +030050 u64 db_id;
Xiao Guangrongbcf6edc2012-09-17 16:31:15 +080051
52 void *priv;
Adrian Hunter00447cc2014-10-30 16:09:42 +020053 struct thread_stack *ts;
Krister Johansen843ff372017-07-05 18:48:08 -070054 struct nsinfo *nsinfo;
Andi Kleendd2e18e2018-12-03 16:18:48 -080055 struct srccode_state srccode_state;
Andi Kleen99f753f2018-09-20 11:05:39 -070056 bool filter;
57 int filter_entry_depth;
Kan Liang771fd152020-03-19 13:25:09 -070058
59 /* LBR call stack stitch */
60 bool lbr_stitch_enable;
Kan Liang9c6c3f42020-03-19 13:25:10 -070061 struct lbr_stitch *lbr_stitch;
Frederic Weisbecker6baa0a5a2009-08-14 12:21:53 +020062};
63
Arnaldo Carvalho de Melo743eb8682011-11-28 07:56:39 -020064struct machine;
Hari Bathinif3b36142017-03-08 02:11:43 +053065struct namespaces;
Namhyung Kim4dfced32013-09-13 16:28:57 +090066struct comm;
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -030067
Adrian Hunter99d725f2013-08-26 16:00:19 +030068struct thread *thread__new(pid_t pid, pid_t tid);
Arnaldo Carvalho de Melo79b6bb72019-11-25 21:58:33 -030069int thread__init_maps(struct thread *thread, struct machine *machine);
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030070void thread__delete(struct thread *thread);
Arnaldo Carvalho de Melof3b623b2015-03-02 22:21:35 -030071
72struct thread *thread__get(struct thread *thread);
73void thread__put(struct thread *thread);
74
75static inline void __thread__zput(struct thread **thread)
76{
77 thread__put(*thread);
78 *thread = NULL;
79}
80
81#define thread__zput(thread) __thread__zput(&thread)
82
David Ahern236a3bb2013-08-14 08:49:27 -060083static inline void thread__exited(struct thread *thread)
84{
85 thread->dead = true;
86}
Arnaldo Carvalho de Melo591765f2010-07-30 18:28:42 -030087
Namhyung Kim7cb10a082019-05-27 15:11:49 +090088struct namespaces *thread__namespaces(struct thread *thread);
Hari Bathinif3b36142017-03-08 02:11:43 +053089int thread__set_namespaces(struct thread *thread, u64 timestamp,
Arnaldo Carvalho de Melo69d81f02019-08-26 19:02:31 -030090 struct perf_record_namespaces *event);
Hari Bathinif3b36142017-03-08 02:11:43 +053091
Adrian Hunter65de51f92014-07-31 09:00:44 +030092int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp,
93 bool exec);
94static inline int thread__set_comm(struct thread *thread, const char *comm,
95 u64 timestamp)
96{
97 return __thread__set_comm(thread, comm, timestamp, false);
98}
99
Arnaldo Carvalho de Melo2f3027a2016-04-26 12:32:50 -0300100int thread__set_comm_from_proc(struct thread *thread);
101
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300102int thread__comm_len(struct thread *thread);
Namhyung Kim4dfced32013-09-13 16:28:57 +0900103struct comm *thread__comm(const struct thread *thread);
Adrian Hunter65de51f92014-07-31 09:00:44 +0300104struct comm *thread__exec_comm(const struct thread *thread);
Namhyung Kim7cb10a082019-05-27 15:11:49 +0900105const char *thread__comm_str(struct thread *thread);
He Kuang8132a2a2016-06-03 03:33:13 +0000106int thread__insert_map(struct thread *thread, struct map *map);
David Miller4f8f3822018-10-30 22:24:04 -0700107int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone);
Arnaldo Carvalho de Melo3f067dc2012-12-07 17:39:39 -0300108size_t thread__fprintf(struct thread *thread, FILE *fp);
John Kacur8b40f522009-09-24 18:02:18 +0200109
Andi Kleen480ca352016-05-23 17:52:24 -0700110struct thread *thread__main_thread(struct machine *machine, struct thread *thread);
111
Arnaldo Carvalho de Melo404eb5a2018-04-26 09:34:37 -0300112struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
113 struct addr_location *al);
Adrian Hunter8e80ad92018-11-06 23:07:10 +0200114struct map *thread__find_map_fb(struct thread *thread, u8 cpumode, u64 addr,
115 struct addr_location *al);
Arnaldo Carvalho de Melo59ee68e2010-01-14 23:45:29 -0200116
Arnaldo Carvalho de Melo117d3c22018-04-25 18:16:53 -0300117struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode,
118 u64 addr, struct addr_location *al);
Adrian Hunter8e80ad92018-11-06 23:07:10 +0200119struct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode,
120 u64 addr, struct addr_location *al);
David Ahernba580412013-06-07 16:22:12 -0600121
Arnaldo Carvalho de Melo26bd9332018-04-25 17:58:03 -0300122void thread__find_cpumode_addr_location(struct thread *thread, u64 addr,
Arnaldo Carvalho de Melo52a3cb82014-03-11 16:16:49 -0300123 struct addr_location *al);
124
Andi Kleen15325932019-03-06 17:55:35 -0300125int thread__memcpy(struct thread *thread, struct machine *machine,
126 void *buf, u64 ip, int len, bool *is64bit);
127
David Ahernba580412013-06-07 16:22:12 -0600128static inline void *thread__priv(struct thread *thread)
129{
130 return thread->priv;
131}
132
133static inline void thread__set_priv(struct thread *thread, void *p)
134{
135 thread->priv = p;
136}
David Ahern1f3878c2013-11-18 13:32:47 -0700137
138static inline bool thread__is_filtered(struct thread *thread)
139{
140 if (symbol_conf.comm_list &&
141 !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) {
142 return true;
143 }
144
David Aherne03eaa42015-03-24 09:52:41 -0600145 if (symbol_conf.pid_list &&
146 !intlist__has_entry(symbol_conf.pid_list, thread->pid_)) {
147 return true;
148 }
149
150 if (symbol_conf.tid_list &&
151 !intlist__has_entry(symbol_conf.tid_list, thread->tid)) {
152 return true;
153 }
154
David Ahern1f3878c2013-11-18 13:32:47 -0700155 return false;
156}
157
Kan Liangff165622020-03-19 13:25:12 -0700158void thread__free_stitch_list(struct thread *thread);
Kan Liang9c6c3f42020-03-19 13:25:10 -0700159
John Kacur8b40f522009-09-24 18:02:18 +0200160#endif /* __PERF_THREAD_H */