Lines Matching refs:thread

22 int thread__init_map_groups(struct thread *thread, struct machine *machine)  in thread__init_map_groups()  argument
24 pid_t pid = thread->pid_; in thread__init_map_groups()
26 if (pid == thread->tid || pid == -1) { in thread__init_map_groups()
27 thread->mg = map_groups__new(machine); in thread__init_map_groups()
29 struct thread *leader = __machine__findnew_thread(machine, pid, pid); in thread__init_map_groups()
31 thread->mg = map_groups__get(leader->mg); in thread__init_map_groups()
36 return thread->mg ? 0 : -1; in thread__init_map_groups()
39 struct thread *thread__new(pid_t pid, pid_t tid) in thread__new()
43 struct thread *thread = zalloc(sizeof(*thread)); in thread__new() local
45 if (thread != NULL) { in thread__new()
46 thread->pid_ = pid; in thread__new()
47 thread->tid = tid; in thread__new()
48 thread->ppid = -1; in thread__new()
49 thread->cpu = -1; in thread__new()
50 INIT_LIST_HEAD(&thread->namespaces_list); in thread__new()
51 INIT_LIST_HEAD(&thread->comm_list); in thread__new()
52 init_rwsem(&thread->namespaces_lock); in thread__new()
53 init_rwsem(&thread->comm_lock); in thread__new()
65 list_add(&comm->list, &thread->comm_list); in thread__new()
66 refcount_set(&thread->refcnt, 1); in thread__new()
67 RB_CLEAR_NODE(&thread->rb_node); in thread__new()
69 thread->nsinfo = nsinfo__new(pid); in thread__new()
70 srccode_state_init(&thread->srccode_state); in thread__new()
73 return thread; in thread__new()
76 free(thread); in thread__new()
80 void thread__delete(struct thread *thread) in thread__delete() argument
85 BUG_ON(!RB_EMPTY_NODE(&thread->rb_node)); in thread__delete()
87 thread_stack__free(thread); in thread__delete()
89 if (thread->mg) { in thread__delete()
90 map_groups__put(thread->mg); in thread__delete()
91 thread->mg = NULL; in thread__delete()
93 down_write(&thread->namespaces_lock); in thread__delete()
95 &thread->namespaces_list, list) { in thread__delete()
99 up_write(&thread->namespaces_lock); in thread__delete()
101 down_write(&thread->comm_lock); in thread__delete()
102 list_for_each_entry_safe(comm, tmp_comm, &thread->comm_list, list) { in thread__delete()
106 up_write(&thread->comm_lock); in thread__delete()
108 nsinfo__zput(thread->nsinfo); in thread__delete()
109 srccode_state_free(&thread->srccode_state); in thread__delete()
111 exit_rwsem(&thread->namespaces_lock); in thread__delete()
112 exit_rwsem(&thread->comm_lock); in thread__delete()
113 free(thread); in thread__delete()
116 struct thread *thread__get(struct thread *thread) in thread__get() argument
118 if (thread) in thread__get()
119 refcount_inc(&thread->refcnt); in thread__get()
120 return thread; in thread__get()
123 void thread__put(struct thread *thread) in thread__put() argument
125 if (thread && refcount_dec_and_test(&thread->refcnt)) { in thread__put()
146 if (!list_empty(&thread->node)) in thread__put()
147 list_del_init(&thread->node); in thread__put()
148 thread__delete(thread); in thread__put()
152 static struct namespaces *__thread__namespaces(const struct thread *thread) in __thread__namespaces() argument
154 if (list_empty(&thread->namespaces_list)) in __thread__namespaces()
157 return list_first_entry(&thread->namespaces_list, struct namespaces, list); in __thread__namespaces()
160 struct namespaces *thread__namespaces(struct thread *thread) in thread__namespaces() argument
164 down_read(&thread->namespaces_lock); in thread__namespaces()
165 ns = __thread__namespaces(thread); in thread__namespaces()
166 up_read(&thread->namespaces_lock); in thread__namespaces()
171 static int __thread__set_namespaces(struct thread *thread, u64 timestamp, in __thread__set_namespaces() argument
174 struct namespaces *new, *curr = __thread__namespaces(thread); in __thread__set_namespaces()
180 list_add(&new->list, &thread->namespaces_list); in __thread__set_namespaces()
195 int thread__set_namespaces(struct thread *thread, u64 timestamp, in thread__set_namespaces() argument
200 down_write(&thread->namespaces_lock); in thread__set_namespaces()
201 ret = __thread__set_namespaces(thread, timestamp, event); in thread__set_namespaces()
202 up_write(&thread->namespaces_lock); in thread__set_namespaces()
206 struct comm *thread__comm(const struct thread *thread) in thread__comm() argument
208 if (list_empty(&thread->comm_list)) in thread__comm()
211 return list_first_entry(&thread->comm_list, struct comm, list); in thread__comm()
214 struct comm *thread__exec_comm(const struct thread *thread) in thread__exec_comm() argument
218 list_for_each_entry(comm, &thread->comm_list, list) { in thread__exec_comm()
231 if (second_last && !last->start && thread->pid_ == thread->tid) in thread__exec_comm()
237 static int ____thread__set_comm(struct thread *thread, const char *str, in ____thread__set_comm() argument
240 struct comm *new, *curr = thread__comm(thread); in ____thread__set_comm()
243 if (!thread->comm_set) { in ____thread__set_comm()
251 list_add(&new->list, &thread->comm_list); in ____thread__set_comm()
254 unwind__flush_access(thread->mg); in ____thread__set_comm()
257 thread->comm_set = true; in ____thread__set_comm()
262 int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp, in __thread__set_comm() argument
267 down_write(&thread->comm_lock); in __thread__set_comm()
268 ret = ____thread__set_comm(thread, str, timestamp, exec); in __thread__set_comm()
269 up_write(&thread->comm_lock); in __thread__set_comm()
273 int thread__set_comm_from_proc(struct thread *thread) in thread__set_comm_from_proc() argument
281 thread->pid_, thread->tid) >= (int)sizeof(path)) && in thread__set_comm_from_proc()
284 err = thread__set_comm(thread, comm, 0); in thread__set_comm_from_proc()
290 static const char *__thread__comm_str(const struct thread *thread) in __thread__comm_str() argument
292 const struct comm *comm = thread__comm(thread); in __thread__comm_str()
300 const char *thread__comm_str(struct thread *thread) in thread__comm_str() argument
304 down_read(&thread->comm_lock); in thread__comm_str()
305 str = __thread__comm_str(thread); in thread__comm_str()
306 up_read(&thread->comm_lock); in thread__comm_str()
312 int thread__comm_len(struct thread *thread) in thread__comm_len() argument
314 if (!thread->comm_len) { in thread__comm_len()
315 const char *comm = thread__comm_str(thread); in thread__comm_len()
318 thread->comm_len = strlen(comm); in thread__comm_len()
321 return thread->comm_len; in thread__comm_len()
324 size_t thread__fprintf(struct thread *thread, FILE *fp) in thread__fprintf() argument
326 return fprintf(fp, "Thread %d %s\n", thread->tid, thread__comm_str(thread)) + in thread__fprintf()
327 map_groups__fprintf(thread->mg, fp); in thread__fprintf()
330 int thread__insert_map(struct thread *thread, struct map *map) in thread__insert_map() argument
334 ret = unwind__prepare_access(thread->mg, map, NULL); in thread__insert_map()
338 map_groups__fixup_overlappings(thread->mg, map, stderr); in thread__insert_map()
339 map_groups__insert(thread->mg, map); in thread__insert_map()
344 static int __thread__prepare_access(struct thread *thread) in __thread__prepare_access() argument
348 struct maps *maps = &thread->mg->maps; in __thread__prepare_access()
354 err = unwind__prepare_access(thread->mg, map, &initialized); in __thread__prepare_access()
364 static int thread__prepare_access(struct thread *thread) in thread__prepare_access() argument
369 err = __thread__prepare_access(thread); in thread__prepare_access()
374 static int thread__clone_map_groups(struct thread *thread, in thread__clone_map_groups() argument
375 struct thread *parent, in thread__clone_map_groups()
379 if (thread->pid_ == parent->pid_) in thread__clone_map_groups()
380 return thread__prepare_access(thread); in thread__clone_map_groups()
382 if (thread->mg == parent->mg) { in thread__clone_map_groups()
384 thread->pid_, thread->tid, parent->pid_, parent->tid); in thread__clone_map_groups()
388 return do_maps_clone ? map_groups__clone(thread, parent->mg) : 0; in thread__clone_map_groups()
391 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone) in thread__fork() argument
398 err = thread__set_comm(thread, comm, timestamp); in thread__fork()
403 thread->ppid = parent->tid; in thread__fork()
404 return thread__clone_map_groups(thread, parent, do_maps_clone); in thread__fork()
407 void thread__find_cpumode_addr_location(struct thread *thread, u64 addr, in thread__find_cpumode_addr_location() argument
419 thread__find_symbol(thread, cpumodes[i], addr, al); in thread__find_cpumode_addr_location()
425 struct thread *thread__main_thread(struct machine *machine, struct thread *thread) in thread__main_thread() argument
427 if (thread->pid_ == thread->tid) in thread__main_thread()
428 return thread__get(thread); in thread__main_thread()
430 if (thread->pid_ == -1) in thread__main_thread()
433 return machine__find_thread(machine, thread->pid_, thread->pid_); in thread__main_thread()
436 int thread__memcpy(struct thread *thread, struct machine *machine, in thread__memcpy() argument
446 if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso || in thread__memcpy()