From 34b4448a8163c7a42dfcc44fbcca06db0d0d7173 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 13 Jun 2025 03:57:13 +0700 Subject: [PATCH] Split BasicCpuInfo_arm. --- src/backend/cpu/cpu.cmake | 11 +++- src/backend/cpu/platform/BasicCpuInfo.h | 6 +- src/backend/cpu/platform/BasicCpuInfo_arm.cpp | 53 +-------------- .../cpu/platform/BasicCpuInfo_arm_mac.cpp | 32 +++++++++ .../cpu/platform/BasicCpuInfo_arm_unix.cpp | 65 +++++++++++++++++++ .../cpu/platform/BasicCpuInfo_arm_win.cpp | 27 ++++++++ 6 files changed, 138 insertions(+), 56 deletions(-) create mode 100644 src/backend/cpu/platform/BasicCpuInfo_arm_mac.cpp create mode 100644 src/backend/cpu/platform/BasicCpuInfo_arm_unix.cpp create mode 100644 src/backend/cpu/platform/BasicCpuInfo_arm_win.cpp diff --git a/src/backend/cpu/cpu.cmake b/src/backend/cpu/cpu.cmake index c485683a..f9a02abd 100644 --- a/src/backend/cpu/cpu.cmake +++ b/src/backend/cpu/cpu.cmake @@ -49,8 +49,15 @@ endif() if (XMRIG_ARM) list(APPEND SOURCES_BACKEND_CPU src/backend/cpu/platform/BasicCpuInfo_arm.cpp) - if (XMRIG_OS_UNIX) - list(APPEND SOURCES_BACKEND_CPU src/backend/cpu/platform/lscpu_arm.cpp) + if (XMRIG_OS_WIN) + list(APPEND SOURCES_BACKEND_CPU src/backend/cpu/platform/BasicCpuInfo_arm_win.cpp) + elseif(XMRIG_OS_APPLE) + list(APPEND SOURCES_BACKEND_CPU src/backend/cpu/platform/BasicCpuInfo_arm_mac.cpp) + else() + list(APPEND SOURCES_BACKEND_CPU + src/backend/cpu/platform/lscpu_arm.cpp + src/backend/cpu/platform/BasicCpuInfo_arm_unix.cpp + ) endif() else() list(APPEND SOURCES_BACKEND_CPU src/backend/cpu/platform/BasicCpuInfo.cpp) diff --git a/src/backend/cpu/platform/BasicCpuInfo.h b/src/backend/cpu/platform/BasicCpuInfo.h index f56d5425..5ea5661d 100644 --- a/src/backend/cpu/platform/BasicCpuInfo.h +++ b/src/backend/cpu/platform/BasicCpuInfo.h @@ -1,7 +1,7 @@ /* XMRig * Copyright (c) 2017-2019 XMR-Stak , - * Copyright (c) 2018-2023 SChernykh - * Copyright (c) 2016-2023 XMRig + * Copyright (c) 2018-2025 SChernykh + * Copyright (c) 2016-2025 XMRig * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -85,6 +85,8 @@ private: uint32_t m_family = 0; uint32_t m_model = 0; uint32_t m_stepping = 0; +# else + void init_arm(); # endif Assembly m_assembly = Assembly::NONE; diff --git a/src/backend/cpu/platform/BasicCpuInfo_arm.cpp b/src/backend/cpu/platform/BasicCpuInfo_arm.cpp index 3a88a756..476d150c 100644 --- a/src/backend/cpu/platform/BasicCpuInfo_arm.cpp +++ b/src/backend/cpu/platform/BasicCpuInfo_arm.cpp @@ -16,44 +16,16 @@ * along with this program. If not, see . */ -#include "base/tools/String.h" - - #include #include #include #include -#if __ARM_FEATURE_CRYPTO && !defined(__APPLE__) && !defined(XMRIG_OS_WIN) -# include -# if !defined(XMRIG_OS_FREEBSD) -# include -# else -# include -# include -# ifndef ID_AA64ISAR0_AES_VAL -# define ID_AA64ISAR0_AES_VAL ID_AA64ISAR0_AES -# endif -# endif -#endif - - #include "backend/cpu/platform/BasicCpuInfo.h" #include "3rdparty/rapidjson/document.h" -#if defined(XMRIG_OS_UNIX) -namespace xmrig { - -extern String cpu_name_arm(); - -} // namespace xmrig -#elif defined(XMRIG_OS_MACOS) -# include -#endif - - xmrig::BasicCpuInfo::BasicCpuInfo() : m_threads(std::thread::hardware_concurrency()) { @@ -68,30 +40,7 @@ xmrig::BasicCpuInfo::BasicCpuInfo() : memcpy(m_brand, "ARMv7", 5); # endif -# if __ARM_FEATURE_CRYPTO -# if defined(__APPLE__) - m_flags.set(FLAG_AES, true); -# elif defined(XMRIG_OS_FREEBSD) - uint64_t isar0 = READ_SPECIALREG(id_aa64isar0_el1); - m_flags.set(FLAG_AES, ID_AA64ISAR0_AES_VAL(isar0) >= ID_AA64ISAR0_AES_BASE); -# elif (defined(XMRIG_OS_WIN)) - m_flags.set(FLAG_AES, true); // FIXME -# else - m_flags.set(FLAG_AES, getauxval(AT_HWCAP) & HWCAP_AES); -# endif -# endif - -# if defined(XMRIG_OS_UNIX) - auto name = cpu_name_arm(); - if (!name.isNull()) { - strncpy(m_brand, name, sizeof(m_brand) - 1); - } - - m_flags.set(FLAG_PDPE1GB, std::ifstream("/sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages").good()); -# elif defined(XMRIG_OS_MACOS) - size_t buflen = sizeof(m_brand); - sysctlbyname("machdep.cpu.brand_string", &m_brand, &buflen, nullptr, 0); -# endif + init_arm(); } diff --git a/src/backend/cpu/platform/BasicCpuInfo_arm_mac.cpp b/src/backend/cpu/platform/BasicCpuInfo_arm_mac.cpp new file mode 100644 index 00000000..f1c35c6f --- /dev/null +++ b/src/backend/cpu/platform/BasicCpuInfo_arm_mac.cpp @@ -0,0 +1,32 @@ +/* XMRig + * Copyright (c) 2018-2025 SChernykh + * Copyright (c) 2016-2025 XMRig + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "backend/cpu/platform/BasicCpuInfo.h" + +#include + + +void xmrig::BasicCpuInfo::init_arm() +{ +# if __ARM_FEATURE_CRYPTO + m_flags.set(FLAG_AES, true); // FIXME +# endif + + size_t buflen = sizeof(m_brand); + sysctlbyname("machdep.cpu.brand_string", &m_brand, &buflen, nullptr, 0); +} diff --git a/src/backend/cpu/platform/BasicCpuInfo_arm_unix.cpp b/src/backend/cpu/platform/BasicCpuInfo_arm_unix.cpp new file mode 100644 index 00000000..98faf9b9 --- /dev/null +++ b/src/backend/cpu/platform/BasicCpuInfo_arm_unix.cpp @@ -0,0 +1,65 @@ +/* XMRig + * Copyright (c) 2018-2025 SChernykh + * Copyright (c) 2016-2025 XMRig + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "backend/cpu/platform/BasicCpuInfo.h" +#include "base/tools/String.h" + + +#if __ARM_FEATURE_CRYPTO +# include +# if !defined(XMRIG_OS_FREEBSD) +# include +# else +# include +# include +# ifndef ID_AA64ISAR0_AES_VAL +# define ID_AA64ISAR0_AES_VAL ID_AA64ISAR0_AES +# endif +# endif +#endif + + +namespace xmrig { + + +extern String cpu_name_arm(); + + +} // namespace xmrig + + +void xmrig::BasicCpuInfo::init_arm() +{ +# if __ARM_FEATURE_CRYPTO +# if defined(XMRIG_OS_FREEBSD) + uint64_t isar0 = READ_SPECIALREG(id_aa64isar0_el1); + m_flags.set(FLAG_AES, ID_AA64ISAR0_AES_VAL(isar0) >= ID_AA64ISAR0_AES_BASE); +# else + m_flags.set(FLAG_AES, getauxval(AT_HWCAP) & HWCAP_AES); +# endif +# endif + +# if defined(XMRIG_OS_UNIX) + auto name = cpu_name_arm(); + if (!name.isNull()) { + strncpy(m_brand, name, sizeof(m_brand) - 1); + } + + m_flags.set(FLAG_PDPE1GB, std::ifstream("/sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages").good()); +# endif +} diff --git a/src/backend/cpu/platform/BasicCpuInfo_arm_win.cpp b/src/backend/cpu/platform/BasicCpuInfo_arm_win.cpp new file mode 100644 index 00000000..623248a1 --- /dev/null +++ b/src/backend/cpu/platform/BasicCpuInfo_arm_win.cpp @@ -0,0 +1,27 @@ +/* XMRig + * Copyright (c) 2018-2025 SChernykh + * Copyright (c) 2016-2025 XMRig + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "backend/cpu/platform/BasicCpuInfo.h" + + +void xmrig::BasicCpuInfo::init_arm() +{ +# if __ARM_FEATURE_CRYPTO + m_flags.set(FLAG_AES, true); // FIXME +# endif +}