tp: move cpu idle and frequency to linux module

Change-Id: Ia26ab2afbbf668a3040c40556af00ade4158ebfd
diff --git a/Android.bp b/Android.bp
index 2657b2e..ccc9966 100644
--- a/Android.bp
+++ b/Android.bp
@@ -13143,8 +13143,6 @@
         "src/trace_processor/perfetto_sql/stdlib/common/slices.sql",
         "src/trace_processor/perfetto_sql/stdlib/common/timestamps.sql",
         "src/trace_processor/perfetto_sql/stdlib/counters/intervals.sql",
-        "src/trace_processor/perfetto_sql/stdlib/cpu/freq.sql",
-        "src/trace_processor/perfetto_sql/stdlib/cpu/idle.sql",
         "src/trace_processor/perfetto_sql/stdlib/deprecated/v42/common/args.sql",
         "src/trace_processor/perfetto_sql/stdlib/deprecated/v42/common/counters.sql",
         "src/trace_processor/perfetto_sql/stdlib/deprecated/v42/common/metadata.sql",
@@ -13158,11 +13156,12 @@
         "src/trace_processor/perfetto_sql/stdlib/graphs/search.sql",
         "src/trace_processor/perfetto_sql/stdlib/intervals/intersect.sql",
         "src/trace_processor/perfetto_sql/stdlib/intervals/overlap.sql",
+        "src/trace_processor/perfetto_sql/stdlib/linux/cpu/frequency.sql",
+        "src/trace_processor/perfetto_sql/stdlib/linux/cpu/idle.sql",
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/general.sql",
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/process.sql",
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/system.sql",
         "src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/thread.sql",
-        "src/trace_processor/perfetto_sql/stdlib/linux/cpu_idle.sql",
         "src/trace_processor/perfetto_sql/stdlib/memory/android/gpu.sql",
         "src/trace_processor/perfetto_sql/stdlib/memory/heap_graph_dominator_tree.sql",
         "src/trace_processor/perfetto_sql/stdlib/memory/linux/general.sql",
diff --git a/BUILD b/BUILD
index 1cd6e6d..a343145 100644
--- a/BUILD
+++ b/BUILD
@@ -2596,15 +2596,6 @@
     ],
 )
 
