GeezerVison is showing github.com — [perf] optimize test-perf-04 by deliver_running_primary_thread_enable · feiyunwill/CGraph@cb64f0e
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: python/PyCGraph.cpp +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -40,7 +40,8 @@ PYBIND11_MODULE(pycgraph, cg) { |
40 | 40 | .def_readwrite("secondary_thread_priority", &UThreadPoolConfig::secondary_thread_priority_) |
41 | 41 | .def_readwrite("bind_cpu_enable", &UThreadPoolConfig::bind_cpu_enable_) |
42 | 42 | .def_readwrite("batch_task_enable", &UThreadPoolConfig::batch_task_enable_) |
43 | | - .def_readwrite("monitor_enable", &UThreadPoolConfig::monitor_enable_); |
| 43 | + .def_readwrite("monitor_enable", &UThreadPoolConfig::monitor_enable_) |
| 44 | + .def_readwrite("deliver_running_primary_thread_enable", &UThreadPoolConfig::deliver_running_primary_thread_enable_); |
44 | 45 |
|
45 | 46 | py::class_<GElementRelation>(cg, "GElementRelation") |
46 | 47 | .def(py::init<>()) |
|
Collapse file
Copy file name to clipboardExpand all lines: src/UtilsCtrl/ThreadPool/UThreadPool.cpp +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -210,9 +210,10 @@ CIndex UThreadPool::dispatch(const CIndex origIndex) { |
210 | 210 | CIndex realIndex = 0; |
211 | 211 | if (CGRAPH_DEFAULT_TASK_STRATEGY == origIndex) { |
212 | 212 | realIndex = cur_index_.fetch_add(1, std::memory_order_relaxed) % config_.max_thread_size_; |
213 | | - if (realIndex >= 0 && realIndex < config_.default_thread_size_ |
| 213 | + if (!config_.deliver_running_primary_thread_enable_ |
| 214 | + && realIndex >= 0 && realIndex < config_.default_thread_size_ |
214 | 215 | && primary_threads_[realIndex]->is_running_.load(std::memory_order_relaxed)) { |
215 | | - // 如果是默认调度,并且被放置到 正在running 的pt中,则切换为 trigger_one 的策略,防止阻塞 |
| 216 | + // 如果是默认调度,并且被放置到 正在running 的pt中,则切换为 trigger_all 的策略,防止阻塞 |
216 | 217 | realIndex = CGRAPH_TRIGGER_ALL_THREAD_STRATEGY; |
217 | 218 | } |
218 | 219 | } else { |
@@ -274,7 +275,7 @@ CVoid UThreadPool::monitor() { |
274 | 275 | CSize UThreadPool::wakeupAllThread() { |
275 | 276 | CSize size = 0; |
276 | 277 | if (wakeup_mutex_.try_lock()) { |
277 | | - for (const auto& pt : primary_threads_) { |
| 278 | + for (auto* pt : primary_threads_) { |
278 | 279 | if (pt->wakeup()) { |
279 | 280 | ++size; |
280 | 281 | } |
@@ -285,7 +286,7 @@ CSize UThreadPool::wakeupAllThread() { |
285 | 286 | ++size; |
286 | 287 | } |
287 | 288 | } |
288 | | - wakeup_mutex_.unlock(); |
| 289 | + wakeup_mutex_.unlock(); |
289 | 290 | } |
290 | 291 |
|
291 | 292 | return size; |
|
Collapse file
Copy file name to clipboardExpand all lines: src/UtilsCtrl/ThreadPool/UThreadPoolConfig.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,6 +38,7 @@ struct UThreadPoolConfig : public CStruct { |
38 | 38 | CBool bind_cpu_enable_ = CGRAPH_BIND_CPU_ENABLE; |
39 | 39 | CBool batch_task_enable_ = CGRAPH_BATCH_TASK_ENABLE; |
40 | 40 | CBool monitor_enable_ = CGRAPH_MONITOR_ENABLE; |
| 41 | + CBool deliver_running_primary_thread_enable_ = CGRAPH_DELIVER_RUNNING_PRIMARY_THREAD_ENABLE; |
41 | 42 |
|
42 | 43 | CStatus check() const { |
43 | 44 | CGRAPH_FUNCTION_BEGIN |
|
Collapse file
Copy file name to clipboardExpand all lines: src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -62,6 +62,7 @@ static const CBool CGRAPH_MONITOR_ENABLE = false; |
62 | 62 | static const CSec CGRAPH_MONITOR_SPAN = 5; // 监控线程执行间隔,单位为s |
63 | 63 | static const CMSec CGRAPH_QUEUE_EMPTY_INTERVAL = 1000; // 队列为空时,等待的时间。仅针对辅助线程,单位为ms |
64 | 64 | static const CBool CGRAPH_BIND_CPU_ENABLE = false; // 是否开启绑定cpu模式(仅针对主线程) |
| 65 | +static const CBool CGRAPH_DELIVER_RUNNING_PRIMARY_THREAD_ENABLE = false; // 是否可以将任务投递到正在运行主线程的队列中。开启后,遇到描述情况,则退化为投递到公共队列,并且触发所有线程 |
65 | 66 | static const CInt CGRAPH_PRIMARY_THREAD_POLICY = CGRAPH_THREAD_SCHED_OTHER; // 主线程调度策略 |
66 | 67 | static const CInt CGRAPH_SECONDARY_THREAD_POLICY = CGRAPH_THREAD_SCHED_OTHER; // 辅助线程调度策略 |
67 | 68 | static const CInt CGRAPH_PRIMARY_THREAD_PRIORITY = CGRAPH_THREAD_MIN_PRIORITY; // 主线程调度优先级(取值范围0~99,配合调度策略一起使用,不建议不了解相关内容的童鞋做修改) |
|
Collapse file
Copy file name to clipboardExpand all lines: test/Performance/test-performance-04.cpp +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,6 +23,7 @@ void test_performance_04() { |
23 | 23 | config.max_task_steal_range_ = nodePerLayer - 1; |
24 | 24 | config.primary_thread_busy_epoch_ = 500; |
25 | 25 | config.primary_thread_empty_interval_ = 0; |
| 26 | + config.deliver_running_primary_thread_enable_ = true; |
26 | 27 | pipeline->setUniqueThreadPoolConfig(config); |
27 | 28 |
|
28 | 29 | // 实现一个全连接 |
|