-
Notifications
You must be signed in to change notification settings - Fork 784
Expand file tree
/
Copy pathutils.sql
More file actions
198 lines (172 loc) · 5.31 KB
/
utils.sql
File metadata and controls
198 lines (172 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
--
-- Copyright 2024 The Android Open Source Project
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- https://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
INCLUDE PERFETTO MODULE wattson.curves.cpu_1d;
INCLUDE PERFETTO MODULE wattson.curves.cpu_2d;
INCLUDE PERFETTO MODULE wattson.curves.gpu;
INCLUDE PERFETTO MODULE wattson.curves.l3;
INCLUDE PERFETTO MODULE wattson.curves.tpu;
INCLUDE PERFETTO MODULE wattson.device_infos;
INCLUDE PERFETTO MODULE wattson.utils;
-- 1D LUT
CREATE PERFETTO TABLE _filtered_curves_1d_raw AS
SELECT cp.policy, freq_khz, active, idle0, idle1, static
FROM _device_curves_1d AS dc
JOIN _wattson_device AS device
ON dc.device = device.name
JOIN _dev_cpu_policy_map AS cp
ON dc.policy = cp.policy;
CREATE PERFETTO TABLE _filtered_curves_1d AS
SELECT policy, freq_khz, -1 AS idle, active AS curve_value, static
FROM _filtered_curves_1d_raw
UNION
SELECT policy, freq_khz, 0, idle0, static FROM _filtered_curves_1d_raw
UNION
SELECT policy, freq_khz, 1, idle1, static FROM _filtered_curves_1d_raw;
CREATE PERFETTO INDEX freq_1d ON _filtered_curves_1d(policy, freq_khz, idle);
-- 2D LUT; with dependency on another CPU
CREATE PERFETTO TABLE _filtered_curves_2d_raw AS
SELECT
dc.policy,
dc.freq_khz,
dc.dep_policy,
dc.dep_freq,
dc.active,
dc.idle0,
dc.idle1,
dc.static,
dc.interconnect
FROM _device_curves_2d AS dc
JOIN _wattson_device AS device
ON dc.device = device.name;
CREATE PERFETTO TABLE _filtered_curves_2d AS
SELECT freq_khz, dep_policy, dep_freq, -1 AS idle, static, active AS curve_value
FROM _filtered_curves_2d_raw
UNION
SELECT freq_khz, dep_policy, dep_freq, 0, static, idle0
FROM _filtered_curves_2d_raw
UNION
SELECT freq_khz, dep_policy, dep_freq, 1, static, idle1
FROM _filtered_curves_2d_raw;
CREATE PERFETTO INDEX freq_2d ON _filtered_curves_2d(
freq_khz,
dep_policy,
dep_freq,
idle
);
-- L3 cache LUT
CREATE PERFETTO TABLE _filtered_curves_l3 AS
SELECT dc.freq_khz, dc.dep_policy, dc.dep_freq, dc.l3_hit, dc.l3_miss
FROM _device_curves_l3 AS dc
JOIN _wattson_device AS device
ON dc.device = device.name;
CREATE PERFETTO INDEX freq_l3 ON _filtered_curves_l3(
freq_khz,
dep_policy,
dep_freq
);
-- Device specific GPU curves
CREATE PERFETTO TABLE _gpu_filtered_curves_raw AS
SELECT freq_khz, active, idle1, idle2
FROM _gpu_device_curves AS dc
JOIN _wattson_device AS device
ON dc.device = device.name;
CREATE PERFETTO TABLE _gpu_filtered_curves AS
SELECT freq_khz, 2 AS idle, active AS curve_value FROM _gpu_filtered_curves_raw
UNION ALL
SELECT freq_khz, 1 AS idle, idle1 AS curve_value FROM _gpu_filtered_curves_raw
UNION ALL
SELECT freq_khz, 0 AS idle, idle2 AS curve_value FROM _gpu_filtered_curves_raw;
CREATE PERFETTO INDEX gpu_freq ON _gpu_filtered_curves(freq_khz, idle);
-- Device specific TPU curves
CREATE PERFETTO TABLE _tpu_filtered_curves AS
SELECT cluster, freq, requests, active
FROM _tpu_device_curves AS dc
JOIN _wattson_device AS device
ON dc.device = device.name;
CREATE PERFETTO INDEX tpu_curves ON _tpu_filtered_curves(
cluster,
freq,
requests
);
-- Device specific interconnect curves
CREATE PERFETTO TABLE _filtered_curves_interconnect AS
SELECT
dc.policy,
dc.freq_khz,
dc.dep_policy,
dc.dep_freq,
dc.interconnect AS curve_value
FROM _filtered_curves_2d_raw AS dc
WHERE
dc.interconnect > 0;
CREATE PERFETTO INDEX freq_interconnect ON _filtered_curves_interconnect(
policy,
freq_khz,
dep_policy,
dep_freq
);
-- Constructs table specifying CPUs that are DSU dependent
CREATE PERFETTO TABLE _cpu_w_dsu_dependency AS
SELECT DISTINCT cpu
FROM _filtered_curves_2d_raw
JOIN _dev_cpu_policy_map USING (policy)
WHERE
dep_policy = _dsu_dep!();
-- Chooses the minimum vote for CPUs with dependencies
CREATE PERFETTO TABLE _cpu_w_dependency_default_vote AS
WITH
policy_vote AS (
SELECT policy, dep_policy, min(dep_freq) AS dep_freq
FROM _filtered_curves_2d_raw
GROUP BY
policy
)
SELECT cpu, dep_policy, dep_freq
FROM policy_vote
JOIN _dev_cpu_policy_map USING (policy);
-- CPUs that need to be checked for static calculation
CREATE PERFETTO TABLE _cpus_for_static AS
SELECT DISTINCT m.cpu
FROM _filtered_curves_2d_raw AS c
JOIN _dev_cpu_policy_map AS m USING (policy)
WHERE
static > 0
UNION
SELECT DISTINCT m.cpu
FROM _filtered_curves_1d AS c
JOIN _dev_cpu_policy_map AS m USING (policy)
WHERE
static > 0;
-- Contructs table specifying CPU dependency of each CPU (if applicable)
CREATE PERFETTO TABLE _cpu_lut_dependencies AS
WITH
base_cpus AS (
SELECT DISTINCT m.cpu, m.policy
FROM _filtered_curves_2d_raw AS c
JOIN _dev_cpu_policy_map AS m USING (policy)
WHERE
dep_policy != _dsu_dep!()
),
dep_cpus AS (
SELECT DISTINCT m.cpu AS dep_cpu, m.policy AS dep_policy
FROM _filtered_curves_2d_raw AS c
JOIN _dev_cpu_policy_map AS m
ON c.dep_policy = m.policy
)
SELECT b.cpu, d.dep_cpu
FROM base_cpus AS b
CROSS JOIN dep_cpus AS d
WHERE
b.policy != d.dep_policy;