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