governor.h
Go to the documentation of this file.
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _TBB_governor_H
#define _TBB_governor_H
#include "tbb/task_scheduler_init.h"
#include "../rml/include/rml_tbb.h"
#include "tbb_misc.h" // for AvailableHwConcurrency
#include "tls.h"
#if __TBB_SURVIVE_THREAD_SWITCH
#include "cilk-tbb-interop.h"
#endif /* __TBB_SURVIVE_THREAD_SWITCH */
namespace tbb {
namespace internal {
class market;
class generic_scheduler;
class __TBB_InitOnce;
namespace rml {
class tbb_client;
}
//------------------------------------------------------------------------
// Class governor
//------------------------------------------------------------------------
class governor {
private:
friend class __TBB_InitOnce;
friend class market;
static basic_tls<uintptr_t> theTLS;
static unsigned DefaultNumberOfThreads;
static size_t DefaultPageSize;
static rml::tbb_factory theRMLServerFactory;
static bool UsePrivateRML;
// Flags for runtime-specific conditions
static bool is_speculation_enabled;
static bool is_rethrow_broken;
static void acquire_resources ();
static void release_resources ();
static rml::tbb_server* create_rml_server ( rml::tbb_client& );
static void auto_terminate(void* scheduler);
public:
static unsigned default_num_threads () {
// No memory fence required, because at worst each invoking thread calls AvailableHwConcurrency once.
return DefaultNumberOfThreads ? DefaultNumberOfThreads :
DefaultNumberOfThreads = AvailableHwConcurrency();
}
static size_t default_page_size () {
return DefaultPageSize ? DefaultPageSize :
DefaultPageSize = DefaultSystemPageSize();
}
static void one_time_init();
static generic_scheduler* init_scheduler( int num_threads, stack_size_type stack_size, bool auto_init );
static generic_scheduler* init_scheduler_weak();
static bool terminate_scheduler( generic_scheduler* s, bool blocking );
static void sign_on( generic_scheduler* s );
static void sign_off( generic_scheduler* s );
static bool is_set( generic_scheduler* s );
static void assume_scheduler( generic_scheduler* s );
static uintptr_t tls_value_of( generic_scheduler* s );
// TODO IDEA: refactor bit manipulations over pointer types to a class?
static generic_scheduler* tls_scheduler_of( uintptr_t v ) {
return (generic_scheduler*)(v & ~uintptr_t(1));
}
static generic_scheduler* local_scheduler () {
uintptr_t v = theTLS.get();
return (v&1) ? tls_scheduler_of(v) : init_scheduler( task_scheduler_init::automatic, 0, /*auto_init=*/true );
}
static generic_scheduler* local_scheduler_weak () {
uintptr_t v = theTLS.get();
return v ? tls_scheduler_of(v) : init_scheduler_weak();
}
static generic_scheduler* local_scheduler_if_initialized () {
return tls_scheduler_of( theTLS.get() );
}
static void terminate_auto_initialized_scheduler() {
auto_terminate( local_scheduler_if_initialized() );
}
static void print_version_info ();
static void initialize_rml_factory ();
static bool does_client_join_workers (const tbb::internal::rml::tbb_client &client);
#if __TBB_SURVIVE_THREAD_SWITCH
static __cilk_tbb_retcode stack_op_handler( __cilk_tbb_stack_op op, void* );
#endif /* __TBB_SURVIVE_THREAD_SWITCH */
static bool speculation_enabled() { return is_speculation_enabled; }
static bool rethrow_exception_broken() { return is_rethrow_broken; }
}; // class governor
} // namespace internal
} // namespace tbb
#endif /* _TBB_governor_H */
task_scheduler_init.h
cilk-tbb-interop.h
__cilk_tbb_stack_op
__cilk_tbb_stack_op
Definition: cilk-tbb-interop.h:44
__cilk_tbb_retcode
int __cilk_tbb_retcode
Definition: cilk-tbb-interop.h:42
tbb_misc.h
tls.h
s
void const char const char int ITT_FORMAT __itt_group_sync s
Definition: ittnotify_static.h:91
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
tbb::stack_size_type
std::size_t stack_size_type
Definition: task_scheduler_init.h:42
tbb::internal::DefaultSystemPageSize
size_t DefaultSystemPageSize()
Returns OS regular memory page size.
Definition: tbb_misc.cpp:70
tbb::internal::AvailableHwConcurrency
int AvailableHwConcurrency()
Returns maximal parallelism level supported by the current OS configuration.
internal
Definition: _flow_graph_async_msg_impl.h:24
tbb::internal::scheduler
Definition: task.h:110
tbb::task_scheduler_init::automatic
static const int automatic
Typedef for number of threads that is automatic.
Definition: task_scheduler_init.h:83
tbb::internal::governor
The class handles access to the single instance of market, and to TLS to keep scheduler instances.
Definition: governor.h:48
tbb::internal::governor::terminate_scheduler
static bool terminate_scheduler(generic_scheduler *s, bool blocking)
Processes scheduler termination request (possibly nested) in a master thread.
Definition: governor.cpp:205
tbb::internal::governor::is_set
static bool is_set(generic_scheduler *s)
Used to check validity of the local scheduler TLS contents.
Definition: governor.cpp:120
tbb::internal::governor::release_resources
static void release_resources()
Destroy the thread-local storage key and deinitialize RML.
Definition: governor.cpp:79
tbb::internal::governor::is_rethrow_broken
static bool is_rethrow_broken
Definition: governor.h:68
tbb::internal::governor::local_scheduler_if_initialized
static generic_scheduler * local_scheduler_if_initialized()
Definition: governor.h:139
tbb::internal::governor::init_scheduler_weak
static generic_scheduler * init_scheduler_weak()
Automatic initialization of scheduler in a master thread with default settings without arena.
Definition: governor.cpp:164
tbb::internal::governor::tls_value_of
static uintptr_t tls_value_of(generic_scheduler *s)
Computes the value of the TLS.
Definition: governor.cpp:110
tbb::internal::governor::does_client_join_workers
static bool does_client_join_workers(const tbb::internal::rml::tbb_client &client)
Definition: market.cpp:304
tbb::internal::governor::sign_off
static void sign_off(generic_scheduler *s)
Unregister TBB scheduler instance from thread-local storage.
Definition: governor.cpp:145
tbb::internal::governor::print_version_info
static void print_version_info()
Definition: governor.cpp:229
tbb::internal::governor::local_scheduler_weak
static generic_scheduler * local_scheduler_weak()
Definition: governor.h:134
tbb::internal::governor::speculation_enabled
static bool speculation_enabled()
Definition: governor.h:158
tbb::internal::governor::auto_terminate
static void auto_terminate(void *scheduler)
The internal routine to undo automatic initialization.
Definition: governor.cpp:215
tbb::internal::governor::terminate_auto_initialized_scheduler
static void terminate_auto_initialized_scheduler()
Undo automatic initialization if necessary; call when a thread exits.
Definition: governor.h:144
tbb::internal::governor::acquire_resources
static void acquire_resources()
Create key for thread-local storage and initialize RML.
Definition: governor.cpp:67
tbb::internal::governor::DefaultPageSize
static size_t DefaultPageSize
Caches the size of OS regular memory page.
Definition: governor.h:60
tbb::internal::governor::theTLS
static basic_tls< uintptr_t > theTLS
TLS for scheduler instances associated with individual threads.
Definition: governor.h:54
tbb::internal::governor::default_page_size
static size_t default_page_size()
Definition: governor.h:89
tbb::internal::governor::default_num_threads
static unsigned default_num_threads()
Definition: governor.h:84
tbb::internal::governor::sign_on
static void sign_on(generic_scheduler *s)
Register TBB scheduler instance in thread-local storage.
Definition: governor.cpp:124
tbb::internal::governor::tls_scheduler_of
static generic_scheduler * tls_scheduler_of(uintptr_t v)
Converts TLS value to the scheduler pointer.
Definition: governor.h:122
tbb::internal::governor::assume_scheduler
static void assume_scheduler(generic_scheduler *s)
Temporarily set TLS slot to the given scheduler.
Definition: governor.cpp:116
tbb::internal::governor::init_scheduler
static generic_scheduler * init_scheduler(int num_threads, stack_size_type stack_size, bool auto_init)
Processes scheduler initialization request (possibly nested) in a master thread.
Definition: governor.cpp:172
tbb::internal::governor::theRMLServerFactory
static rml::tbb_factory theRMLServerFactory
Definition: governor.h:62
tbb::internal::governor::UsePrivateRML
static bool UsePrivateRML
Definition: governor.h:64
tbb::internal::governor::rethrow_exception_broken
static bool rethrow_exception_broken()
Definition: governor.h:159
tbb::internal::governor::initialize_rml_factory
static void initialize_rml_factory()
Definition: governor.cpp:242
tbb::internal::governor::DefaultNumberOfThreads
static unsigned DefaultNumberOfThreads
Caches the maximal level of parallelism supported by the hardware.
Definition: governor.h:57
tbb::internal::governor::create_rml_server
static rml::tbb_server * create_rml_server(rml::tbb_client &)
Definition: governor.cpp:92
tbb::internal::governor::local_scheduler
static generic_scheduler * local_scheduler()
Obtain the thread-local instance of the TBB scheduler.
Definition: governor.h:129
tbb::internal::governor::is_speculation_enabled
static bool is_speculation_enabled
Definition: governor.h:67
tbb::internal::governor::one_time_init
static void one_time_init()
Definition: governor.cpp:156
tbb::internal::market
Definition: market.h:45
tbb::internal::generic_scheduler
Work stealing task scheduler.
Definition: scheduler.h:140
tbb::internal::__TBB_InitOnce
Class that supports TBB initialization.
Definition: tbb_main.h:37
tbb::internal::basic_tls< uintptr_t >
tbb::internal::basic_tls::get
T get()
Definition: tls.h:57

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.