GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • python
    • PyCGraph.cpp
  • src/UtilsCtrl/ThreadPool
    • UThreadPool.cpp
    • UThreadPoolConfig.h
    • UThreadPoolDefine.h
  • test/Performance
    • test-performance-04.cpp
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎python/PyCGraph.cpp‎

Copy file name to clipboardExpand all lines: python/PyCGraph.cpp
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ PYBIND11_MODULE(pycgraph, cg) {
4040
.def_readwrite("secondary_thread_priority", &UThreadPoolConfig::secondary_thread_priority_)
4141
.def_readwrite("bind_cpu_enable", &UThreadPoolConfig::bind_cpu_enable_)
4242
.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_);
4445

4546
py::class_<GElementRelation>(cg, "GElementRelation")
4647
.def(py::init<>())
Collapse file

‎src/UtilsCtrl/ThreadPool/UThreadPool.cpp‎

Copy file name to clipboardExpand all lines: src/UtilsCtrl/ThreadPool/UThreadPool.cpp
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,10 @@ CIndex UThreadPool::dispatch(const CIndex origIndex) {
210210
CIndex realIndex = 0;
211211
if (CGRAPH_DEFAULT_TASK_STRATEGY == origIndex) {
212212
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_
214215
&& primary_threads_[realIndex]->is_running_.load(std::memory_order_relaxed)) {
215-
// 如果是默认调度,并且被放置到 正在running 的pt中,则切换为 trigger_one 的策略,防止阻塞
216+
// 如果是默认调度,并且被放置到 正在running 的pt中,则切换为 trigger_all 的策略,防止阻塞
216217
realIndex = CGRAPH_TRIGGER_ALL_THREAD_STRATEGY;
217218
}
218219
} else {
@@ -274,7 +275,7 @@ CVoid UThreadPool::monitor() {
274275
CSize UThreadPool::wakeupAllThread() {
275276
CSize size = 0;
276277
if (wakeup_mutex_.try_lock()) {
277-
for (const auto& pt : primary_threads_) {
278+
for (auto* pt : primary_threads_) {
278279
if (pt->wakeup()) {
279280
++size;
280281
}
@@ -285,7 +286,7 @@ CSize UThreadPool::wakeupAllThread() {
285286
++size;
286287
}
287288
}
288-
wakeup_mutex_.unlock();
289+
wakeup_mutex_.unlock();
289290
}
290291

291292
return size;
Collapse file

‎src/UtilsCtrl/ThreadPool/UThreadPoolConfig.h‎

Copy file name to clipboardExpand all lines: src/UtilsCtrl/ThreadPool/UThreadPoolConfig.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct UThreadPoolConfig : public CStruct {
3838
CBool bind_cpu_enable_ = CGRAPH_BIND_CPU_ENABLE;
3939
CBool batch_task_enable_ = CGRAPH_BATCH_TASK_ENABLE;
4040
CBool monitor_enable_ = CGRAPH_MONITOR_ENABLE;
41+
CBool deliver_running_primary_thread_enable_ = CGRAPH_DELIVER_RUNNING_PRIMARY_THREAD_ENABLE;
4142

4243
CStatus check() const {
4344
CGRAPH_FUNCTION_BEGIN
Collapse file

‎src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h‎

Copy file name to clipboardExpand all lines: src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ static const CBool CGRAPH_MONITOR_ENABLE = false;
6262
static const CSec CGRAPH_MONITOR_SPAN = 5; // 监控线程执行间隔,单位为s
6363
static const CMSec CGRAPH_QUEUE_EMPTY_INTERVAL = 1000; // 队列为空时,等待的时间。仅针对辅助线程,单位为ms
6464
static const CBool CGRAPH_BIND_CPU_ENABLE = false; // 是否开启绑定cpu模式(仅针对主线程)
65+
static const CBool CGRAPH_DELIVER_RUNNING_PRIMARY_THREAD_ENABLE = false; // 是否可以将任务投递到正在运行主线程的队列中。开启后,遇到描述情况,则退化为投递到公共队列,并且触发所有线程
6566
static const CInt CGRAPH_PRIMARY_THREAD_POLICY = CGRAPH_THREAD_SCHED_OTHER; // 主线程调度策略
6667
static const CInt CGRAPH_SECONDARY_THREAD_POLICY = CGRAPH_THREAD_SCHED_OTHER; // 辅助线程调度策略
6768
static const CInt CGRAPH_PRIMARY_THREAD_PRIORITY = CGRAPH_THREAD_MIN_PRIORITY; // 主线程调度优先级(取值范围0~99,配合调度策略一起使用,不建议不了解相关内容的童鞋做修改)
Collapse file

‎test/Performance/test-performance-04.cpp‎

Copy file name to clipboardExpand all lines: test/Performance/test-performance-04.cpp
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void test_performance_04() {
2323
config.max_task_steal_range_ = nodePerLayer - 1;
2424
config.primary_thread_busy_epoch_ = 500;
2525
config.primary_thread_empty_interval_ = 0;
26+
config.deliver_running_primary_thread_enable_ = true;
2627
pipeline->setUniqueThreadPoolConfig(config);
2728

2829
// 实现一个全连接

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.