Skip to content

Commit

Permalink
HACK: Log the affinity masks.
Browse files Browse the repository at this point in the history
Something isn't working with the kokoro bot. Maybe this will tell us why.
  • Loading branch information
ben-clayton committed Jun 5, 2020
1 parent b0280cb commit 541b46d
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ const ProcessorGroups& getProcessorGroups() {
}
}
}
// printf("*** Processor groups ***\n");
// for (size_t i = 0; i < out.count; i++) {
// printf("** Group %d\n", (int)i);
// printf(" Count: %d\n", (int)out.groups[i].count);
// printf(" Mask: 0x%8llx\n", (uint64_t)out.groups[i].affinity);
// }
return out;
}();
return groups;
Expand Down Expand Up @@ -138,13 +144,20 @@ Thread::Affinity Thread::Affinity::all(
const auto& group = groups.groups[groupIdx];
Core core;
core.windows.group = static_cast<decltype(Core::windows.group)>(groupIdx);
for (size_t coreIdx = 0; coreIdx < sizeof(KAFFINITY) * 8; coreIdx++) {
for (unsigned int coreIdx = 0; coreIdx < group.count; coreIdx++) {
if ((group.affinity >> coreIdx) & 1) {
core.windows.index = static_cast<decltype(core.windows.index)>(coreIdx);
affinity.cores.emplace_back(std::move(core));
}
}
}

// printf("*** all() - count: %d***\n", (int)affinity.cores.size());
// for (auto core : affinity.cores) {
// printf("- g:%d i:%d\n", (int)core.windows.group,
// (int)core.windows.index);
// }

#elif defined(__linux__)
auto thread = pthread_self();
cpu_set_t cpuset;
Expand Down Expand Up @@ -199,6 +212,14 @@ std::shared_ptr<Thread::Affinity::Policy> Thread::Affinity::Policy::anyOf(
out.cores.push_back(core);
}
}

// printf("*** anyOf(threadId: %d, affinty: %d) ***\n", (int)threadId,
// (int)affinity.cores.size());
// for (auto core : out.cores) {
// printf("- g:%d i:%d\n", (int)core.windows.group,
// (int)core.windows.index);
//}

return out;
#else
return Affinity(affinity, allocator);
Expand Down Expand Up @@ -291,16 +312,19 @@ Thread::Thread(Affinity&& affinity, Func&& func) {
CHECK_WIN32(InitializeProcThreadAttributeList(attributes, 1, 0, &size));
defer(DeleteProcThreadAttributeList(attributes));

GROUP_AFFINITY groupAffinity = {};

auto count = affinity.count();
if (count > 0) {
GROUP_AFFINITY groupAffinity = {};
groupAffinity.Group = affinity[0].windows.group;
for (size_t i = 0; i < count; i++) {
auto core = affinity[i];
MARL_ASSERT(groupAffinity.Group == core.windows.group,
"Cannot create thread that uses multiple affinity groups");
groupAffinity.Mask |= (1ULL << core.windows.index);
}
// printf("groupAffinity.Group: 0x%x\n", (int)groupAffinity.Group);
// printf("groupAffinity.Mask: 0x%x\n", (int)groupAffinity.Mask);
CHECK_WIN32(UpdateProcThreadAttribute(
attributes, 0, PROC_THREAD_ATTRIBUTE_GROUP_AFFINITY, &groupAffinity,
sizeof(groupAffinity), nullptr, nullptr));
Expand Down

0 comments on commit 541b46d

Please sign in to comment.