Lines Matching refs:thread
13 int thread__init_map_groups(struct thread *thread, struct machine *machine) in thread__init_map_groups() argument
15 struct thread *leader; in thread__init_map_groups()
16 pid_t pid = thread->pid_; in thread__init_map_groups()
18 if (pid == thread->tid || pid == -1) { in thread__init_map_groups()
19 thread->mg = map_groups__new(machine); in thread__init_map_groups()
23 thread->mg = map_groups__get(leader->mg); in thread__init_map_groups()
26 return thread->mg ? 0 : -1; in thread__init_map_groups()
29 struct thread *thread__new(pid_t pid, pid_t tid) in thread__new()
33 struct thread *thread = zalloc(sizeof(*thread)); in thread__new() local
35 if (thread != NULL) { in thread__new()
36 thread->pid_ = pid; in thread__new()
37 thread->tid = tid; in thread__new()
38 thread->ppid = -1; in thread__new()
39 thread->cpu = -1; in thread__new()
40 INIT_LIST_HEAD(&thread->comm_list); in thread__new()
42 if (unwind__prepare_access(thread) < 0) in thread__new()
55 list_add(&comm->list, &thread->comm_list); in thread__new()
56 atomic_set(&thread->refcnt, 0); in thread__new()
57 RB_CLEAR_NODE(&thread->rb_node); in thread__new()
60 return thread; in thread__new()
63 free(thread); in thread__new()
67 void thread__delete(struct thread *thread) in thread__delete() argument
71 BUG_ON(!RB_EMPTY_NODE(&thread->rb_node)); in thread__delete()
73 thread_stack__free(thread); in thread__delete()
75 if (thread->mg) { in thread__delete()
76 map_groups__put(thread->mg); in thread__delete()
77 thread->mg = NULL; in thread__delete()
79 list_for_each_entry_safe(comm, tmp, &thread->comm_list, list) { in thread__delete()
83 unwind__finish_access(thread); in thread__delete()
85 free(thread); in thread__delete()
88 struct thread *thread__get(struct thread *thread) in thread__get() argument
90 if (thread) in thread__get()
91 atomic_inc(&thread->refcnt); in thread__get()
92 return thread; in thread__get()
95 void thread__put(struct thread *thread) in thread__put() argument
97 if (thread && atomic_dec_and_test(&thread->refcnt)) { in thread__put()
98 list_del_init(&thread->node); in thread__put()
99 thread__delete(thread); in thread__put()
103 struct comm *thread__comm(const struct thread *thread) in thread__comm() argument
105 if (list_empty(&thread->comm_list)) in thread__comm()
108 return list_first_entry(&thread->comm_list, struct comm, list); in thread__comm()
111 struct comm *thread__exec_comm(const struct thread *thread) in thread__exec_comm() argument
115 list_for_each_entry(comm, &thread->comm_list, list) { in thread__exec_comm()
124 int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp, in __thread__set_comm() argument
127 struct comm *new, *curr = thread__comm(thread); in __thread__set_comm()
131 if (!thread->comm_set) { in __thread__set_comm()
139 list_add(&new->list, &thread->comm_list); in __thread__set_comm()
142 unwind__flush_access(thread); in __thread__set_comm()
145 thread->comm_set = true; in __thread__set_comm()
150 const char *thread__comm_str(const struct thread *thread) in thread__comm_str() argument
152 const struct comm *comm = thread__comm(thread); in thread__comm_str()
161 int thread__comm_len(struct thread *thread) in thread__comm_len() argument
163 if (!thread->comm_len) { in thread__comm_len()
164 const char *comm = thread__comm_str(thread); in thread__comm_len()
167 thread->comm_len = strlen(comm); in thread__comm_len()
170 return thread->comm_len; in thread__comm_len()
173 size_t thread__fprintf(struct thread *thread, FILE *fp) in thread__fprintf() argument
175 return fprintf(fp, "Thread %d %s\n", thread->tid, thread__comm_str(thread)) + in thread__fprintf()
176 map_groups__fprintf(thread->mg, fp); in thread__fprintf()
179 void thread__insert_map(struct thread *thread, struct map *map) in thread__insert_map() argument
181 map_groups__fixup_overlappings(thread->mg, map, stderr); in thread__insert_map()
182 map_groups__insert(thread->mg, map); in thread__insert_map()
185 static int thread__clone_map_groups(struct thread *thread, in thread__clone_map_groups() argument
186 struct thread *parent) in thread__clone_map_groups()
191 if (thread->pid_ == parent->pid_) in thread__clone_map_groups()
194 if (thread->mg == parent->mg) { in thread__clone_map_groups()
196 thread->pid_, thread->tid, parent->pid_, parent->tid); in thread__clone_map_groups()
202 if (map_groups__clone(thread->mg, parent->mg, i) < 0) in thread__clone_map_groups()
208 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp) in thread__fork() argument
216 err = thread__set_comm(thread, comm, timestamp); in thread__fork()
221 thread->ppid = parent->tid; in thread__fork()
222 return thread__clone_map_groups(thread, parent); in thread__fork()
225 void thread__find_cpumode_addr_location(struct thread *thread, in thread__find_cpumode_addr_location() argument
238 thread__find_addr_location(thread, cpumodes[i], type, addr, al); in thread__find_cpumode_addr_location()