• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2023 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
16
17CREATE TABLE internal_cpu_sizes AS
18SELECT 0 AS n, 'little' AS size
19UNION
20SELECT 1 AS n, 'big' AS size
21UNION
22SELECT 2 AS n, 'huge' AS size;
23
24CREATE TABLE internal_ranked_cpus AS
25SELECT
26 (DENSE_RANK() OVER win) - 1 AS n,
27 cpu
28FROM (
29  SELECT
30    track.cpu AS cpu,
31    MAX(counter.value) AS maxfreq
32  FROM counter
33  JOIN cpu_counter_track AS track
34  ON (counter.track_id = track.id)
35  WHERE track.name = "cpufreq"
36  GROUP BY track.cpu
37)
38WINDOW win AS (ORDER BY maxfreq);
39
40-- Guess size of CPU.
41-- On some multicore devices the cores are heterogeneous and divided
42-- into two or more 'sizes'. In a typical case a device might have 8
43-- cores of which 4 are 'little' (low power & low performance) and 4
44-- are 'big' (high power & high performance). This functions attempts
45-- to map a given CPU index onto the relevant descriptor. For
46-- homogeneous systems this returns NULL.
47--
48-- @arg cpu_index INT   Index of the CPU whose size we will guess.
49-- @ret STRING          A descriptive size ('little', 'big', 'huge', etc) or NULL if we have insufficient information.
50SELECT CREATE_FUNCTION(
51  'GUESS_CPU_SIZE(cpu_index INT)',
52  'STRING',
53  '
54  SELECT
55    IIF((SELECT COUNT(DISTINCT n) FROM internal_ranked_cpus) >= 2, size, null) as size
56  FROM internal_ranked_cpus
57  LEFT JOIN internal_cpu_sizes USING(n)
58  WHERE cpu = $cpu_index;
59  '
60);
61