From e107d1f5b0841eb880706b4e07b3e515f6d5000e Mon Sep 17 00:00:00 2001 From: liangwenjia <1757640220@qq.com> Date: Wed, 6 Mar 2024 16:34:40 +0800 Subject: [PATCH] fix the bug --- plugin/thread_pool/numa_affinity_manager.cc | 13 ++++++++++--- plugin/thread_pool/numa_affinity_manager.h | 4 +++- plugin/thread_pool/threadpool_unix.cc | 7 +------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/plugin/thread_pool/numa_affinity_manager.cc b/plugin/thread_pool/numa_affinity_manager.cc index e8563a6b9..f2304c504 100644 --- a/plugin/thread_pool/numa_affinity_manager.cc +++ b/plugin/thread_pool/numa_affinity_manager.cc @@ -74,13 +74,20 @@ bool numa_affinity_manager::init_foreground_cpu_map() { return false; } + bool msk_bitset = false; for (int j = 0; j < cpu_per_numa; j++) { if (foreground_cpu_map_opts == nullptr || numa_bitmask_isbitset(foreground_cpu_map_opts.get(), start + j)) { numa_bitmask_setbit(msk, start + j); + msk_bitset = true; } } - foreground_cpu_map.emplace_back(msk, free_cpumask_func); + if (msk_bitset) { + foreground_cpu_map.emplace_back(msk, free_cpumask_func); + } else { + free_cpumask_func(msk); + } + start += cpu_per_numa; } @@ -91,7 +98,7 @@ bool numa_affinity_manager::bind_foreground_thread(int group_id) { if (!threadpool_sched_affinity) { XLockGuard lk(lock); my_thread_os_id_t tid = my_thread_os_id(); - foreground_threads.insert(std::pair(tid, -1)); + foreground_threads[tid] = group_id; return false; } @@ -112,7 +119,7 @@ bool numa_affinity_manager::bind_foreground_thread(int group_id) { bitmask *msk = foreground_cpu_map[group_id%foreground_cpu_map.size()].get(); ret = bind_thread(tid, msk); if (ret) { - foreground_threads.insert(std::pair(tid, group_id)); + foreground_threads[tid] = group_id; } } return !ret; diff --git a/plugin/thread_pool/numa_affinity_manager.h b/plugin/thread_pool/numa_affinity_manager.h index e3c3eac31..b10e65b3d 100644 --- a/plugin/thread_pool/numa_affinity_manager.h +++ b/plugin/thread_pool/numa_affinity_manager.h @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include #include "storage/perfschema/pfs_buffer_container.h" @@ -72,7 +74,7 @@ private: std::map > background_cpu_map_opts; bool bind_background_ok{false}; std::map > background_threads; - std::map foreground_threads; + std::unordered_map foreground_threads; }; #endif // NUMA_AFFINITY_MANAGER_H_ diff --git a/plugin/thread_pool/threadpool_unix.cc b/plugin/thread_pool/threadpool_unix.cc index c966fa738..425cdc3b5 100644 --- a/plugin/thread_pool/threadpool_unix.cc +++ b/plugin/thread_pool/threadpool_unix.cc @@ -395,10 +395,6 @@ int change_group(connection_t *c, thread_group_t *group, thread_group_t *to_grou if (!to_group->thread_count) ret = create_worker(to_group, false); mysql_mutex_unlock(&to_group->mutex); - if (threadpool_sched_affinity) { - group_affinity.bind_foreground_thread(to_group - all_groups); - } - return ret; } @@ -1654,8 +1650,6 @@ static void *worker_main(void *param) { handle_event(connection); } - group_affinity.remove_foreground_thread(); - /* Thread shutdown: cleanup per-worker-thread structure. */ mysql_cond_destroy(&this_thread.cond); @@ -1670,6 +1664,7 @@ static void *worker_main(void *param) { thread_group_destroy(thread_group); } + group_affinity.remove_foreground_thread(); my_thread_end(); return nullptr; } -- Gitee