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

Function set_affinity

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

Source from the content-addressed store, hash-verified

78}
79
80static bool set_affinity(const std::vector<int>& ids) {
81 if (ids.empty()) return false;
82 const int highest = *std::max_element(ids.begin(), ids.end());
83 if (highest < 0) return false;
84 const size_t count = (std::max)(initial_cpu_count(), (size_t) highest + 1);
85 DynamicCpuSet set(count);
86 if (!set) return false;
87 for (int id : ids) {
88 if (id < 0 || (size_t) id >= count) return false;
89 CPU_SET_S((size_t) id, set.bytes(), set.get());
90 }
91 const int error = pthread_setaffinity_np(pthread_self(), set.bytes(), set.get());
92 if (error != 0) {
93 std::fprintf(stderr, "pthread_setaffinity_np failed: %s\n", std::strerror(error));
94 return false;
95 }
96 return true;
97}
98
99class OriginalAffinity {
100public:

Callers 5

restoreMethod · 0.85
~OriginalAffinityMethod · 0.85
round_trip_sparse_nestedFunction · 0.85
round_trip_high_cpuFunction · 0.85
dangling_else_guardFunction · 0.85

Calls 6

initial_cpu_countFunction · 0.85
getMethod · 0.65
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
bytesMethod · 0.45

Tested by

no test coverage detected