^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * thread-stack.h: Synthesize a thread's stack using call / return events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2014, Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef __PERF_THREAD_STACK_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define __PERF_THREAD_STACK_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct comm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct ip_callchain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct symbol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct dso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct comm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct perf_sample;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct addr_location;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct call_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * Call/Return flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * CALL_RETURN_NO_CALL: 'return' but no matching 'call'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * CALL_RETURN_NO_RETURN: 'call' but no matching 'return'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * CALL_RETURN_NON_CALL: a branch but not a 'call' to the start of a different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * symbol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) CALL_RETURN_NO_CALL = 1 << 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) CALL_RETURN_NO_RETURN = 1 << 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) CALL_RETURN_NON_CALL = 1 << 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * struct call_return - paired call/return information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * @thread: thread in which call/return occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * @comm: comm in which call/return occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * @cp: call path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * @call_time: timestamp of call (if known)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * @return_time: timestamp of return (if known)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * @branch_count: number of branches seen between call and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * @insn_count: approx. number of instructions between call and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * @cyc_count: approx. number of cycles between call and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * @call_ref: external reference to 'call' sample (e.g. db_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * @return_ref: external reference to 'return' sample (e.g. db_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * @db_id: id used for db-export
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * @parent_db_id: id of parent call used for db-export
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * @flags: Call/Return flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct call_return {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct thread *thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct comm *comm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct call_path *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) u64 call_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) u64 return_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) u64 branch_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) u64 insn_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) u64 cyc_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) u64 call_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) u64 return_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u64 db_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) u64 parent_db_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * struct call_return_processor - provides a call-back to consume call-return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * @cpr: call path root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * @process: call-back that accepts call/return information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * @data: anonymous data for call-back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct call_return_processor {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct call_path_root *cpr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) int (*process)(struct call_return *cr, u64 *parent_db_id, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) int thread_stack__event(struct thread *thread, int cpu, u32 flags, u64 from_ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) u64 to_ip, u16 insn_len, u64 trace_nr, bool callstack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) unsigned int br_stack_sz, bool mispred_all);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) void thread_stack__set_trace_nr(struct thread *thread, int cpu, u64 trace_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) void thread_stack__sample(struct thread *thread, int cpu, struct ip_callchain *chain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) size_t sz, u64 ip, u64 kernel_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) void thread_stack__sample_late(struct thread *thread, int cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct ip_callchain *chain, size_t sz, u64 ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) u64 kernel_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) void thread_stack__br_sample(struct thread *thread, int cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct branch_stack *dst, unsigned int sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) void thread_stack__br_sample_late(struct thread *thread, int cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct branch_stack *dst, unsigned int sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) u64 sample_ip, u64 kernel_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) int thread_stack__flush(struct thread *thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) void thread_stack__free(struct thread *thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) size_t thread_stack__depth(struct thread *thread, int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct call_return_processor *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) call_return_processor__new(int (*process)(struct call_return *cr, u64 *parent_db_id, void *data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) void call_return_processor__free(struct call_return_processor *crp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) int thread_stack__process(struct thread *thread, struct comm *comm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct perf_sample *sample,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct addr_location *from_al,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct addr_location *to_al, u64 ref,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct call_return_processor *crp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #endif