-# GN target: //src/trace_processor/perfetto_sql/stdlib/cpu:cpu
-perfetto_filegroup(
-    name = "src_trace_processor_perfetto_sql_stdlib_cpu_cpu",
-    srcs = [
-        "src/trace_processor/perfetto_sql/stdlib/cpu/freq.sql",
-        "src/trace_processor/perfetto_sql/stdlib/cpu/idle.sql",
-    ],
-)
-
 # GN target: //src/trace_processor/perfetto_sql/stdlib/deprecated/v42/common:common
 perfetto_filegroup(
     name = "src_trace_processor_perfetto_sql_stdlib_deprecated_v42_common_common",
@@ -2667,14 +2658,15 @@
 # GN target: //src/trace_processor/perfetto_sql/stdlib/linux/cpu:cpu
 perfetto_filegroup(
     name = "src_trace_processor_perfetto_sql_stdlib_linux_cpu_cpu",
+    srcs = [
+        "src/trace_processor/perfetto_sql/stdlib/linux/cpu/frequency.sql",
+        "src/trace_processor/perfetto_sql/stdlib/linux/cpu/idle.sql",
+    ],
 )
 
 # GN target: //src/trace_processor/perfetto_sql/stdlib/linux:linux
 perfetto_filegroup(
     name = "src_trace_processor_perfetto_sql_stdlib_linux_linux",
-    srcs = [
-        "src/trace_processor/perfetto_sql/stdlib/linux/cpu_idle.sql",
-    ],
 )
 
 # GN target: //src/trace_processor/perfetto_sql/stdlib/memory/android:android
@@ -2820,7 +2812,6 @@
         ":src_trace_processor_perfetto_sql_stdlib_chrome_chrome_sql",
         ":src_trace_processor_perfetto_sql_stdlib_common_common",
         ":src_trace_processor_perfetto_sql_stdlib_counters_counters",
-        ":src_trace_processor_perfetto_sql_stdlib_cpu_cpu",
         ":src_trace_processor_perfetto_sql_stdlib_deprecated_v42_common_common",
         ":src_trace_processor_perfetto_sql_stdlib_export_export",
         ":src_trace_processor_perfetto_sql_stdlib_gpu_gpu",
diff --git a/CHANGELOG b/CHANGELOG
index e70fc6c..e077252 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -9,6 +9,13 @@
     * Moved `cpu.utilization` package to `linux.cpu.utilization`. The
       functionality inside this package only works properly on Linux
       and Linux derived OSes (e.g. Android).
+    * Moved `cpu.freq` module to `linux.cpu.frequency` and renamed
+      `cpu_freq_counters` to `cpu_frequency_counters` for the same
+      reason as above.
+    * Moved `cpu.idle` module to `linux.cpu.idle` for the same
+      reason as above.
+    * Moved `linux.cpu_idle` to `linux.cpu.idle` to make it
+      consistent with above changes.
   Trace Processor:
     *
   UI:
diff --git a/src/trace_processor/perfetto_sql/stdlib/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/BUILD.gn
index b306c84..9441df6 100644
--- a/src/trace_processor/perfetto_sql/stdlib/BUILD.gn
+++ b/src/trace_processor/perfetto_sql/stdlib/BUILD.gn
@@ -23,7 +23,6 @@
     "chrome:chrome_sql",
     "common",
     "counters",
-    "cpu",
     "deprecated/v42/common",
     "export",
     "gpu",
diff --git a/src/trace_processor/perfetto_sql/stdlib/cpu/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/cpu/BUILD.gn
deleted file mode 100644
index 3f3971c..0000000
--- a/src/trace_processor/perfetto_sql/stdlib/cpu/BUILD.gn
+++ /dev/null
@@ -1,22 +0,0 @@
-# Copyright (C) 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
-#
-#      http://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.
-
-import("../../../../../gn/perfetto_sql.gni")
-
-perfetto_sql_source_set("cpu") {
-  sources = [
-    "freq.sql",
-    "idle.sql",
-  ]
-}
diff --git a/src/trace_processor/perfetto_sql/stdlib/cpu/idle.sql b/src/trace_processor/perfetto_sql/stdlib/cpu/idle.sql
deleted file mode 100644
index 181eaa5..0000000
--- a/src/trace_processor/perfetto_sql/stdlib/cpu/idle.sql
+++ /dev/null
@@ -1,52 +0,0 @@
---
--- 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 counters.intervals;
-
--- Counter information for each idle state change for each CPU. Finds each time
--- region where a CPU idle state is constant.
-CREATE PERFETTO TABLE cpu_idle_counters(
-  -- Counter id.
-  id INT,
-  -- Joinable with 'counter_track.id'.
-  track_id INT,
-  -- Starting timestamp of the counter.
-  ts LONG,
-  -- Duration in which the counter is contant and idle state doesn't change.
-  dur INT,
-  -- Idle state of the CPU that corresponds to this counter. An idle state of -1
-  -- is defined to be active state for the CPU, and the larger the integer, the
-  -- deeper the idle state of the CPU. NULL if not found or undefined.
-  idle INT,
-  -- CPU that corresponds to this counter.
-  cpu INT
-)
-AS
-SELECT
-  count_w_dur.id,
-  count_w_dur.track_id,
-  count_w_dur.ts,
-  count_w_dur.dur,
-  cast_int!(IIF(count_w_dur.value = 4294967295, -1, count_w_dur.value)) AS idle,
-  cct.cpu
-FROM
-counter_leading_intervals!((
-  SELECT c.*
-  FROM counter c
-  JOIN cpu_counter_track cct
-  ON cct.id = c.track_id and cct.name = 'cpuidle'
-)) count_w_dur
-JOIN cpu_counter_track cct
-ON track_id = cct.id;
diff --git a/src/trace_processor/perfetto_sql/stdlib/linux/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/linux/BUILD.gn
index 11767a9..7014a70 100644
--- a/src/trace_processor/perfetto_sql/stdlib/linux/BUILD.gn
+++ b/src/trace_processor/perfetto_sql/stdlib/linux/BUILD.gn
@@ -15,6 +15,6 @@
 import("../../../../../gn/perfetto_sql.gni")
 
 perfetto_sql_source_set("linux") {
-  sources = [ "cpu_idle.sql" ]
+  sources = []
   deps = [ "cpu" ]
 }
diff --git a/src/trace_processor/perfetto_sql/stdlib/linux/cpu/BUILD.gn b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/BUILD.gn
index 2bc004c..a9d870a 100644
--- a/src/trace_processor/perfetto_sql/stdlib/linux/cpu/BUILD.gn
+++ b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/BUILD.gn
@@ -15,6 +15,9 @@
 import("../../../../../../gn/perfetto_sql.gni")
 
 perfetto_sql_source_set("cpu") {
-  sources = []
+  sources = [
+    "frequency.sql",
+    "idle.sql",
+  ]
   deps = [ "utilization" ]
 }
diff --git a/src/trace_processor/perfetto_sql/stdlib/cpu/freq.sql b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/frequency.sql
similarity index 96%
rename from src/trace_processor/perfetto_sql/stdlib/cpu/freq.sql
rename to src/trace_processor/perfetto_sql/stdlib/linux/cpu/frequency.sql
index 5dd2a48..4d1c566 100644
--- a/src/trace_processor/perfetto_sql/stdlib/cpu/freq.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/frequency.sql
@@ -17,7 +17,7 @@
 
 -- Counter information for each frequency change for each CPU. Finds each time
 -- region where a CPU frequency is constant.
-CREATE PERFETTO TABLE cpu_freq_counters(
+CREATE PERFETTO TABLE cpu_frequency_counters(
   -- Counter id.
   id INT,
   -- Joinable with 'counter_track.id'.
@@ -48,4 +48,3 @@
 )) count_w_dur
 JOIN cpu_counter_track cct
 ON track_id = cct.id;
-
diff --git a/src/trace_processor/perfetto_sql/stdlib/linux/cpu/idle.sql b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/idle.sql
new file mode 100644
index 0000000..7019187
--- /dev/null
+++ b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/idle.sql
@@ -0,0 +1,103 @@
+--
+-- 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 counters.intervals;
+INCLUDE PERFETTO MODULE linux.cpu.frequency;
+
+-- Counter information for each idle state change for each CPU. Finds each time
+-- region where a CPU idle state is constant.
+CREATE PERFETTO TABLE cpu_idle_counters(
+  -- Counter id.
+  id INT,
+  -- Joinable with 'counter_track.id'.
+  track_id INT,
+  -- Starting timestamp of the counter.
+  ts LONG,
+  -- Duration in which the counter is contant and idle state doesn't change.
+  dur INT,
+  -- Idle state of the CPU that corresponds to this counter. An idle state of -1
+  -- is defined to be active state for the CPU, and the larger the integer, the
+  -- deeper the idle state of the CPU. NULL if not found or undefined.
+  idle INT,
+  -- CPU that corresponds to this counter.
+  cpu INT
+)
+AS
+SELECT
+  count_w_dur.id,
+  count_w_dur.track_id,
+  count_w_dur.ts,
+  count_w_dur.dur,
+  cast_int!(IIF(count_w_dur.value = 4294967295, -1, count_w_dur.value)) AS idle,
+  cct.cpu
+FROM
+counter_leading_intervals!((
+  SELECT c.*
+  FROM counter c
+  JOIN cpu_counter_track cct
+  ON cct.id = c.track_id and cct.name = 'cpuidle'
+)) count_w_dur
+JOIN cpu_counter_track cct
+ON track_id = cct.id;
+
+CREATE PERFETTO VIEW _freq_counters_for_sp_jn AS
+SELECT ts, dur, cpu
+FROM cpu_frequency_counters;
+
+CREATE PERFETTO VIEW _idle_counters_for_sp_jn AS
+SELECT ts, dur, cpu, idle
+FROM cpu_idle_counters;
+
+-- Combined cpu freq & idle counter
+CREATE VIRTUAL TABLE _freq_idle_counters
+USING span_join(
+  _freq_counters_for_sp_jn PARTITIONED cpu,
+  _idle_counters_for_sp_jn PARTITIONED cpu
+);
+
+-- Aggregates cpu idle statistics per core.
+CREATE PERFETTO TABLE cpu_idle_stats(
+  -- CPU core number.
+  cpu INT,
+  -- CPU idle state (C-states).
+  state INT,
+  -- The count of entering idle state.
+  count INT,
+  -- Total CPU core idle state duration in nanoseconds.
+  dur INT,
+  -- Average CPU core idle state duration in nanoseconds.
+  avg_dur INT,
+  -- Idle state percentage of non suspend time (C-states + P-states).
+  idle_percent FLOAT
+)
+AS
+WITH
+total AS (
+  SELECT
+    cpu,
+    sum(dur) AS dur
+  FROM _freq_idle_counters
+  GROUP BY cpu
+)
+SELECT
+  cpu,
+  (idle + 1) AS state,
+  COUNT(idle) AS count,
+  SUM(dur) AS dur,
+  SUM(dur) / COUNT(idle) AS avg_dur,
+  SUM(dur) * 100.0 / (SELECT dur FROM total t WHERE t.cpu = ific.cpu) AS idle_percent
+FROM _freq_idle_counters ific
+WHERE idle >=0
+GROUP BY cpu, idle;
diff --git a/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/general.sql b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/general.sql
index de0e45b..e8d05e2 100644
--- a/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/general.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/linux/cpu/utilization/general.sql
@@ -13,7 +13,7 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 
-INCLUDE PERFETTO MODULE cpu.freq;
+INCLUDE PERFETTO MODULE linux.cpu.frequency;
 
 -- Returns the timestamp of the start of the partition that contains the |ts|.
 CREATE PERFETTO FUNCTION _partition_start(ts INT, size INT) RETURNS INT AS
@@ -83,7 +83,7 @@
     dur,
     cpu,
     freq
-FROM cpu_freq_counters;
+FROM cpu_frequency_counters;
 
 CREATE PERFETTO VIEW _sched_without_id AS
 SELECT ts, dur, utid, cpu
diff --git a/src/trace_processor/perfetto_sql/stdlib/linux/cpu_idle.sql b/src/trace_processor/perfetto_sql/stdlib/linux/cpu_idle.sql
deleted file mode 100644
index d4aeeb2..0000000
--- a/src/trace_processor/perfetto_sql/stdlib/linux/cpu_idle.sql
+++ /dev/null
@@ -1,81 +0,0 @@
---
--- Copyright 2023 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.
-
--- CPU frequency counter per core.
-CREATE PERFETTO VIEW _cpu_freq_counters
-AS
-SELECT
-  ts,
-  dur,
-  value AS freq_value,
-  cct.cpu
-FROM experimental_counter_dur ecd
-LEFT JOIN cpu_counter_track cct
-  ON ecd.track_id = cct.id
-WHERE cct.name = 'cpufreq';
-
--- CPU idle counter per core.
-CREATE PERFETTO VIEW _cpu_idle_counters
-AS
-SELECT
-  ts,
-  dur,
-  -- Correct 4294967295 to -1 (both of them means an exit from the current state).
-  iif(value = 4294967295, -1, CAST(value AS int)) AS idle_value,
-  cct.cpu
-FROM experimental_counter_dur ecd
-LEFT JOIN cpu_counter_track cct
-  ON ecd.track_id = cct.id
-WHERE cct.name = 'cpuidle';
-
--- Combined cpu freq & idle counter
-CREATE VIRTUAL TABLE _freq_idle_counters
-USING
-  span_join(_cpu_freq_counters PARTITIONED cpu, _cpu_idle_counters PARTITIONED cpu);
-
--- Aggregates cpu idle statistics per core.
-CREATE PERFETTO TABLE linux_cpu_idle_stats(
-  -- CPU core number.
-  cpu INT,
-  -- CPU idle state (C-states).
-  state INT,
-  -- The count of entering idle state.
-  count INT,
-  -- Total CPU core idle state duration in nanoseconds.
-  dur INT,
-  -- Average CPU core idle state duration in nanoseconds.
-  avg_dur INT,
-  -- Idle state percentage of non suspend time (C-states + P-states).
-  idle_percent FLOAT
-)
-AS
-WITH
-total AS (
-  SELECT
-    cpu,
-    sum(dur) AS dur
-  FROM _freq_idle_counters
-  GROUP BY cpu
-)
-SELECT
-  cpu,
-  (idle_value + 1) AS state,
-  COUNT(idle_value) AS count,
-  SUM(dur) AS dur,
-  SUM(dur) / COUNT(idle_value) AS avg_dur,
-  SUM(dur) * 100.0 / (SELECT dur FROM total t WHERE t.cpu = ific.cpu) AS idle_percent
-FROM _freq_idle_counters ific
-WHERE idle_value >=0
-GROUP BY cpu, idle_value;
diff --git a/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_idle.sql b/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_idle.sql
index 5060f50..78f0781 100644
--- a/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_idle.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_idle.sql
@@ -13,7 +13,7 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 
-INCLUDE PERFETTO MODULE cpu.idle;
+INCLUDE PERFETTO MODULE linux.cpu.idle;
 INCLUDE PERFETTO MODULE wattson.device_infos;
 
 -- Get the corresponding deep idle time offset based on device and CPU.
diff --git a/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_split.sql b/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_split.sql
index f42d84b..b4988b7 100644
--- a/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_split.sql
+++ b/src/trace_processor/perfetto_sql/stdlib/wattson/cpu_split.sql
@@ -13,7 +13,7 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 
-INCLUDE PERFETTO MODULE cpu.freq;
+INCLUDE PERFETTO MODULE linux.cpu.frequency;
 INCLUDE PERFETTO MODULE time.conversion;
 INCLUDE PERFETTO MODULE wattson.arm_dsu;
 INCLUDE PERFETTO MODULE wattson.cpu_idle;
@@ -28,7 +28,7 @@
   freq,
   cf.cpu,
   d_map.policy
-FROM cpu_freq_counters as cf
+FROM cpu_frequency_counters as cf
 JOIN _dev_cpu_policy_map as d_map
 ON cf.cpu = d_map.cpu;
 
@@ -51,7 +51,7 @@
 ),
 window_end AS (
   SELECT ts + dur as end_ts
-  FROM cpu_freq_counters
+  FROM cpu_frequency_counters
   ORDER by ts DESC
   LIMIT 1
 )
