18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * thread-stack.h: Synthesize a thread's stack using call / return events 48c2ecf20Sopenharmony_ci * Copyright (c) 2014, Intel Corporation. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef __PERF_THREAD_STACK_H 88c2ecf20Sopenharmony_ci#define __PERF_THREAD_STACK_H 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <sys/types.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/types.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_cistruct thread; 158c2ecf20Sopenharmony_cistruct comm; 168c2ecf20Sopenharmony_cistruct ip_callchain; 178c2ecf20Sopenharmony_cistruct symbol; 188c2ecf20Sopenharmony_cistruct dso; 198c2ecf20Sopenharmony_cistruct comm; 208c2ecf20Sopenharmony_cistruct perf_sample; 218c2ecf20Sopenharmony_cistruct addr_location; 228c2ecf20Sopenharmony_cistruct call_path; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* 258c2ecf20Sopenharmony_ci * Call/Return flags. 268c2ecf20Sopenharmony_ci * 278c2ecf20Sopenharmony_ci * CALL_RETURN_NO_CALL: 'return' but no matching 'call' 288c2ecf20Sopenharmony_ci * CALL_RETURN_NO_RETURN: 'call' but no matching 'return' 298c2ecf20Sopenharmony_ci * CALL_RETURN_NON_CALL: a branch but not a 'call' to the start of a different 308c2ecf20Sopenharmony_ci * symbol 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_cienum { 338c2ecf20Sopenharmony_ci CALL_RETURN_NO_CALL = 1 << 0, 348c2ecf20Sopenharmony_ci CALL_RETURN_NO_RETURN = 1 << 1, 358c2ecf20Sopenharmony_ci CALL_RETURN_NON_CALL = 1 << 2, 368c2ecf20Sopenharmony_ci}; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/** 398c2ecf20Sopenharmony_ci * struct call_return - paired call/return information. 408c2ecf20Sopenharmony_ci * @thread: thread in which call/return occurred 418c2ecf20Sopenharmony_ci * @comm: comm in which call/return occurred 428c2ecf20Sopenharmony_ci * @cp: call path 438c2ecf20Sopenharmony_ci * @call_time: timestamp of call (if known) 448c2ecf20Sopenharmony_ci * @return_time: timestamp of return (if known) 458c2ecf20Sopenharmony_ci * @branch_count: number of branches seen between call and return 468c2ecf20Sopenharmony_ci * @insn_count: approx. number of instructions between call and return 478c2ecf20Sopenharmony_ci * @cyc_count: approx. number of cycles between call and return 488c2ecf20Sopenharmony_ci * @call_ref: external reference to 'call' sample (e.g. db_id) 498c2ecf20Sopenharmony_ci * @return_ref: external reference to 'return' sample (e.g. db_id) 508c2ecf20Sopenharmony_ci * @db_id: id used for db-export 518c2ecf20Sopenharmony_ci * @parent_db_id: id of parent call used for db-export 528c2ecf20Sopenharmony_ci * @flags: Call/Return flags 538c2ecf20Sopenharmony_ci */ 548c2ecf20Sopenharmony_cistruct call_return { 558c2ecf20Sopenharmony_ci struct thread *thread; 568c2ecf20Sopenharmony_ci struct comm *comm; 578c2ecf20Sopenharmony_ci struct call_path *cp; 588c2ecf20Sopenharmony_ci u64 call_time; 598c2ecf20Sopenharmony_ci u64 return_time; 608c2ecf20Sopenharmony_ci u64 branch_count; 618c2ecf20Sopenharmony_ci u64 insn_count; 628c2ecf20Sopenharmony_ci u64 cyc_count; 638c2ecf20Sopenharmony_ci u64 call_ref; 648c2ecf20Sopenharmony_ci u64 return_ref; 658c2ecf20Sopenharmony_ci u64 db_id; 668c2ecf20Sopenharmony_ci u64 parent_db_id; 678c2ecf20Sopenharmony_ci u32 flags; 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/** 718c2ecf20Sopenharmony_ci * struct call_return_processor - provides a call-back to consume call-return 728c2ecf20Sopenharmony_ci * information. 738c2ecf20Sopenharmony_ci * @cpr: call path root 748c2ecf20Sopenharmony_ci * @process: call-back that accepts call/return information 758c2ecf20Sopenharmony_ci * @data: anonymous data for call-back 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_cistruct call_return_processor { 788c2ecf20Sopenharmony_ci struct call_path_root *cpr; 798c2ecf20Sopenharmony_ci int (*process)(struct call_return *cr, u64 *parent_db_id, void *data); 808c2ecf20Sopenharmony_ci void *data; 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ciint thread_stack__event(struct thread *thread, int cpu, u32 flags, u64 from_ip, 848c2ecf20Sopenharmony_ci u64 to_ip, u16 insn_len, u64 trace_nr, bool callstack, 858c2ecf20Sopenharmony_ci unsigned int br_stack_sz, bool mispred_all); 868c2ecf20Sopenharmony_civoid thread_stack__set_trace_nr(struct thread *thread, int cpu, u64 trace_nr); 878c2ecf20Sopenharmony_civoid thread_stack__sample(struct thread *thread, int cpu, struct ip_callchain *chain, 888c2ecf20Sopenharmony_ci size_t sz, u64 ip, u64 kernel_start); 898c2ecf20Sopenharmony_civoid thread_stack__sample_late(struct thread *thread, int cpu, 908c2ecf20Sopenharmony_ci struct ip_callchain *chain, size_t sz, u64 ip, 918c2ecf20Sopenharmony_ci u64 kernel_start); 928c2ecf20Sopenharmony_civoid thread_stack__br_sample(struct thread *thread, int cpu, 938c2ecf20Sopenharmony_ci struct branch_stack *dst, unsigned int sz); 948c2ecf20Sopenharmony_civoid thread_stack__br_sample_late(struct thread *thread, int cpu, 958c2ecf20Sopenharmony_ci struct branch_stack *dst, unsigned int sz, 968c2ecf20Sopenharmony_ci u64 sample_ip, u64 kernel_start); 978c2ecf20Sopenharmony_ciint thread_stack__flush(struct thread *thread); 988c2ecf20Sopenharmony_civoid thread_stack__free(struct thread *thread); 998c2ecf20Sopenharmony_cisize_t thread_stack__depth(struct thread *thread, int cpu); 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_cistruct call_return_processor * 1028c2ecf20Sopenharmony_cicall_return_processor__new(int (*process)(struct call_return *cr, u64 *parent_db_id, void *data), 1038c2ecf20Sopenharmony_ci void *data); 1048c2ecf20Sopenharmony_civoid call_return_processor__free(struct call_return_processor *crp); 1058c2ecf20Sopenharmony_ciint thread_stack__process(struct thread *thread, struct comm *comm, 1068c2ecf20Sopenharmony_ci struct perf_sample *sample, 1078c2ecf20Sopenharmony_ci struct addr_location *from_al, 1088c2ecf20Sopenharmony_ci struct addr_location *to_al, u64 ref, 1098c2ecf20Sopenharmony_ci struct call_return_processor *crp); 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#endif 112