]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/CpuAffinitySet.cc
4 * DEBUG: section 54 Interprocess Communication
9 #include "base/TextException.h"
10 #include "CpuAffinitySet.h"
21 CpuAffinitySet::CpuAffinitySet()
24 CPU_ZERO(&theOrigCpuSet
);
28 CpuAffinitySet::apply()
30 Must(CPU_COUNT(&theCpuSet
) > 0); // CPU affinity mask set
34 if (sched_getaffinity(0, sizeof(theOrigCpuSet
), &theOrigCpuSet
)) {
35 debugs(54, DBG_IMPORTANT
, "ERROR: failed to get CPU affinity for "
36 "process PID " << getpid() << ", ignoring CPU affinity for "
37 "this process: " << xstrerror());
40 memcpy(&cpuSet
, &theCpuSet
, sizeof(cpuSet
));
41 (void) CPU_AND(&cpuSet
, &cpuSet
, &theOrigCpuSet
);
42 if (CPU_COUNT(&cpuSet
) <= 0) {
43 debugs(54, DBG_IMPORTANT
, "ERROR: invalid CPU affinity for process "
44 "PID " << getpid() << ", may be caused by an invalid core in "
45 "'cpu_affinity_map' or by external affinity restrictions");
46 } else if (sched_setaffinity(0, sizeof(cpuSet
), &cpuSet
)) {
47 debugs(54, DBG_IMPORTANT
, "ERROR: failed to set CPU affinity for "
48 "process PID " << getpid() << ": " << xstrerror());
53 CPU_ZERO(&theOrigCpuSet
);
57 CpuAffinitySet::undo()
60 if (sched_setaffinity(0, sizeof(theOrigCpuSet
), &theOrigCpuSet
)) {
61 debugs(54, DBG_IMPORTANT
, "ERROR: failed to restore original CPU "
62 "affinity for process PID " << getpid() << ": " <<
65 CPU_ZERO(&theOrigCpuSet
);
70 CpuAffinitySet::applied() const
72 return (CPU_COUNT(&theOrigCpuSet
) > 0);
76 CpuAffinitySet::set(const cpu_set_t
&aCpuSet
)
78 memcpy(&theCpuSet
, &aCpuSet
, sizeof(theCpuSet
));