From ff92d10a0485717149b6cebc7122a3d545d48fd3 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Mon, 13 Jan 2025 05:43:09 +1100 Subject: osd: Added helper for getting CPU cache line size. --- src/osd/modules/lib/osdlib_unix.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/osd/modules/lib/osdlib_unix.cpp') diff --git a/src/osd/modules/lib/osdlib_unix.cpp b/src/osd/modules/lib/osdlib_unix.cpp index 20f6a9ab40c..36004580222 100644 --- a/src/osd/modules/lib/osdlib_unix.cpp +++ b/src/osd/modules/lib/osdlib_unix.cpp @@ -53,6 +53,7 @@ void osd_process_kill() kill(getpid(), SIGKILL); } + //============================================================ // osd_break_into_debugger //============================================================ @@ -68,6 +69,31 @@ void osd_break_into_debugger(const char *message) #endif } + +//============================================================ +// osd_get_cache_line_size +//============================================================ + +std::pair osd_get_cache_line_size() noexcept +{ +#if defined(__linux__) + FILE *const f = std::fopen("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size", "r"); + if (!f) + return std::make_pair(std::error_condition(errno, std::generic_category()), 0U); + + unsigned result = 0; + auto const cnt = std::fscanf(f, "%u", &result); + std::fclose(f); + if (1 == cnt) + return std::make_pair(std::error_condition(), result); + else + return std::make_pair(std::errc::io_error, 0U); +#else // defined(__linux__) + return std::make_pair(std::errc::not_supported, 0U); +#endif +} + + #ifdef SDLMAME_ANDROID std::string osd_get_clipboard_text() noexcept { -- cgit v1.2.3-70-g09d2