John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 1 | #ifndef __PERF_THREAD_H |
| 2 | #define __PERF_THREAD_H |
| 3 | |
Arnaldo Carvalho de Melo | e1ed3a5 | 2015-04-07 11:59:50 -0300 | [diff] [blame] | 4 | #include <linux/atomic.h> |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 5 | #include <linux/rbtree.h> |
Frederic Weisbecker | 1902efe | 2013-09-11 16:56:44 +0200 | [diff] [blame] | 6 | #include <linux/list.h> |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 7 | #include <unistd.h> |
Arnaldo Carvalho de Melo | 9d2f8e2 | 2012-10-06 15:43:20 -0300 | [diff] [blame] | 8 | #include <sys/types.h> |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 9 | #include "symbol.h" |
David Ahern | 1f3878c | 2013-11-18 13:32:47 -0700 | [diff] [blame] | 10 | #include <strlist.h> |
David Ahern | e03eaa4 | 2015-03-24 09:52:41 -0600 | [diff] [blame] | 11 | #include <intlist.h> |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 12 | |
Adrian Hunter | 00447cc | 2014-10-30 16:09:42 +0200 | [diff] [blame] | 13 | struct thread_stack; |
| 14 | |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 15 | struct thread { |
Arnaldo Carvalho de Melo | 720a3ae | 2010-06-17 08:37:44 -0300 | [diff] [blame] | 16 | union { |
| 17 | struct rb_node rb_node; |
| 18 | struct list_head node; |
| 19 | }; |
Arnaldo Carvalho de Melo | 93d5731 | 2014-03-21 17:57:01 -0300 | [diff] [blame] | 20 | struct map_groups *mg; |
Adrian Hunter | 99d725f | 2013-08-26 16:00:19 +0300 | [diff] [blame] | 21 | pid_t pid_; /* Not all tools update this */ |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 22 | pid_t tid; |
David Ahern | 70c57ef | 2013-05-25 22:47:10 -0600 | [diff] [blame] | 23 | pid_t ppid; |
Adrian Hunter | bf49c35 | 2014-07-22 16:17:24 +0300 | [diff] [blame] | 24 | int cpu; |
Arnaldo Carvalho de Melo | e1ed3a5 | 2015-04-07 11:59:50 -0300 | [diff] [blame] | 25 | atomic_t refcnt; |
Ingo Molnar | 0ec04e1 | 2009-09-16 17:40:48 +0200 | [diff] [blame] | 26 | char shortname[3]; |
Arnaldo Carvalho de Melo | faa5c5c | 2010-02-19 23:02:07 -0200 | [diff] [blame] | 27 | bool comm_set; |
Arnaldo Carvalho de Melo | 8606606 | 2015-05-15 17:29:56 -0300 | [diff] [blame] | 28 | int comm_len; |
David Ahern | 236a3bb | 2013-08-14 08:49:27 -0600 | [diff] [blame] | 29 | bool dead; /* if set thread has exited */ |
Frederic Weisbecker | 1902efe | 2013-09-11 16:56:44 +0200 | [diff] [blame] | 30 | struct list_head comm_list; |
Adrian Hunter | 0db15b1 | 2014-10-23 13:45:13 +0300 | [diff] [blame] | 31 | u64 db_id; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 32 | |
| 33 | void *priv; |
Adrian Hunter | 00447cc | 2014-10-30 16:09:42 +0200 | [diff] [blame] | 34 | struct thread_stack *ts; |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 35 | }; |
| 36 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 37 | struct machine; |
Namhyung Kim | 4dfced3 | 2013-09-13 16:28:57 +0900 | [diff] [blame] | 38 | struct comm; |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame] | 39 | |
Adrian Hunter | 99d725f | 2013-08-26 16:00:19 +0300 | [diff] [blame] | 40 | struct thread *thread__new(pid_t pid, pid_t tid); |
Jiri Olsa | cddcef6 | 2014-04-09 20:54:29 +0200 | [diff] [blame] | 41 | int thread__init_map_groups(struct thread *thread, struct machine *machine); |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 42 | void thread__delete(struct thread *thread); |
Arnaldo Carvalho de Melo | f3b623b | 2015-03-02 22:21:35 -0300 | [diff] [blame] | 43 | |
| 44 | struct thread *thread__get(struct thread *thread); |
| 45 | void thread__put(struct thread *thread); |
| 46 | |
| 47 | static inline void __thread__zput(struct thread **thread) |
| 48 | { |
| 49 | thread__put(*thread); |
| 50 | *thread = NULL; |
| 51 | } |
| 52 | |
| 53 | #define thread__zput(thread) __thread__zput(&thread) |
| 54 | |
David Ahern | 236a3bb | 2013-08-14 08:49:27 -0600 | [diff] [blame] | 55 | static inline void thread__exited(struct thread *thread) |
| 56 | { |
| 57 | thread->dead = true; |
| 58 | } |
Arnaldo Carvalho de Melo | 591765f | 2010-07-30 18:28:42 -0300 | [diff] [blame] | 59 | |
Adrian Hunter | 65de51f | 2014-07-31 09:00:44 +0300 | [diff] [blame] | 60 | int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp, |
| 61 | bool exec); |
| 62 | static inline int thread__set_comm(struct thread *thread, const char *comm, |
| 63 | u64 timestamp) |
| 64 | { |
| 65 | return __thread__set_comm(thread, comm, timestamp, false); |
| 66 | } |
| 67 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 68 | int thread__comm_len(struct thread *thread); |
Namhyung Kim | 4dfced3 | 2013-09-13 16:28:57 +0900 | [diff] [blame] | 69 | struct comm *thread__comm(const struct thread *thread); |
Adrian Hunter | 65de51f | 2014-07-31 09:00:44 +0300 | [diff] [blame] | 70 | struct comm *thread__exec_comm(const struct thread *thread); |
Frederic Weisbecker | b9c5143 | 2013-09-11 14:46:56 +0200 | [diff] [blame] | 71 | const char *thread__comm_str(const struct thread *thread); |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 72 | void thread__insert_map(struct thread *thread, struct map *map); |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 73 | int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp); |
Arnaldo Carvalho de Melo | 3f067dc | 2012-12-07 17:39:39 -0300 | [diff] [blame] | 74 | size_t thread__fprintf(struct thread *thread, FILE *fp); |
John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 75 | |
Arnaldo Carvalho de Melo | bb871a9 | 2014-10-23 12:50:25 -0300 | [diff] [blame] | 76 | void thread__find_addr_map(struct thread *thread, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 77 | u8 cpumode, enum map_type type, u64 addr, |
Adrian Hunter | 326f59b | 2013-08-08 14:32:27 +0300 | [diff] [blame] | 78 | struct addr_location *al); |
Arnaldo Carvalho de Melo | 59ee68e | 2010-01-14 23:45:29 -0200 | [diff] [blame] | 79 | |
Arnaldo Carvalho de Melo | bb871a9 | 2014-10-23 12:50:25 -0300 | [diff] [blame] | 80 | void thread__find_addr_location(struct thread *thread, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 81 | u8 cpumode, enum map_type type, u64 addr, |
Adrian Hunter | 61710bd | 2013-08-08 14:32:26 +0300 | [diff] [blame] | 82 | struct addr_location *al); |
David Ahern | ba58041 | 2013-06-07 16:22:12 -0600 | [diff] [blame] | 83 | |
Arnaldo Carvalho de Melo | 52a3cb8 | 2014-03-11 16:16:49 -0300 | [diff] [blame] | 84 | void thread__find_cpumode_addr_location(struct thread *thread, |
Arnaldo Carvalho de Melo | 52a3cb8 | 2014-03-11 16:16:49 -0300 | [diff] [blame] | 85 | enum map_type type, u64 addr, |
| 86 | struct addr_location *al); |
| 87 | |
David Ahern | ba58041 | 2013-06-07 16:22:12 -0600 | [diff] [blame] | 88 | static inline void *thread__priv(struct thread *thread) |
| 89 | { |
| 90 | return thread->priv; |
| 91 | } |
| 92 | |
| 93 | static inline void thread__set_priv(struct thread *thread, void *p) |
| 94 | { |
| 95 | thread->priv = p; |
| 96 | } |
David Ahern | 1f3878c | 2013-11-18 13:32:47 -0700 | [diff] [blame] | 97 | |
| 98 | static inline bool thread__is_filtered(struct thread *thread) |
| 99 | { |
| 100 | if (symbol_conf.comm_list && |
| 101 | !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) { |
| 102 | return true; |
| 103 | } |
| 104 | |
David Ahern | e03eaa4 | 2015-03-24 09:52:41 -0600 | [diff] [blame] | 105 | if (symbol_conf.pid_list && |
| 106 | !intlist__has_entry(symbol_conf.pid_list, thread->pid_)) { |
| 107 | return true; |
| 108 | } |
| 109 | |
| 110 | if (symbol_conf.tid_list && |
| 111 | !intlist__has_entry(symbol_conf.tid_list, thread->tid)) { |
| 112 | return true; |
| 113 | } |
| 114 | |
David Ahern | 1f3878c | 2013-11-18 13:32:47 -0700 | [diff] [blame] | 115 | return false; |
| 116 | } |
| 117 | |
John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 118 | #endif /* __PERF_THREAD_H */ |