diff options
author | Ruy Contributors <ruy-eng@google.com> | 2024-03-21 13:37:27 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-03-21 13:38:08 -0700 |
commit | c08ec529fc91722bde519628d9449258082eb847 (patch) | |
tree | 94d13e5cd31b3fb7ec34bd2f6ef3fa941277c353 | |
parent | 587c2cf8b11d3c32fa26887063eda3171a3d353e (diff) | |
download | ruy-upstream-master.tar.gz |
Change QueryCacheParams to return if there was an error and handle that during Initializeupstream-master
PiperOrigin-RevId: 617949545
-rw-r--r-- | ruy/cpuinfo.cc | 19 | ||||
-rw-r--r-- | 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<int>::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 <cstdio> #include <mutex> -#include <string> #include <vector> #endif |