summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/drift.py26
-rw-r--r--lib/loader/energytrace.py9
-rw-r--r--lib/loader/generic.py12
3 files changed, 47 insertions, 0 deletions
diff --git a/lib/drift.py b/lib/drift.py
index cb769f4..f2dd889 100644
--- a/lib/drift.py
+++ b/lib/drift.py
@@ -337,3 +337,29 @@ def compensate_drift_greedy(event_timestamps, transition_start_candidate_weights
)
return compensated_timestamps
+
+
+def compensate_etplusplus(
+ data, timestamps, event_timestamps, statechange_indexes, offline_index=None
+):
+ """Use hardware state changes reported by EnergyTrace++ to determine transition timestamps."""
+ expected_transition_start_timestamps = event_timestamps[::2]
+ compensated_timestamps = list()
+ drift = 0
+ for i, expected_start_ts in enumerate(expected_transition_start_timestamps):
+ expected_end_ts = event_timestamps[i * 2 + 1]
+ et_timestamps_start = bisect_left(timestamps, expected_start_ts - 10e-3)
+ et_timestamps_end = bisect_right(timestamps, expected_start_ts + 10e-3)
+
+ candidate_indexes = list()
+ for index in statechange_indexes:
+ if et_timestamps_start <= index <= et_timestamps_end:
+ candidate_indexes.append(index)
+
+ if len(candidate_indexes) == 2:
+ drift = timestamps[candidate_indexes[0]] - expected_start_ts
+
+ compensated_timestamps.append(expected_start_ts + drift)
+ compensated_timestamps.append(expected_end_ts + drift)
+
+ return compensated_timestamps
diff --git a/lib/loader/energytrace.py b/lib/loader/energytrace.py
index 0ffaac7..0386b99 100644
--- a/lib/loader/energytrace.py
+++ b/lib/loader/energytrace.py
@@ -680,6 +680,15 @@ class EnergyTraceWithLogicAnalyzer(ExternalTimerSync):
self.sync_data = self.sync_data[:x]
break
+ # Each synchronization pulse consists of two LogicAnalyzer pulses, so four
+ # entries in time_stamp_data (rising edge, falling edge, rising edge, falling edge).
+ # If we have less then twelve entries, we observed no transitions and don't even have
+ # valid synchronization data. In this case, we bail out.
+ if len(self.sync_data) < 12:
+ raise RuntimeError(
+ f"LogicAnalyzer sync data has length {len(time_stamp_data)}, expected >= 12"
+ )
+
self.online_timestamps = self.sync_data[2:3] + self.sync_data[4:-7]
self.online_timestamps = (
np.array(self.online_timestamps) - self.online_timestamps[0]
diff --git a/lib/loader/generic.py b/lib/loader/generic.py
index 78305e0..67535bc 100644
--- a/lib/loader/generic.py
+++ b/lib/loader/generic.py
@@ -29,6 +29,17 @@ class ExternalTimerSync:
if os.getenv("DFATOOL_COMPENSATE_DRIFT"):
import dfatool.drift
+ if len(self.hw_statechange_indexes):
+ # measurement was performed with EnergyTrace++
+ # (i.e., with cpu state annotations)
+ return dfatool.drift.compensate_etplusplus(
+ data,
+ timestamps,
+ event_timestamps,
+ self.hw_statechange_indexes,
+ offline_index=offline_index,
+ )
+
return dfatool.drift.compensate(
data, timestamps, event_timestamps, offline_index=offline_index
)
@@ -41,6 +52,7 @@ class ExternalTimerSync:
# * self.sync_min_high_count, self.sync_min_low_count: outlier handling in synchronization pulse detection
# * self.sync_power, self.sync_min_duration: synchronization pulse parameters. one pulse before the measurement, two pulses afterwards
# expected_trace must contain online timestamps
+ # TODO automatically determine sync_power if it is None
def analyze_states(self, expected_trace, repeat_id, online_timestamps=None):
"""
:param online_timestamps: must start at 0, if set