From: svenpanne@chromium.org Date: Fri, 2 May 2014 12:35:51 +0000 (+0000) Subject: Move cache line size calculation directly into CPU::FlushICache. X-Git-Tag: upstream/4.7.83~9294 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=461bb09b4aca295a408cc3c5a563db374929327f;p=platform%2Fupstream%2Fv8.git Move cache line size calculation directly into CPU::FlushICache. This disentagles the initialization/dependency mess quite a bit and makes things vastly simpler. If the 'mrs' on every flush is too expensive (which it is hopefully not), the cache line sizes will have to be instance variables of the CPU class and FlushICache will have to be a member function. This would involve some more or less tricky refactorings, which we shouldn't do until we are *really* forced to do. BUG=359977 LOG=y R=rodolph.perfetta@gmail.com Review URL: https://codereview.chromium.org/269543016 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21119 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/arm64/cpu-arm64.cc b/src/arm64/cpu-arm64.cc index c360f0a..0e1ed91 100644 --- a/src/arm64/cpu-arm64.cc +++ b/src/arm64/cpu-arm64.cc @@ -18,19 +18,37 @@ namespace internal { bool CpuFeatures::initialized_ = false; #endif unsigned CpuFeatures::supported_ = 0; -unsigned CpuFeatures::found_by_runtime_probing_only_ = 0; unsigned CpuFeatures::cross_compile_ = 0; -// Initialise to smallest possible cache size. -unsigned CpuFeatures::dcache_line_size_ = 1; -unsigned CpuFeatures::icache_line_size_ = 1; +class CacheLineSizes { + public: + CacheLineSizes() { +#ifdef USE_SIMULATOR + cache_type_register_ = 0; +#else + // Copy the content of the cache type register to a core register. + __asm__ __volatile__ ("mrs %[ctr], ctr_el0" // NOLINT + : [ctr] "=r" (cache_type_register_)); +#endif + }; -void CPU::FlushICache(void* address, size_t length) { - if (length == 0) { - return; + uint32_t icache_line_size() const { return ExtractCacheLineSize(0); } + uint32_t dcache_line_size() const { return ExtractCacheLineSize(16); } + + private: + uint32_t ExtractCacheLineSize(int cache_line_size_shift) const { + // The cache type register holds the size of the caches as a power of two. + return 1 << ((cache_type_register_ >> cache_line_size_shift) & 0xf); } + uint32_t cache_type_register_; +}; + + +void CPU::FlushICache(void* address, size_t length) { + if (length == 0) return; + #ifdef USE_SIMULATOR // TODO(all): consider doing some cache simulation to ensure every address // run has been synced. @@ -43,8 +61,9 @@ void CPU::FlushICache(void* address, size_t length) { uintptr_t start = reinterpret_cast(address); // Sizes will be used to generate a mask big enough to cover a pointer. - uintptr_t dsize = static_cast(CpuFeatures::dcache_line_size()); - uintptr_t isize = static_cast(CpuFeatures::icache_line_size()); + CacheLineSizes sizes; + uintptr_t dsize = sizes.dcache_line_size(); + uintptr_t isize = sizes.icache_line_size(); // Cache line sizes are always a power of 2. ASSERT(CountSetBits(dsize, 64) == 1); ASSERT(CountSetBits(isize, 64) == 1); @@ -107,25 +126,6 @@ void CPU::FlushICache(void* address, size_t length) { void CpuFeatures::Probe(bool serializer_enabled) { - // Compute I and D cache line size. The cache type register holds - // information about the caches. - uint32_t cache_type_register = GetCacheType(); - - static const int kDCacheLineSizeShift = 16; - static const int kICacheLineSizeShift = 0; - static const uint32_t kDCacheLineSizeMask = 0xf << kDCacheLineSizeShift; - static const uint32_t kICacheLineSizeMask = 0xf << kICacheLineSizeShift; - - // The cache type register holds the size of the I and D caches as a power of - // two. - uint32_t dcache_line_size_power_of_two = - (cache_type_register & kDCacheLineSizeMask) >> kDCacheLineSizeShift; - uint32_t icache_line_size_power_of_two = - (cache_type_register & kICacheLineSizeMask) >> kICacheLineSizeShift; - - dcache_line_size_ = 1 << dcache_line_size_power_of_two; - icache_line_size_ = 1 << icache_line_size_power_of_two; - // AArch64 has no configuration options, no further probing is required. supported_ = 0; @@ -135,32 +135,6 @@ void CpuFeatures::Probe(bool serializer_enabled) { } -unsigned CpuFeatures::dcache_line_size() { - ASSERT(initialized_); - return dcache_line_size_; -} - - -unsigned CpuFeatures::icache_line_size() { - ASSERT(initialized_); - return icache_line_size_; -} - - -uint32_t CpuFeatures::GetCacheType() { -#ifdef USE_SIMULATOR - // This will lead to a cache with 1 byte long lines, which is fine since the - // simulator will not need this information. - return 0; -#else - uint32_t cache_type_register; - // Copy the content of the cache type register to a core register. - __asm__ __volatile__ ("mrs %[ctr], ctr_el0" // NOLINT - : [ctr] "=r" (cache_type_register)); - return cache_type_register; -#endif -} - } } // namespace v8::internal #endif // V8_TARGET_ARCH_ARM64 diff --git a/src/arm64/cpu-arm64.h b/src/arm64/cpu-arm64.h index ec3b19d..4f7b499 100644 --- a/src/arm64/cpu-arm64.h +++ b/src/arm64/cpu-arm64.h @@ -61,20 +61,11 @@ class CpuFeatures : public AllStatic { static bool SupportsCrankshaft() { return true; } private: - // Return the content of the cache type register. - static uint32_t GetCacheType(); - - // I and D cache line size in bytes. - static unsigned icache_line_size_; - static unsigned dcache_line_size_; - #ifdef DEBUG static bool initialized_; #endif // This isn't used (and is always 0), but it is required by V8. - static unsigned found_by_runtime_probing_only_; - static unsigned cross_compile_; friend class PlatformFeatureScope;