MCPcopy Create free account
hub / github.com/Niko1221/Strata / main

Function main

engine/src/kernels/cpu/pool_affinity_test.cpp:133–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131}
132
133int main() {
134 if (!host_sibling_layout()) return 1;
135 const auto all = cpu::physical_cores(false);
136 std::vector<int> cores;
137 std::vector<ULONG> ids;
138 for (int core : all) {
139 if (std::any_of(cores.begin(), cores.end(), [core](int other) { return other / 64 == core / 64; })) continue;
140 ULONG id = 0;
141 if (!cpu::detail::cpu_set_for_core(core, id)) continue;
142 cores.push_back(core);
143 ids.push_back(id);
144 }
145 if (!check(!cores.empty(), "no usable CPU Sets")) return 1;
146 if (!check(cores.size() == GetActiveProcessorGroupCount(), "CPU Sets do not cover all active groups")) return 1;
147
148 // Hard pins belong on pool-owned threads; never contaminate the caller under test with one.
149 for (size_t i = 0; i < cores.size(); ++i) {
150 bool ok = false;
151 std::thread worker([&] {
152 if (!cpu::detail::set_thread_group_affinity(cores[i], (int) i)) return;
153 GROUP_AFFINITY pinned{};
154 if (!GetThreadGroupAffinity(GetCurrentThread(), &pinned)) return;
155 ok = pinned.Group == cores[i] / 64 && pinned.Mask == (KAFFINITY(1) << (cores[i] & 63));
156 // Host placement must also preserve an existing restrictive hard affinity.
157 const auto previous = cpu::pin_current_thread(cores.back());
158 cpu::restore_thread_affinity(previous);
159 GROUP_AFFINITY after{};
160 ok = ok && previous.valid && GetThreadGroupAffinity(GetCurrentThread(), &after) &&
161 after.Group == pinned.Group && after.Mask == pinned.Mask;
162 });
163 worker.join();
164 if (!check(ok, "worker hard pin / caller hard-affinity preservation")) return 1;
165 }
166
167 bool host_ok = false;
168 std::thread host([&] { host_ok = host_round_trips(cores, ids); });
169 host.join();
170 if (!host_ok || !inherited_default(cores.back(), ids.back(), cores.front(), ids.front())) return 1;
171 std::printf("Windows affinity test: worker pins, host CPU Sets and process-default restoration passed (%zu groups)\n", cores.size());
172 return 0;
173}

Callers

nothing calls this directly

Calls 15

host_sibling_layoutFunction · 0.85
host_round_tripsFunction · 0.85
inherited_defaultFunction · 0.85
push_backMethod · 0.80
frontMethod · 0.80
physical_coresFunction · 0.70
cpu_set_for_coreFunction · 0.70
checkFunction · 0.70
pin_current_threadFunction · 0.70
restore_thread_affinityFunction · 0.70
beginMethod · 0.45

Tested by

no test coverage detected