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

Function round_trip_high_cpu

engine/src/kernels/cpu/pool_affinity_linux_test.cpp:172–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170}
171
172static bool round_trip_high_cpu(const std::vector<int>& allowed, bool require_high) {
173 const auto it = std::find_if(allowed.begin(), allowed.end(), [](int id) { return id >= 64; });
174 if (it == allowed.end()) {
175 if (require_high) {
176 std::fprintf(stderr, "Linux affinity test: --require-high-cpu requested, but no allowed CPU ID is >= 64\n");
177 return false;
178 }
179 std::puts("SKIP high-CPU affinity path: no allowed CPU ID is >= 64 (use --require-high-cpu to require it)");
180 return true;
181 }
182 const int target = allowed.front() == *it ? (allowed.size() > 1 ? allowed.back() : *it) : allowed.front();
183 if (target == *it) {
184 if (require_high) {
185 std::fprintf(stderr, "Linux affinity test: --require-high-cpu needs at least two allowed CPUs to test restoration\n");
186 return false;
187 }
188 std::puts("SKIP high-CPU affinity round trip: only one CPU is allowed, so no meaningful pin transition is possible");
189 return true;
190 }
191
192 // Restrict the caller to one high-numbered CPU, then pin to a different originally allowed CPU.
193 // Restoring the high-only mask catches truncation even when the original process mask is sparse.
194 const std::vector<int> high_only{*it};
195 if (!set_affinity(high_only) || !expect_affinity(high_only, "establish high-only mask") ||
196 !topology_respects_current_mask()) return false;
197 const auto previous = cpu::pin_current_thread(target);
198 const bool pinned = previous.valid && expect_affinity({target}, "pin away from high-only mask");
199 cpu::restore_thread_affinity(previous);
200 const bool restored = pinned && expect_affinity(high_only, "restore high-only mask");
201 if (restored) std::printf("High-CPU affinity round trip: saved CPU %d, pin target %d\n", *it, target);
202 return restored;
203}
204
205static bool negative_cpu_is_noop() {
206 std::vector<int> before;

Callers 1

mainFunction · 0.85

Calls 10

set_affinityFunction · 0.85
expect_affinityFunction · 0.85
frontMethod · 0.80
pin_current_threadFunction · 0.70
restore_thread_affinityFunction · 0.70
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected