From e383b3dcc4650f81de4a20735d8a37b0720377f6 Mon Sep 17 00:00:00 2001 From: Bora Guvendik Date: Mon, 22 Nov 2021 16:12:48 -0800 Subject: util/cbmem: Rebase to handle negative timestamps Rebase all of the timestamps to the lowest (potentially negative) value in the list when displaying them. Also drop the extra `timestamp_print_*_entry` calls for time 0 and instead inserted a "dummy" timestamp entry of time 0 into the table. TEST=Boot to OS after adding negative timestamps, cbmem -t Signed-off-by: Bora Guvendik Change-Id: I7eb519c360e066d48dde205401e4ccd3b0b3d8a5 Reviewed-on: https://review.coreboot.org/c/coreboot/+/59555 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner Reviewed-by: Tim Wawrzynczak Reviewed-by: Subrata Banik --- util/cbmem/cbmem.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'util') diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c index bff863f3b8..51b4adc80c 100644 --- a/util/cbmem/cbmem.c +++ b/util/cbmem/cbmem.c @@ -621,23 +621,30 @@ static void dump_timestamps(int mach_readable) if (!tst_p) die("Unable to map full timestamp table\n"); - /* Report the base time within the table. */ - prev_stamp = 0; - if (mach_readable) - timestamp_print_parseable_entry(0, tst_p->base_time, - prev_stamp); - else - timestamp_print_entry(0, tst_p->base_time, prev_stamp); - prev_stamp = tst_p->base_time; - - sorted_tst_p = malloc(size); + sorted_tst_p = malloc(size + sizeof(struct timestamp_entry)); if (!sorted_tst_p) die("Failed to allocate memory"); aligned_memcpy(sorted_tst_p, tst_p, size); + /* + * Insert a timestamp to represent the base time (start of coreboot), + * in case we have to rebase for negative timestamps below. + */ + sorted_tst_p->entries[tst_p->num_entries].entry_id = 0; + sorted_tst_p->entries[tst_p->num_entries].entry_stamp = 0; + sorted_tst_p->num_entries += 1; + qsort(&sorted_tst_p->entries[0], sorted_tst_p->num_entries, sizeof(struct timestamp_entry), compare_timestamp_entries); + /* + * If there are negative timestamp entries, rebase all of the + * timestamps to the lowest one in the list. + */ + if (sorted_tst_p->entries[0].entry_stamp < 0) + sorted_tst_p->base_time = -sorted_tst_p->entries[0].entry_stamp; + prev_stamp = 0; + total_time = 0; for (uint32_t i = 0; i < sorted_tst_p->num_entries; i++) { uint64_t stamp; -- cgit v1.2.3