162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * call-path.h: Manipulate a tree data structure containing function call paths 462306a36Sopenharmony_ci * Copyright (c) 2014, Intel Corporation. 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#ifndef __PERF_CALL_PATH_H 862306a36Sopenharmony_ci#define __PERF_CALL_PATH_H 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <sys/types.h> 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include <linux/types.h> 1362306a36Sopenharmony_ci#include <linux/rbtree.h> 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci/** 1662306a36Sopenharmony_ci * struct call_path - node in list of calls leading to a function call. 1762306a36Sopenharmony_ci * @parent: call path to the parent function call 1862306a36Sopenharmony_ci * @sym: symbol of function called 1962306a36Sopenharmony_ci * @ip: only if sym is null, the ip of the function 2062306a36Sopenharmony_ci * @db_id: id used for db-export 2162306a36Sopenharmony_ci * @in_kernel: whether function is a in the kernel 2262306a36Sopenharmony_ci * @rb_node: node in parent's tree of called functions 2362306a36Sopenharmony_ci * @children: tree of call paths of functions called 2462306a36Sopenharmony_ci * 2562306a36Sopenharmony_ci * In combination with the call_return structure, the call_path structure 2662306a36Sopenharmony_ci * defines a context-sensitive call-graph. 2762306a36Sopenharmony_ci */ 2862306a36Sopenharmony_cistruct call_path { 2962306a36Sopenharmony_ci struct call_path *parent; 3062306a36Sopenharmony_ci struct symbol *sym; 3162306a36Sopenharmony_ci u64 ip; 3262306a36Sopenharmony_ci u64 db_id; 3362306a36Sopenharmony_ci bool in_kernel; 3462306a36Sopenharmony_ci struct rb_node rb_node; 3562306a36Sopenharmony_ci struct rb_root children; 3662306a36Sopenharmony_ci}; 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#define CALL_PATH_BLOCK_SHIFT 8 3962306a36Sopenharmony_ci#define CALL_PATH_BLOCK_SIZE (1 << CALL_PATH_BLOCK_SHIFT) 4062306a36Sopenharmony_ci#define CALL_PATH_BLOCK_MASK (CALL_PATH_BLOCK_SIZE - 1) 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_cistruct call_path_block { 4362306a36Sopenharmony_ci struct call_path cp[CALL_PATH_BLOCK_SIZE]; 4462306a36Sopenharmony_ci struct list_head node; 4562306a36Sopenharmony_ci}; 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci/** 4862306a36Sopenharmony_ci * struct call_path_root - root of all call paths. 4962306a36Sopenharmony_ci * @call_path: root call path 5062306a36Sopenharmony_ci * @blocks: list of blocks to store call paths 5162306a36Sopenharmony_ci * @next: next free space 5262306a36Sopenharmony_ci * @sz: number of spaces 5362306a36Sopenharmony_ci */ 5462306a36Sopenharmony_cistruct call_path_root { 5562306a36Sopenharmony_ci struct call_path call_path; 5662306a36Sopenharmony_ci struct list_head blocks; 5762306a36Sopenharmony_ci size_t next; 5862306a36Sopenharmony_ci size_t sz; 5962306a36Sopenharmony_ci}; 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_cistruct call_path_root *call_path_root__new(void); 6262306a36Sopenharmony_civoid call_path_root__free(struct call_path_root *cpr); 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_cistruct call_path *call_path__findnew(struct call_path_root *cpr, 6562306a36Sopenharmony_ci struct call_path *parent, 6662306a36Sopenharmony_ci struct symbol *sym, u64 ip, u64 ks); 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci#endif 69