mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Use cpuinfo if cpuid not available
This commit is contained in:
parent
22549cc43b
commit
a874945e0e
@ -246,7 +246,10 @@ include (cmake/find_re2.cmake)
|
||||
include (cmake/find_rdkafka.cmake)
|
||||
include (cmake/find_capnp.cmake)
|
||||
include (cmake/find_llvm.cmake)
|
||||
include (cmake/find_cpuid.cmake)
|
||||
include (cmake/find_cpuid.cmake) # Freebsd, bundled
|
||||
if (NOT USE_CPUID)
|
||||
include (cmake/find_cpuinfo.cmake) # Debian
|
||||
endif()
|
||||
include (cmake/find_libgsasl.cmake)
|
||||
include (cmake/find_libxml2.cmake)
|
||||
include (cmake/find_protobuf.cmake)
|
||||
|
@ -2,11 +2,11 @@ if (NOT ARCH_ARM)
|
||||
option (USE_INTERNAL_CPUID_LIBRARY "Set to FALSE to use system cpuid library instead of bundled" ${NOT_UNBUNDLED})
|
||||
endif ()
|
||||
|
||||
#if (USE_INTERNAL_CPUID_LIBRARY AND NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/libcpuid/include/cpuid/libcpuid.h")
|
||||
# message (WARNING "submodule contrib/libcpuid is missing. to fix try run: \n git submodule update --init --recursive")
|
||||
# set (USE_INTERNAL_CPUID_LIBRARY 0)
|
||||
# set (MISSING_INTERNAL_CPUID_LIBRARY 1)
|
||||
#endif ()
|
||||
if (USE_INTERNAL_CPUID_LIBRARY AND NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/libcpuid/CMakeLists.txt")
|
||||
message (WARNING "submodule contrib/libcpuid is missing. to fix try run: \n git submodule update --init --recursive")
|
||||
set (USE_INTERNAL_CPUID_LIBRARY 0)
|
||||
set (MISSING_INTERNAL_CPUID_LIBRARY 1)
|
||||
endif ()
|
||||
|
||||
if (NOT USE_INTERNAL_CPUID_LIBRARY)
|
||||
find_library (CPUID_LIBRARY cpuid)
|
||||
@ -20,10 +20,12 @@ if (CPUID_LIBRARY AND CPUID_INCLUDE_DIR)
|
||||
add_definitions(-DHAVE_STDINT_H)
|
||||
# TODO: make virtual target cpuid:cpuid with COMPILE_DEFINITIONS property
|
||||
endif ()
|
||||
set (USE_CPUID 1)
|
||||
elseif (NOT MISSING_INTERNAL_CPUID_LIBRARY)
|
||||
set (CPUID_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libcpuid/include)
|
||||
set (USE_INTERNAL_CPUID_LIBRARY 1)
|
||||
set (CPUID_LIBRARY cpuid)
|
||||
set (USE_CPUID 1)
|
||||
endif ()
|
||||
|
||||
message (STATUS "Using cpuid: ${CPUID_INCLUDE_DIR} : ${CPUID_LIBRARY}")
|
||||
message (STATUS "Using cpuid=${USE_CPUID}: ${CPUID_INCLUDE_DIR} : ${CPUID_LIBRARY}")
|
||||
|
17
cmake/find_cpuinfo.cmake
Normal file
17
cmake/find_cpuinfo.cmake
Normal file
@ -0,0 +1,17 @@
|
||||
option(USE_INTERNAL_CPUINFO_LIBRARY "Set to FALSE to use system cpuinfo library instead of bundled" ${NOT_UNBUNDLED})
|
||||
|
||||
if(NOT USE_INTERNAL_CPUINFO_LIBRARY)
|
||||
find_library(CPUINFO_LIBRARY cpuinfo)
|
||||
find_path(CPUINFO_INCLUDE_DIR NAMES cpuinfo.h PATHS ${CPUINFO_INCLUDE_PATHS})
|
||||
endif()
|
||||
|
||||
if(CPUID_LIBRARY AND CPUID_INCLUDE_DIR)
|
||||
set(USE_CPUINFO 1)
|
||||
elseif(NOT MISSING_INTERNAL_CPUINFO_LIBRARY)
|
||||
set(CPUINFO_INCLUDE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libcpuinfo/include)
|
||||
set(USE_INTERNAL_CPUINFO_LIBRARY 1)
|
||||
set(CPUINFO_LIBRARY cpuinfo)
|
||||
set(USE_CPUINFO 1)
|
||||
endif()
|
||||
|
||||
message(STATUS "Using cpuinfo=${USE_CPUINFO}: ${CPUINFO_INCLUDE_DIR} : ${CPUINFO_LIBRARY}")
|
@ -203,8 +203,12 @@ target_link_libraries (clickhouse_common_io
|
||||
${CMAKE_DL_LIBS}
|
||||
)
|
||||
|
||||
if (NOT ARCH_ARM AND CPUID_LIBRARY)
|
||||
target_link_libraries (clickhouse_common_io PRIVATE ${CPUID_LIBRARY})
|
||||
if(CPUID_LIBRARY)
|
||||
target_link_libraries(clickhouse_common_io PRIVATE ${CPUID_LIBRARY})
|
||||
endif()
|
||||
|
||||
if(CPUINFO_LIBRARY)
|
||||
target_link_libraries(clickhouse_common_io PRIVATE ${CPUINFO_LIBRARY})
|
||||
endif()
|
||||
|
||||
target_link_libraries (dbms
|
||||
|
@ -18,6 +18,8 @@
|
||||
#cmakedefine01 USE_XXHASH
|
||||
#cmakedefine01 USE_INTERNAL_LLVM_LIBRARY
|
||||
#cmakedefine01 USE_PROTOBUF
|
||||
#cmakedefine01 USE_CPUID
|
||||
#cmakedefine01 USE_CPUINFO
|
||||
|
||||
#cmakedefine01 CLICKHOUSE_SPLIT_BINARY
|
||||
#cmakedefine01 LLVM_HAS_RTTI
|
||||
|
@ -1,19 +1,20 @@
|
||||
#include <Common/getNumberOfPhysicalCPUCores.h>
|
||||
#include <thread>
|
||||
|
||||
#if defined(__x86_64__)
|
||||
|
||||
#include <libcpuid/libcpuid.h>
|
||||
#include <Common/Exception.h>
|
||||
|
||||
#include <Common/config.h>
|
||||
#if USE_CPUID
|
||||
# include <libcpuid/libcpuid.h>
|
||||
# include <Common/Exception.h>
|
||||
namespace DB { namespace ErrorCodes { extern const int CPUID_ERROR; }}
|
||||
|
||||
#elseif USE_CPUINFO
|
||||
# include <cpuinfo.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
unsigned getNumberOfPhysicalCPUCores()
|
||||
{
|
||||
#if defined(__x86_64__)
|
||||
#if USE_CPUID
|
||||
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()), DB::ErrorCodes::CPUID_ERROR);
|
||||
@ -37,6 +38,13 @@ unsigned getNumberOfPhysicalCPUCores()
|
||||
|
||||
if (res != 0)
|
||||
return res;
|
||||
#elseif USE_CPUINFO
|
||||
uint32_t cores = 0;
|
||||
if (cpuinfo_initialize())
|
||||
cores = cpuinfo_get_cores_count();
|
||||
|
||||
if (cores)
|
||||
return cores;
|
||||
#endif
|
||||
|
||||
/// As a fallback (also for non-x86 architectures) assume there are no hyper-threading on the system.
|
||||
|
Loading…
Reference in New Issue
Block a user