Skip to content

Commit

Permalink
Delay control variable initialization
Browse files Browse the repository at this point in the history
Previous to this commit, global scheduler observers would be initialized before the global TBB controllers.
  • Loading branch information
SoilRos committed Apr 17, 2024
1 parent 224eca3 commit 157328b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
24 changes: 18 additions & 6 deletions src/tbb/global_control.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2023 Intel Corporation
Copyright (c) 2005-2024 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
#include "oneapi/tbb/detail/_config.h"
#include "oneapi/tbb/detail/_template_helpers.h"

#include "oneapi/tbb/cache_aligned_allocator.h"
#include "oneapi/tbb/global_control.h"
#include "oneapi/tbb/tbb_allocator.h"
#include "oneapi/tbb/spin_mutex.h"
Expand Down Expand Up @@ -139,11 +140,22 @@ class alignas(max_nfs_size) lifetime_control : public control_storage {
}
};

static allowed_parallelism_control allowed_parallelism_ctl;
static stack_size_control stack_size_ctl;
static terminate_on_exception_control terminate_on_exception_ctl;
static lifetime_control lifetime_ctl;
static control_storage *controls[] = {&allowed_parallelism_ctl, &stack_size_ctl, &terminate_on_exception_ctl, &lifetime_ctl};
static control_storage* controls[] = {nullptr, nullptr, nullptr, nullptr};

void global_control_acquire() {
controls[0] = new (cache_aligned_allocate(sizeof(allowed_parallelism_control))) allowed_parallelism_control{};
controls[1] = new (cache_aligned_allocate(sizeof(stack_size_control))) stack_size_control{};
controls[2] = new (cache_aligned_allocate(sizeof(terminate_on_exception_control))) terminate_on_exception_control{};
controls[3] = new (cache_aligned_allocate(sizeof(lifetime_control))) lifetime_control{};
}

void global_control_release() {
for (auto& ptr : controls) {
ptr->~control_storage();
cache_aligned_deallocate(ptr);
ptr = nullptr;
}
}

void global_control_lock() {
for (auto& ctl : controls) {
Expand Down
6 changes: 5 additions & 1 deletion src/tbb/governor.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2023 Intel Corporation
Copyright (c) 2005-2024 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,6 +42,8 @@ namespace detail {
namespace r1 {

void clear_address_waiter_table();
void global_control_acquire();
void global_control_release();

//! global_control.cpp contains definition
bool remove_and_check_if_empty(d1::global_control& gc);
Expand All @@ -60,6 +62,7 @@ namespace system_topology {
//------------------------------------------------------------------------

void governor::acquire_resources () {
global_control_acquire();
#if __TBB_USE_POSIX
int status = theTLS.create(auto_terminate);
#else
Expand All @@ -85,6 +88,7 @@ void governor::release_resources () {

system_topology::destroy();
dynamic_unlink_all();
global_control_release();
}

rml::tbb_server* governor::create_rml_server ( rml::tbb_client& client ) {
Expand Down

0 comments on commit 157328b

Please sign in to comment.