dbms: porting to aarch64 [#METR-19609].

This commit is contained in:
Alexey Milovidov 2016-01-13 05:11:40 +03:00
parent 54d3af930c
commit e522ec23f9
4 changed files with 52 additions and 11 deletions

View File

@ -0,0 +1,4 @@
#pragma once
/// Получить количество ядер CPU без учёта hyper-threading.
unsigned getNumberOfPhysicalCPUCores();

View File

@ -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

View File

@ -3,7 +3,9 @@
#include <DB/Core/Field.h>
#include <DB/IO/WriteHelpers.h>
#include <Poco/Timespan.h>
#include <cpuid/libcpuid.h>
#include <DB/Common/getNumberOfPhysicalCPUCores.h>
#include <DB/IO/CompressedStream.h>
#include <DB/IO/ReadHelpers.h>
@ -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();
}
};

View File

@ -0,0 +1,38 @@
#include <DB/Common/getNumberOfPhysicalCPUCores.h>
#if defined(__x86_64__)
#include <cpuid/libcpuid.h>
#include <DB/Common/Exception.h>
namespace ErrorCodes
{
extern const int CPUID_ERROR;
}
#elif defined(__aarch64__)
#include <thread>
#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
}