From 2e0f688b97dcae1a08a1e2f982332b01bd342d5d Mon Sep 17 00:00:00 2001 From: Seth Hillbrand <seth@kipro-pcb.com> Date: Fri, 3 Jan 2025 14:00:07 -0800 Subject: [PATCH] Add Advanced Config parameter for thread count Allows us to limit the threading state manually without recompiling --- common/advanced_config.cpp | 8 +++++++- include/advanced_config.h | 9 +++++++++ include/singleton.h | 4 +++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/common/advanced_config.cpp b/common/advanced_config.cpp index 3fbe56d7cf..70df2e915b 100644 --- a/common/advanced_config.cpp +++ b/common/advanced_config.cpp @@ -121,9 +121,9 @@ static const wxChar EnableExtensionSnaps[] = wxT( "EnableExtensionSnaps" ); static const wxChar ExtensionSnapTimeoutMs[] = wxT( "ExtensionSnapTimeoutMs" ); static const wxChar ExtensionSnapActivateOnHover[] = wxT( "ExtensionSnapActivateOnHover" ); static const wxChar EnableSnapAnchorsDebug[] = wxT( "EnableSnapAnchorsDebug" ); -static const wxChar EnableJobset[] = wxT( "EnableJobset" ); static const wxChar MinParallelAngle[] = wxT( "MinParallelAngle" ); static const wxChar HoleWallPaintingMultiplier[] = wxT( "HoleWallPaintingMultiplier" ); +static const wxChar MaximumThreads[] = wxT( "MaximumThreads" ); } // namespace KEYS @@ -296,6 +296,8 @@ ADVANCED_CFG::ADVANCED_CFG() m_MinParallelAngle = 0.001; m_HoleWallPaintingMultiplier = 1.5; + m_MaximumThreads = 0; + loadFromConfigFile(); } @@ -565,6 +567,10 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg ) &m_HoleWallPaintingMultiplier, m_HoleWallPaintingMultiplier, 0.1, 100.0 ) ); + configParams.push_back( new PARAM_CFG_INT( true, AC_KEYS::MaximumThreads, + &m_MaximumThreads, m_MaximumThreads, + 0, 500 ) ); + // Special case for trace mask setting...we just grab them and set them immediately // Because we even use wxLogTrace inside of advanced config wxString traceMasks; diff --git a/include/advanced_config.h b/include/advanced_config.h index d3a31201ec..e329aa26a5 100644 --- a/include/advanced_config.h +++ b/include/advanced_config.h @@ -707,6 +707,15 @@ public: */ double m_HoleWallPaintingMultiplier; + /** + * Default value for the maximum number of threads to use for parallel processing. + * Setting this value to 0 or less will mean that we use the number of cores available + * + * Setting name: "MaximumThreads" + * Default value: 0 + */ + int m_MaximumThreads; + ///@} private: diff --git a/include/singleton.h b/include/singleton.h index 7a0f5f1a86..27b9dd74ca 100644 --- a/include/singleton.h +++ b/include/singleton.h @@ -21,6 +21,7 @@ #define KICAD_SINGLETON_H #include <bs_thread_pool.hpp> +#include <advanced_config.h> class KICAD_SINGLETON { @@ -38,7 +39,8 @@ public: void Init() { - m_ThreadPool = new BS::thread_pool(); + int num_threads = std::max( 0, ADVANCED_CFG::GetCfg().m_MaximumThreads ); + m_ThreadPool = new BS::thread_pool( num_threads ); } BS::thread_pool* m_ThreadPool;