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
3 changes: 2 additions & 1 deletion python/PyCGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ PYBIND11_MODULE(pycgraph, cg) {
.def_readwrite("secondary_thread_priority", &UThreadPoolConfig::secondary_thread_priority_)
.def_readwrite("bind_cpu_enable", &UThreadPoolConfig::bind_cpu_enable_)
.def_readwrite("batch_task_enable", &UThreadPoolConfig::batch_task_enable_)
.def_readwrite("monitor_enable", &UThreadPoolConfig::monitor_enable_);
.def_readwrite("monitor_enable", &UThreadPoolConfig::monitor_enable_)
.def_readwrite("deliver_running_primary_thread_enable", &UThreadPoolConfig::deliver_running_primary_thread_enable_);

py::class_<GElementRelation>(cg, "GElementRelation")
.def(py::init<>())
Expand Down
9 changes: 5 additions & 4 deletions src/UtilsCtrl/ThreadPool/UThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ CIndex UThreadPool::dispatch(const CIndex origIndex) {
CIndex realIndex = 0;
if (CGRAPH_DEFAULT_TASK_STRATEGY == origIndex) {
realIndex = cur_index_.fetch_add(1, std::memory_order_relaxed) % config_.max_thread_size_;
if (realIndex >= 0 && realIndex < config_.default_thread_size_
if (!config_.deliver_running_primary_thread_enable_
&& realIndex >= 0 && realIndex < config_.default_thread_size_
&& primary_threads_[realIndex]->is_running_.load(std::memory_order_relaxed)) {
// 如果是默认调度,并且被放置到 正在running 的pt中,则切换为 trigger_one 的策略,防止阻塞
// 如果是默认调度,并且被放置到 正在running 的pt中,则切换为 trigger_all 的策略,防止阻塞
realIndex = CGRAPH_TRIGGER_ALL_THREAD_STRATEGY;
}
} else {
Expand Down Expand Up @@ -274,7 +275,7 @@ CVoid UThreadPool::monitor() {
CSize UThreadPool::wakeupAllThread() {
CSize size = 0;
if (wakeup_mutex_.try_lock()) {
for (const auto& pt : primary_threads_) {
for (auto* pt : primary_threads_) {
if (pt->wakeup()) {
++size;
}
Expand All @@ -285,7 +286,7 @@ CSize UThreadPool::wakeupAllThread() {
++size;
}
}
wakeup_mutex_.unlock();
wakeup_mutex_.unlock();
}

return size;
Expand Down
1 change: 1 addition & 0 deletions src/UtilsCtrl/ThreadPool/UThreadPoolConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct UThreadPoolConfig : public CStruct {
CBool bind_cpu_enable_ = CGRAPH_BIND_CPU_ENABLE;
CBool batch_task_enable_ = CGRAPH_BATCH_TASK_ENABLE;
CBool monitor_enable_ = CGRAPH_MONITOR_ENABLE;
CBool deliver_running_primary_thread_enable_ = CGRAPH_DELIVER_RUNNING_PRIMARY_THREAD_ENABLE;

CStatus check() const {
CGRAPH_FUNCTION_BEGIN
Expand Down
1 change: 1 addition & 0 deletions src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ static const CBool CGRAPH_MONITOR_ENABLE = false;
static const CSec CGRAPH_MONITOR_SPAN = 5; // 监控线程执行间隔,单位为s
static const CMSec CGRAPH_QUEUE_EMPTY_INTERVAL = 1000; // 队列为空时,等待的时间。仅针对辅助线程,单位为ms
static const CBool CGRAPH_BIND_CPU_ENABLE = false; // 是否开启绑定cpu模式(仅针对主线程)
static const CBool CGRAPH_DELIVER_RUNNING_PRIMARY_THREAD_ENABLE = false; // 是否可以将任务投递到正在运行主线程的队列中。开启后,遇到描述情况,则退化为投递到公共队列,并且触发所有线程
static const CInt CGRAPH_PRIMARY_THREAD_POLICY = CGRAPH_THREAD_SCHED_OTHER; // 主线程调度策略
static const CInt CGRAPH_SECONDARY_THREAD_POLICY = CGRAPH_THREAD_SCHED_OTHER; // 辅助线程调度策略
static const CInt CGRAPH_PRIMARY_THREAD_PRIORITY = CGRAPH_THREAD_MIN_PRIORITY; // 主线程调度优先级(取值范围0~99,配合调度策略一起使用,不建议不了解相关内容的童鞋做修改)
Expand Down
1 change: 1 addition & 0 deletions test/Performance/test-performance-04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void test_performance_04() {
config.max_task_steal_range_ = nodePerLayer - 1;
config.primary_thread_busy_epoch_ = 500;
config.primary_thread_empty_interval_ = 0;
config.deliver_running_primary_thread_enable_ = true;
pipeline->setUniqueThreadPoolConfig(config);

// 实现一个全连接
Expand Down
Loading