Lines Matching full:thread

12 #include "thread.h"
13 #include "thread-stack.h"
25 int thread__init_maps(struct thread *thread, struct machine *machine) in thread__init_maps() argument
27 pid_t pid = thread__pid(thread); in thread__init_maps()
29 if (pid == thread__tid(thread) || pid == -1) { in thread__init_maps()
30 thread__set_maps(thread, maps__new(machine)); in thread__init_maps()
32 struct thread *leader = machine__findnew_thread(machine, pid, pid); in thread__init_maps()
35 thread__set_maps(thread, maps__get(thread__maps(leader))); in thread__init_maps()
40 return thread__maps(thread) ? 0 : -1; in thread__init_maps()
43 struct thread *thread__new(pid_t pid, pid_t tid) in thread__new()
45 RC_STRUCT(thread) *_thread = zalloc(sizeof(*_thread)); in thread__new()
46 struct thread *thread; in thread__new() local
48 if (ADD_RC_CHK(thread, _thread) != NULL) { in thread__new()
52 thread__set_pid(thread, pid); in thread__new()
53 thread__set_tid(thread, tid); in thread__new()
54 thread__set_ppid(thread, -1); in thread__new()
55 thread__set_cpu(thread, -1); in thread__new()
56 thread__set_guest_cpu(thread, -1); in thread__new()
57 thread__set_e_machine(thread, EM_NONE); in thread__new()
58 thread__set_lbr_stitch_enable(thread, false); in thread__new()
59 INIT_LIST_HEAD(thread__namespaces_list(thread)); in thread__new()
60 INIT_LIST_HEAD(thread__comm_list(thread)); in thread__new()
61 init_rwsem(thread__namespaces_lock(thread)); in thread__new()
62 init_rwsem(thread__comm_lock(thread)); in thread__new()
69 list_add(&comm->list, thread__comm_list(thread)); in thread__new()
70 refcount_set(thread__refcnt(thread), 1); in thread__new()
71 /* Thread holds first ref to nsdata. */ in thread__new()
72 RC_CHK_ACCESS(thread)->nsinfo = nsinfo__new(pid); in thread__new()
73 srccode_state_init(thread__srccode_state(thread)); in thread__new()
76 return thread; in thread__new()
79 thread__delete(thread); in thread__new()
92 void thread__delete(struct thread *thread) in thread__delete() argument
97 thread_stack__free(thread); in thread__delete()
99 if (thread__maps(thread)) { in thread__delete()
100 maps__put(thread__maps(thread)); in thread__delete()
101 thread__set_maps(thread, NULL); in thread__delete()
103 down_write(thread__namespaces_lock(thread)); in thread__delete()
105 thread__namespaces_list(thread), list) { in thread__delete()
109 up_write(thread__namespaces_lock(thread)); in thread__delete()
111 down_write(thread__comm_lock(thread)); in thread__delete()
112 list_for_each_entry_safe(comm, tmp_comm, thread__comm_list(thread), list) { in thread__delete()
116 up_write(thread__comm_lock(thread)); in thread__delete()
118 nsinfo__zput(RC_CHK_ACCESS(thread)->nsinfo); in thread__delete()
119 srccode_state_free(thread__srccode_state(thread)); in thread__delete()
121 exit_rwsem(thread__namespaces_lock(thread)); in thread__delete()
122 exit_rwsem(thread__comm_lock(thread)); in thread__delete()
123 thread__free_stitch_list(thread); in thread__delete()
126 thread__priv_destructor(thread__priv(thread)); in thread__delete()
128 RC_CHK_FREE(thread); in thread__delete()
131 struct thread *thread__get(struct thread *thread) in thread__get() argument
133 struct thread *result; in thread__get()
135 if (RC_CHK_GET(result, thread)) in thread__get()
136 refcount_inc(thread__refcnt(thread)); in thread__get()
141 void thread__put(struct thread *thread) in thread__put() argument
143 if (thread && refcount_dec_and_test(thread__refcnt(thread))) in thread__put()
144 thread__delete(thread); in thread__put()
146 RC_CHK_PUT(thread); in thread__put()
149 static struct namespaces *__thread__namespaces(struct thread *thread) in __thread__namespaces() argument
151 if (list_empty(thread__namespaces_list(thread))) in __thread__namespaces()
154 return list_first_entry(thread__namespaces_list(thread), struct namespaces, list); in __thread__namespaces()
157 struct namespaces *thread__namespaces(struct thread *thread) in thread__namespaces() argument
161 down_read(thread__namespaces_lock(thread)); in thread__namespaces()
162 ns = __thread__namespaces(thread); in thread__namespaces()
163 up_read(thread__namespaces_lock(thread)); in thread__namespaces()
168 static int __thread__set_namespaces(struct thread *thread, u64 timestamp, in __thread__set_namespaces() argument
171 struct namespaces *new, *curr = __thread__namespaces(thread); in __thread__set_namespaces()
177 list_add(&new->list, thread__namespaces_list(thread)); in __thread__set_namespaces()
182 * of this thread. Update end time for the namespaces in __thread__set_namespaces()
192 int thread__set_namespaces(struct thread *thread, u64 timestamp, in thread__set_namespaces() argument
197 down_write(thread__namespaces_lock(thread)); in thread__set_namespaces()
198 ret = __thread__set_namespaces(thread, timestamp, event); in thread__set_namespaces()
199 up_write(thread__namespaces_lock(thread)); in thread__set_namespaces()
203 struct comm *thread__comm(struct thread *thread) in thread__comm() argument
205 if (list_empty(thread__comm_list(thread))) in thread__comm()
208 return list_first_entry(thread__comm_list(thread), struct comm, list); in thread__comm()
211 struct comm *thread__exec_comm(struct thread *thread) in thread__exec_comm() argument
215 list_for_each_entry(comm, thread__comm_list(thread), list) { in thread__exec_comm()
224 * thread (created by processing a synthesized fork event). For a main in thread__exec_comm()
225 * thread, that is very probably wrong. Prefer a later comm to avoid in thread__exec_comm()
228 if (second_last && !last->start && thread__pid(thread) == thread__tid(thread)) in thread__exec_comm()
234 static int ____thread__set_comm(struct thread *thread, const char *str, in ____thread__set_comm() argument
237 struct comm *new, *curr = thread__comm(thread); in ____thread__set_comm()
240 if (!thread__comm_set(thread)) { in ____thread__set_comm()
248 list_add(&new->list, thread__comm_list(thread)); in ____thread__set_comm()
251 unwind__flush_access(thread__maps(thread)); in ____thread__set_comm()
254 thread__set_comm_set(thread, true); in ____thread__set_comm()
259 int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp, in __thread__set_comm() argument
264 down_write(thread__comm_lock(thread)); in __thread__set_comm()
265 ret = ____thread__set_comm(thread, str, timestamp, exec); in __thread__set_comm()
266 up_write(thread__comm_lock(thread)); in __thread__set_comm()
270 int thread__set_comm_from_proc(struct thread *thread) in thread__set_comm_from_proc() argument
278 thread__pid(thread), thread__tid(thread)) >= (int)sizeof(path)) && in thread__set_comm_from_proc()
281 err = thread__set_comm(thread, comm, 0); in thread__set_comm_from_proc()
287 static const char *__thread__comm_str(struct thread *thread) in __thread__comm_str() argument
289 const struct comm *comm = thread__comm(thread); in __thread__comm_str()
297 const char *thread__comm_str(struct thread *thread) in thread__comm_str() argument
301 down_read(thread__comm_lock(thread)); in thread__comm_str()
302 str = __thread__comm_str(thread); in thread__comm_str()
303 up_read(thread__comm_lock(thread)); in thread__comm_str()
308 static int __thread__comm_len(struct thread *thread, const char *comm) in __thread__comm_len() argument
312 thread__set_comm_len(thread, strlen(comm)); in __thread__comm_len()
314 return thread__var_comm_len(thread); in __thread__comm_len()
318 int thread__comm_len(struct thread *thread) in thread__comm_len() argument
320 int comm_len = thread__var_comm_len(thread); in thread__comm_len()
325 down_read(thread__comm_lock(thread)); in thread__comm_len()
326 comm = __thread__comm_str(thread); in thread__comm_len()
327 comm_len = __thread__comm_len(thread, comm); in thread__comm_len()
328 up_read(thread__comm_lock(thread)); in thread__comm_len()
334 size_t thread__fprintf(struct thread *thread, FILE *fp) in thread__fprintf() argument
336 return fprintf(fp, "Thread %d %s\n", thread__tid(thread), thread__comm_str(thread)) + in thread__fprintf()
337 maps__fprintf(thread__maps(thread), fp); in thread__fprintf()
340 int thread__insert_map(struct thread *thread, struct map *map) in thread__insert_map() argument
344 ret = unwind__prepare_access(thread__maps(thread), map, NULL); in thread__insert_map()
348 return maps__fixup_overlap_and_insert(thread__maps(thread), map); in thread__insert_map()
366 static int thread__prepare_access(struct thread *thread) in thread__prepare_access() argument
373 args.maps = thread__maps(thread); in thread__prepare_access()
374 maps__for_each_map(thread__maps(thread), thread__prepare_access_maps_cb, &args); in thread__prepare_access()
380 static int thread__clone_maps(struct thread *thread, struct thread *parent, bool do_maps_clone) in thread__clone_maps() argument
382 /* This is new thread, we share map groups for process. */ in thread__clone_maps()
383 if (thread__pid(thread) == thread__pid(parent)) in thread__clone_maps()
384 return thread__prepare_access(thread); in thread__clone_maps()
386 if (maps__equal(thread__maps(thread), thread__maps(parent))) { in thread__clone_maps()
387 pr_debug("broken map groups on thread %d/%d parent %d/%d\n", in thread__clone_maps()
388 thread__pid(thread), thread__tid(thread), in thread__clone_maps()
393 return do_maps_clone ? maps__copy_from(thread__maps(thread), thread__maps(parent)) : 0; in thread__clone_maps()
396 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone) in thread__fork() argument
403 err = thread__set_comm(thread, comm, timestamp); in thread__fork()
408 thread__set_ppid(thread, thread__tid(parent)); in thread__fork()
409 return thread__clone_maps(thread, parent, do_maps_clone); in thread__fork()
412 void thread__find_cpumode_addr_location(struct thread *thread, u64 addr, in thread__find_cpumode_addr_location() argument
424 thread__find_symbol(thread, cpumodes[i], addr, al); in thread__find_cpumode_addr_location()
459 uint16_t thread__e_machine(struct thread *thread, struct machine *machine) in thread__e_machine() argument
462 uint16_t e_machine = RC_CHK_ACCESS(thread)->e_machine; in thread__e_machine()
467 tid = thread__tid(thread); in thread__e_machine()
468 pid = thread__pid(thread); in thread__e_machine()
470 struct thread *parent = machine__findnew_thread(machine, pid, pid); in thread__e_machine()
474 thread__set_e_machine(thread, e_machine); in thread__e_machine()
479 /* Reading on the PID thread. First try to find from the maps. */ in thread__e_machine()
480 e_machine = maps__for_each_map(thread__maps(thread), in thread__e_machine()
500 thread__set_e_machine(thread, e_machine); in thread__e_machine()
506 struct thread *thread__main_thread(struct machine *machine, struct thread *thread) in thread__main_thread() argument
508 if (thread__pid(thread) == thread__tid(thread)) in thread__main_thread()
509 return thread__get(thread); in thread__main_thread()
511 if (thread__pid(thread) == -1) in thread__main_thread()
514 return machine__find_thread(machine, thread__pid(thread), thread__pid(thread)); in thread__main_thread()
517 int thread__memcpy(struct thread *thread, struct machine *machine, in thread__memcpy() argument
529 if (!thread__find_map(thread, cpumode, ip, &al)) { in thread__memcpy()
550 void thread__free_stitch_list(struct thread *thread) in thread__free_stitch_list() argument
552 struct lbr_stitch *lbr_stitch = thread__lbr_stitch(thread); in thread__free_stitch_list()
573 free(thread__lbr_stitch(thread)); in thread__free_stitch_list()
574 thread__set_lbr_stitch(thread, NULL); in thread__free_stitch_list()