diff --git a/test/trace_processor/diff_tests/include_index.py b/test/trace_processor/diff_tests/include_index.py
index d3dba5c..a19dbc3 100644
--- a/test/trace_processor/diff_tests/include_index.py
+++ b/test/trace_processor/diff_tests/include_index.py
@@ -106,7 +106,6 @@
 from diff_tests.stdlib.common.tests import StdlibCommon
 from diff_tests.stdlib.common.tests import StdlibCommon
 from diff_tests.stdlib.counters.tests import StdlibCounterIntervals
-from diff_tests.stdlib.cpu.tests import Cpu
 from diff_tests.stdlib.dynamic_tables.tests import DynamicTables
 from diff_tests.stdlib.export.tests import ExportTests
 from diff_tests.stdlib.gpu.tests import Gpu
@@ -115,7 +114,7 @@
 from diff_tests.stdlib.graphs.search_tests import GraphSearchTests
 from diff_tests.stdlib.intervals.intersect_tests import IntervalsIntersect
 from diff_tests.stdlib.intervals.tests import StdlibIntervals
-from diff_tests.stdlib.linux.tests import LinuxStdlib
+from diff_tests.stdlib.linux.cpu import LinuxCpu
 from diff_tests.stdlib.memory.heap_graph_dominator_tree_tests import HeapGraphDominatorTree
 from diff_tests.stdlib.memory.tests import Memory
 from diff_tests.stdlib.pkvm.tests import Pkvm
@@ -270,7 +269,7 @@
 
   stdlib_tests = [
       *AndroidStdlib(index_path, 'stdlib/android', 'AndroidStdlib').fetch(),
-      *Cpu(index_path, 'stdlib/cpu', 'Cpu').fetch(),
+      *LinuxCpu(index_path, 'stdlib/linux/cpu', 'LinuxCpu').fetch(),
       *DominatorTree(index_path, 'stdlib/graphs', 'DominatorTree').fetch(),
       *ExportTests(index_path, 'stdlib/export', 'ExportTests').fetch(),
       *Frames(index_path, 'stdlib/android', 'Frames').fetch(),
@@ -283,7 +282,6 @@
                               'StdlibCounterIntervals').fetch(),
       *DynamicTables(index_path, 'stdlib/dynamic_tables',
                      'DynamicTables').fetch(),
-      *LinuxStdlib(index_path, 'stdlib/linux', 'LinuxStdlib').fetch(),
       *Memory(index_path, 'stdlib/memory', 'Memory').fetch(),
       *PreludeMathFunctions(index_path, 'stdlib/prelude',
                             'PreludeMathFunctions').fetch(),
diff --git a/test/trace_processor/diff_tests/stdlib/cpu/tests.py b/test/trace_processor/diff_tests/stdlib/linux/cpu.py
similarity index 78%
rename from test/trace_processor/diff_tests/stdlib/cpu/tests.py
rename to test/trace_processor/diff_tests/stdlib/linux/cpu.py
index 32458a2..b1a4a07 100644
--- a/test/trace_processor/diff_tests/stdlib/cpu/tests.py
+++ b/test/trace_processor/diff_tests/stdlib/linux/cpu.py
@@ -13,12 +13,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from python.generators.diff_tests.testing import Csv, Path, DataPath
+from python.generators.diff_tests.testing import Csv, DataPath, TextProto
 from python.generators.diff_tests.testing import DiffTestBlueprint
 from python.generators.diff_tests.testing import TestSuite
 
 
