From 143306883caa22810b88f1a71b7b1991cbbadb87 Mon Sep 17 00:00:00 2001 From: xufei Date: Wed, 28 Jun 2023 12:40:05 +0800 Subject: [PATCH] cherry-pick #7693 (#7712) --- dbms/src/Common/tests/gtest_cpu_affinity_manager.cpp | 11 +++++++++++ dbms/src/Flash/Mpp/MinTSOScheduler.cpp | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/dbms/src/Common/tests/gtest_cpu_affinity_manager.cpp b/dbms/src/Common/tests/gtest_cpu_affinity_manager.cpp index af4502ac97a..c9627dcdd3d 100644 --- a/dbms/src/Common/tests/gtest_cpu_affinity_manager.cpp +++ b/dbms/src/Common/tests/gtest_cpu_affinity_manager.cpp @@ -24,8 +24,10 @@ #include #include +#include #include #include +#include #include #include @@ -82,6 +84,15 @@ TEST(CPUAffinityManagerTest, CPUAffinityManager) int ret = sched_getaffinity(0, sizeof(cpu_set), &cpu_set); ASSERT_EQ(ret, 0) << strerror(errno); + auto n_cpu = std::thread::hardware_concurrency(); + auto cpu_cores = cpu_affinity.cpuSetToVec(cpu_set); + if (n_cpu != cpu_cores.size()) + { + LOG_INFO(Logger::get(), "n_cpu = {}, cpu_cores = {}, CPU number and CPU cores not match, don't not check CPUAffinityManager", n_cpu, cpu_cores); + return; + } + LOG_DEBUG(Logger::get(), "n_cpu = {}, cpu_cores = {}", n_cpu, cpu_cores); + cpu_affinity.bindSelfQueryThread(); cpu_set_t cpu_set0; ret = sched_getaffinity(0, sizeof(cpu_set0), &cpu_set0); diff --git a/dbms/src/Flash/Mpp/MinTSOScheduler.cpp b/dbms/src/Flash/Mpp/MinTSOScheduler.cpp index b7deae93311..634f5012f9f 100644 --- a/dbms/src/Flash/Mpp/MinTSOScheduler.cpp +++ b/dbms/src/Flash/Mpp/MinTSOScheduler.cpp @@ -191,7 +191,7 @@ bool MinTSOScheduler::scheduleImp(const UInt64 tso, const MPPQueryTaskSetPtr & q { auto needed_threads = schedule_entry.getNeededThreads(); auto check_for_new_min_tso = tso <= min_tso && estimated_thread_usage + needed_threads <= thread_hard_limit; - auto check_for_not_min_tso = (active_set.size() < active_set_soft_limit || tso <= *active_set.rbegin()) && (estimated_thread_usage + needed_threads <= thread_soft_limit); + auto check_for_not_min_tso = (active_set.size() < active_set_soft_limit || active_set.find(tso) != active_set.end()) && (estimated_thread_usage + needed_threads <= thread_soft_limit); if (check_for_new_min_tso || check_for_not_min_tso) { updateMinTSO(tso, false, isWaiting ? "from the waiting set" : "when directly schedule it");