Bora Guvendik has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/59555 )
Change subject: util/cbmem: Rebase to handle negative timestamps ......................................................................
util/cbmem: Rebase to handle negative timestamps
Rebase all of the timestamps to the lowest(negative) value in the list when displaying them.
TEST=Boot to OS after adding negative timestamps, cbmem -t
timestamp_add(TS_ME_BOOT_STALL_DONE, 0 - ts[6]); timestamp_add(TS_ME_ICC_CONFIG_START, 0 - ts[7]); timestamp_add(TS_ME_HOST_BOOT_PREP_DONE, 0 - ts[10]); timestamp_add(TS_ME_RECEIVED_CRDA_FROM_PMC, 0 - ts[19]);
0:1st timestamp 0 944:CSE sent 'Boot Stall Done' to PMC 296,000 945:CSE started to handle ICC configuration 303,000 (7,000) 946:CSE sent 'Host BIOS Prep Done' to PMC 308,000 (5,000) 947:CSE received 'CPU Reset Done Ack sent' from PMC 1,074,000 (766,000) 11:start of bootblock 1,101,606 (27,606) 12:end of bootblock 1,161,989 (60,382)
Signed-off-by: Bora Guvendik bora.guvendik@intel.com Change-Id: I7eb519c360e066d48dde205401e4ccd3b0b3d8a5 --- M util/cbmem/cbmem.c 1 file changed, 49 insertions(+), 9 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/55/59555/1
diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c index 085e004..5aec7fd 100644 --- a/util/cbmem/cbmem.c +++ b/util/cbmem/cbmem.c @@ -589,6 +589,39 @@ return 0; }
+static void rebase_timestamp_entries(struct timestamp_table *sorted_tst_p, + uint32_t num_entries) +{ + uint64_t rebase_delta; + struct timestamp_entry *tse; + + if (!sorted_tst_p || num_entries <= 0) + return; + + if (sorted_tst_p->entries[0].entry_stamp >= 0) + return; + + rebase_delta = 0 - sorted_tst_p->entries[0].entry_stamp; + + if (rebase_delta > sorted_tst_p->base_time) + sorted_tst_p->base_time = 0; + else + sorted_tst_p->base_time -= rebase_delta; + + for (uint32_t i = 0; i < num_entries; i++) { + tse = &sorted_tst_p->entries[i]; + + /* Rebase all timestamps. */ + if (tse->entry_stamp > 0) + tse->entry_stamp += rebase_delta; + else + tse->entry_stamp = 0 - tse->entry_stamp; + } + + qsort(&sorted_tst_p->entries[0], sorted_tst_p->num_entries, + sizeof(struct timestamp_entry), compare_timestamp_entries); +} + /* dump the timestamp table */ static void dump_timestamps(int mach_readable) { @@ -621,15 +654,6 @@ 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); if (!sorted_tst_p) die("Failed to allocate memory"); @@ -638,6 +662,22 @@ 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) + rebase_timestamp_entries(sorted_tst_p, sorted_tst_p->num_entries); + + /* Report the base time within the table. */ + prev_stamp = 0; + if (mach_readable) + timestamp_print_parseable_entry(0, sorted_tst_p->base_time, + prev_stamp); + else + timestamp_print_entry(0, sorted_tst_p->base_time, prev_stamp); + prev_stamp = sorted_tst_p->base_time; + total_time = 0; for (uint32_t i = 0; i < sorted_tst_p->num_entries; i++) { uint64_t stamp;