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 cda1436
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
44 changes: 22 additions & 22 deletions src/scheduler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,28 +143,28 @@ TEST_P(WithBoundScheduler, FibersResumeOnSameStdThread) {
}

TEST_F(WithoutBoundScheduler, TasksOnlyScheduledOnWorkerThreads) {
marl::Scheduler::Config cfg;
cfg.setWorkerThreadCount(8);

auto scheduler = std::unique_ptr<marl::Scheduler>(new marl::Scheduler(cfg));
scheduler->bind();
defer(scheduler->unbind());

std::mutex mutex;
marl::containers::unordered_set<std::thread::id> threads(allocator);
marl::WaitGroup wg;
for (int i = 0; i < 10000; i++) {
wg.add(1);
marl::schedule([&mutex, &threads, wg] {
defer(wg.done());
std::unique_lock<std::mutex> lock(mutex);
threads.emplace(std::this_thread::get_id());
});
}
wg.wait();

ASSERT_LE(threads.size(), 8U);
ASSERT_EQ(threads.count(std::this_thread::get_id()), 0U);
printf("**%d\n", __LINE__); marl::Scheduler::Config cfg;
printf("**%d\n", __LINE__); cfg.setWorkerThreadCount(8);
printf("**%d\n", __LINE__);
printf("**%d\n", __LINE__); auto scheduler = std::unique_ptr<marl::Scheduler>(new marl::Scheduler(cfg));
printf("**%d\n", __LINE__); scheduler->bind();
printf("**%d\n", __LINE__); defer(scheduler->unbind());
printf("**%d\n", __LINE__);
printf("**%d\n", __LINE__); std::mutex mutex;
printf("**%d\n", __LINE__); marl::containers::unordered_set<std::thread::id> threads(allocator);
printf("**%d\n", __LINE__); marl::WaitGroup wg;
printf("**%d\n", __LINE__); for (int i = 0; i < 10; i++) {
printf("**%d\n", __LINE__); wg.add(1);
printf("**%d\n", __LINE__); marl::schedule([&mutex, &threads, wg] {
printf("**%d\n", __LINE__); defer(wg.done());
printf("**%d\n", __LINE__); std::unique_lock<std::mutex> lock(mutex);
printf("**%d\n", __LINE__); threads.emplace(std::this_thread::get_id());
printf("**%d\n", __LINE__); });
printf("**%d\n", __LINE__); }
printf("**%d\n", __LINE__); wg.wait();
printf("**%d\n", __LINE__);
printf("**%d\n", __LINE__); ASSERT_LE(threads.size(), 8U);
printf("**%d\n", __LINE__); ASSERT_EQ(threads.count(std::this_thread::get_id()), 0U);
}

// Test that a marl::Scheduler *with dedicated worker threads* can be used
Expand Down
22 changes: 21 additions & 1 deletion 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,19 @@ 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 +211,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

0 comments on commit cda1436

Please sign in to comment.