Lines Matching full:thread

25 #include "thread.h"
46 static void __machine__remove_thread(struct machine *machine, struct thread *th, bool lock);
87 static void thread__set_guest_comm(struct thread *thread, pid_t pid) in thread__set_guest_comm() argument
92 thread__set_comm(thread, comm, 0); in thread__set_guest_comm()
128 struct thread *thread = machine__findnew_thread(machine, -1, in machine__init() local
131 if (thread == NULL) in machine__init()
134 thread__set_guest_comm(thread, pid); in machine__init()
135 thread__put(thread); in machine__init()
216 struct thread *t = rb_entry(nd, struct thread, rb_node); in machine__delete_threads()
243 struct thread *thread, *n; in machine__exit() local
252 list_for_each_entry_safe(thread, n, &threads->dead, node) in machine__exit()
253 list_del_init(&thread->node); in machine__exit()
411 * To support that, copy the host thread's maps to the guest thread's maps.
414 * thread's maps have been set up.
416 * This function returns the guest thread. Apart from keeping the data
417 * structures sane, using a thread belonging to the guest machine, instead
418 * of the host thread, allows it to have its own comm (refer
421 static struct thread *findnew_guest_code(struct machine *machine, in findnew_guest_code()
425 struct thread *host_thread; in findnew_guest_code()
426 struct thread *thread; in findnew_guest_code() local
432 thread = machine__findnew_thread(machine, -1, pid); in findnew_guest_code()
433 if (!thread) in findnew_guest_code()
437 if (thread->maps->nr_maps) in findnew_guest_code()
438 return thread; in findnew_guest_code()
444 thread__set_guest_comm(thread, pid); in findnew_guest_code()
450 err = maps__clone(thread, host_thread->maps); in findnew_guest_code()
455 return thread; in findnew_guest_code()
458 thread__zput(thread); in findnew_guest_code()
462 struct thread *machines__findnew_guest_code(struct machines *machines, pid_t pid) in machines__findnew_guest_code()
470 struct thread *machine__findnew_guest_code(struct machine *machine, pid_t pid) in machine__findnew_guest_code()
511 struct thread *th, pid_t pid) in machine__update_thread_pid()
513 struct thread *leader; in machine__update_thread_pid()
539 * tid. Consequently there never should be any maps on a thread in machine__update_thread_pid()
543 pr_err("Discarding thread maps for %d:%d\n", in machine__update_thread_pid()
562 static struct thread*
566 struct thread *th; in __threads__get_last_match()
581 static struct thread*
585 struct thread *th = NULL; in threads__get_last_match()
594 __threads__set_last_match(struct threads *threads, struct thread *th) in __threads__set_last_match()
600 threads__set_last_match(struct threads *threads, struct thread *th) in threads__set_last_match()
607 * Caller must eventually drop thread->refcnt returned with a successful
608 * lookup/new thread inserted.
610 static struct thread *____machine__findnew_thread(struct machine *machine, in ____machine__findnew_thread()
617 struct thread *th; in ____machine__findnew_thread()
626 th = rb_entry(parent, struct thread, rb_node); in ____machine__findnew_thread()
654 * within thread__init_maps to find the thread in ____machine__findnew_thread()
674 struct thread *__machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid) in __machine__findnew_thread()
679 struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, in machine__findnew_thread()
683 struct thread *th; in machine__findnew_thread()
691 struct thread *machine__find_thread(struct machine *machine, pid_t pid, in machine__find_thread()
695 struct thread *th; in machine__find_thread()
705 * So here a single thread is created for that, but actually there is a separate
706 * idle task per cpu, so there should be one 'struct thread' per cpu, but there
710 struct thread *machine__idle_thread(struct machine *machine) in machine__idle_thread()
712 struct thread *thread = machine__findnew_thread(machine, 0, 0); in machine__idle_thread() local
714 if (!thread || thread__set_comm(thread, "swapper", 0) || in machine__idle_thread()
715 thread__set_namespaces(thread, 0, NULL)) in machine__idle_thread()
718 return thread; in machine__idle_thread()
722 struct thread *thread) in machine__thread_exec_comm() argument
725 return thread__exec_comm(thread); in machine__thread_exec_comm()
727 return thread__comm(thread); in machine__thread_exec_comm()
733 struct thread *thread = machine__findnew_thread(machine, in machine__process_comm_event() local
745 if (thread == NULL || in machine__process_comm_event()
746 __thread__set_comm(thread, event->comm.comm, sample->time, exec)) { in machine__process_comm_event()
751 thread__put(thread); in machine__process_comm_event()
760 struct thread *thread = machine__findnew_thread(machine, in machine__process_namespaces_event() local
776 if (thread == NULL || in machine__process_namespaces_event()
777 thread__set_namespaces(thread, sample->time, &event->namespaces)) { in machine__process_namespaces_event()
782 thread__put(thread); in machine__process_namespaces_event()
1095 struct thread *pos = rb_entry(nd, struct thread, rb_node); in machine__fprintf()
1864 struct thread *thread; in machine__process_mmap2_event() local
1898 thread = machine__findnew_thread(machine, event->mmap2.pid, in machine__process_mmap2_event()
1900 if (thread == NULL) in machine__process_mmap2_event()
1907 event->mmap2.filename, thread); in machine__process_mmap2_event()
1912 ret = thread__insert_map(thread, map); in machine__process_mmap2_event()
1916 thread__put(thread); in machine__process_mmap2_event()
1923 thread__put(thread); in machine__process_mmap2_event()
1932 struct thread *thread; in machine__process_mmap_event() local
1955 thread = machine__findnew_thread(machine, event->mmap.pid, in machine__process_mmap_event()
1957 if (thread == NULL) in machine__process_mmap_event()
1965 NULL, prot, 0, NULL, event->mmap.filename, thread); in machine__process_mmap_event()
1970 ret = thread__insert_map(thread, map); in machine__process_mmap_event()
1974 thread__put(thread); in machine__process_mmap_event()
1981 thread__put(thread); in machine__process_mmap_event()
1987 static void __machine__remove_thread(struct machine *machine, struct thread *th, bool lock) in __machine__remove_thread()
2012 * thread. in __machine__remove_thread()
2020 void machine__remove_thread(struct machine *machine, struct thread *th) in machine__remove_thread()
2028 struct thread *thread = machine__find_thread(machine, in machine__process_fork_event() local
2031 struct thread *parent = machine__findnew_thread(machine, in machine__process_fork_event()
2041 * There may be an existing thread that is not actually the parent, in machine__process_fork_event()
2043 * (fork) event that would have removed the thread was lost. Assume the in machine__process_fork_event()
2047 dump_printf("removing erroneous parent thread %d/%d\n", in machine__process_fork_event()
2055 /* if a thread currently exists for the thread id remove it */ in machine__process_fork_event()
2056 if (thread != NULL) { in machine__process_fork_event()
2057 machine__remove_thread(machine, thread); in machine__process_fork_event()
2058 thread__put(thread); in machine__process_fork_event()
2061 thread = machine__findnew_thread(machine, event->fork.pid, in machine__process_fork_event()
2064 * When synthesizing FORK events, we are trying to create thread in machine__process_fork_event()
2080 if (thread == NULL || parent == NULL || in machine__process_fork_event()
2081 thread__fork(thread, parent, sample->time, do_maps_clone) < 0) { in machine__process_fork_event()
2085 thread__put(thread); in machine__process_fork_event()
2094 struct thread *thread = machine__find_thread(machine, in machine__process_exit_event() local
2101 if (thread != NULL) { in machine__process_exit_event()
2102 thread__exited(thread); in machine__process_exit_event()
2103 thread__put(thread); in machine__process_exit_event()
2163 static void ip__resolve_ams(struct thread *thread, in ip__resolve_ams() argument
2177 thread__find_cpumode_addr_location(thread, ip, &al); in ip__resolve_ams()
2189 static void ip__resolve_data(struct thread *thread, in ip__resolve_data() argument
2197 thread__find_symbol(thread, m, addr, &al); in ip__resolve_data()
2217 ip__resolve_ams(al->thread, &mi->iaddr, sample->ip); in sample__resolve_mem()
2218 ip__resolve_data(al->thread, al->cpumode, &mi->daddr, in sample__resolve_mem()
2252 static int add_callchain_ip(struct thread *thread, in add_callchain_ip() argument
2273 thread__find_cpumode_addr_location(thread, ip, &al); in add_callchain_ip()
2298 thread__find_symbol(thread, *cpumode, ip, &al); in add_callchain_ip()
2343 ip__resolve_ams(al->thread, &bi[i].to, entries[i].to); in sample__resolve_bstack()
2344 ip__resolve_ams(al->thread, &bi[i].from, entries[i].from); in sample__resolve_bstack()
2414 static int lbr_callchain_add_kernel_ip(struct thread *thread, in lbr_callchain_add_kernel_ip() argument
2428 err = add_callchain_ip(thread, cursor, parent, in lbr_callchain_add_kernel_ip()
2438 err = add_callchain_ip(thread, cursor, parent, in lbr_callchain_add_kernel_ip()
2448 static void save_lbr_cursor_node(struct thread *thread, in save_lbr_cursor_node() argument
2452 struct lbr_stitch *lbr_stitch = thread->lbr_stitch; in save_lbr_cursor_node()
2473 static int lbr_callchain_add_lbr_ip(struct thread *thread, in lbr_callchain_add_lbr_ip() argument
2494 if (thread->lbr_stitch) { in lbr_callchain_add_lbr_ip()
2509 err = add_callchain_ip(thread, cursor, parent, in lbr_callchain_add_lbr_ip()
2522 if (thread->lbr_stitch && (cursor->pos != cursor->nr)) { in lbr_callchain_add_lbr_ip()
2534 err = add_callchain_ip(thread, cursor, parent, in lbr_callchain_add_lbr_ip()
2540 save_lbr_cursor_node(thread, cursor, i); in lbr_callchain_add_lbr_ip()
2549 err = add_callchain_ip(thread, cursor, parent, in lbr_callchain_add_lbr_ip()
2555 save_lbr_cursor_node(thread, cursor, i); in lbr_callchain_add_lbr_ip()
2562 err = add_callchain_ip(thread, cursor, parent, in lbr_callchain_add_lbr_ip()
2572 static int lbr_callchain_add_stitched_lbr_ip(struct thread *thread, in lbr_callchain_add_stitched_lbr_ip() argument
2575 struct lbr_stitch *lbr_stitch = thread->lbr_stitch; in lbr_callchain_add_stitched_lbr_ip()
2597 static struct stitch_list *get_stitch_node(struct thread *thread) in get_stitch_node() argument
2599 struct lbr_stitch *lbr_stitch = thread->lbr_stitch; in get_stitch_node()
2613 static bool has_stitched_lbr(struct thread *thread, in has_stitched_lbr() argument
2623 struct lbr_stitch *lbr_stitch = thread->lbr_stitch; in has_stitched_lbr()
2669 stitch_node = get_stitch_node(thread); in has_stitched_lbr()
2685 static bool alloc_lbr_stitch(struct thread *thread, unsigned int max_lbr) in alloc_lbr_stitch() argument
2687 if (thread->lbr_stitch) in alloc_lbr_stitch()
2690 thread->lbr_stitch = zalloc(sizeof(*thread->lbr_stitch)); in alloc_lbr_stitch()
2691 if (!thread->lbr_stitch) in alloc_lbr_stitch()
2694 thread->lbr_stitch->prev_lbr_cursor = calloc(max_lbr + 1, sizeof(struct callchain_cursor_node)); in alloc_lbr_stitch()
2695 if (!thread->lbr_stitch->prev_lbr_cursor) in alloc_lbr_stitch()
2698 INIT_LIST_HEAD(&thread->lbr_stitch->lists); in alloc_lbr_stitch()
2699 INIT_LIST_HEAD(&thread->lbr_stitch->free_lists); in alloc_lbr_stitch()
2704 zfree(&thread->lbr_stitch); in alloc_lbr_stitch()
2707 thread->lbr_stitch_enable = false; in alloc_lbr_stitch()
2718 static int resolve_lbr_callchain_sample(struct thread *thread, in resolve_lbr_callchain_sample() argument
2743 if (thread->lbr_stitch_enable && !sample->no_hw_idx && in resolve_lbr_callchain_sample()
2744 (max_lbr > 0) && alloc_lbr_stitch(thread, max_lbr)) { in resolve_lbr_callchain_sample()
2745 lbr_stitch = thread->lbr_stitch; in resolve_lbr_callchain_sample()
2747 stitched_lbr = has_stitched_lbr(thread, sample, in resolve_lbr_callchain_sample()
2760 err = lbr_callchain_add_kernel_ip(thread, cursor, sample, in resolve_lbr_callchain_sample()
2766 err = lbr_callchain_add_lbr_ip(thread, cursor, sample, parent, in resolve_lbr_callchain_sample()
2772 err = lbr_callchain_add_stitched_lbr_ip(thread, cursor); in resolve_lbr_callchain_sample()
2779 err = lbr_callchain_add_stitched_lbr_ip(thread, cursor); in resolve_lbr_callchain_sample()
2783 err = lbr_callchain_add_lbr_ip(thread, cursor, sample, parent, in resolve_lbr_callchain_sample()
2789 err = lbr_callchain_add_kernel_ip(thread, cursor, sample, in resolve_lbr_callchain_sample()
2801 static int find_prev_cpumode(struct ip_callchain *chain, struct thread *thread, in find_prev_cpumode() argument
2813 err = add_callchain_ip(thread, cursor, parent, in find_prev_cpumode()
2823 struct thread *thread, int usr_idx) in get_leaf_frame_caller() argument
2825 if (machine__normalized_is(thread->maps->machine, "arm64")) in get_leaf_frame_caller()
2826 return get_leaf_frame_caller_aarch64(sample, thread, usr_idx); in get_leaf_frame_caller()
2831 static int thread__resolve_callchain_sample(struct thread *thread, in thread__resolve_callchain_sample() argument
2855 err = resolve_lbr_callchain_sample(thread, cursor, sample, parent, in thread__resolve_callchain_sample()
2866 skip_idx = arch_skip_callchain_idx(thread, chain); in thread__resolve_callchain_sample()
2918 err = add_callchain_ip(thread, cursor, parent, in thread__resolve_callchain_sample()
2925 err = add_callchain_ip(thread, cursor, parent, root_al, in thread__resolve_callchain_sample()
2943 err = find_prev_cpumode(chain, thread, cursor, parent, root_al, in thread__resolve_callchain_sample()
2965 err = find_prev_cpumode(chain, thread, cursor, parent, in thread__resolve_callchain_sample()
2983 leaf_frame_caller = get_leaf_frame_caller(sample, thread, usr_idx); in thread__resolve_callchain_sample()
2992 err = add_callchain_ip(thread, cursor, parent, in thread__resolve_callchain_sample()
3000 err = add_callchain_ip(thread, cursor, parent, in thread__resolve_callchain_sample()
3074 static int thread__resolve_callchain_unwind(struct thread *thread, in thread__resolve_callchain_unwind() argument
3091 thread, sample, max_stack, false); in thread__resolve_callchain_unwind()
3094 int thread__resolve_callchain(struct thread *thread, in thread__resolve_callchain() argument
3107 ret = thread__resolve_callchain_sample(thread, cursor, in thread__resolve_callchain()
3113 ret = thread__resolve_callchain_unwind(thread, cursor, in thread__resolve_callchain()
3117 ret = thread__resolve_callchain_unwind(thread, cursor, in thread__resolve_callchain()
3122 ret = thread__resolve_callchain_sample(thread, cursor, in thread__resolve_callchain()
3132 int (*fn)(struct thread *thread, void *p), in machine__for_each_thread() argument
3137 struct thread *thread; in machine__for_each_thread() local
3145 thread = rb_entry(nd, struct thread, rb_node); in machine__for_each_thread()
3146 rc = fn(thread, priv); in machine__for_each_thread()
3151 list_for_each_entry(thread, &threads->dead, node) { in machine__for_each_thread()
3152 rc = fn(thread, priv); in machine__for_each_thread()
3161 int (*fn)(struct thread *thread, void *p), in machines__for_each_thread() argument
3192 struct thread *thread; in machine__set_current_tid() local
3206 thread = machine__findnew_thread(machine, pid, tid); in machine__set_current_tid()
3207 if (!thread) in machine__set_current_tid()
3210 thread->cpu = cpu; in machine__set_current_tid()
3211 thread__put(thread); in machine__set_current_tid()