Configuration of TBB work pool threads executed from the background
slicing process: 1) "C" locales are always enforced. 2) OSX Quality of Service level is set to make sure the slicing runs on fat cores on Apple Silicon if some fat cores are available.
This commit is contained in:
parent
05a157c916
commit
9bc69efde6
4 changed files with 58 additions and 28 deletions
|
@ -6,6 +6,9 @@
|
|||
#include <thread>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include <tbb/task_scheduler_observer.h>
|
||||
#include <tbb/enumerable_thread_specific.h>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
// Set / get thread name.
|
||||
|
@ -26,6 +29,10 @@ inline bool set_thread_name(boost::thread &thread, const std::string &thread_nam
|
|||
bool set_current_thread_name(const char *thread_name);
|
||||
inline bool set_current_thread_name(const std::string &thread_name) { return set_current_thread_name(thread_name.c_str()); }
|
||||
|
||||
// OSX specific: Set Quality of Service to "user initiated", so that the threads will be scheduled to high performance
|
||||
// cores if available.
|
||||
void set_current_thread_qos();
|
||||
|
||||
// Returns nullopt if not supported.
|
||||
// Not supported by OSX.
|
||||
// Naming threads is only supported on newer Windows 10.
|
||||
|
@ -53,6 +60,25 @@ template<class Fn> inline boost::thread create_thread(Fn &&fn)
|
|||
return create_thread(attrs, std::forward<Fn>(fn));
|
||||
}
|
||||
|
||||
// For unknown reasons and in sporadic cases when GCode export is processing, some participating thread
|
||||
// in tbb::parallel_pipeline has not set locales to "C", probably because this thread is newly spawned.
|
||||
// So in this class method on_scheduler_entry is called for every thread before it starts participating
|
||||
// in tbb::parallel_pipeline to ensure that locales are set correctly
|
||||
//
|
||||
// For tbb::parallel_pipeline, it seems that on_scheduler_entry is called for every layer and every filter.
|
||||
// We ensure using thread-local storage that locales will be set to "C" just once for any participating thread.
|
||||
class TBBLocalesSetter : public tbb::task_scheduler_observer
|
||||
{
|
||||
public:
|
||||
TBBLocalesSetter() { this->observe(true); }
|
||||
~TBBLocalesSetter() override { this->observe(false); };
|
||||
|
||||
void on_scheduler_entry(bool is_worker) override;
|
||||
|
||||
private:
|
||||
tbb::enumerable_thread_specific<bool, tbb::cache_aligned_allocator<bool>, tbb::ets_key_usage_type::ets_key_per_instance> m_is_locales_sets{ false };
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // GUI_THREAD_HPP
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue