Skip to content

Commit

Permalink
Use cluster_cpus_list to detect clusters for ARM
Browse files Browse the repository at this point in the history
On newer kernels (6.x+) a separate topology node exists to express the
list of cpus associated with each cluster. The cluster topology node
explicitly refers to cores that share some resources (e.g. cache) as
opposed to 'core_siblings', which only indicate they are on the same
physical package.

This distinction is relevant on 6.x, where some devices may have all
their cores on a single physical package but cores do not all share the
same resources on that package. In these cases, the existing logic
incorrectly reports that there is a single cluster (because all cores
are siblings), even though not all cores share the same resources.

Test: Verified on ARM64 Android device that has multiple clusters, where
core_siblings reports all cores are siblings.
Test: Added mock hardware tests, verified pass on ARM64 hardware.
  • Loading branch information
prashanthswami committed Apr 23, 2024
1 parent 3c8b153 commit f99a280
Show file tree
Hide file tree
Showing 7 changed files with 2,961 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,11 @@ IF(CPUINFO_SUPPORTED_PLATFORM AND CPUINFO_BUILD_MOCK_TESTS)
TARGET_LINK_LIBRARIES(pixel-2-xl-test PRIVATE cpuinfo_mock gtest)
ADD_TEST(NAME pixel-2-xl-test COMMAND pixel-2-xl-test)

ADD_EXECUTABLE(pixel-8-test test/mock/pixel-8.cc)
TARGET_INCLUDE_DIRECTORIES(pixel-8-test BEFORE PRIVATE test/mock)
TARGET_LINK_LIBRARIES(pixel-8-test PRIVATE cpuinfo_mock gtest)
ADD_TEST(NAME pixel-8-test COMMAND pixel-8-test)

ADD_EXECUTABLE(xiaomi-mi-5c-test test/mock/xiaomi-mi-5c.cc)
TARGET_INCLUDE_DIRECTORIES(xiaomi-mi-5c-test BEFORE PRIVATE test/mock)
TARGET_LINK_LIBRARIES(xiaomi-mi-5c-test PRIVATE cpuinfo_mock gtest)
Expand Down
2 changes: 2 additions & 0 deletions scripts/android-arm64-mock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ adb push build/android/arm64-v8a/pixel-c-test /data/local/tmp/pixel-c-test
adb push build/android/arm64-v8a/pixel-xl-test /data/local/tmp/pixel-xl-test
adb push build/android/arm64-v8a/pixel-test /data/local/tmp/pixel-test
adb push build/android/arm64-v8a/pixel-2-xl-test /data/local/tmp/pixel-2-xl-test
adb push build/android/arm64-v8a/pixel-8-test /data/local/tmp/pixel-8-test
adb push build/android/arm64-v8a/xiaomi-mi-5c-test /data/local/tmp/xiaomi-mi-5c-test
adb push build/android/arm64-v8a/xiaomi-redmi-note-3-test /data/local/tmp/xiaomi-redmi-note-3-test
adb push build/android/arm64-v8a/xiaomi-redmi-note-4-test /data/local/tmp/xiaomi-redmi-note-4-test
Expand Down Expand Up @@ -75,6 +76,7 @@ adb shell "/data/local/tmp/pixel-c-test --gtest_color=yes"
adb shell "/data/local/tmp/pixel-xl-test --gtest_color=yes"
adb shell "/data/local/tmp/pixel-test --gtest_color=yes"
adb shell "/data/local/tmp/pixel-2-xl-test --gtest_color=yes"
adb shell "/data/local/tmp/pixel-8-test --gtest_color=yes"
adb shell "/data/local/tmp/xiaomi-mi-5c-test --gtest_color=yes"
adb shell "/data/local/tmp/xiaomi-redmi-note-3-test --gtest_color=yes"
adb shell "/data/local/tmp/xiaomi-redmi-note-4-test --gtest_color=yes"
Expand Down
2 changes: 2 additions & 0 deletions scripts/android-armv7-mock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ adb push build/android/armeabi-v7a/pixel-c-test /data/local/tmp/pixel-c-test
adb push build/android/armeabi-v7a/pixel-xl-test /data/local/tmp/pixel-xl-test
adb push build/android/armeabi-v7a/pixel-test /data/local/tmp/pixel-test
adb push build/android/armeabi-v7a/pixel-2-xl-test /data/local/tmp/pixel-2-xl-test
adb push build/android/armeabi-v7a/pixel-8-test /data/local/tmp/pixel-8-test
adb push build/android/armeabi-v7a/xiaomi-mi-5c-test /data/local/tmp/xiaomi-mi-5c-test
adb push build/android/armeabi-v7a/xiaomi-redmi-2a-test /data/local/tmp/xiaomi-redmi-2a-test
adb push build/android/armeabi-v7a/xiaomi-redmi-note-3-test /data/local/tmp/xiaomi-redmi-note-3-test
Expand Down Expand Up @@ -145,6 +146,7 @@ adb shell "/data/local/tmp/pixel-c-test --gtest_color=yes"
adb shell "/data/local/tmp/pixel-xl-test --gtest_color=yes"
adb shell "/data/local/tmp/pixel-test --gtest_color=yes"
adb shell "/data/local/tmp/pixel-2-xl-test --gtest_color=yes"
adb shell "/data/local/tmp/pixel-8-test --gtest_color=yes"
adb shell "/data/local/tmp/xiaomi-mi-5c-test --gtest_color=yes"
adb shell "/data/local/tmp/xiaomi-redmi-2a-test --gtest_color=yes"
adb shell "/data/local/tmp/xiaomi-redmi-note-3-test --gtest_color=yes"
Expand Down
36 changes: 35 additions & 1 deletion src/arm/linux/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,52 @@ void cpuinfo_arm_linux_init(void) {
}

/* Propagate topology group IDs among siblings */
bool detected_core_siblings_list_node = false;
bool detected_cluster_cpus_list_node = false;
for (uint32_t i = 0; i < arm_linux_processors_count; i++) {
if (!bitmask_all(arm_linux_processors[i].flags, CPUINFO_LINUX_FLAG_VALID)) {
continue;
}

if (arm_linux_processors[i].flags & CPUINFO_LINUX_FLAG_PACKAGE_ID) {
if (!bitmask_all(arm_linux_processors[i].flags, CPUINFO_LINUX_FLAG_PACKAGE_ID)) {
continue;
}

/* Use the cluster_cpus_list topology node if available. If not
* found, cache the result to avoid repeatedly attempting to
* read the non-existent paths.
* */
if (!detected_core_siblings_list_node && !detected_cluster_cpus_list_node) {
if (cpuinfo_linux_detect_cluster_cpus(
arm_linux_processors_count,
i,
(cpuinfo_siblings_callback)cluster_siblings_parser,
arm_linux_processors)) {
detected_cluster_cpus_list_node = true;
continue;
} else {
detected_core_siblings_list_node = true;
}
}

/* The cached result above will guarantee only one of the blocks
* below will execute, with a bias towards cluster_cpus_list.
**/
if (detected_core_siblings_list_node) {
cpuinfo_linux_detect_core_siblings(
arm_linux_processors_count,
i,
(cpuinfo_siblings_callback)cluster_siblings_parser,
arm_linux_processors);
}

if (detected_cluster_cpus_list_node) {
cpuinfo_linux_detect_cluster_cpus(
arm_linux_processors_count,
i,
(cpuinfo_siblings_callback)cluster_siblings_parser,
arm_linux_processors);
}
}

/* Propagate all cluster IDs */
Expand Down
Loading

0 comments on commit f99a280

Please sign in to comment.