1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2012 The Chromium OS Authors.
9 /* this file is included from a tool so uses uint32_t instead of u32, etc. */
13 * This affects the granularity of our trace. We can bin function
14 * entry points into groups on the basis that functions typically
15 * have a minimum size, so entry points can't appear any closer
16 * than this to each other.
18 * The value here assumes a minimum instruction size of 4 bytes,
19 * or that instructions are 2 bytes but there are at least 2 of
20 * them in every function. Given that each function needs a call to
21 * __cyg_profile_func_enter() and __cyg_profile_func_exit() as well,
22 * we cannot have functions smaller that 16 bytes.
24 * Increasing this value reduces the number of functions we can
25 * resolve, but reduces the size of the uintptr_t array used for
26 * our function list, which is the length of the code divided by
29 FUNC_SITE_SIZE = 16, /* distance between function sites */
34 enum trace_chunk_type {
39 /* A trace record for a function, as written to the profile output file */
40 struct trace_output_func {
41 uint32_t offset; /* Function offset into code */
42 uint32_t call_count; /* Number of times called */
45 /* A header at the start of the trace output buffer */
46 struct trace_output_hdr {
47 enum trace_chunk_type type; /* Record type */
48 uint32_t version; /* Version (TRACE_VERSION) */
49 uint32_t rec_count; /* Number of records */
50 uint32_t spare; /* 0 */
51 uint64_t text_base; /* Value of CONFIG_TEXT_BASE */
52 uint64_t spare2; /* 0 */
55 /* Print statistics about traced function calls */
56 void trace_print_stats(void);
59 * Dump a list of functions and call counts into a buffer
61 * Each record in the buffer is a struct trace_func_stats. The 'needed'
62 * parameter returns the number of bytes needed to complete the operation,
63 * which may be more than buff_size if your buffer is too small.
65 * @param buff Buffer in which to place data, or NULL to count size
66 * @param buff_size Size of buffer
67 * @param needed Returns number of bytes used / needed
68 * Return: 0 if ok, -1 on error (buffer exhausted)
70 int trace_list_functions(void *buff, size_t buff_size, size_t *needed);
72 /* Flags for ftrace_record */
74 FUNCF_EXIT = 0UL << 30,
75 FUNCF_ENTRY = 1UL << 30,
76 /* two more values are available */
78 FUNCF_TIMESTAMP_MASK = 0x3fffffff,
81 #define TRACE_CALL_TYPE(call) ((call)->flags & 0xc0000000UL)
83 /* Information about a single function entry/exit */
85 uint32_t func; /* Function offset */
86 uint32_t caller; /* Caller function offset */
87 uint32_t flags; /* Flags and timestamp */
90 int trace_list_calls(void *buff, size_t buff_size, size_t *needed);
93 * Turn function tracing on and off
95 * Don't enable trace if it has not been initialised.
97 * @param enabled 1 to enable trace, 0 to disable
99 void trace_set_enabled(int enabled);
101 int trace_early_init(void);
104 * Init the trace system
106 * This should be called after relocation with a suitably large buffer
107 * (typically as large as the U-Boot text area)
109 * @param buff Pointer to trace buffer
110 * @param buff_size Size of trace buffer
112 int trace_init(void *buff, size_t buff_size);