Lines Matching full:thread

27 #include "thread.h"
67 static void thread__set_guest_comm(struct thread *thread, pid_t pid) in thread__set_guest_comm() argument
72 thread__set_comm(thread, comm, 0); in thread__set_guest_comm()
110 struct thread *thread = machine__findnew_thread(machine, -1, in machine__init() local
113 if (thread == NULL) in machine__init()
116 thread__set_guest_comm(thread, pid); in machine__init()
117 thread__put(thread); in machine__init()
376 * To support that, copy the host thread's maps to the guest thread's maps.
379 * thread's maps have been set up.
381 * This function returns the guest thread. Apart from keeping the data
382 * structures sane, using a thread belonging to the guest machine, instead
383 * of the host thread, allows it to have its own comm (refer
386 static struct thread *findnew_guest_code(struct machine *machine, in findnew_guest_code()
390 struct thread *host_thread; in findnew_guest_code()
391 struct thread *thread; in findnew_guest_code() local
397 thread = machine__findnew_thread(machine, -1, pid); in findnew_guest_code()
398 if (!thread) in findnew_guest_code()
402 if (!maps__empty(thread__maps(thread))) in findnew_guest_code()
403 return thread; in findnew_guest_code()
409 thread__set_guest_comm(thread, pid); in findnew_guest_code()
415 err = maps__copy_from(thread__maps(thread), thread__maps(host_thread)); in findnew_guest_code()
420 return thread; in findnew_guest_code()
423 thread__zput(thread); in findnew_guest_code()
427 struct thread *machines__findnew_guest_code(struct machines *machines, pid_t pid) in machines__findnew_guest_code()
435 struct thread *machine__findnew_guest_code(struct machine *machine, pid_t pid) in machine__findnew_guest_code()
476 struct thread *th, pid_t pid) in machine__update_thread_pid()
478 struct thread *leader; in machine__update_thread_pid()
504 * tid. Consequently there never should be any maps on a thread in machine__update_thread_pid()
508 pr_err("Discarding thread maps for %d:%d\n", in machine__update_thread_pid()
523 * Caller must eventually drop thread->refcnt returned with a successful
524 * lookup/new thread inserted.
526 static struct thread *__machine__findnew_thread(struct machine *machine, in __machine__findnew_thread()
531 struct thread *th = threads__find(&machine->threads, tid); in __machine__findnew_thread()
548 * thread__init_maps to find the thread leader and that would in __machine__findnew_thread()
552 pr_err("Thread init failed thread %d\n", pid); in __machine__findnew_thread()
563 struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid) in machine__findnew_thread()
568 struct thread *machine__find_thread(struct machine *machine, pid_t pid, in machine__find_thread()
576 * So here a single thread is created for that, but actually there is a separate
577 * idle task per cpu, so there should be one 'struct thread' per cpu, but there
581 struct thread *machine__idle_thread(struct machine *machine) in machine__idle_thread()
583 struct thread *thread = machine__findnew_thread(machine, 0, 0); in machine__idle_thread() local
585 if (!thread || thread__set_comm(thread, "swapper", 0) || in machine__idle_thread()
586 thread__set_namespaces(thread, 0, NULL)) in machine__idle_thread()
589 return thread; in machine__idle_thread()
593 struct thread *thread) in machine__thread_exec_comm() argument
596 return thread__exec_comm(thread); in machine__thread_exec_comm()
598 return thread__comm(thread); in machine__thread_exec_comm()
604 struct thread *thread = machine__findnew_thread(machine, in machine__process_comm_event() local
616 if (thread == NULL || in machine__process_comm_event()
617 __thread__set_comm(thread, event->comm.comm, sample->time, exec)) { in machine__process_comm_event()
622 thread__put(thread); in machine__process_comm_event()
631 struct thread *thread = machine__findnew_thread(machine, in machine__process_namespaces_event() local
647 if (thread == NULL || in machine__process_namespaces_event()
648 thread__set_namespaces(thread, sample->time, &event->namespaces)) { in machine__process_namespaces_event()
653 thread__put(thread); in machine__process_namespaces_event()
939 static int machine_fprintf_cb(struct thread *thread, void *data) in machine_fprintf_cb() argument
944 args->printed += thread__fprintf(thread, args->fp); in machine_fprintf_cb()
1732 struct thread *thread; in machine__process_mmap2_event() local
1766 thread = machine__findnew_thread(machine, event->mmap2.pid, in machine__process_mmap2_event()
1768 if (thread == NULL) in machine__process_mmap2_event()
1775 event->mmap2.filename, thread); in machine__process_mmap2_event()
1780 ret = thread__insert_map(thread, map); in machine__process_mmap2_event()
1784 thread__put(thread); in machine__process_mmap2_event()
1791 thread__put(thread); in machine__process_mmap2_event()
1800 struct thread *thread; in machine__process_mmap_event() local
1823 thread = machine__findnew_thread(machine, event->mmap.pid, in machine__process_mmap_event()
1825 if (thread == NULL) in machine__process_mmap_event()
1833 &dso_id_empty, prot, /*flags=*/0, event->mmap.filename, thread); in machine__process_mmap_event()
1838 ret = thread__insert_map(thread, map); in machine__process_mmap_event()
1842 thread__put(thread); in machine__process_mmap_event()
1849 thread__put(thread); in machine__process_mmap_event()
1855 void machine__remove_thread(struct machine *machine, struct thread *th) in machine__remove_thread()
1863 struct thread *thread = machine__find_thread(machine, in machine__process_fork_event() local
1866 struct thread *parent = machine__findnew_thread(machine, in machine__process_fork_event()
1876 * There may be an existing thread that is not actually the parent, in machine__process_fork_event()
1878 * (fork) event that would have removed the thread was lost. Assume the in machine__process_fork_event()
1882 dump_printf("removing erroneous parent thread %d/%d\n", in machine__process_fork_event()
1890 /* if a thread currently exists for the thread id remove it */ in machine__process_fork_event()
1891 if (thread != NULL) { in machine__process_fork_event()
1892 machine__remove_thread(machine, thread); in machine__process_fork_event()
1893 thread__put(thread); in machine__process_fork_event()
1896 thread = machine__findnew_thread(machine, event->fork.pid, in machine__process_fork_event()
1899 * When synthesizing FORK events, we are trying to create thread in machine__process_fork_event()
1915 if (thread == NULL || parent == NULL || in machine__process_fork_event()
1916 thread__fork(thread, parent, sample->time, do_maps_clone) < 0) { in machine__process_fork_event()
1920 thread__put(thread); in machine__process_fork_event()
1929 struct thread *thread = machine__find_thread(machine, in machine__process_exit_event() local
1938 if (thread != NULL) { in machine__process_exit_event()
1940 thread__set_exited(thread, /*exited=*/true); in machine__process_exit_event()
1942 machine__remove_thread(machine, thread); in machine__process_exit_event()
1944 thread__put(thread); in machine__process_exit_event()
2000 static void ip__resolve_ams(struct thread *thread, in ip__resolve_ams() argument
2014 thread__find_cpumode_addr_location(thread, ip, /*symbols=*/true, &al); in ip__resolve_ams()
2019 ams->ms.thread = thread__get(al.thread); in ip__resolve_ams()
2027 static void ip__resolve_data(struct thread *thread, in ip__resolve_data() argument
2035 thread__find_symbol(thread, m, addr, &al); in ip__resolve_data()
2040 ams->ms.thread = thread__get(al.thread); in ip__resolve_data()
2056 ip__resolve_ams(al->thread, mem_info__iaddr(mi), sample->ip); in sample__resolve_mem()
2057 ip__resolve_data(al->thread, al->cpumode, mem_info__daddr(mi), in sample__resolve_mem()
2123 .thread = thread__get(ms->thread), in append_inlines()
2146 static int add_callchain_ip(struct thread *thread, in add_callchain_ip() argument
2169 thread__find_cpumode_addr_location(thread, ip, symbols, &al); in add_callchain_ip()
2197 thread__find_symbol(thread, *cpumode, ip, &al); in add_callchain_ip()
2199 thread__find_map(thread, *cpumode, ip, &al); in add_callchain_ip()
2223 ms.thread = thread__get(al.thread); in add_callchain_ip()
2254 ip__resolve_ams(al->thread, &bi[i].to, entries[i].to); in sample__resolve_bstack()
2255 ip__resolve_ams(al->thread, &bi[i].from, entries[i].from); in sample__resolve_bstack()
2327 static int lbr_callchain_add_kernel_ip(struct thread *thread, in lbr_callchain_add_kernel_ip() argument
2342 err = add_callchain_ip(thread, cursor, parent, in lbr_callchain_add_kernel_ip()
2353 err = add_callchain_ip(thread, cursor, parent, in lbr_callchain_add_kernel_ip()
2364 static void save_lbr_cursor_node(struct thread *thread, in save_lbr_cursor_node() argument
2368 struct lbr_stitch *lbr_stitch = thread__lbr_stitch(thread); in save_lbr_cursor_node()
2386 lbr_stitch->prev_lbr_cursor[idx].ms.thread = thread__get(cursor->curr->ms.thread); in save_lbr_cursor_node()
2393 static int lbr_callchain_add_lbr_ip(struct thread *thread, in lbr_callchain_add_lbr_ip() argument
2415 if (thread__lbr_stitch(thread)) { in lbr_callchain_add_lbr_ip()
2436 err = add_callchain_ip(thread, cursor, parent, in lbr_callchain_add_lbr_ip()
2449 if (thread__lbr_stitch(thread) && (cursor->pos != cursor->nr)) { in lbr_callchain_add_lbr_ip()
2461 err = add_callchain_ip(thread, cursor, parent, in lbr_callchain_add_lbr_ip()
2467 save_lbr_cursor_node(thread, cursor, i); in lbr_callchain_add_lbr_ip()
2476 err = add_callchain_ip(thread, cursor, parent, in lbr_callchain_add_lbr_ip()
2482 save_lbr_cursor_node(thread, cursor, i); in lbr_callchain_add_lbr_ip()
2496 err = add_callchain_ip(thread, cursor, parent, in lbr_callchain_add_lbr_ip()
2507 static int lbr_callchain_add_stitched_lbr_ip(struct thread *thread, in lbr_callchain_add_stitched_lbr_ip() argument
2510 struct lbr_stitch *lbr_stitch = thread__lbr_stitch(thread); in lbr_callchain_add_stitched_lbr_ip()
2532 static struct stitch_list *get_stitch_node(struct thread *thread) in get_stitch_node() argument
2534 struct lbr_stitch *lbr_stitch = thread__lbr_stitch(thread); in get_stitch_node()
2548 static bool has_stitched_lbr(struct thread *thread, in has_stitched_lbr() argument
2558 struct lbr_stitch *lbr_stitch = thread__lbr_stitch(thread); in has_stitched_lbr()
2604 stitch_node = get_stitch_node(thread); in has_stitched_lbr()
2611 stitch_node->cursor.ms.thread = in has_stitched_lbr()
2612 thread__get(lbr_stitch->prev_lbr_cursor[i].ms.thread); in has_stitched_lbr()
2624 static bool alloc_lbr_stitch(struct thread *thread, unsigned int max_lbr) in alloc_lbr_stitch() argument
2626 if (thread__lbr_stitch(thread)) in alloc_lbr_stitch()
2629 thread__set_lbr_stitch(thread, zalloc(sizeof(struct lbr_stitch))); in alloc_lbr_stitch()
2630 if (!thread__lbr_stitch(thread)) in alloc_lbr_stitch()
2633 thread__lbr_stitch(thread)->prev_lbr_cursor = in alloc_lbr_stitch()
2635 if (!thread__lbr_stitch(thread)->prev_lbr_cursor) in alloc_lbr_stitch()
2638 thread__lbr_stitch(thread)->prev_lbr_cursor_size = max_lbr + 1; in alloc_lbr_stitch()
2640 INIT_LIST_HEAD(&thread__lbr_stitch(thread)->lists); in alloc_lbr_stitch()
2641 INIT_LIST_HEAD(&thread__lbr_stitch(thread)->free_lists); in alloc_lbr_stitch()
2646 free(thread__lbr_stitch(thread)); in alloc_lbr_stitch()
2647 thread__set_lbr_stitch(thread, NULL); in alloc_lbr_stitch()
2650 thread__set_lbr_stitch_enable(thread, false); in alloc_lbr_stitch()
2661 static int resolve_lbr_callchain_sample(struct thread *thread, in resolve_lbr_callchain_sample() argument
2687 if (thread__lbr_stitch_enable(thread) && !sample->no_hw_idx && in resolve_lbr_callchain_sample()
2688 (max_lbr > 0) && alloc_lbr_stitch(thread, max_lbr)) { in resolve_lbr_callchain_sample()
2689 lbr_stitch = thread__lbr_stitch(thread); in resolve_lbr_callchain_sample()
2691 stitched_lbr = has_stitched_lbr(thread, sample, in resolve_lbr_callchain_sample()
2708 err = lbr_callchain_add_kernel_ip(thread, cursor, sample, in resolve_lbr_callchain_sample()
2714 err = lbr_callchain_add_lbr_ip(thread, cursor, sample, parent, in resolve_lbr_callchain_sample()
2720 err = lbr_callchain_add_stitched_lbr_ip(thread, cursor); in resolve_lbr_callchain_sample()
2727 err = lbr_callchain_add_stitched_lbr_ip(thread, cursor); in resolve_lbr_callchain_sample()
2731 err = lbr_callchain_add_lbr_ip(thread, cursor, sample, parent, in resolve_lbr_callchain_sample()
2737 err = lbr_callchain_add_kernel_ip(thread, cursor, sample, in resolve_lbr_callchain_sample()
2749 static int find_prev_cpumode(struct ip_callchain *chain, struct thread *thread, in find_prev_cpumode() argument
2761 err = add_callchain_ip(thread, cursor, parent, in find_prev_cpumode()
2771 struct thread *thread, int usr_idx) in get_leaf_frame_caller() argument
2773 if (machine__normalized_is(maps__machine(thread__maps(thread)), "arm64")) in get_leaf_frame_caller()
2774 return get_leaf_frame_caller_aarch64(sample, thread, usr_idx); in get_leaf_frame_caller()
2779 static int thread__resolve_callchain_sample(struct thread *thread, in thread__resolve_callchain_sample() argument
2804 err = resolve_lbr_callchain_sample(thread, cursor, sample, parent, in thread__resolve_callchain_sample()
2816 skip_idx = arch_skip_callchain_idx(thread, chain); in thread__resolve_callchain_sample()
2868 err = add_callchain_ip(thread, cursor, parent, in thread__resolve_callchain_sample()
2875 err = add_callchain_ip(thread, cursor, parent, root_al, in thread__resolve_callchain_sample()
2894 err = find_prev_cpumode(chain, thread, cursor, parent, root_al, in thread__resolve_callchain_sample()
2916 err = find_prev_cpumode(chain, thread, cursor, parent, in thread__resolve_callchain_sample()
2934 leaf_frame_caller = get_leaf_frame_caller(sample, thread, usr_idx); in thread__resolve_callchain_sample()
2943 err = add_callchain_ip(thread, cursor, parent, in thread__resolve_callchain_sample()
2951 err = add_callchain_ip(thread, cursor, parent, in thread__resolve_callchain_sample()
2987 static int thread__resolve_callchain_unwind(struct thread *thread, in thread__resolve_callchain_unwind() argument
3007 thread, sample, max_stack, false); in thread__resolve_callchain_unwind()
3010 int __thread__resolve_callchain(struct thread *thread, in __thread__resolve_callchain() argument
3027 ret = thread__resolve_callchain_sample(thread, cursor, in __thread__resolve_callchain()
3033 ret = thread__resolve_callchain_unwind(thread, cursor, in __thread__resolve_callchain()
3037 ret = thread__resolve_callchain_unwind(thread, cursor, in __thread__resolve_callchain()
3042 ret = thread__resolve_callchain_sample(thread, cursor, in __thread__resolve_callchain()
3052 int (*fn)(struct thread *thread, void *p), in machine__for_each_thread() argument
3059 int (*fn)(struct thread *thread, void *p), in machines__for_each_thread() argument
3080 static int thread_list_cb(struct thread *thread, void *data) in thread_list_cb() argument
3088 entry->thread = thread__get(thread); in thread_list_cb()
3103 thread__zput(pos->thread); in thread_list__delete()
3120 struct thread *thread; in machine__set_current_tid() local
3134 thread = machine__findnew_thread(machine, pid, tid); in machine__set_current_tid()
3135 if (!thread) in machine__set_current_tid()
3138 thread__set_cpu(thread, cpu); in machine__set_current_tid()
3139 thread__put(thread); in machine__set_current_tid()