• Home
  • Raw
  • Download

Lines Matching full:thread

10 #include "thread.h"
11 #include "thread-stack.h"
22 int thread__init_maps(struct thread *thread, struct machine *machine) in thread__init_maps() argument
24 pid_t pid = thread__pid(thread); in thread__init_maps()
26 if (pid == thread__tid(thread) || pid == -1) { in thread__init_maps()
27 thread__set_maps(thread, maps__new(machine)); in thread__init_maps()
29 struct thread *leader = __machine__findnew_thread(machine, pid, pid); in thread__init_maps()
32 thread__set_maps(thread, maps__get(thread__maps(leader))); in thread__init_maps()
37 return thread__maps(thread) ? 0 : -1; in thread__init_maps()
40 struct thread *thread__new(pid_t pid, pid_t tid) in thread__new()
42 RC_STRUCT(thread) *_thread = zalloc(sizeof(*_thread)); in thread__new()
43 struct thread *thread; in thread__new() local
45 if (ADD_RC_CHK(thread, _thread) != NULL) { in thread__new()
49 thread__set_pid(thread, pid); in thread__new()
50 thread__set_tid(thread, tid); in thread__new()
51 thread__set_ppid(thread, -1); in thread__new()
52 thread__set_cpu(thread, -1); in thread__new()
53 thread__set_guest_cpu(thread, -1); in thread__new()
54 thread__set_lbr_stitch_enable(thread, false); in thread__new()
55 INIT_LIST_HEAD(thread__namespaces_list(thread)); in thread__new()
56 INIT_LIST_HEAD(thread__comm_list(thread)); in thread__new()
57 init_rwsem(thread__namespaces_lock(thread)); in thread__new()
58 init_rwsem(thread__comm_lock(thread)); in thread__new()
65 list_add(&comm->list, thread__comm_list(thread)); in thread__new()
66 refcount_set(thread__refcnt(thread), 1); in thread__new()
67 /* Thread holds first ref to nsdata. */ in thread__new()
68 RC_CHK_ACCESS(thread)->nsinfo = nsinfo__new(pid); in thread__new()
69 srccode_state_init(thread__srccode_state(thread)); in thread__new()
72 return thread; in thread__new()
75 thread__delete(thread); in thread__new()
88 void thread__delete(struct thread *thread) in thread__delete() argument
93 thread_stack__free(thread); in thread__delete()
95 if (thread__maps(thread)) { in thread__delete()
96 maps__put(thread__maps(thread)); in thread__delete()
97 thread__set_maps(thread, NULL); in thread__delete()
99 down_write(thread__namespaces_lock(thread)); in thread__delete()
101 thread__namespaces_list(thread), list) { in thread__delete()
105 up_write(thread__namespaces_lock(thread)); in thread__delete()
107 down_write(thread__comm_lock(thread)); in thread__delete()
108 list_for_each_entry_safe(comm, tmp_comm, thread__comm_list(thread), list) { in thread__delete()
112 up_write(thread__comm_lock(thread)); in thread__delete()
114 nsinfo__zput(RC_CHK_ACCESS(thread)->nsinfo); in thread__delete()
115 srccode_state_free(thread__srccode_state(thread)); in thread__delete()
117 exit_rwsem(thread__namespaces_lock(thread)); in thread__delete()
118 exit_rwsem(thread__comm_lock(thread)); in thread__delete()
119 thread__free_stitch_list(thread); in thread__delete()
122 thread__priv_destructor(thread__priv(thread)); in thread__delete()
124 RC_CHK_FREE(thread); in thread__delete()
127 struct thread *thread__get(struct thread *thread) in thread__get() argument
129 struct thread *result; in thread__get()
131 if (RC_CHK_GET(result, thread)) in thread__get()
132 refcount_inc(thread__refcnt(thread)); in thread__get()
137 void thread__put(struct thread *thread) in thread__put() argument
139 if (thread && refcount_dec_and_test(thread__refcnt(thread))) in thread__put()
140 thread__delete(thread); in thread__put()
142 RC_CHK_PUT(thread); in thread__put()
145 static struct namespaces *__thread__namespaces(struct thread *thread) in __thread__namespaces() argument
147 if (list_empty(thread__namespaces_list(thread))) in __thread__namespaces()
150 return list_first_entry(thread__namespaces_list(thread), struct namespaces, list); in __thread__namespaces()
153 struct namespaces *thread__namespaces(struct thread *thread) in thread__namespaces() argument
157 down_read(thread__namespaces_lock(thread)); in thread__namespaces()
158 ns = __thread__namespaces(thread); in thread__namespaces()
159 up_read(thread__namespaces_lock(thread)); in thread__namespaces()
164 static int __thread__set_namespaces(struct thread *thread, u64 timestamp, in __thread__set_namespaces() argument
167 struct namespaces *new, *curr = __thread__namespaces(thread); in __thread__set_namespaces()
173 list_add(&new->list, thread__namespaces_list(thread)); in __thread__set_namespaces()
178 * of this thread. Update end time for the namespaces in __thread__set_namespaces()
188 int thread__set_namespaces(struct thread *thread, u64 timestamp, in thread__set_namespaces() argument
193 down_write(thread__namespaces_lock(thread)); in thread__set_namespaces()
194 ret = __thread__set_namespaces(thread, timestamp, event); in thread__set_namespaces()
195 up_write(thread__namespaces_lock(thread)); in thread__set_namespaces()
199 struct comm *thread__comm(struct thread *thread) in thread__comm() argument
201 if (list_empty(thread__comm_list(thread))) in thread__comm()
204 return list_first_entry(thread__comm_list(thread), struct comm, list); in thread__comm()
207 struct comm *thread__exec_comm(struct thread *thread) in thread__exec_comm() argument
211 list_for_each_entry(comm, thread__comm_list(thread), list) { in thread__exec_comm()
220 * thread (created by processing a synthesized fork event). For a main in thread__exec_comm()
221 * thread, that is very probably wrong. Prefer a later comm to avoid in thread__exec_comm()
224 if (second_last && !last->start && thread__pid(thread) == thread__tid(thread)) in thread__exec_comm()
230 static int ____thread__set_comm(struct thread *thread, const char *str, in ____thread__set_comm() argument
233 struct comm *new, *curr = thread__comm(thread); in ____thread__set_comm()
236 if (!thread__comm_set(thread)) { in ____thread__set_comm()
244 list_add(&new->list, thread__comm_list(thread)); in ____thread__set_comm()
247 unwind__flush_access(thread__maps(thread)); in ____thread__set_comm()
250 thread__set_comm_set(thread, true); in ____thread__set_comm()
255 int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp, in __thread__set_comm() argument
260 down_write(thread__comm_lock(thread)); in __thread__set_comm()
261 ret = ____thread__set_comm(thread, str, timestamp, exec); in __thread__set_comm()
262 up_write(thread__comm_lock(thread)); in __thread__set_comm()
266 int thread__set_comm_from_proc(struct thread *thread) in thread__set_comm_from_proc() argument
274 thread__pid(thread), thread__tid(thread)) >= (int)sizeof(path)) && in thread__set_comm_from_proc()
277 err = thread__set_comm(thread, comm, 0); in thread__set_comm_from_proc()
283 static const char *__thread__comm_str(struct thread *thread) in __thread__comm_str() argument
285 const struct comm *comm = thread__comm(thread); in __thread__comm_str()
293 const char *thread__comm_str(struct thread *thread) in thread__comm_str() argument
297 down_read(thread__comm_lock(thread)); in thread__comm_str()
298 str = __thread__comm_str(thread); in thread__comm_str()
299 up_read(thread__comm_lock(thread)); in thread__comm_str()
304 static int __thread__comm_len(struct thread *thread, const char *comm) in __thread__comm_len() argument
308 thread__set_comm_len(thread, strlen(comm)); in __thread__comm_len()
310 return thread__var_comm_len(thread); in __thread__comm_len()
314 int thread__comm_len(struct thread *thread) in thread__comm_len() argument
316 int comm_len = thread__var_comm_len(thread); in thread__comm_len()
321 down_read(thread__comm_lock(thread)); in thread__comm_len()
322 comm = __thread__comm_str(thread); in thread__comm_len()
323 comm_len = __thread__comm_len(thread, comm); in thread__comm_len()
324 up_read(thread__comm_lock(thread)); in thread__comm_len()
330 size_t thread__fprintf(struct thread *thread, FILE *fp) in thread__fprintf() argument
332 return fprintf(fp, "Thread %d %s\n", thread__tid(thread), thread__comm_str(thread)) + in thread__fprintf()
333 maps__fprintf(thread__maps(thread), fp); in thread__fprintf()
336 int thread__insert_map(struct thread *thread, struct map *map) in thread__insert_map() argument
340 ret = unwind__prepare_access(thread__maps(thread), map, NULL); in thread__insert_map()
344 maps__fixup_overlappings(thread__maps(thread), map, stderr); in thread__insert_map()
345 return maps__insert(thread__maps(thread), map); in thread__insert_map()
348 static int __thread__prepare_access(struct thread *thread) in __thread__prepare_access() argument
352 struct maps *maps = thread__maps(thread); in __thread__prepare_access()
358 err = unwind__prepare_access(thread__maps(thread), rb_node->map, &initialized); in __thread__prepare_access()
368 static int thread__prepare_access(struct thread *thread) in thread__prepare_access() argument
373 err = __thread__prepare_access(thread); in thread__prepare_access()
378 static int thread__clone_maps(struct thread *thread, struct thread *parent, bool do_maps_clone) in thread__clone_maps() argument
380 /* This is new thread, we share map groups for process. */ in thread__clone_maps()
381 if (thread__pid(thread) == thread__pid(parent)) in thread__clone_maps()
382 return thread__prepare_access(thread); in thread__clone_maps()
384 if (thread__maps(thread) == thread__maps(parent)) { in thread__clone_maps()
385 pr_debug("broken map groups on thread %d/%d parent %d/%d\n", in thread__clone_maps()
386 thread__pid(thread), thread__tid(thread), in thread__clone_maps()
391 return do_maps_clone ? maps__clone(thread, thread__maps(parent)) : 0; in thread__clone_maps()
394 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone) in thread__fork() argument
401 err = thread__set_comm(thread, comm, timestamp); in thread__fork()
406 thread__set_ppid(thread, thread__tid(parent)); in thread__fork()
407 return thread__clone_maps(thread, parent, do_maps_clone); in thread__fork()
410 void thread__find_cpumode_addr_location(struct thread *thread, u64 addr, in thread__find_cpumode_addr_location() argument
422 thread__find_symbol(thread, cpumodes[i], addr, al); in thread__find_cpumode_addr_location()
428 struct thread *thread__main_thread(struct machine *machine, struct thread *thread) in thread__main_thread() argument
430 if (thread__pid(thread) == thread__tid(thread)) in thread__main_thread()
431 return thread__get(thread); in thread__main_thread()
433 if (thread__pid(thread) == -1) in thread__main_thread()
436 return machine__find_thread(machine, thread__pid(thread), thread__pid(thread)); in thread__main_thread()
439 int thread__memcpy(struct thread *thread, struct machine *machine, in thread__memcpy() argument
451 if (!thread__find_map(thread, cpumode, ip, &al)) { in thread__memcpy()
472 void thread__free_stitch_list(struct thread *thread) in thread__free_stitch_list() argument
474 struct lbr_stitch *lbr_stitch = thread__lbr_stitch(thread); in thread__free_stitch_list()
491 free(thread__lbr_stitch(thread)); in thread__free_stitch_list()
492 thread__set_lbr_stitch(thread, NULL); in thread__free_stitch_list()