From e522ec23f993979256cfd53190adde33ce623f88 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 13 Jan 2016 05:11:40 +0300 Subject: [PATCH] dbms: porting to aarch64 [#METR-19609]. --- .../DB/Common/getNumberOfPhysicalCPUCores.h | 4 ++ dbms/include/DB/Core/Defines.h | 6 +++ dbms/include/DB/Interpreters/SettingsCommon.h | 15 ++------ .../Common/getNumberOfPhysicalCPUCores.cpp | 38 +++++++++++++++++++ 4 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 dbms/include/DB/Common/getNumberOfPhysicalCPUCores.h create mode 100644 dbms/src/Common/getNumberOfPhysicalCPUCores.cpp diff --git a/dbms/include/DB/Common/getNumberOfPhysicalCPUCores.h b/dbms/include/DB/Common/getNumberOfPhysicalCPUCores.h new file mode 100644 index 00000000000..52fc74bf01e --- /dev/null +++ b/dbms/include/DB/Common/getNumberOfPhysicalCPUCores.h @@ -0,0 +1,4 @@ +#pragma once + +/// Получить количество ядер CPU без учёта hyper-threading. +unsigned getNumberOfPhysicalCPUCores(); diff --git a/dbms/include/DB/Core/Defines.h b/dbms/include/DB/Core/Defines.h index dd559f80bbc..7e820848493 100644 --- a/dbms/include/DB/Core/Defines.h +++ b/dbms/include/DB/Core/Defines.h @@ -82,3 +82,9 @@ #define ALWAYS_INLINE __attribute__((__always_inline__)) #define NO_INLINE __attribute__((__noinline__)) + +#define PLATFORM_NOT_SUPPORTED "The only supported platforms are x86_64 and AArch64 (work in progress)" + +#if !defined(__x86_64__) && !defined(__aarch64__) + #error PLATFORM_NOT_SUPPORTED +#endif diff --git a/dbms/include/DB/Interpreters/SettingsCommon.h b/dbms/include/DB/Interpreters/SettingsCommon.h index a47018af15a..a182a7d5175 100644 --- a/dbms/include/DB/Interpreters/SettingsCommon.h +++ b/dbms/include/DB/Interpreters/SettingsCommon.h @@ -3,7 +3,9 @@ #include #include #include -#include + +#include + #include #include @@ -13,7 +15,6 @@ namespace DB namespace ErrorCodes { - extern const int CPUID_ERROR; extern const int TYPE_MISMATCH; extern const int UNKNOWN_LOAD_BALANCING; extern const int UNKNOWN_OVERFLOW_MODE; @@ -151,15 +152,7 @@ struct SettingMaxThreads /// Выполняется один раз за всё время. Выполняется из одного потока. UInt64 getAutoValueImpl() const { - cpu_raw_data_t raw_data; - if (0 != cpuid_get_raw_data(&raw_data)) - throw Exception("Cannot cpuid_get_raw_data: " + String(cpuid_error()), ErrorCodes::CPUID_ERROR); - - cpu_id_t data; - if (0 != cpu_identify(&raw_data, &data)) - throw Exception("Cannot cpu_identify: " + String(cpuid_error()), ErrorCodes::CPUID_ERROR); - - return data.num_cores * data.total_logical_cpus / data.num_logical_cpus; + return getNumberOfPhysicalCPUCores(); } }; diff --git a/dbms/src/Common/getNumberOfPhysicalCPUCores.cpp b/dbms/src/Common/getNumberOfPhysicalCPUCores.cpp new file mode 100644 index 00000000000..927aa41e2c8 --- /dev/null +++ b/dbms/src/Common/getNumberOfPhysicalCPUCores.cpp @@ -0,0 +1,38 @@ +#include + +#if defined(__x86_64__) + + #include + #include + + namespace ErrorCodes + { + extern const int CPUID_ERROR; + } + +#elif defined(__aarch64__) + + #include + +#endif + + +unsigned getNumberOfPhysicalCPUCores() +{ +#if defined(__x86_64__) + + cpu_raw_data_t raw_data; + if (0 != cpuid_get_raw_data(&raw_data)) + throw DB::Exception("Cannot cpuid_get_raw_data: " + std::string(cpuid_error()), ErrorCodes::CPUID_ERROR); + + cpu_id_t data; + if (0 != cpu_identify(&raw_data, &data)) + throw DB::Exception("Cannot cpu_identify: " + std::string(cpuid_error()), ErrorCodes::CPUID_ERROR); + + return data.num_cores * data.total_logical_cpus / data.num_logical_cpus; + +#elif defined(__aarch64__) + /// Считаем, что на этой системе нет hyper-threading. + return std::thread::hardware_concurrency(); +#endif +}