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()
46 RC_STRUCT(thread) *_thread = zalloc(sizeof(*_thread)); in thread__new()
47 struct thread *thread; in thread__new() local
49 if (ADD_RC_CHK(thread, _thread) != NULL) { in thread__new()
53 thread__set_pid(thread, pid); in thread__new()
54 thread__set_tid(thread, tid); in thread__new()
55 thread__set_ppid(thread, -1); in thread__new()
56 thread__set_cpu(thread, -1); in thread__new()
57 thread__set_guest_cpu(thread, -1); in thread__new()
58 thread__set_e_machine(thread, EM_NONE); in thread__new()
59 thread__set_lbr_stitch_enable(thread, false); in thread__new()
60 INIT_LIST_HEAD(thread__namespaces_list(thread)); in thread__new()
61 INIT_LIST_HEAD(thread__comm_list(thread)); in thread__new()
62 init_rwsem(thread__namespaces_lock(thread)); in thread__new()
63 init_rwsem(thread__comm_lock(thread)); in thread__new()
70 list_add(&comm->list, thread__comm_list(thread)); in thread__new()
71 refcount_set(thread__refcnt(thread), 1); in thread__new()
72 /* Thread holds first ref to nsdata. */ in thread__new()
73 RC_CHK_ACCESS(thread)->nsinfo = nsinfo__new(pid); in thread__new()
74 srccode_state_init(thread__srccode_state(thread)); in thread__new()
77 return thread; in thread__new()
80 thread__delete(thread); in thread__new()
93 void thread__delete(struct thread *thread) in thread__delete() argument
98 thread_stack__free(thread); in thread__delete()
100 if (thread__maps(thread)) { in thread__delete()
101 maps__put(thread__maps(thread)); in thread__delete()
102 thread__set_maps(thread, NULL); in thread__delete()
104 down_write(thread__namespaces_lock(thread)); in thread__delete()
106 thread__namespaces_list(thread), list) { in thread__delete()
110 up_write(thread__namespaces_lock(thread)); in thread__delete()
112 down_write(thread__comm_lock(thread)); in thread__delete()
113 list_for_each_entry_safe(comm, tmp_comm, thread__comm_list(thread), list) { in thread__delete()
117 up_write(thread__comm_lock(thread)); in thread__delete()
119 nsinfo__zput(RC_CHK_ACCESS(thread)->nsinfo); in thread__delete()
120 srccode_state_free(thread__srccode_state(thread)); in thread__delete()
122 exit_rwsem(thread__namespaces_lock(thread)); in thread__delete()
123 exit_rwsem(thread__comm_lock(thread)); in thread__delete()
124 thread__free_stitch_list(thread); in thread__delete()
127 thread__priv_destructor(thread__priv(thread)); in thread__delete()
129 RC_CHK_FREE(thread); in thread__delete()
132 struct thread *thread__get(struct thread *thread) in thread__get() argument
134 struct thread *result; in thread__get()
136 if (RC_CHK_GET(result, thread)) in thread__get()
137 refcount_inc(thread__refcnt(thread)); in thread__get()
142 void thread__put(struct thread *thread) in thread__put() argument
144 if (thread && refcount_dec_and_test(thread__refcnt(thread))) in thread__put()
145 thread__delete(thread); in thread__put()
147 RC_CHK_PUT(thread); in thread__put()
150 static struct namespaces *__thread__namespaces(struct thread *thread) in __thread__namespaces() argument
152 if (list_empty(thread__namespaces_list(thread))) in __thread__namespaces()
155 return list_first_entry(thread__namespaces_list(thread), struct namespaces, list); in __thread__namespaces()
158 struct namespaces *thread__namespaces(struct thread *thread) in thread__namespaces() argument
162 down_read(thread__namespaces_lock(thread)); in thread__namespaces()
163 ns = __thread__namespaces(thread); in thread__namespaces()
164 up_read(thread__namespaces_lock(thread)); in thread__namespaces()
169 static int __thread__set_namespaces(struct thread *thread, u64 timestamp, in __thread__set_namespaces() argument
172 struct namespaces *new, *curr = __thread__namespaces(thread); in __thread__set_namespaces()
178 list_add(&new->list, thread__namespaces_list(thread)); in __thread__set_namespaces()
183 * of this thread. Update end time for the namespaces in __thread__set_namespaces()
193 int thread__set_namespaces(struct thread *thread, u64 timestamp, in thread__set_namespaces() argument
198 down_write(thread__namespaces_lock(thread)); in thread__set_namespaces()
199 ret = __thread__set_namespaces(thread, timestamp, event); in thread__set_namespaces()
200 up_write(thread__namespaces_lock(thread)); in thread__set_namespaces()
204 static struct comm *__thread__comm(struct thread *thread) in __thread__comm() argument
205 SHARED_LOCKS_REQUIRED(thread__comm_lock(thread)) in __thread__comm()
207 if (list_empty(thread__comm_list(thread))) in __thread__comm()
210 return list_first_entry(thread__comm_list(thread), struct comm, list); in __thread__comm()
213 struct comm *thread__comm(struct thread *thread) in thread__comm() argument
217 down_read(thread__comm_lock(thread)); in thread__comm()
218 res = __thread__comm(thread); in thread__comm()
219 up_read(thread__comm_lock(thread)); in thread__comm()
223 struct comm *thread__exec_comm(struct thread *thread) in thread__exec_comm() argument
227 down_read(thread__comm_lock(thread)); in thread__exec_comm()
228 list_for_each_entry(comm, thread__comm_list(thread), list) { in thread__exec_comm()
230 up_read(thread__comm_lock(thread)); in thread__exec_comm()
236 up_read(thread__comm_lock(thread)); in thread__exec_comm()
240 * thread (created by processing a synthesized fork event). For a main in thread__exec_comm()
241 * thread, that is very probably wrong. Prefer a later comm to avoid in thread__exec_comm()
244 if (second_last && !last->start && thread__pid(thread) == thread__tid(thread)) in thread__exec_comm()
250 static int ____thread__set_comm(struct thread *thread, const char *str, in ____thread__set_comm() argument
252 EXCLUSIVE_LOCKS_REQUIRED(thread__comm_lock(thread)) in ____thread__set_comm()
254 struct comm *new, *curr = __thread__comm(thread); in ____thread__set_comm()
257 if (!thread__comm_set(thread)) { in ____thread__set_comm()
265 list_add(&new->list, thread__comm_list(thread)); in ____thread__set_comm()
268 unwind__flush_access(thread__maps(thread)); in ____thread__set_comm()
271 thread__set_comm_set(thread, true); in ____thread__set_comm()
276 int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp, in __thread__set_comm() argument
281 down_write(thread__comm_lock(thread)); in __thread__set_comm()
282 ret = ____thread__set_comm(thread, str, timestamp, exec); in __thread__set_comm()
283 up_write(thread__comm_lock(thread)); in __thread__set_comm()
287 int thread__set_comm_from_proc(struct thread *thread) in thread__set_comm_from_proc() argument
295 thread__pid(thread), thread__tid(thread)) >= (int)sizeof(path)) && in thread__set_comm_from_proc()
298 err = thread__set_comm(thread, comm, 0); in thread__set_comm_from_proc()
304 static const char *__thread__comm_str(struct thread *thread) in __thread__comm_str() argument
305 SHARED_LOCKS_REQUIRED(thread__comm_lock(thread)) in __thread__comm_str()
307 const struct comm *comm = __thread__comm(thread); in __thread__comm_str()
315 const char *thread__comm_str(struct thread *thread) in thread__comm_str() argument
319 down_read(thread__comm_lock(thread)); in thread__comm_str()
320 str = __thread__comm_str(thread); in thread__comm_str()
321 up_read(thread__comm_lock(thread)); in thread__comm_str()
326 static int __thread__comm_len(struct thread *thread, const char *comm) in __thread__comm_len() argument
330 thread__set_comm_len(thread, strlen(comm)); in __thread__comm_len()
332 return thread__var_comm_len(thread); in __thread__comm_len()
336 int thread__comm_len(struct thread *thread) in thread__comm_len() argument
338 int comm_len = thread__var_comm_len(thread); in thread__comm_len()
343 down_read(thread__comm_lock(thread)); in thread__comm_len()
344 comm = __thread__comm_str(thread); in thread__comm_len()
345 comm_len = __thread__comm_len(thread, comm); in thread__comm_len()
346 up_read(thread__comm_lock(thread)); in thread__comm_len()
352 size_t thread__fprintf(struct thread *thread, FILE *fp) in thread__fprintf() argument
354 return fprintf(fp, "Thread %d %s\n", thread__tid(thread), thread__comm_str(thread)) + in thread__fprintf()
355 maps__fprintf(thread__maps(thread), fp); in thread__fprintf()
358 int thread__insert_map(struct thread *thread, struct map *map) in thread__insert_map() argument
362 ret = unwind__prepare_access(thread__maps(thread), map, NULL); in thread__insert_map()
366 return maps__fixup_overlap_and_insert(thread__maps(thread), map); in thread__insert_map()
384 static int thread__prepare_access(struct thread *thread) in thread__prepare_access() argument
391 args.maps = thread__maps(thread); in thread__prepare_access()
392 maps__for_each_map(thread__maps(thread), thread__prepare_access_maps_cb, &args); in thread__prepare_access()
398 static int thread__clone_maps(struct thread *thread, struct thread *parent, bool do_maps_clone) in thread__clone_maps() argument
400 /* This is new thread, we share map groups for process. */ in thread__clone_maps()
401 if (thread__pid(thread) == thread__pid(parent)) in thread__clone_maps()
402 return thread__prepare_access(thread); in thread__clone_maps()
404 if (maps__equal(thread__maps(thread), thread__maps(parent))) { in thread__clone_maps()
405 pr_debug("broken map groups on thread %d/%d parent %d/%d\n", in thread__clone_maps()
406 thread__pid(thread), thread__tid(thread), in thread__clone_maps()
411 return do_maps_clone ? maps__copy_from(thread__maps(thread), thread__maps(parent)) : 0; in thread__clone_maps()
414 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone) in thread__fork() argument
421 err = thread__set_comm(thread, comm, timestamp); in thread__fork()
426 thread__set_ppid(thread, thread__tid(parent)); in thread__fork()
427 return thread__clone_maps(thread, parent, do_maps_clone); in thread__fork()
430 void thread__find_cpumode_addr_location(struct thread *thread, u64 addr, in thread__find_cpumode_addr_location() argument
443 thread__find_symbol(thread, cpumodes[i], addr, al); in thread__find_cpumode_addr_location()
445 thread__find_map(thread, cpumodes[i], addr, al); in thread__find_cpumode_addr_location()
481 uint16_t thread__e_machine(struct thread *thread, struct machine *machine) in thread__e_machine() argument
484 uint16_t e_machine = RC_CHK_ACCESS(thread)->e_machine; in thread__e_machine()
489 tid = thread__tid(thread); in thread__e_machine()
490 pid = thread__pid(thread); in thread__e_machine()
492 struct thread *parent = machine__findnew_thread(machine, pid, pid); in thread__e_machine()
497 thread__set_e_machine(thread, e_machine); in thread__e_machine()
502 /* Reading on the PID thread. First try to find from the maps. */ in thread__e_machine()
503 e_machine = maps__for_each_map(thread__maps(thread), in thread__e_machine()
523 thread__set_e_machine(thread, e_machine); in thread__e_machine()
529 struct thread *thread__main_thread(struct machine *machine, struct thread *thread) in thread__main_thread() argument
531 if (thread__pid(thread) == thread__tid(thread)) in thread__main_thread()
532 return thread__get(thread); in thread__main_thread()
534 if (thread__pid(thread) == -1) in thread__main_thread()
537 return machine__find_thread(machine, thread__pid(thread), thread__pid(thread)); in thread__main_thread()
540 int thread__memcpy(struct thread *thread, struct machine *machine, in thread__memcpy() argument
552 if (!thread__find_map(thread, cpumode, ip, &al)) { in thread__memcpy()
573 void thread__free_stitch_list(struct thread *thread) in thread__free_stitch_list() argument
575 struct lbr_stitch *lbr_stitch = thread__lbr_stitch(thread); in thread__free_stitch_list()
596 free(thread__lbr_stitch(thread)); in thread__free_stitch_list()
597 thread__set_lbr_stitch(thread, NULL); in thread__free_stitch_list()