blob: e7aee024f030d1a889bcb324578fd636c39eab33 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glassb2e16a82013-06-11 11:14:39 -07002/*
3 * Copyright (c) 2012 The Chromium OS Authors.
Simon Glassb2e16a82013-06-11 11:14:39 -07004 */
5
6#ifndef __TRACE_H
7#define __TRACE_H
8
9enum {
10 /*
11 * This affects the granularity of our trace. We can bin function
12 * entry points into groups on the basis that functions typically
13 * have a minimum size, so entry points can't appear any closer
14 * than this to each other.
15 *
16 * The value here assumes a minimum instruction size of 4 bytes,
17 * or that instructions are 2 bytes but there are at least 2 of
18 * them in every function.
19 *
20 * Increasing this value reduces the number of functions we can
21 * resolve, but reduces the size of the uintptr_t array used for
22 * our function list, which is the length of the code divided by
23 * this value.
24 */
25 FUNC_SITE_SIZE = 4, /* distance between function sites */
26};
27
28enum trace_chunk_type {
29 TRACE_CHUNK_FUNCS,
30 TRACE_CHUNK_CALLS,
31};
32
33/* A trace record for a function, as written to the profile output file */
34struct trace_output_func {
35 uint32_t offset; /* Function offset into code */
36 uint32_t call_count; /* Number of times called */
37};
38
39/* A header at the start of the trace output buffer */
40struct trace_output_hdr {
41 enum trace_chunk_type type; /* Record type */
Heinrich Schuchardt2b7a3882019-06-14 21:50:55 +020042 size_t rec_count; /* Number of records */
Simon Glassb2e16a82013-06-11 11:14:39 -070043};
44
45/* Print statistics about traced function calls */
46void trace_print_stats(void);
47
48/**
49 * Dump a list of functions and call counts into a buffer
50 *
51 * Each record in the buffer is a struct trace_func_stats. The 'needed'
52 * parameter returns the number of bytes needed to complete the operation,
53 * which may be more than buff_size if your buffer is too small.
54 *
55 * @param buff Buffer in which to place data, or NULL to count size
56 * @param buff_size Size of buffer
57 * @param needed Returns number of bytes used / needed
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010058 * Return: 0 if ok, -1 on error (buffer exhausted)
Simon Glassb2e16a82013-06-11 11:14:39 -070059 */
Heinrich Schuchardt2b7a3882019-06-14 21:50:55 +020060int trace_list_functions(void *buff, size_t buff_size, size_t *needed);
Simon Glassb2e16a82013-06-11 11:14:39 -070061
62/* Flags for ftrace_record */
63enum ftrace_flags {
64 FUNCF_EXIT = 0UL << 30,
65 FUNCF_ENTRY = 1UL << 30,
66 FUNCF_TEXTBASE = 2UL << 30,
67
68 FUNCF_TIMESTAMP_MASK = 0x3fffffff,
69};
70
71#define TRACE_CALL_TYPE(call) ((call)->flags & 0xc0000000UL)
72
73/* Information about a single function entry/exit */
74struct trace_call {
75 uint32_t func; /* Function offset */
76 uint32_t caller; /* Caller function offset */
77 uint32_t flags; /* Flags and timestamp */
78};
79
Heinrich Schuchardt2b7a3882019-06-14 21:50:55 +020080int trace_list_calls(void *buff, size_t buff_size, size_t *needed);
Simon Glassb2e16a82013-06-11 11:14:39 -070081
82/**
83 * Turn function tracing on and off
84 *
85 * Don't enable trace if it has not been initialised.
86 *
87 * @param enabled 1 to enable trace, 0 to disable
88 */
89void trace_set_enabled(int enabled);
90
Simon Glassb2e16a82013-06-11 11:14:39 -070091int trace_early_init(void);
Simon Glassb2e16a82013-06-11 11:14:39 -070092
93/**
94 * Init the trace system
95 *
96 * This should be called after relocation with a suitably large buffer
97 * (typically as large as the U-Boot text area)
98 *
99 * @param buff Pointer to trace buffer
100 * @param buff_size Size of trace buffer
101 */
102int trace_init(void *buff, size_t buff_size);
103
104#endif