blob: 9b8a54dc34a81963d8026e226bcd3334713b1606 [file] [log] [blame]
John Kacur8b40f522009-09-24 18:02:18 +02001#ifndef __PERF_THREAD_H
2#define __PERF_THREAD_H
3
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +02004#include <linux/rbtree.h>
Frederic Weisbecker1902efe2013-09-11 16:56:44 +02005#include <linux/list.h>
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +02006#include <unistd.h>
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -03007#include <sys/types.h>
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +02008#include "symbol.h"
David Ahern1f3878c2013-11-18 13:32:47 -07009#include <strlist.h>
David Aherne03eaa42015-03-24 09:52:41 -060010#include <intlist.h>
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +020011
Adrian Hunter00447cc2014-10-30 16:09:42 +020012struct thread_stack;
13
Arnaldo Carvalho de Melo9958e1f2009-12-11 14:50:36 -020014struct thread {
Arnaldo Carvalho de Melo720a3ae2010-06-17 08:37:44 -030015 union {
16 struct rb_node rb_node;
17 struct list_head node;
18 };
Arnaldo Carvalho de Melo93d57312014-03-21 17:57:01 -030019 struct map_groups *mg;
Adrian Hunter99d725f2013-08-26 16:00:19 +030020 pid_t pid_; /* Not all tools update this */
Adrian Hunter38051232013-07-04 16:20:31 +030021 pid_t tid;
David Ahern70c57ef2013-05-25 22:47:10 -060022 pid_t ppid;
Adrian Hunterbf49c352014-07-22 16:17:24 +030023 int cpu;
Arnaldo Carvalho de Melof3b623b2015-03-02 22:21:35 -030024 int refcnt;
Ingo Molnar0ec04e12009-09-16 17:40:48 +020025 char shortname[3];
Arnaldo Carvalho de Melofaa5c5c2010-02-19 23:02:07 -020026 bool comm_set;
David Ahern236a3bb2013-08-14 08:49:27 -060027 bool dead; /* if set thread has exited */
Frederic Weisbecker1902efe2013-09-11 16:56:44 +020028 struct list_head comm_list;
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +020029 int comm_len;
Adrian Hunter0db15b12014-10-23 13:45:13 +030030 u64 db_id;
Xiao Guangrongbcf6edc2012-09-17 16:31:15 +080031
32 void *priv;
Adrian Hunter00447cc2014-10-30 16:09:42 +020033 struct thread_stack *ts;
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +020034};
35
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020036struct machine;
Namhyung Kim4dfced32013-09-13 16:28:57 +090037struct comm;
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -030038
Adrian Hunter99d725f2013-08-26 16:00:19 +030039struct thread *thread__new(pid_t pid, pid_t tid);
Jiri Olsacddcef62014-04-09 20:54:29 +020040int thread__init_map_groups(struct thread *thread, struct machine *machine);
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030041void thread__delete(struct thread *thread);
Arnaldo Carvalho de Melof3b623b2015-03-02 22:21:35 -030042
43struct thread *thread__get(struct thread *thread);
44void thread__put(struct thread *thread);
45
46static inline void __thread__zput(struct thread **thread)
47{
48 thread__put(*thread);
49 *thread = NULL;
50}
51
52#define thread__zput(thread) __thread__zput(&thread)
53
David Ahern236a3bb2013-08-14 08:49:27 -060054static inline void thread__exited(struct thread *thread)
55{
56 thread->dead = true;
57}
Arnaldo Carvalho de Melo591765f2010-07-30 18:28:42 -030058
Adrian Hunter65de51f2014-07-31 09:00:44 +030059int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp,
60 bool exec);
61static inline int thread__set_comm(struct thread *thread, const char *comm,
62 u64 timestamp)
63{
64 return __thread__set_comm(thread, comm, timestamp, false);
65}
66
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030067int thread__comm_len(struct thread *thread);
Namhyung Kim4dfced32013-09-13 16:28:57 +090068struct comm *thread__comm(const struct thread *thread);
Adrian Hunter65de51f2014-07-31 09:00:44 +030069struct comm *thread__exec_comm(const struct thread *thread);
Frederic Weisbeckerb9c51432013-09-11 14:46:56 +020070const char *thread__comm_str(const struct thread *thread);
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030071void thread__insert_map(struct thread *thread, struct map *map);
Frederic Weisbecker162f0be2013-09-11 16:18:24 +020072int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp);
Arnaldo Carvalho de Melo3f067dc2012-12-07 17:39:39 -030073size_t thread__fprintf(struct thread *thread, FILE *fp);
John Kacur8b40f522009-09-24 18:02:18 +020074
Arnaldo Carvalho de Melobb871a92014-10-23 12:50:25 -030075void thread__find_addr_map(struct thread *thread,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020076 u8 cpumode, enum map_type type, u64 addr,
Adrian Hunter326f59b2013-08-08 14:32:27 +030077 struct addr_location *al);
Arnaldo Carvalho de Melo59ee68e2010-01-14 23:45:29 -020078
Arnaldo Carvalho de Melobb871a92014-10-23 12:50:25 -030079void thread__find_addr_location(struct thread *thread,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020080 u8 cpumode, enum map_type type, u64 addr,
Adrian Hunter61710bd2013-08-08 14:32:26 +030081 struct addr_location *al);
David Ahernba580412013-06-07 16:22:12 -060082
Arnaldo Carvalho de Melo52a3cb82014-03-11 16:16:49 -030083void thread__find_cpumode_addr_location(struct thread *thread,
Arnaldo Carvalho de Melo52a3cb82014-03-11 16:16:49 -030084 enum map_type type, u64 addr,
85 struct addr_location *al);
86
David Ahernba580412013-06-07 16:22:12 -060087static inline void *thread__priv(struct thread *thread)
88{
89 return thread->priv;
90}
91
92static inline void thread__set_priv(struct thread *thread, void *p)
93{
94 thread->priv = p;
95}
David Ahern1f3878c2013-11-18 13:32:47 -070096
97static inline bool thread__is_filtered(struct thread *thread)
98{
99 if (symbol_conf.comm_list &&
100 !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) {
101 return true;
102 }
103
David Aherne03eaa42015-03-24 09:52:41 -0600104 if (symbol_conf.pid_list &&
105 !intlist__has_entry(symbol_conf.pid_list, thread->pid_)) {
106 return true;
107 }
108
109 if (symbol_conf.tid_list &&
110 !intlist__has_entry(symbol_conf.tid_list, thread->tid)) {
111 return true;
112 }
113
David Ahern1f3878c2013-11-18 13:32:47 -0700114 return false;
115}
116
John Kacur8b40f522009-09-24 18:02:18 +0200117#endif /* __PERF_THREAD_H */