Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * thread-stack.h: Synthesize a thread's stack using call / return events
0004  * Copyright (c) 2014, Intel Corporation.
0005  */
0006 
0007 #ifndef __PERF_THREAD_STACK_H
0008 #define __PERF_THREAD_STACK_H
0009 
0010 #include <sys/types.h>
0011 
0012 #include <linux/types.h>
0013 
0014 struct thread;
0015 struct comm;
0016 struct ip_callchain;
0017 struct symbol;
0018 struct dso;
0019 struct perf_sample;
0020 struct addr_location;
0021 struct call_path;
0022 
0023 /*
0024  * Call/Return flags.
0025  *
0026  * CALL_RETURN_NO_CALL: 'return' but no matching 'call'
0027  * CALL_RETURN_NO_RETURN: 'call' but no matching 'return'
0028  * CALL_RETURN_NON_CALL: a branch but not a 'call' to the start of a different
0029  *                       symbol
0030  */
0031 enum {
0032     CALL_RETURN_NO_CALL = 1 << 0,
0033     CALL_RETURN_NO_RETURN   = 1 << 1,
0034     CALL_RETURN_NON_CALL    = 1 << 2,
0035 };
0036 
0037 /**
0038  * struct call_return - paired call/return information.
0039  * @thread: thread in which call/return occurred
0040  * @comm: comm in which call/return occurred
0041  * @cp: call path
0042  * @call_time: timestamp of call (if known)
0043  * @return_time: timestamp of return (if known)
0044  * @branch_count: number of branches seen between call and return
0045  * @insn_count: approx. number of instructions between call and return
0046  * @cyc_count: approx. number of cycles between call and return
0047  * @call_ref: external reference to 'call' sample (e.g. db_id)
0048  * @return_ref:  external reference to 'return' sample (e.g. db_id)
0049  * @db_id: id used for db-export
0050  * @parent_db_id: id of parent call used for db-export
0051  * @flags: Call/Return flags
0052  */
0053 struct call_return {
0054     struct thread *thread;
0055     struct comm *comm;
0056     struct call_path *cp;
0057     u64 call_time;
0058     u64 return_time;
0059     u64 branch_count;
0060     u64 insn_count;
0061     u64 cyc_count;
0062     u64 call_ref;
0063     u64 return_ref;
0064     u64 db_id;
0065     u64 parent_db_id;
0066     u32 flags;
0067 };
0068 
0069 /**
0070  * struct call_return_processor - provides a call-back to consume call-return
0071  *                                information.
0072  * @cpr: call path root
0073  * @process: call-back that accepts call/return information
0074  * @data: anonymous data for call-back
0075  */
0076 struct call_return_processor {
0077     struct call_path_root *cpr;
0078     int (*process)(struct call_return *cr, u64 *parent_db_id, void *data);
0079     void *data;
0080 };
0081 
0082 int thread_stack__event(struct thread *thread, int cpu, u32 flags, u64 from_ip,
0083             u64 to_ip, u16 insn_len, u64 trace_nr, bool callstack,
0084             unsigned int br_stack_sz, bool mispred_all);
0085 void thread_stack__set_trace_nr(struct thread *thread, int cpu, u64 trace_nr);
0086 void thread_stack__sample(struct thread *thread, int cpu, struct ip_callchain *chain,
0087               size_t sz, u64 ip, u64 kernel_start);
0088 void thread_stack__sample_late(struct thread *thread, int cpu,
0089                    struct ip_callchain *chain, size_t sz, u64 ip,
0090                    u64 kernel_start);
0091 void thread_stack__br_sample(struct thread *thread, int cpu,
0092                  struct branch_stack *dst, unsigned int sz);
0093 void thread_stack__br_sample_late(struct thread *thread, int cpu,
0094                   struct branch_stack *dst, unsigned int sz,
0095                   u64 sample_ip, u64 kernel_start);
0096 int thread_stack__flush(struct thread *thread);
0097 void thread_stack__free(struct thread *thread);
0098 size_t thread_stack__depth(struct thread *thread, int cpu);
0099 
0100 struct call_return_processor *
0101 call_return_processor__new(int (*process)(struct call_return *cr, u64 *parent_db_id, void *data),
0102                void *data);
0103 void call_return_processor__free(struct call_return_processor *crp);
0104 int thread_stack__process(struct thread *thread, struct comm *comm,
0105               struct perf_sample *sample,
0106               struct addr_location *from_al,
0107               struct addr_location *to_al, u64 ref,
0108               struct call_return_processor *crp);
0109 
0110 #endif