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

Function get_affinity

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

Query with CPU_ALLOC rather than cpu_set_t: this must observe CPUs beyond CPU_SETSIZE too.

Source from the content-addressed store, hash-verified

56
57// Query with CPU_ALLOC rather than cpu_set_t: this must observe CPUs beyond CPU_SETSIZE too.
58static bool get_affinity(std::vector<int>& ids) {
59 size_t count = initial_cpu_count();
60 for (int attempt = 0; attempt < 8; ++attempt) {
61 DynamicCpuSet set(count);
62 if (!set) return false;
63 const int error = pthread_getaffinity_np(pthread_self(), set.bytes(), set.get());
64 if (error == 0) {
65 ids.clear();
66 for (size_t i = 0; i < set.count(); ++i)
67 if (CPU_ISSET_S(i, set.bytes(), set.get())) ids.push_back((int) i);
68 return !ids.empty();
69 }
70 if (error != EINVAL || count > (size_t(1) << 20)) {
71 std::fprintf(stderr, "pthread_getaffinity_np failed: %s\n", std::strerror(error));
72 return false;
73 }
74 count *= 2;
75 }
76 std::fprintf(stderr, "pthread_getaffinity_np still needs a larger CPU set\n");
77 return false;
78}
79
80static bool set_affinity(const std::vector<int>& ids) {
81 if (ids.empty()) return false;

Callers 6

captureMethod · 0.85
expect_affinityFunction · 0.85
negative_cpu_is_noopFunction · 0.85
worker_thread_can_pinFunction · 0.85

Calls 7

initial_cpu_countFunction · 0.85
push_backMethod · 0.80
getMethod · 0.65
bytesMethod · 0.45
clearMethod · 0.45
countMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected