Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 2 | #ifndef __PERF_THREAD_H |
| 3 | #define __PERF_THREAD_H |
| 4 | |
Elena Reshetova | e34f5b1 | 2017-02-21 17:35:02 +0200 | [diff] [blame] | 5 | #include <linux/refcount.h> |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 6 | #include <linux/rbtree.h> |
Frederic Weisbecker | 1902efe | 2013-09-11 16:56:44 +0200 | [diff] [blame] | 7 | #include <linux/list.h> |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 8 | #include <unistd.h> |
Arnaldo Carvalho de Melo | 9d2f8e2 | 2012-10-06 15:43:20 -0300 | [diff] [blame] | 9 | #include <sys/types.h> |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 10 | #include "symbol.h" |
David Ahern | 1f3878c | 2013-11-18 13:32:47 -0700 | [diff] [blame] | 11 | #include <strlist.h> |
David Ahern | e03eaa4 | 2015-03-24 09:52:41 -0600 | [diff] [blame] | 12 | #include <intlist.h> |
Kan Liang | b32ee9e | 2017-09-29 07:47:52 -0700 | [diff] [blame] | 13 | #include "rwsem.h" |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 14 | |
Adrian Hunter | 00447cc | 2014-10-30 16:09:42 +0200 | [diff] [blame] | 15 | struct thread_stack; |
He Kuang | f83c041 | 2016-06-03 03:33:12 +0000 | [diff] [blame] | 16 | struct unwind_libunwind_ops; |
Adrian Hunter | 00447cc | 2014-10-30 16:09:42 +0200 | [diff] [blame] | 17 | |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 18 | struct thread { |
Arnaldo Carvalho de Melo | 720a3ae | 2010-06-17 08:37:44 -0300 | [diff] [blame] | 19 | union { |
| 20 | struct rb_node rb_node; |
| 21 | struct list_head node; |
| 22 | }; |
Arnaldo Carvalho de Melo | 93d5731 | 2014-03-21 17:57:01 -0300 | [diff] [blame] | 23 | struct map_groups *mg; |
Adrian Hunter | 99d725f | 2013-08-26 16:00:19 +0300 | [diff] [blame] | 24 | pid_t pid_; /* Not all tools update this */ |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 25 | pid_t tid; |
David Ahern | 70c57ef | 2013-05-25 22:47:10 -0600 | [diff] [blame] | 26 | pid_t ppid; |
Adrian Hunter | bf49c35 | 2014-07-22 16:17:24 +0300 | [diff] [blame] | 27 | int cpu; |
Elena Reshetova | e34f5b1 | 2017-02-21 17:35:02 +0200 | [diff] [blame] | 28 | refcount_t refcnt; |
Arnaldo Carvalho de Melo | faa5c5c | 2010-02-19 23:02:07 -0200 | [diff] [blame] | 29 | bool comm_set; |
Arnaldo Carvalho de Melo | 8606606 | 2015-05-15 17:29:56 -0300 | [diff] [blame] | 30 | int comm_len; |
David Ahern | 236a3bb | 2013-08-14 08:49:27 -0600 | [diff] [blame] | 31 | bool dead; /* if set thread has exited */ |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 32 | struct list_head namespaces_list; |
Kan Liang | b32ee9e | 2017-09-29 07:47:52 -0700 | [diff] [blame] | 33 | struct rw_semaphore namespaces_lock; |
Frederic Weisbecker | 1902efe | 2013-09-11 16:56:44 +0200 | [diff] [blame] | 34 | struct list_head comm_list; |
Kan Liang | b32ee9e | 2017-09-29 07:47:52 -0700 | [diff] [blame] | 35 | struct rw_semaphore comm_lock; |
Adrian Hunter | 0db15b1 | 2014-10-23 13:45:13 +0300 | [diff] [blame] | 36 | u64 db_id; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 37 | |
| 38 | void *priv; |
Adrian Hunter | 00447cc | 2014-10-30 16:09:42 +0200 | [diff] [blame] | 39 | struct thread_stack *ts; |
Krister Johansen | 843ff37 | 2017-07-05 18:48:08 -0700 | [diff] [blame] | 40 | struct nsinfo *nsinfo; |
Jiri Olsa | e583d70 | 2016-04-07 09:11:12 +0200 | [diff] [blame] | 41 | #ifdef HAVE_LIBUNWIND_SUPPORT |
He Kuang | f83c041 | 2016-06-03 03:33:12 +0000 | [diff] [blame] | 42 | void *addr_space; |
| 43 | struct unwind_libunwind_ops *unwind_libunwind_ops; |
Jiri Olsa | e583d70 | 2016-04-07 09:11:12 +0200 | [diff] [blame] | 44 | #endif |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 45 | }; |
| 46 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 47 | struct machine; |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 48 | struct namespaces; |
Namhyung Kim | 4dfced3 | 2013-09-13 16:28:57 +0900 | [diff] [blame] | 49 | struct comm; |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame] | 50 | |
Adrian Hunter | 99d725f | 2013-08-26 16:00:19 +0300 | [diff] [blame] | 51 | struct thread *thread__new(pid_t pid, pid_t tid); |
Jiri Olsa | cddcef6 | 2014-04-09 20:54:29 +0200 | [diff] [blame] | 52 | 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] | 53 | void thread__delete(struct thread *thread); |
Arnaldo Carvalho de Melo | f3b623b | 2015-03-02 22:21:35 -0300 | [diff] [blame] | 54 | |
| 55 | struct thread *thread__get(struct thread *thread); |
| 56 | void thread__put(struct thread *thread); |
| 57 | |
| 58 | static 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 Ahern | 236a3bb | 2013-08-14 08:49:27 -0600 | [diff] [blame] | 66 | static inline void thread__exited(struct thread *thread) |
| 67 | { |
| 68 | thread->dead = true; |
| 69 | } |
Arnaldo Carvalho de Melo | 591765f | 2010-07-30 18:28:42 -0300 | [diff] [blame] | 70 | |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 71 | struct namespaces *thread__namespaces(const struct thread *thread); |
| 72 | int thread__set_namespaces(struct thread *thread, u64 timestamp, |
| 73 | struct namespaces_event *event); |
| 74 | |
Adrian Hunter | 65de51f | 2014-07-31 09:00:44 +0300 | [diff] [blame] | 75 | int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp, |
| 76 | bool exec); |
| 77 | static 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 Melo | 2f3027a | 2016-04-26 12:32:50 -0300 | [diff] [blame] | 83 | int thread__set_comm_from_proc(struct thread *thread); |
| 84 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 85 | int thread__comm_len(struct thread *thread); |
Namhyung Kim | 4dfced3 | 2013-09-13 16:28:57 +0900 | [diff] [blame] | 86 | struct comm *thread__comm(const struct thread *thread); |
Adrian Hunter | 65de51f | 2014-07-31 09:00:44 +0300 | [diff] [blame] | 87 | struct comm *thread__exec_comm(const struct thread *thread); |
Frederic Weisbecker | b9c5143 | 2013-09-11 14:46:56 +0200 | [diff] [blame] | 88 | const char *thread__comm_str(const struct thread *thread); |
He Kuang | 8132a2a | 2016-06-03 03:33:13 +0000 | [diff] [blame] | 89 | int thread__insert_map(struct thread *thread, struct map *map); |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 90 | 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] | 91 | size_t thread__fprintf(struct thread *thread, FILE *fp); |
John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 92 | |
Andi Kleen | 480ca35 | 2016-05-23 17:52:24 -0700 | [diff] [blame] | 93 | struct thread *thread__main_thread(struct machine *machine, struct thread *thread); |
| 94 | |
Arnaldo Carvalho de Melo | bb871a9 | 2014-10-23 12:50:25 -0300 | [diff] [blame] | 95 | void thread__find_addr_map(struct thread *thread, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 96 | u8 cpumode, enum map_type type, u64 addr, |
Adrian Hunter | 326f59b | 2013-08-08 14:32:27 +0300 | [diff] [blame] | 97 | struct addr_location *al); |
Arnaldo Carvalho de Melo | 59ee68e | 2010-01-14 23:45:29 -0200 | [diff] [blame] | 98 | |
Arnaldo Carvalho de Melo | bb871a9 | 2014-10-23 12:50:25 -0300 | [diff] [blame] | 99 | void thread__find_addr_location(struct thread *thread, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 100 | u8 cpumode, enum map_type type, u64 addr, |
Adrian Hunter | 61710bd | 2013-08-08 14:32:26 +0300 | [diff] [blame] | 101 | struct addr_location *al); |
David Ahern | ba58041 | 2013-06-07 16:22:12 -0600 | [diff] [blame] | 102 | |
Arnaldo Carvalho de Melo | 52a3cb8 | 2014-03-11 16:16:49 -0300 | [diff] [blame] | 103 | void thread__find_cpumode_addr_location(struct thread *thread, |
Arnaldo Carvalho de Melo | 52a3cb8 | 2014-03-11 16:16:49 -0300 | [diff] [blame] | 104 | enum map_type type, u64 addr, |
| 105 | struct addr_location *al); |
| 106 | |
David Ahern | ba58041 | 2013-06-07 16:22:12 -0600 | [diff] [blame] | 107 | static inline void *thread__priv(struct thread *thread) |
| 108 | { |
| 109 | return thread->priv; |
| 110 | } |
| 111 | |
| 112 | static inline void thread__set_priv(struct thread *thread, void *p) |
| 113 | { |
| 114 | thread->priv = p; |
| 115 | } |
David Ahern | 1f3878c | 2013-11-18 13:32:47 -0700 | [diff] [blame] | 116 | |
| 117 | static 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 Ahern | e03eaa4 | 2015-03-24 09:52:41 -0600 | [diff] [blame] | 124 | 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 Ahern | 1f3878c | 2013-11-18 13:32:47 -0700 | [diff] [blame] | 134 | return false; |
| 135 | } |
| 136 | |
John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 137 | #endif /* __PERF_THREAD_H */ |