Lines Matching refs:thread

19 int thread__init_map_groups(struct thread *thread, struct machine *machine)  in thread__init_map_groups()  argument
21 pid_t pid = thread->pid_; in thread__init_map_groups()
23 if (pid == thread->tid || pid == -1) { in thread__init_map_groups()
24 thread->mg = map_groups__new(machine); in thread__init_map_groups()
26 struct thread *leader = __machine__findnew_thread(machine, pid, pid); in thread__init_map_groups()
28 thread->mg = map_groups__get(leader->mg); in thread__init_map_groups()
33 return thread->mg ? 0 : -1; in thread__init_map_groups()
36 struct thread *thread__new(pid_t pid, pid_t tid) in thread__new()
40 struct thread *thread = zalloc(sizeof(*thread)); in thread__new() local
42 if (thread != NULL) { in thread__new()
43 thread->pid_ = pid; in thread__new()
44 thread->tid = tid; in thread__new()
45 thread->ppid = -1; in thread__new()
46 thread->cpu = -1; in thread__new()
47 INIT_LIST_HEAD(&thread->namespaces_list); in thread__new()
48 INIT_LIST_HEAD(&thread->comm_list); in thread__new()
49 init_rwsem(&thread->namespaces_lock); in thread__new()
50 init_rwsem(&thread->comm_lock); in thread__new()
62 list_add(&comm->list, &thread->comm_list); in thread__new()
63 refcount_set(&thread->refcnt, 1); in thread__new()
64 RB_CLEAR_NODE(&thread->rb_node); in thread__new()
66 thread->nsinfo = nsinfo__new(pid); in thread__new()
69 return thread; in thread__new()
72 free(thread); in thread__new()
76 void thread__delete(struct thread *thread) in thread__delete() argument
81 BUG_ON(!RB_EMPTY_NODE(&thread->rb_node)); in thread__delete()
83 thread_stack__free(thread); in thread__delete()
85 if (thread->mg) { in thread__delete()
86 map_groups__put(thread->mg); in thread__delete()
87 thread->mg = NULL; in thread__delete()
89 down_write(&thread->namespaces_lock); in thread__delete()
91 &thread->namespaces_list, list) { in thread__delete()
95 up_write(&thread->namespaces_lock); in thread__delete()
97 down_write(&thread->comm_lock); in thread__delete()
98 list_for_each_entry_safe(comm, tmp_comm, &thread->comm_list, list) { in thread__delete()
102 up_write(&thread->comm_lock); in thread__delete()
104 unwind__finish_access(thread); in thread__delete()
105 nsinfo__zput(thread->nsinfo); in thread__delete()
107 exit_rwsem(&thread->namespaces_lock); in thread__delete()
108 exit_rwsem(&thread->comm_lock); in thread__delete()
109 free(thread); in thread__delete()
112 struct thread *thread__get(struct thread *thread) in thread__get() argument
114 if (thread) in thread__get()
115 refcount_inc(&thread->refcnt); in thread__get()
116 return thread; in thread__get()
119 void thread__put(struct thread *thread) in thread__put() argument
121 if (thread && refcount_dec_and_test(&thread->refcnt)) { in thread__put()
126 list_del_init(&thread->node); in thread__put()
127 thread__delete(thread); in thread__put()
131 struct namespaces *thread__namespaces(const struct thread *thread) in thread__namespaces() argument
133 if (list_empty(&thread->namespaces_list)) in thread__namespaces()
136 return list_first_entry(&thread->namespaces_list, struct namespaces, list); in thread__namespaces()
139 static int __thread__set_namespaces(struct thread *thread, u64 timestamp, in __thread__set_namespaces() argument
142 struct namespaces *new, *curr = thread__namespaces(thread); in __thread__set_namespaces()
148 list_add(&new->list, &thread->namespaces_list); in __thread__set_namespaces()
163 int thread__set_namespaces(struct thread *thread, u64 timestamp, in thread__set_namespaces() argument
168 down_write(&thread->namespaces_lock); in thread__set_namespaces()
169 ret = __thread__set_namespaces(thread, timestamp, event); in thread__set_namespaces()
170 up_write(&thread->namespaces_lock); in thread__set_namespaces()
174 struct comm *thread__comm(const struct thread *thread) in thread__comm() argument
176 if (list_empty(&thread->comm_list)) in thread__comm()
179 return list_first_entry(&thread->comm_list, struct comm, list); in thread__comm()
182 struct comm *thread__exec_comm(const struct thread *thread) in thread__exec_comm() argument
186 list_for_each_entry(comm, &thread->comm_list, list) { in thread__exec_comm()
195 static int ____thread__set_comm(struct thread *thread, const char *str, in ____thread__set_comm() argument
198 struct comm *new, *curr = thread__comm(thread); in ____thread__set_comm()
201 if (!thread->comm_set) { in ____thread__set_comm()
209 list_add(&new->list, &thread->comm_list); in ____thread__set_comm()
212 unwind__flush_access(thread); in ____thread__set_comm()
215 thread->comm_set = true; in ____thread__set_comm()
220 int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp, in __thread__set_comm() argument
225 down_write(&thread->comm_lock); in __thread__set_comm()
226 ret = ____thread__set_comm(thread, str, timestamp, exec); in __thread__set_comm()
227 up_write(&thread->comm_lock); in __thread__set_comm()
231 int thread__set_comm_from_proc(struct thread *thread) in thread__set_comm_from_proc() argument
239 thread->pid_, thread->tid) >= (int)sizeof(path)) && in thread__set_comm_from_proc()
242 err = thread__set_comm(thread, comm, 0); in thread__set_comm_from_proc()
248 static const char *__thread__comm_str(const struct thread *thread) in __thread__comm_str() argument
250 const struct comm *comm = thread__comm(thread); in __thread__comm_str()
258 const char *thread__comm_str(const struct thread *thread) in thread__comm_str() argument
262 down_read((struct rw_semaphore *)&thread->comm_lock); in thread__comm_str()
263 str = __thread__comm_str(thread); in thread__comm_str()
264 up_read((struct rw_semaphore *)&thread->comm_lock); in thread__comm_str()
270 int thread__comm_len(struct thread *thread) in thread__comm_len() argument
272 if (!thread->comm_len) { in thread__comm_len()
273 const char *comm = thread__comm_str(thread); in thread__comm_len()
276 thread->comm_len = strlen(comm); in thread__comm_len()
279 return thread->comm_len; in thread__comm_len()
282 size_t thread__fprintf(struct thread *thread, FILE *fp) in thread__fprintf() argument
284 return fprintf(fp, "Thread %d %s\n", thread->tid, thread__comm_str(thread)) + in thread__fprintf()
285 map_groups__fprintf(thread->mg, fp); in thread__fprintf()
288 int thread__insert_map(struct thread *thread, struct map *map) in thread__insert_map() argument
292 ret = unwind__prepare_access(thread, map, NULL); in thread__insert_map()
296 map_groups__fixup_overlappings(thread->mg, map, stderr); in thread__insert_map()
297 map_groups__insert(thread->mg, map); in thread__insert_map()
302 static int __thread__prepare_access(struct thread *thread) in __thread__prepare_access() argument
306 struct maps *maps = &thread->mg->maps; in __thread__prepare_access()
312 err = unwind__prepare_access(thread, map, &initialized); in __thread__prepare_access()
322 static int thread__prepare_access(struct thread *thread) in thread__prepare_access() argument
327 err = __thread__prepare_access(thread); in thread__prepare_access()
332 static int thread__clone_map_groups(struct thread *thread, in thread__clone_map_groups() argument
333 struct thread *parent) in thread__clone_map_groups()
336 if (thread->pid_ == parent->pid_) in thread__clone_map_groups()
337 return thread__prepare_access(thread); in thread__clone_map_groups()
339 if (thread->mg == parent->mg) { in thread__clone_map_groups()
341 thread->pid_, thread->tid, parent->pid_, parent->tid); in thread__clone_map_groups()
346 if (map_groups__clone(thread, parent->mg) < 0) in thread__clone_map_groups()
352 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp) in thread__fork() argument
359 err = thread__set_comm(thread, comm, timestamp); in thread__fork()
364 thread->ppid = parent->tid; in thread__fork()
365 return thread__clone_map_groups(thread, parent); in thread__fork()
368 void thread__find_cpumode_addr_location(struct thread *thread, u64 addr, in thread__find_cpumode_addr_location() argument
380 thread__find_symbol(thread, cpumodes[i], addr, al); in thread__find_cpumode_addr_location()
386 struct thread *thread__main_thread(struct machine *machine, struct thread *thread) in thread__main_thread() argument
388 if (thread->pid_ == thread->tid) in thread__main_thread()
389 return thread__get(thread); in thread__main_thread()
391 if (thread->pid_ == -1) in thread__main_thread()
394 return machine__find_thread(machine, thread->pid_, thread->pid_); in thread__main_thread()