]> git.ipfire.org Git - thirdparty/squid.git/blob - src/CpuAffinity.cc
Merged from trunk
[thirdparty/squid.git] / src / CpuAffinity.cc
1 /*
2 * $Id$
3 *
4 * DEBUG: section 54 Interprocess Communication
5 *
6 */
7
8 #include "squid.h"
9 #include "base/TextException.h"
10 #include "CpuAffinity.h"
11 #include "CpuAffinityMap.h"
12 #include "CpuAffinitySet.h"
13 #include "Debug.h"
14 #include "protos.h"
15 #include "structs.h"
16
17 #include <algorithm>
18
19 static CpuAffinitySet *TheCpuAffinitySet = NULL;
20
21 void
22 CpuAffinityInit()
23 {
24 Must(!TheCpuAffinitySet);
25 if (Config.cpuAffinityMap) {
26 const int processNumber = InDaemonMode() ? KidIdentifier : 1;
27 TheCpuAffinitySet = Config.cpuAffinityMap->calculateSet(processNumber);
28 if (TheCpuAffinitySet)
29 TheCpuAffinitySet->apply();
30 }
31 }
32
33 void
34 CpuAffinityReconfigure()
35 {
36 if (TheCpuAffinitySet) {
37 TheCpuAffinitySet->undo();
38 delete TheCpuAffinitySet;
39 TheCpuAffinitySet = NULL;
40 }
41 CpuAffinityInit();
42 }
43
44 void
45 CpuAffinityCheck()
46 {
47 if (Config.cpuAffinityMap) {
48 Must(!Config.cpuAffinityMap->processes().empty());
49 const int maxProcess =
50 *std::max_element(Config.cpuAffinityMap->processes().begin(),
51 Config.cpuAffinityMap->processes().end());
52
53 // in no-deamon mode, there is one process regardless of squid.conf
54 const int numberOfProcesses = InDaemonMode() ? NumberOfKids() : 1;
55
56 if (maxProcess > numberOfProcesses) {
57 debugs(54, DBG_IMPORTANT, "WARNING: 'cpu_affinity_map' has "
58 "non-existing process number(s)");
59 }
60 }
61 }