From c08ec529fc91722bde519628d9449258082eb847 Mon Sep 17 00:00:00 2001 From: Ruy Contributors Date: Thu, 21 Mar 2024 13:37:27 -0700 Subject: Change QueryCacheParams to return if there was an error and handle that during Initialize PiperOrigin-RevId: 617949545 --- ruy/cpuinfo.cc | 19 +++++++++++++------ ruy/profiler/instrumentation.h | 1 - 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ruy/cpuinfo.cc b/ruy/cpuinfo.cc index 0969cd7..5daee0b 100644 --- a/ruy/cpuinfo.cc +++ b/ruy/cpuinfo.cc @@ -39,7 +39,7 @@ bool CpuInfo::EnsureInitialized() { } namespace { -void QueryCacheParams(CpuCacheParams* cache_params) { +bool QueryCacheParams(CpuCacheParams* cache_params) { const int processors_count = cpuinfo_get_processors_count(); RUY_DCHECK_GT(processors_count, 0); int overall_local_cache_size = std::numeric_limits::max(); @@ -57,14 +57,16 @@ void QueryCacheParams(CpuCacheParams* cache_params) { // L2. } if (!cache->processor_count) { - continue; // crashes from Chrome on Android suggests that might happen? + // This may happen in a sand-boxed process, e.g.: a browser renderer. + continue; } const cpuinfo_processor* processor_start = cpuinfo_get_processor(cache->processor_start); const cpuinfo_processor* processor_end = cpuinfo_get_processor( cache->processor_start + cache->processor_count - 1); if (!processor_start || !processor_end) { - continue; // crashes from Chrome on Android suggests this might happen. + // This may happen in a sand-boxed process, e.g.: a browser renderer. + continue; } const bool is_local = processor_start->core == processor_end->core; if (is_local) { @@ -76,8 +78,9 @@ void QueryCacheParams(CpuCacheParams* cache_params) { if (!local_cache_size) { local_cache_size = last_level_cache_size; } - RUY_DCHECK_GT(local_cache_size, 0); - RUY_DCHECK_GT(last_level_cache_size, 0); + if (local_cache_size == 0 || last_level_cache_size == 0) { + return false; + } RUY_DCHECK_GE(last_level_cache_size, local_cache_size); overall_local_cache_size = std::min(overall_local_cache_size, local_cache_size); @@ -86,6 +89,7 @@ void QueryCacheParams(CpuCacheParams* cache_params) { } cache_params->local_cache_size = overall_local_cache_size; cache_params->last_level_cache_size = overall_last_level_cache_size; + return true; } } // end namespace @@ -95,7 +99,10 @@ CpuInfo::InitStatus CpuInfo::Initialize() { MakeDummyCacheParams(&cache_params_); return InitStatus::kFailed; } - QueryCacheParams(&cache_params_); + if (!QueryCacheParams(&cache_params_)) { + MakeDummyCacheParams(&cache_params_); + return InitStatus::kFailed; + } return InitStatus::kInitialized; } diff --git a/ruy/profiler/instrumentation.h b/ruy/profiler/instrumentation.h index 2b15ae3..c4df1e6 100644 --- a/ruy/profiler/instrumentation.h +++ b/ruy/profiler/instrumentation.h @@ -19,7 +19,6 @@ limitations under the License. #ifdef RUY_PROFILER #include #include -#include #include #endif -- cgit v1.2.3