Commit fb7db41cd46e96621fd97b827622668ee2c6b845
1 parent
2e65959be6
Exists in
master
and in
53 other branches
bootstage: Allow marking a particular line of code
Add a function which allows a (file, function, line number) to be marked in bootstage. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>
Showing 2 changed files with 52 additions and 0 deletions Side-by-side Diff
common/bootstage.c
... | ... | @@ -30,6 +30,8 @@ |
30 | 30 | |
31 | 31 | #include <common.h> |
32 | 32 | #include <libfdt.h> |
33 | +#include <malloc.h> | |
34 | +#include <linux/compiler.h> | |
33 | 35 | |
34 | 36 | DECLARE_GLOBAL_DATA_PTR; |
35 | 37 | |
... | ... | @@ -115,6 +117,33 @@ |
115 | 117 | if (id == BOOTSTAGE_ID_ALLOC) |
116 | 118 | flags = BOOTSTAGEF_ALLOC; |
117 | 119 | return bootstage_add_record(id, name, flags, timer_get_boot_us()); |
120 | +} | |
121 | + | |
122 | +ulong bootstage_mark_code(const char *file, const char *func, int linenum) | |
123 | +{ | |
124 | + char *str, *p; | |
125 | + __maybe_unused char *end; | |
126 | + int len = 0; | |
127 | + | |
128 | + /* First work out the length we need to allocate */ | |
129 | + if (linenum != -1) | |
130 | + len = 11; | |
131 | + if (func) | |
132 | + len += strlen(func); | |
133 | + if (file) | |
134 | + len += strlen(file); | |
135 | + | |
136 | + str = malloc(len + 1); | |
137 | + p = str; | |
138 | + end = p + len; | |
139 | + if (file) | |
140 | + p += snprintf(p, end - p, "%s,", file); | |
141 | + if (linenum != -1) | |
142 | + p += snprintf(p, end - p, "%d", linenum); | |
143 | + if (func) | |
144 | + p += snprintf(p, end - p, ": %s", func); | |
145 | + | |
146 | + return bootstage_mark_name(BOOTSTAGE_ID_ALLOC, str); | |
118 | 147 | } |
119 | 148 | |
120 | 149 | uint32_t bootstage_start(enum bootstage_id id, const char *name) |
include/bootstage.h
... | ... | @@ -267,6 +267,19 @@ |
267 | 267 | ulong bootstage_mark_name(enum bootstage_id id, const char *name); |
268 | 268 | |
269 | 269 | /** |
270 | + * Mark a time stamp in the given function and line number | |
271 | + * | |
272 | + * See BOOTSTAGE_MARKER() for a convenient macro. | |
273 | + * | |
274 | + * @param file Filename to record (NULL if none) | |
275 | + * @param func Function name to record | |
276 | + * @param linenum Line number to record | |
277 | + * @return recorded time stamp | |
278 | + */ | |
279 | +ulong bootstage_mark_code(const char *file, const char *func, | |
280 | + int linenum); | |
281 | + | |
282 | +/** | |
270 | 283 | * Mark the start of a bootstage activity. The end will be marked later with |
271 | 284 | * bootstage_accum() and at that point we accumulate the time taken. Calling |
272 | 285 | * this function turns the given id into a accumulator rather than and |
... | ... | @@ -358,6 +371,12 @@ |
358 | 371 | return 0; |
359 | 372 | } |
360 | 373 | |
374 | +static inline ulong bootstage_mark_code(const char *file, const char *func, | |
375 | + int linenum) | |
376 | +{ | |
377 | + return 0; | |
378 | +} | |
379 | + | |
361 | 380 | static inline uint32_t bootstage_start(enum bootstage_id id, const char *name) |
362 | 381 | { |
363 | 382 | return 0; |
... | ... | @@ -378,6 +397,10 @@ |
378 | 397 | return 0; /* Pretend to succeed */ |
379 | 398 | } |
380 | 399 | #endif /* CONFIG_BOOTSTAGE */ |
400 | + | |
401 | +/* Helper macro for adding a bootstage to a line of code */ | |
402 | +#define BOOTSTAGE_MARKER() \ | |
403 | + bootstage_mark_code(__FILE__, __func__, __LINE__) | |
381 | 404 | |
382 | 405 | #endif |