• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2024 The Android Open Source Project
3--
4-- Licensed under the Apache License, Version 2.0 (the "License");
5-- you may not use this file except in compliance with the License.
6-- You may obtain a copy of the License at
7--
8--     https://www.apache.org/licenses/LICENSE-2.0
9--
10-- Unless required by applicable law or agreed to in writing, software
11-- distributed under the License is distributed on an "AS IS" BASIS,
12-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-- See the License for the specific language governing permissions and
14-- limitations under the License.
15
16INCLUDE PERFETTO MODULE linux.cpu.frequency;
17
18INCLUDE PERFETTO MODULE wattson.device_infos;
19
20CREATE PERFETTO TABLE _adjusted_cpu_freq AS
21WITH
22  _cpu_freq AS (
23    SELECT
24      ts,
25      dur,
26      freq,
27      cf.ucpu AS cpu,
28      d_map.policy
29    FROM cpu_frequency_counters AS cf
30    JOIN _dev_cpu_policy_map AS d_map
31      ON cf.ucpu = d_map.cpu
32  ),
33  -- Get first freq transition per CPU
34  first_cpu_freq_slices AS (
35    SELECT
36      min(ts) AS ts,
37      cpu
38    FROM _cpu_freq
39    GROUP BY
40      cpu
41  )
42-- Prepend NULL slices up to first freq events on a per CPU basis
43SELECT
44  -- Construct slices from first cpu ts up to first freq event for each cpu
45  trace_start() AS ts,
46  first_slices.ts - trace_start() AS dur,
47  NULL AS freq,
48  first_slices.cpu,
49  d_map.policy
50FROM first_cpu_freq_slices AS first_slices
51JOIN _dev_cpu_policy_map AS d_map
52  ON first_slices.cpu = d_map.cpu
53WHERE
54  dur > 0
55UNION ALL
56SELECT
57  ts,
58  dur,
59  freq,
60  cpu,
61  policy
62FROM _cpu_freq
63UNION ALL
64-- Add empty cpu freq counters for CPUs that are physically present, but did not
65-- have a single freq event register. The time region needs to be defined so
66-- that interval_intersect doesn't remove the undefined time region.
67SELECT
68  trace_start() AS ts,
69  trace_dur() AS dur,
70  NULL AS freq,
71  cpu,
72  NULL AS policy
73FROM _dev_cpu_policy_map
74WHERE
75  NOT cpu IN (
76    SELECT
77      cpu
78    FROM first_cpu_freq_slices
79  );
80