Skip to content

Commit 787a503

Browse files
authored
Merge pull request #183 from intel-innersource/rdementi/no_restore_affinity1
don't restore the affinity if it was not changed
2 parents 32173a5 + 5bb73dc commit 787a503

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/cpucounters.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class TemporalThreadAffinity // speedup trick for Linux, FreeBSD, DragonFlyBSD,
133133
TemporalThreadAffinity(); // forbidden
134134
#if defined(__FreeBSD__) || (defined(__DragonFly__) && __DragonFly_version >= 400707)
135135
cpu_set_t old_affinity;
136-
const bool restore;
136+
bool restore;
137137

138138
public:
139139
TemporalThreadAffinity(uint32 core_id, bool checkStatus = true, const bool restore_ = true)
@@ -152,6 +152,7 @@ class TemporalThreadAffinity // speedup trick for Linux, FreeBSD, DragonFlyBSD,
152152
// CPU_CMP() returns true if old_affinity is NOT equal to new_affinity
153153
if (!(CPU_CMP(&old_affinity, &new_affinity)))
154154
{
155+
restore = false;
155156
return; // the same affinity => return
156157
}
157158
res = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &new_affinity);
@@ -171,7 +172,7 @@ class TemporalThreadAffinity // speedup trick for Linux, FreeBSD, DragonFlyBSD,
171172
cpu_set_t * old_affinity;
172173
static constexpr auto maxCPUs = 8192;
173174
const size_t set_size;
174-
const bool restore;
175+
bool restore;
175176

176177
public:
177178
TemporalThreadAffinity(const uint32 core_id, bool checkStatus = true, const bool restore_ = true)
@@ -193,6 +194,7 @@ class TemporalThreadAffinity // speedup trick for Linux, FreeBSD, DragonFlyBSD,
193194
if (CPU_EQUAL_S(set_size, old_affinity, new_affinity))
194195
{
195196
CPU_FREE(new_affinity);
197+
restore = false;
196198
return;
197199
}
198200
res = pthread_setaffinity_np(pthread_self(), set_size, new_affinity);

src/utils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ ThreadGroupTempAffinity::ThreadGroupTempAffinity(uint32 core_id, bool checkStatu
8888
if (GetThreadGroupAffinity(GetCurrentThread(), &PreviousGroupAffinity)
8989
&& (std::memcmp(&NewGroupAffinity, &PreviousGroupAffinity, sizeof(GROUP_AFFINITY)) == 0))
9090
{
91+
restore = false;
9192
return;
9293
}
9394
const auto res = SetThreadGroupAffinity(GetCurrentThread(), &NewGroupAffinity, &PreviousGroupAffinity);

src/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void print_cpu_details();
144144
class ThreadGroupTempAffinity
145145
{
146146
GROUP_AFFINITY PreviousGroupAffinity;
147-
const bool restore;
147+
bool restore;
148148

149149
ThreadGroupTempAffinity(); // forbidden
150150
ThreadGroupTempAffinity(const ThreadGroupTempAffinity &); // forbidden

0 commit comments

Comments
 (0)