2016-01-13 02:11:40 +00:00
|
|
|
#include <DB/Common/getNumberOfPhysicalCPUCores.h>
|
|
|
|
|
|
|
|
#if defined(__x86_64__)
|
|
|
|
|
|
|
|
#include <cpuid/libcpuid.h>
|
|
|
|
#include <DB/Common/Exception.h>
|
|
|
|
|
2016-01-13 02:25:10 +00:00
|
|
|
namespace DB { namespace ErrorCodes { extern const int CPUID_ERROR; }}
|
2016-01-13 02:11:40 +00:00
|
|
|
|
|
|
|
#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))
|
2016-01-13 02:25:46 +00:00
|
|
|
throw DB::Exception("Cannot cpuid_get_raw_data: " + std::string(cpuid_error()), DB::ErrorCodes::CPUID_ERROR);
|
2016-01-13 02:11:40 +00:00
|
|
|
|
|
|
|
cpu_id_t data;
|
|
|
|
if (0 != cpu_identify(&raw_data, &data))
|
2016-01-13 02:25:46 +00:00
|
|
|
throw DB::Exception("Cannot cpu_identify: " + std::string(cpuid_error()), DB::ErrorCodes::CPUID_ERROR);
|
2016-01-13 02:11:40 +00:00
|
|
|
|
|
|
|
return data.num_cores * data.total_logical_cpus / data.num_logical_cpus;
|
|
|
|
|
|
|
|
#elif defined(__aarch64__)
|
|
|
|
/// Считаем, что на этой системе нет hyper-threading.
|
|
|
|
return std::thread::hardware_concurrency();
|
|
|
|
#endif
|
|
|
|
}
|