-class Cpu(TestSuite):
+class LinuxCpu(TestSuite):
 
   def test_cpu_utilization_per_second(self):
     return DiffTestBlueprint(
@@ -189,13 +189,13 @@
     return DiffTestBlueprint(
         trace=DataPath('android_cpu_eos.pb'),
         query=("""
-             INCLUDE PERFETTO MODULE cpu.freq;
+             INCLUDE PERFETTO MODULE linux.cpu.frequency;
              select
                track_id,
                freq,
                cpu,
                sum(dur) as dur
-             from cpu_freq_counters
+             from cpu_frequency_counters
              GROUP BY freq, cpu
              """),
         out=Csv("""
@@ -223,7 +223,7 @@
     return DiffTestBlueprint(
         trace=DataPath('android_cpu_eos.pb'),
         query=("""
-             INCLUDE PERFETTO MODULE cpu.idle;
+             INCLUDE PERFETTO MODULE linux.cpu.idle;
              select
                track_id,
                idle,
@@ -247,3 +247,80 @@
              32,1,2,5532102915
              1,1,3,5462026920
             """))
+
+  def test_linux_cpu_idle_stats(self):
+      return DiffTestBlueprint(
+          trace=TextProto(r"""
+          packet {
+            ftrace_events {
+              cpu: 0
+              event: {
+                timestamp: 200000000000
+                pid: 2
+                cpu_frequency: {
+                  state : 1704000
+                  cpu_id: 0
+                }
+              }
+              event: {
+                timestamp: 200000000000
+                pid: 2
+                cpu_idle: {
+                  state: 4294967295
+                  cpu_id: 0
+                }
+              }
+              event {
+                timestamp: 200001000000
+                pid: 2
+                cpu_idle: {
+                  state : 1
+                  cpu_id: 0
+                }
+              }
+              event: {
+                timestamp: 200002000000
+                pid  : 2
+                cpu_idle: {
+                  state : 4294967295
+                  cpu_id: 0
+                }
+              }
+              event {
+                timestamp: 200003000000
+                pid: 2
+                cpu_idle: {
+                  state : 1
+                  cpu_id: 0
+                }
+              }
+              event: {
+                timestamp: 200004000000
+                pid: 2
+                cpu_idle: {
+                  state : 4294967295
+                  cpu_id: 0
+                }
+              }
+              event: {
+                timestamp: 200005000000
+                pid: 2
+                cpu_frequency: {
+                  state: 300000
+                  cpu_id: 0
+                }
+              }
+            }
+            trusted_uid: 9999
+            trusted_packet_sequence_id: 2
+          }
+         """),
+         query="""
+         INCLUDE PERFETTO MODULE linux.cpu.idle;
+         SELECT * FROM cpu_idle_stats;
+         """,
+         out=Csv("""
+         "cpu","state","count","dur","avg_dur","idle_percent"
+         0,2,2,2000000,1000000,40.000000
+         """))
+
diff --git a/test/trace_processor/diff_tests/stdlib/linux/tests.py b/test/trace_processor/diff_tests/stdlib/linux/tests.py
deleted file mode 100644
index b2e8135..0000000
--- a/test/trace_processor/diff_tests/stdlib/linux/tests.py
+++ /dev/null
@@ -1,99 +0,0 @@
-#!/usr/bin/env python3
-# Copyright (C) 2023 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 a
-#
-#      http://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.
-
-from python.generators.diff_tests.testing import Path, DataPath, Metric
-from python.generators.diff_tests.testing import Csv, Json, TextProto
-from python.generators.diff_tests.testing import DiffTestBlueprint
-from python.generators.diff_tests.testing import TestSuite
-
-
-class LinuxStdlib(TestSuite):
-
-  def test_linux_cpu_idle_stats(self):
-      return DiffTestBlueprint(
-          trace=TextProto(r"""
-          packet {
-            ftrace_events {
-              cpu: 0
-              event: {
-                timestamp: 200000000000
-                pid: 2
-                cpu_frequency: {
-                  state : 1704000
-                  cpu_id: 0
-                }
-              }
-              event: {
-                timestamp: 200000000000
-                pid: 2
-                cpu_idle: {
-                  state: 4294967295
-                  cpu_id: 0
-                }
-              }
-              event {
-                timestamp: 200001000000
-                pid: 2
-                cpu_idle: {
-                  state : 1
-                  cpu_id: 0
-                }
-              }
-              event: {
-                timestamp: 200002000000
-                pid  : 2
-                cpu_idle: {
-                  state : 4294967295
-                  cpu_id: 0
-                }
-              }
-              event {
-                timestamp: 200003000000
-                pid: 2
-                cpu_idle: {
-                  state : 1
-                  cpu_id: 0
-                }
-              }
-              event: {
-                timestamp: 200004000000
-                pid: 2
-                cpu_idle: {
-                  state : 4294967295
-                  cpu_id: 0
-                }
-              }
-              event: {
-                timestamp: 200005000000
-                pid: 2
-                cpu_frequency: {
-                  state: 300000
-                  cpu_id: 0
-                }
-              }
-            }
-            trusted_uid: 9999
-            trusted_packet_sequence_id: 2
-          }
-         """),
-         query="""
-         INCLUDE PERFETTO MODULE linux.cpu_idle;
-         SELECT * FROM linux_cpu_idle_stats;
-         """,
-         out=Csv("""
-         "cpu","state","count","dur","avg_dur","idle_percent"
-         0,2,2,2000000,1000000,50.000013
-         """))
-