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