]> git.ipfire.org Git - thirdparty/squid.git/blob - src/CpuAffinity.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[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 "structs.h"
14
15 #include <algorithm>
16
17 static CpuAffinitySet *TheCpuAffinitySet = NULL;
18
19
20 void
21 CpuAffinityInit()
22 {
23 Must(!TheCpuAffinitySet);
24 if (Config.cpuAffinityMap) {
25 const int processNumber = InDaemonMode() ? KidIdentifier : 1;
26 TheCpuAffinitySet = Config.cpuAffinityMap->calculateSet(processNumber);
27 if (TheCpuAffinitySet)
28 TheCpuAffinitySet->apply();
29 }
30 }
31
32 void
33 CpuAffinityReconfigure()
34 {
35 if (TheCpuAffinitySet) {
36 TheCpuAffinitySet->undo();
37 delete TheCpuAffinitySet;
38 TheCpuAffinitySet = NULL;
39 }
40 CpuAffinityInit();
41 }
42
43 void
44 CpuAffinityCheck()
45 {
46 if (Config.cpuAffinityMap) {
47 Must(!Config.cpuAffinityMap->processes().empty());
48 const int maxProcess =
49 *std::max_element(Config.cpuAffinityMap->processes().begin(),
50 Config.cpuAffinityMap->processes().end());
51
52 // in no-deamon mode, there is one process regardless of squid.conf
53 const int numberOfProcesses = InDaemonMode() ? NumberOfKids() : 1;
54
55 if (maxProcess > numberOfProcesses) {
56 debugs(54, DBG_IMPORTANT, "WARNING: 'cpu_affinity_map' has "
57 "non-existing process number(s)");
58 }
59 }
60 }