Commit 8c688c99 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Merge branch 'entry_affinity_as_static' into 'master'

Make the entry affinity pointer a static variable in a function rather a global

Here is what I hinted to in #204. I find this clearer to read. Do you agree with that change ?

See merge request !229
parents 55333951 57490cba
...@@ -85,11 +85,6 @@ const char *engine_policy_names[13] = {"none", ...@@ -85,11 +85,6 @@ const char *engine_policy_names[13] = {"none",
/** The rank of the engine as a global variable (for messages). */ /** The rank of the engine as a global variable (for messages). */
int engine_rank; int engine_rank;
#ifdef HAVE_SETAFFINITY
/** The initial affinity of the main thread (set by engin_pin()) */
static cpu_set_t entry_affinity;
#endif
/** /**
* @brief Link a density/force task to a cell. * @brief Link a density/force task to a cell.
* *
...@@ -3010,6 +3005,7 @@ void engine_dump_snapshot(struct engine *e) { ...@@ -3010,6 +3005,7 @@ void engine_dump_snapshot(struct engine *e) {
static cpu_set_t *engine_entry_affinity() { static cpu_set_t *engine_entry_affinity() {
static int use_entry_affinity = 0; static int use_entry_affinity = 0;
static cpu_set_t entry_affinity;
if (!use_entry_affinity) { if (!use_entry_affinity) {
pthread_t engine = pthread_self(); pthread_t engine = pthread_self();
...@@ -3050,7 +3046,8 @@ void engine_pin() { ...@@ -3050,7 +3046,8 @@ void engine_pin() {
void engine_unpin() { void engine_unpin() {
#ifdef HAVE_SETAFFINITY #ifdef HAVE_SETAFFINITY
pthread_t main_thread = pthread_self(); pthread_t main_thread = pthread_self();
pthread_setaffinity_np(main_thread, sizeof(entry_affinity), &entry_affinity); cpu_set_t *entry_affinity = engine_entry_affinity();
pthread_setaffinity_np(main_thread, sizeof(*entry_affinity), entry_affinity);
#else #else
error("SWIFT was not compiled with support for pinning."); error("SWIFT was not compiled with support for pinning.");
#endif #endif
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment