blob: 14d44c3235b8982a8fb9bf0eebb0ac85224ef017 [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 Weisbecker6baa0a52009-08-14 12:21:53 +02006#include <linux/rbtree.h>
Frederic Weisbecker1902efe2013-09-11 16:56:44 +02007#include <linux/list.h>
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +02008#include <unistd.h>
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -03009#include <sys/types.h>
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +020010#include "symbol.h"
David Ahern1f3878c2013-11-18 13:32:47 -070011#include <strlist.h>
David Aherne03eaa42015-03-24 09:52:41 -060012#include <intlist.h>
Kan Liangb32ee9e2017-09-29 07:47:52 -070013#include "rwsem.h"
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +020014
Adrian Hunter00447cc2014-10-30 16:09:42 +020015struct thread_stack;
He Kuangf83c0412016-06-03 03:33:12 +000016struct unwind_libunwind_ops;
Adrian Hunter00447cc2014-10-30 16:09:42 +020017
Arnaldo Carvalho de Melo9958e1f2009-12-11 14:50:36 -020018struct thread {
Arnaldo Carvalho de Melo720a3ae2010-06-17 08:37:44 -030019 union {
20 struct rb_node rb_node;
21 struct list_head node;
22 };
Arnaldo Carvalho de Melo93d57312014-03-21 17:57:01 -030023 struct map_groups *mg;
Adrian Hunter99d725f2013-08-26 16:00:19 +030024 pid_t pid_; /* Not all tools update this */
Adrian Hunter38051232013-07-04 16:20:31 +030025 pid_t tid;
David Ahern70c57ef2013-05-25 22:47:10 -060026 pid_t ppid;
Adrian Hunterbf49c352014-07-22 16:17:24 +030027 int cpu;
Elena Reshetovae34f5b12017-02-21 17:35:02 +020028 refcount_t refcnt;
Arnaldo Carvalho de Melofaa5c5c2010-02-19 23:02:07 -020029 bool comm_set;
Arnaldo Carvalho de Melo86066062015-05-15 17:29:56 -030030 int comm_len;
David Ahern236a3bb2013-08-14 08:49:27 -060031 bool dead; /* if set thread has exited */
Hari Bathinif3b36142017-03-08 02:11:43 +053032 struct list_head namespaces_list;
Kan Liangb32ee9e2017-09-29 07:47:52 -070033 struct rw_semaphore namespaces_lock;
Frederic Weisbecker1902efe2013-09-11 16:56:44 +020034 struct list_head comm_list;
Kan Liangb32ee9e2017-09-29 07:47:52 -070035 struct rw_semaphore comm_lock;
Adrian Hunter0db15b12014-10-23 13:45:13 +030036 u64 db_id;
Xiao Guangrongbcf6edc2012-09-17 16:31:15 +080037
38 void *priv;
Adrian Hunter00447cc2014-10-30 16:09:42 +020039 struct thread_stack *ts;
Krister Johansen843ff372017-07-05 18:48:08 -070040 struct nsinfo *nsinfo;
Jiri Olsae583d702016-04-07 09:11:12 +020041#ifdef HAVE_LIBUNWIND_SUPPORT
He Kuangf83c0412016-06-03 03:33:12 +000042 void *addr_space;
43 struct unwind_libunwind_ops *unwind_libunwind_ops;
Jiri Olsae583d702016-04-07 09:11:12 +020044#endif
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +020045};
46
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020047struct machine;
Hari Bathinif3b36142017-03-08 02:11:43 +053048struct namespaces;
Namhyung Kim4dfced32013-09-13 16:28:57 +090049struct comm;
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -030050
Adrian Hunter99d725f2013-08-26 16:00:19 +030051struct thread *thread__new(pid_t pid, pid_t tid);
Jiri Olsacddcef62014-04-09 20:54:29 +020052int thread__init_map_groups(struct thread *thread, struct machine *machine);
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030053void thread__delete(struct thread *thread);
Arnaldo Carvalho de Melof3b623b2015-03-02 22:21:35 -030054
55struct thread *thread__get(struct thread *thread);
56void thread__put(struct thread *thread);
57
58static inline void __thread__zput(struct thread **thread)
59{
60 thread__put(*thread);
61 *thread = NULL;
62}
63
64#define thread__zput(thread) __thread__zput(&thread)
65
David Ahern236a3bb2013-08-14 08:49:27 -060066static inline void thread__exited(struct thread *thread)
67{
68 thread->dead = true;
69}
Arnaldo Carvalho de Melo591765f2010-07-30 18:28:42 -030070
Hari Bathinif3b36142017-03-08 02:11:43 +053071struct namespaces *thread__namespaces(const struct thread *thread);
72int thread__set_namespaces(struct thread *thread, u64 timestamp,
73 struct namespaces_event *event);
74
Adrian Hunter65de51f2014-07-31 09:00:44 +030075int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp,
76 bool exec);
77static inline int thread__set_comm(struct thread *thread, const char *comm,
78 u64 timestamp)
79{
80 return __thread__set_comm(thread, comm, timestamp, false);
81}
82
Arnaldo Carvalho de Melo2f3027a2016-04-26 12:32:50 -030083int thread__set_comm_from_proc(struct thread *thread);
84
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030085int thread__comm_len(struct thread *thread);
Namhyung Kim4dfced32013-09-13 16:28:57 +090086struct comm *thread__comm(const struct thread *thread);
Adrian Hunter65de51f2014-07-31 09:00:44 +030087struct comm *thread__exec_comm(const struct thread *thread);
Frederic Weisbeckerb9c51432013-09-11 14:46:56 +020088const char *thread__comm_str(const struct thread *thread);
He Kuang8132a2a2016-06-03 03:33:13 +000089int thread__insert_map(struct thread *thread, struct map *map);
Frederic Weisbecker162f0be2013-09-11 16:18:24 +020090int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp);
Arnaldo Carvalho de Melo3f067dc2012-12-07 17:39:39 -030091size_t thread__fprintf(struct thread *thread, FILE *fp);
John Kacur8b40f522009-09-24 18:02:18 +020092
Andi Kleen480ca352016-05-23 17:52:24 -070093struct thread *thread__main_thread(struct machine *machine, struct thread *thread);
94
Arnaldo Carvalho de Melobb871a92014-10-23 12:50:25 -030095void thread__find_addr_map(struct thread *thread,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020096 u8 cpumode, enum map_type type, u64 addr,
Adrian Hunter326f59b2013-08-08 14:32:27 +030097 struct addr_location *al);
Arnaldo Carvalho de Melo59ee68e2010-01-14 23:45:29 -020098
Arnaldo Carvalho de Melobb871a92014-10-23 12:50:25 -030099void thread__find_addr_location(struct thread *thread,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200100 u8 cpumode, enum map_type type, u64 addr,
Adrian Hunter61710bd2013-08-08 14:32:26 +0300101 struct addr_location *al);
David Ahernba580412013-06-07 16:22:12 -0600102
Arnaldo Carvalho de Melo52a3cb82014-03-11 16:16:49 -0300103void thread__find_cpumode_addr_location(struct thread *thread,
Arnaldo Carvalho de Melo52a3cb82014-03-11 16:16:49 -0300104 enum map_type type, u64 addr,
105 struct addr_location *al);
106
David Ahernba580412013-06-07 16:22:12 -0600107static inline void *thread__priv(struct thread *thread)
108{
109 return thread->priv;
110}
111
112static inline void thread__set_priv(struct thread *thread, void *p)
113{
114 thread->priv = p;
115}
David Ahern1f3878c2013-11-18 13:32:47 -0700116
117static inline bool thread__is_filtered(struct thread *thread)
118{
119 if (symbol_conf.comm_list &&
120 !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) {
121 return true;
122 }
123
David Aherne03eaa42015-03-24 09:52:41 -0600124 if (symbol_conf.pid_list &&
125 !intlist__has_entry(symbol_conf.pid_list, thread->pid_)) {
126 return true;
127 }
128
129 if (symbol_conf.tid_list &&
130 !intlist__has_entry(symbol_conf.tid_list, thread->tid)) {
131 return true;
132 }
133
David Ahern1f3878c2013-11-18 13:32:47 -0700134 return false;
135}
136
John Kacur8b40f522009-09-24 18:02:18 +0200137#endif /* __PERF_THREAD_H */