Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion be/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ execute_process(
OUTPUT_VARIABLE LLVM_MODULE_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Check if functions are supported in this platform. All flags will generated
# in gensrc/build/common/env_config.h.
# You can check funcion here which depends on platform. Don't forget add this
# to be/src/common/env_config.h.in
include(CheckFunctionExists)
check_function_exists(sched_getcpu HAVE_SCHED_GETCPU)

# compiler flags that are common across debug/release builds
# -Wall: Enable all warnings.
# -Wno-sign-compare: suppress warnings for comparison between signed and unsigned
Expand Down Expand Up @@ -461,7 +469,6 @@ include_directories(
${THIRDPARTY_DIR}/include/event/
)


set(WL_START_GROUP "-Wl,--start-group")
set(WL_END_GROUP "-Wl,--end-group")

Expand Down
3 changes: 2 additions & 1 deletion be/src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ add_library(Common STATIC
configbase.cpp
)

#ADD_BE_TEST(resource_tls_test)
# Generate env_config.h according to env_config.h.in
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/env_config.h.in ${GENSRC_DIR}/common/env_config.h)
5 changes: 3 additions & 2 deletions be/src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,9 @@ namespace config {

CONF_Bool(enable_prefetch, "true");

// cpu count
CONF_Int32(flags_num_cores, "32");
// Number of cores Doris will used, this will effect only when it's greater than 0.
// Otherwise, Doris will use all cores returned from "/proc/cpuinfo".
CONF_Int32(num_cores, "0");

CONF_Bool(thread_creation_fault_injection, "false");

Expand Down
24 changes: 24 additions & 0 deletions be/src/common/env_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#pragma once

namespace doris {

#cmakedefine HAVE_SCHED_GETCPU @HAVE_SCHED_GETCPU@

}
25 changes: 16 additions & 9 deletions be/src/util/cpu_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <sys/sysinfo.h>

#include "common/config.h"
#include "common/env_config.h"
#include "gflags/gflags.h"
#include "gutil/strings/substitute.h"
#include "util/pretty_printer.h"
Expand Down Expand Up @@ -156,13 +157,13 @@ void CpuInfo::init() {
} else {
num_cores_ = 1;
}
if (config::flags_num_cores > 0) num_cores_ = config::flags_num_cores;
if (config::num_cores > 0) num_cores_ = config::num_cores;
max_num_cores_ = get_nprocs_conf();

// Print a warning if something is wrong with sched_getcpu().
#ifdef HAVE_SCHED_GETCPU
if (sched_getcpu() == -1) {
LOG(WARNING) << "Kernel does not support getcpu(). Performance may be impacted.";
LOG(WARNING) << "Kernel does not support sched_getcpu(). Performance may be impacted.";
}
#else
LOG(WARNING) << "Built on a system without sched_getcpu() support. Performance may"
Expand Down Expand Up @@ -284,15 +285,21 @@ void CpuInfo::enable_feature(long flag, bool enable) {
}

int CpuInfo::get_current_core() {
// sched_getcpu() is not supported on some old kernels/glibcs (like the versions that
// shipped with CentOS 5). In that case just pretend we're always running on CPU 0
// so that we can build and run with degraded perf.
// sched_getcpu() is not supported on some old kernels/glibcs (like the versions that
// shipped with CentOS 5). In that case just pretend we're always running on CPU 0
// so that we can build and run with degraded perf.
#ifdef HAVE_SCHED_GETCPU
int cpu = sched_getcpu();
// The syscall may not be supported even if the function exists.
return cpu == -1 ? 0 : cpu;
int cpu = sched_getcpu();
if (cpu < 0) return 0;
if (cpu >= max_num_cores_) {
LOG_FIRST_N(WARNING, 5) << "sched_getcpu() return value " << cpu
<< ", which is greater than get_nprocs_conf() retrun value " << max_num_cores_
<< ", now is " << get_nprocs_conf();
cpu %= max_num_cores_;
}
return cpu;
#else
return 0;
return 0;
#endif
}

Expand Down