wattson: Add DSU support for VM traces
Add framework to have devfreq DSU frequencies on traces that come from
VMs, where there is no physical DSU HW to emulate. Since the DSU
frequencies are a prerequisite for power estimation on some devices,
this patch unblocks power estimation for devices emulated on VMs that
require DSU frequencies.
Test: tools/diff_test_trace_processor.py out/linux/trace_processor_shell --name-filter '.*wattson.*'
Bug: 379936540
Change-Id: Iad3882aad4929789ef83ddb34a2771fef04a39d0
Signed-off-by: Samuel Wu <wusamuel@google.com>
diff --git a/src/trace_processor/perfetto_sql/stdlib/wattson/curves/w_dsu_dependence.sql b/src/trace_processor/perfetto_sql/stdlib/wattson/curves/w_dsu_dependence.sql
index dbaf4ac..9435c09 100644
--- a/src/trace_processor/perfetto_sql/stdlib/wattson/curves/w_dsu_dependence.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/wattson/curves/w_dsu_dependence.sql
@@ -55,6 +55,22 @@
base.freq_7 = lut7.freq_khz AND
base.idle_7 = lut7.idle;
+-- Get nominal devfreq_dsu counter, OR use a dummy one for Pixel 9 VM traces
+-- The VM doesn't have a DSU, so the placeholder value of FMin is put in. The
+-- DSU frequency is a prerequisite for power estimation on Pixel 9.
+CREATE PERFETTO TABLE _dsu_frequency AS
+SELECT * from linux_devfreq_dsu_counter
+UNION ALL
+SELECT
+ 0 as id,
+ trace_start() as ts,
+ trace_end() - trace_start() as dur,
+ 610000 as dsu_freq
+-- Only add this for traces from a VM on Pixel 9 where DSU values aren't present
+WHERE (SELECT str_value FROM metadata WHERE name = 'android_guest_soc_model')
+ IN (SELECT device FROM _use_devfreq)
+ AND (SELECT COUNT(*) FROM linux_devfreq_dsu_counter) = 0;
+
CREATE PERFETTO TABLE _w_dsu_dependence AS
SELECT
c.ts, c.dur,
@@ -80,10 +96,10 @@
FROM _interval_intersect!(
(
_ii_subquery!(_cpu_curves),
- _ii_subquery!(linux_devfreq_dsu_counter)
+ _ii_subquery!(_dsu_frequency)
),
()
) ii
JOIN _cpu_curves AS c ON c._auto_id = id_0
-JOIN linux_devfreq_dsu_counter AS d on d._auto_id = id_1;
+JOIN _dsu_frequency AS d on d._auto_id = id_1;
diff --git a/test/data/wattson_tk4_vm.pb.sha256 b/test/data/wattson_tk4_vm.pb.sha256
new file mode 100644
index 0000000..52b09dd
--- /dev/null
+++ b/test/data/wattson_tk4_vm.pb.sha256
@@ -0,0 +1 @@
+12beb14bc06e28ecbdfc618d423aeea2badd449aeb9ccc65a457aa6c05ebf2be
\ No newline at end of file
diff --git a/test/trace_processor/diff_tests/stdlib/wattson/tests.py b/test/trace_processor/diff_tests/stdlib/wattson/tests.py
index b5c9cae..5b20333 100644
--- a/test/trace_processor/diff_tests/stdlib/wattson/tests.py
+++ b/test/trace_processor/diff_tests/stdlib/wattson/tests.py
@@ -452,3 +452,30 @@
452415394221,69579176303,13654,13361,11651,9609,1
564873995228,135118729231,45223,37594,22798,20132,1
"""))
+
+ # Tests traces from VM that have incomplete CPU tracks
+ def test_wattson_missing_cpus_on_guest(self):
+ return DiffTestBlueprint(
+ trace=DataPath('wattson_tk4_vm.pb'),
+ query=("""
+ INCLUDE PERFETTO MODULE wattson.curves.estimates;
+ SELECT
+ ts, dur, cpu0_mw, cpu1_mw, cpu2_mw, cpu3_mw, cpu4_mw, cpu5_mw,
+ cpu6_mw
+ FROM _system_state_mw
+ WHERE ts > 25150000000
+ LIMIT 10
+ """),
+ out=Csv("""
+ "ts","dur","cpu0_mw","cpu1_mw","cpu2_mw","cpu3_mw","cpu4_mw","cpu5_mw","cpu6_mw"
+ 25150029000,1080,0.000000,0.000000,0.000000,0.000000,70.050000,83.260000,0.000000
+ 25150030640,42920,0.000000,0.000000,0.000000,0.000000,70.050000,70.050000,0.000000
+ 25150073560,99800,0.000000,0.000000,0.000000,0.000000,70.050000,0.000000,0.000000
+ 25150173360,28240,176.280000,0.000000,0.000000,0.000000,70.050000,0.000000,0.000000
+ 25150201600,6480,176.280000,0.000000,0.000000,176.280000,70.050000,0.000000,0.000000
+ 25150208080,29840,176.280000,0.000000,0.000000,176.280000,70.050000,70.050000,0.000000
+ 25150237920,129800,0.000000,0.000000,0.000000,176.280000,70.050000,70.050000,0.000000
+ 25150367720,37480,0.000000,0.000000,0.000000,176.280000,70.050000,0.000000,0.000000
+ 25150405200,15120,0.000000,176.280000,0.000000,176.280000,70.050000,0.000000,0.000000
+ 25150420320,15920,0.000000,176.280000,0.000000,0.000000,70.050000,0.000000,0.000000
+ """))