Skip to content

Commit

Permalink
Fixed error when libcpuid reports zero number of CPU cores [#METR-219…
Browse files Browse the repository at this point in the history
…26].
  • Loading branch information
alexey-milovidov committed Jun 30, 2016
1 parent 5ed881e commit fe216b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dbms/include/DB/Common/getNumberOfPhysicalCPUCores.h
@@ -1,4 +1,4 @@
#pragma once

/// Получить количество ядер CPU без учёта hyper-threading.
/// Get number of CPU cores without hyper-threading.
unsigned getNumberOfPhysicalCPUCores();
11 changes: 6 additions & 5 deletions dbms/src/Common/getNumberOfPhysicalCPUCores.cpp
@@ -1,4 +1,5 @@
#include <DB/Common/getNumberOfPhysicalCPUCores.h>
#include <thread>

#if defined(__x86_64__)

Expand All @@ -7,10 +8,6 @@

namespace DB { namespace ErrorCodes { extern const int CPUID_ERROR; }}

#elif defined(__aarch64__)

#include <thread>

#endif


Expand All @@ -26,10 +23,14 @@ unsigned getNumberOfPhysicalCPUCores()
if (0 != cpu_identify(&raw_data, &data))
throw DB::Exception("Cannot cpu_identify: " + std::string(cpuid_error()), DB::ErrorCodes::CPUID_ERROR);

/// On Xen VMs, libcpuid returns wrong info (zero number of cores). Fallback to alternative method.
if (data.num_cores == 0 || data.total_logical_cpus == 0 || data.num_logical_cpus == 0)
return std::thread::hardware_concurrency();

return data.num_cores * data.total_logical_cpus / data.num_logical_cpus;

#elif defined(__aarch64__)
/// Считаем, что на этой системе нет hyper-threading.
/// Assuming there are no hyper-threading on the system.
return std::thread::hardware_concurrency();
#endif
}

0 comments on commit fe216b7

Please sign in to comment.