System: Use cpuinfo for cache line size check
This commit is contained in:
@ -137,7 +137,7 @@ target_precompile_headers(core PRIVATE "pch.h")
|
||||
target_include_directories(core PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||
target_include_directories(core PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||
target_link_libraries(core PUBLIC Threads::Threads common util ZLIB::ZLIB)
|
||||
target_link_libraries(core PRIVATE xxhash imgui rapidyaml rcheevos)
|
||||
target_link_libraries(core PRIVATE xxhash imgui rapidyaml rcheevos cpuinfo::cpuinfo)
|
||||
|
||||
if(CPU_ARCH_X64)
|
||||
target_compile_definitions(core PUBLIC "ENABLE_RECOMPILER=1" "ENABLE_NEWREC=1" "ENABLE_MMAP_FASTMEM=1")
|
||||
|
||||
@ -54,6 +54,7 @@
|
||||
#include "common/string_util.h"
|
||||
#include "common/threading.h"
|
||||
|
||||
#include "cpuinfo.h"
|
||||
#include "fmt/chrono.h"
|
||||
#include "fmt/format.h"
|
||||
#include "imgui.h"
|
||||
@ -303,18 +304,43 @@ bool System::Internal::PerformEarlyHardwareChecks(Error* error)
|
||||
|
||||
void System::CheckCacheLineSize()
|
||||
{
|
||||
const size_t runtime_cache_line_size = PlatformMisc::GetRuntimeCacheLineSize();
|
||||
if (runtime_cache_line_size == 0)
|
||||
u32 max_line_size = 0;
|
||||
if (cpuinfo_initialize())
|
||||
{
|
||||
const u32 num_l1is = cpuinfo_get_l1i_caches_count();
|
||||
const u32 num_l1ds = cpuinfo_get_l1d_caches_count();
|
||||
const u32 num_l2s = cpuinfo_get_l2_caches_count();
|
||||
for (u32 i = 0; i < num_l1is; i++)
|
||||
{
|
||||
const cpuinfo_cache* cache = cpuinfo_get_l1i_cache(i);
|
||||
if (cache)
|
||||
max_line_size = std::max(max_line_size, cache->line_size);
|
||||
}
|
||||
for (u32 i = 0; i < num_l1ds; i++)
|
||||
{
|
||||
const cpuinfo_cache* cache = cpuinfo_get_l1d_cache(i);
|
||||
if (cache)
|
||||
max_line_size = std::max(max_line_size, cache->line_size);
|
||||
}
|
||||
for (u32 i = 0; i < num_l2s; i++)
|
||||
{
|
||||
const cpuinfo_cache* cache = cpuinfo_get_l2_cache(i);
|
||||
if (cache)
|
||||
max_line_size = std::max(max_line_size, cache->line_size);
|
||||
}
|
||||
}
|
||||
|
||||
if (max_line_size == 0)
|
||||
{
|
||||
ERROR_LOG("Cannot determine size of cache line. Continuing with expectation of {} byte lines.",
|
||||
runtime_cache_line_size);
|
||||
HOST_CACHE_LINE_SIZE);
|
||||
}
|
||||
else if (HOST_CACHE_LINE_SIZE != runtime_cache_line_size)
|
||||
else if (HOST_CACHE_LINE_SIZE != max_line_size)
|
||||
{
|
||||
// Not fatal, but does have performance implications.
|
||||
WARNING_LOG(
|
||||
"Cache line size mismatch. This build was compiled with {} byte lines, but the system has {} byte lines.",
|
||||
HOST_CACHE_LINE_SIZE, runtime_cache_line_size);
|
||||
HOST_CACHE_LINE_SIZE, max_line_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user