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