<p>Philipp Deppenwiese <strong>merged</strong> this change.</p><p><a href="https://review.coreboot.org/26168">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  build bot (Jenkins): Verified
  Martin Roth: Looks good to me, approved
  Philipp Deppenwiese: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">cbmem: Sort timestamp entries<br><br>If the timestamp entries are added out of order, the duration<br>calculation will be wrong.<br><br>AGESA collects timestamp data through all the stages. Then in AmdInitPost<br>it asks for a buffer to write TP_Perf_STRUCT into. agesawrapper will then<br>take the data and call timestamp_add on each entry. This results in<br>the entries being out of order.<br><br>TEST=Built firmware for grunt that manually added entries and then ran<br>cbmem -t/-T to verify the entries were in the correct order.<br><br>Change-Id: I6946a844b71d714141b3372e4c43807cfe3528ad<br>Signed-off-by: Raul E Rangel <rrangel@chromium.org><br>Reviewed-on: https://review.coreboot.org/26168<br>Reviewed-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com><br>Reviewed-by: Martin Roth <martinroth@google.com><br>Tested-by: build bot (Jenkins) <no-reply@coreboot.org><br>---<br>M util/cbmem/cbmem.c<br>1 file changed, 21 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c</span><br><span>index eae5da3..21da71b 100644</span><br><span>--- a/util/cbmem/cbmem.c</span><br><span>+++ b/util/cbmem/cbmem.c</span><br><span>@@ -584,11 +584,20 @@</span><br><span>      return step_time;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int compare_timestamp_entries(const void *a, const void *b)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     const struct timestamp_entry *tse_a = (struct timestamp_entry *)a;</span><br><span style="color: hsl(120, 100%, 40%);">+    const struct timestamp_entry *tse_b = (struct timestamp_entry *)b;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  return tse_a->entry_stamp - tse_b->entry_stamp;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* dump the timestamp table */</span><br><span> static void dump_timestamps(int mach_readable)</span><br><span> {</span><br><span>  int i;</span><br><span>       const struct timestamp_table *tst_p;</span><br><span style="color: hsl(120, 100%, 40%);">+  struct timestamp_table *sorted_tst_p;</span><br><span>        size_t size;</span><br><span>         uint64_t prev_stamp;</span><br><span>         uint64_t total_time;</span><br><span>@@ -625,13 +634,21 @@</span><br><span>                 timestamp_print_entry(0,  tst_p->base_time, prev_stamp);</span><br><span>  prev_stamp = tst_p->base_time;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ sorted_tst_p = malloc(size);</span><br><span style="color: hsl(120, 100%, 40%);">+  if (!sorted_tst_p)</span><br><span style="color: hsl(120, 100%, 40%);">+            die("Failed to allocate memory");</span><br><span style="color: hsl(120, 100%, 40%);">+   memcpy(sorted_tst_p, tst_p, size);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  qsort(&sorted_tst_p->entries[0], sorted_tst_p->num_entries,</span><br><span style="color: hsl(120, 100%, 40%);">+       sizeof(struct timestamp_entry), compare_timestamp_entries);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  total_time = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- for (i = 0; i < tst_p->num_entries; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+      for (i = 0; i < sorted_tst_p->num_entries; i++) {</span><br><span>              uint64_t stamp;</span><br><span style="color: hsl(0, 100%, 40%);">-         const struct timestamp_entry *tse = &tst_p->entries[i];</span><br><span style="color: hsl(120, 100%, 40%);">+                const struct timestamp_entry *tse = &sorted_tst_p->entries[i];</span><br><span> </span><br><span>            /* Make all timestamps absolute. */</span><br><span style="color: hsl(0, 100%, 40%);">-             stamp = tse->entry_stamp + tst_p->base_time;</span><br><span style="color: hsl(120, 100%, 40%);">+            stamp = tse->entry_stamp + sorted_tst_p->base_time;</span><br><span>            if (mach_readable)</span><br><span>                   total_time +=</span><br><span>                                timestamp_print_parseable_entry(tse->entry_id,</span><br><span>@@ -649,6 +666,7 @@</span><br><span>      }</span><br><span> </span><br><span>        unmap_memory(&timestamp_mapping);</span><br><span style="color: hsl(120, 100%, 40%);">+ free(sorted_tst_p);</span><br><span> }</span><br><span> </span><br><span> struct cbmem_console {</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/26168">change 26168</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/26168"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I6946a844b71d714141b3372e4c43807cfe3528ad </div>
<div style="display:none"> Gerrit-Change-Number: 26168 </div>
<div style="display:none"> Gerrit-PatchSet: 6 </div>
<div style="display:none"> Gerrit-Owner: Raul Rangel <rrangel@chromium.org> </div>
<div style="display:none"> Gerrit-Reviewer: Aaron Durbin <adurbin@chromium.org> </div>
<div style="display:none"> Gerrit-Reviewer: Julius Werner <jwerner@chromium.org> </div>
<div style="display:none"> Gerrit-Reviewer: Martin Roth <martinroth@google.com> </div>
<div style="display:none"> Gerrit-Reviewer: Paul Menzel <paulepanter@users.sourceforge.net> </div>
<div style="display:none"> Gerrit-Reviewer: Philipp Deppenwiese <zaolin.daisuki@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Raul Rangel <rrangel@chromium.org> </div>
<div style="display:none"> Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org> </div>