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> |
Arnaldo Carvalho de Melo | e22c1c7 | 2019-01-28 00:07:40 +0100 | [diff] [blame] | 8 | #include <stdio.h> |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 9 | #include <unistd.h> |
Arnaldo Carvalho de Melo | 9d2f8e2 | 2012-10-06 15:43:20 -0300 | [diff] [blame] | 10 | #include <sys/types.h> |
Arnaldo Carvalho de Melo | 4fed072 | 2019-01-27 11:31:39 +0100 | [diff] [blame] | 11 | #include "srccode.h" |
Arnaldo Carvalho de Melo | e22c1c7 | 2019-01-28 00:07:40 +0100 | [diff] [blame] | 12 | #include "symbol_conf.h" |
David Ahern | 1f3878c | 2013-11-18 13:32:47 -0700 | [diff] [blame] | 13 | #include <strlist.h> |
David Ahern | e03eaa4 | 2015-03-24 09:52:41 -0600 | [diff] [blame] | 14 | #include <intlist.h> |
Kan Liang | b32ee9e | 2017-09-29 07:47:52 -0700 | [diff] [blame] | 15 | #include "rwsem.h" |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 16 | |
Arnaldo Carvalho de Melo | e22c1c7 | 2019-01-28 00:07:40 +0100 | [diff] [blame] | 17 | struct addr_location; |
| 18 | struct map; |
Arnaldo Carvalho de Melo | 69d81f0 | 2019-08-26 19:02:31 -0300 | [diff] [blame] | 19 | struct perf_record_namespaces; |
Adrian Hunter | 00447cc | 2014-10-30 16:09:42 +0200 | [diff] [blame] | 20 | struct thread_stack; |
He Kuang | f83c041 | 2016-06-03 03:33:12 +0000 | [diff] [blame] | 21 | struct unwind_libunwind_ops; |
Adrian Hunter | 00447cc | 2014-10-30 16:09:42 +0200 | [diff] [blame] | 22 | |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 23 | struct thread { |
Arnaldo Carvalho de Melo | 720a3ae | 2010-06-17 08:37:44 -0300 | [diff] [blame] | 24 | union { |
| 25 | struct rb_node rb_node; |
| 26 | struct list_head node; |
| 27 | }; |
Arnaldo Carvalho de Melo | fe87797 | 2019-11-25 22:07:43 -0300 | [diff] [blame] | 28 | struct maps *maps; |
Adrian Hunter | 99d725f | 2013-08-26 16:00:19 +0300 | [diff] [blame] | 29 | pid_t pid_; /* Not all tools update this */ |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 30 | pid_t tid; |
David Ahern | 70c57ef | 2013-05-25 22:47:10 -0600 | [diff] [blame] | 31 | pid_t ppid; |
Adrian Hunter | bf49c35 | 2014-07-22 16:17:24 +0300 | [diff] [blame] | 32 | int cpu; |
Elena Reshetova | e34f5b1 | 2017-02-21 17:35:02 +0200 | [diff] [blame] | 33 | refcount_t refcnt; |
Arnaldo Carvalho de Melo | faa5c5c | 2010-02-19 23:02:07 -0200 | [diff] [blame] | 34 | bool comm_set; |
Arnaldo Carvalho de Melo | 8606606 | 2015-05-15 17:29:56 -0300 | [diff] [blame] | 35 | int comm_len; |
David Ahern | 236a3bb | 2013-08-14 08:49:27 -0600 | [diff] [blame] | 36 | bool dead; /* if set thread has exited */ |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 37 | struct list_head namespaces_list; |
Kan Liang | b32ee9e | 2017-09-29 07:47:52 -0700 | [diff] [blame] | 38 | struct rw_semaphore namespaces_lock; |
Frederic Weisbecker | 1902efe | 2013-09-11 16:56:44 +0200 | [diff] [blame] | 39 | struct list_head comm_list; |
Kan Liang | b32ee9e | 2017-09-29 07:47:52 -0700 | [diff] [blame] | 40 | struct rw_semaphore comm_lock; |
Adrian Hunter | 0db15b1 | 2014-10-23 13:45:13 +0300 | [diff] [blame] | 41 | u64 db_id; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 42 | |
| 43 | void *priv; |
Adrian Hunter | 00447cc | 2014-10-30 16:09:42 +0200 | [diff] [blame] | 44 | struct thread_stack *ts; |
Krister Johansen | 843ff37 | 2017-07-05 18:48:08 -0700 | [diff] [blame] | 45 | struct nsinfo *nsinfo; |
Andi Kleen | dd2e18e | 2018-12-03 16:18:48 -0800 | [diff] [blame] | 46 | struct srccode_state srccode_state; |
Andi Kleen | 99f753f | 2018-09-20 11:05:39 -0700 | [diff] [blame] | 47 | bool filter; |
| 48 | int filter_entry_depth; |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 49 | }; |
| 50 | |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 51 | struct machine; |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 52 | struct namespaces; |
Namhyung Kim | 4dfced3 | 2013-09-13 16:28:57 +0900 | [diff] [blame] | 53 | struct comm; |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame] | 54 | |
Adrian Hunter | 99d725f | 2013-08-26 16:00:19 +0300 | [diff] [blame] | 55 | struct thread *thread__new(pid_t pid, pid_t tid); |
Arnaldo Carvalho de Melo | 79b6bb7 | 2019-11-25 21:58:33 -0300 | [diff] [blame] | 56 | int thread__init_maps(struct thread *thread, struct machine *machine); |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 57 | void thread__delete(struct thread *thread); |
Arnaldo Carvalho de Melo | f3b623b | 2015-03-02 22:21:35 -0300 | [diff] [blame] | 58 | |
| 59 | struct thread *thread__get(struct thread *thread); |
| 60 | void thread__put(struct thread *thread); |
| 61 | |
| 62 | static inline void __thread__zput(struct thread **thread) |
| 63 | { |
| 64 | thread__put(*thread); |
| 65 | *thread = NULL; |
| 66 | } |
| 67 | |
| 68 | #define thread__zput(thread) __thread__zput(&thread) |
| 69 | |
David Ahern | 236a3bb | 2013-08-14 08:49:27 -0600 | [diff] [blame] | 70 | static inline void thread__exited(struct thread *thread) |
| 71 | { |
| 72 | thread->dead = true; |
| 73 | } |
Arnaldo Carvalho de Melo | 591765f | 2010-07-30 18:28:42 -0300 | [diff] [blame] | 74 | |
Namhyung Kim | 7cb10a08 | 2019-05-27 15:11:49 +0900 | [diff] [blame] | 75 | struct namespaces *thread__namespaces(struct thread *thread); |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 76 | int thread__set_namespaces(struct thread *thread, u64 timestamp, |
Arnaldo Carvalho de Melo | 69d81f0 | 2019-08-26 19:02:31 -0300 | [diff] [blame] | 77 | struct perf_record_namespaces *event); |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 78 | |
Adrian Hunter | 65de51f | 2014-07-31 09:00:44 +0300 | [diff] [blame] | 79 | int __thread__set_comm(struct thread *thread, const char *comm, u64 timestamp, |
| 80 | bool exec); |
| 81 | static inline int thread__set_comm(struct thread *thread, const char *comm, |
| 82 | u64 timestamp) |
| 83 | { |
| 84 | return __thread__set_comm(thread, comm, timestamp, false); |
| 85 | } |
| 86 | |
Arnaldo Carvalho de Melo | 2f3027a | 2016-04-26 12:32:50 -0300 | [diff] [blame] | 87 | int thread__set_comm_from_proc(struct thread *thread); |
| 88 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 89 | int thread__comm_len(struct thread *thread); |
Namhyung Kim | 4dfced3 | 2013-09-13 16:28:57 +0900 | [diff] [blame] | 90 | struct comm *thread__comm(const struct thread *thread); |
Adrian Hunter | 65de51f | 2014-07-31 09:00:44 +0300 | [diff] [blame] | 91 | struct comm *thread__exec_comm(const struct thread *thread); |
Namhyung Kim | 7cb10a08 | 2019-05-27 15:11:49 +0900 | [diff] [blame] | 92 | const char *thread__comm_str(struct thread *thread); |
He Kuang | 8132a2a | 2016-06-03 03:33:13 +0000 | [diff] [blame] | 93 | int thread__insert_map(struct thread *thread, struct map *map); |
David Miller | 4f8f382 | 2018-10-30 22:24:04 -0700 | [diff] [blame] | 94 | int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone); |
Arnaldo Carvalho de Melo | 3f067dc | 2012-12-07 17:39:39 -0300 | [diff] [blame] | 95 | size_t thread__fprintf(struct thread *thread, FILE *fp); |
John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 96 | |
Andi Kleen | 480ca35 | 2016-05-23 17:52:24 -0700 | [diff] [blame] | 97 | struct thread *thread__main_thread(struct machine *machine, struct thread *thread); |
| 98 | |
Arnaldo Carvalho de Melo | 404eb5a | 2018-04-26 09:34:37 -0300 | [diff] [blame] | 99 | struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr, |
| 100 | struct addr_location *al); |
Adrian Hunter | 8e80ad9 | 2018-11-06 23:07:10 +0200 | [diff] [blame] | 101 | struct map *thread__find_map_fb(struct thread *thread, u8 cpumode, u64 addr, |
| 102 | struct addr_location *al); |
Arnaldo Carvalho de Melo | 59ee68e | 2010-01-14 23:45:29 -0200 | [diff] [blame] | 103 | |
Arnaldo Carvalho de Melo | 117d3c2 | 2018-04-25 18:16:53 -0300 | [diff] [blame] | 104 | struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode, |
| 105 | u64 addr, struct addr_location *al); |
Adrian Hunter | 8e80ad9 | 2018-11-06 23:07:10 +0200 | [diff] [blame] | 106 | struct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode, |
| 107 | u64 addr, struct addr_location *al); |
David Ahern | ba58041 | 2013-06-07 16:22:12 -0600 | [diff] [blame] | 108 | |
Arnaldo Carvalho de Melo | 26bd933 | 2018-04-25 17:58:03 -0300 | [diff] [blame] | 109 | void thread__find_cpumode_addr_location(struct thread *thread, u64 addr, |
Arnaldo Carvalho de Melo | 52a3cb8 | 2014-03-11 16:16:49 -0300 | [diff] [blame] | 110 | struct addr_location *al); |
| 111 | |
Andi Kleen | 1532593 | 2019-03-06 17:55:35 -0300 | [diff] [blame] | 112 | int thread__memcpy(struct thread *thread, struct machine *machine, |
| 113 | void *buf, u64 ip, int len, bool *is64bit); |
| 114 | |
David Ahern | ba58041 | 2013-06-07 16:22:12 -0600 | [diff] [blame] | 115 | static inline void *thread__priv(struct thread *thread) |
| 116 | { |
| 117 | return thread->priv; |
| 118 | } |
| 119 | |
| 120 | static inline void thread__set_priv(struct thread *thread, void *p) |
| 121 | { |
| 122 | thread->priv = p; |
| 123 | } |
David Ahern | 1f3878c | 2013-11-18 13:32:47 -0700 | [diff] [blame] | 124 | |
| 125 | static inline bool thread__is_filtered(struct thread *thread) |
| 126 | { |
| 127 | if (symbol_conf.comm_list && |
| 128 | !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) { |
| 129 | return true; |
| 130 | } |
| 131 | |
David Ahern | e03eaa4 | 2015-03-24 09:52:41 -0600 | [diff] [blame] | 132 | if (symbol_conf.pid_list && |
| 133 | !intlist__has_entry(symbol_conf.pid_list, thread->pid_)) { |
| 134 | return true; |
| 135 | } |
| 136 | |
| 137 | if (symbol_conf.tid_list && |
| 138 | !intlist__has_entry(symbol_conf.tid_list, thread->tid)) { |
| 139 | return true; |
| 140 | } |
| 141 | |
David Ahern | 1f3878c | 2013-11-18 13:32:47 -0700 | [diff] [blame] | 142 | return false; |
| 143 | } |
| 144 | |
John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 145 | #endif /* __PERF_THREAD_H */ |