]> git.ipfire.org Git - thirdparty/squid.git/blob - src/CpuAffinity.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / CpuAffinity.cc
1 /*
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 /* DEBUG: section 54 Interprocess Communication */
10
11 #include "squid.h"
12 #include "base/TextException.h"
13 #include "CpuAffinity.h"
14 #include "CpuAffinityMap.h"
15 #include "CpuAffinitySet.h"
16 #include "Debug.h"
17 #include "globals.h"
18 #include "SquidConfig.h"
19 #include "tools.h"
20
21 #include <algorithm>
22
23 static CpuAffinitySet *TheCpuAffinitySet = NULL;
24
25 void
26 CpuAffinityInit()
27 {
28 Must(!TheCpuAffinitySet);
29 if (Config.cpuAffinityMap) {
30 const int processNumber = InDaemonMode() ? KidIdentifier : 1;
31 TheCpuAffinitySet = Config.cpuAffinityMap->calculateSet(processNumber);
32 if (TheCpuAffinitySet)
33 TheCpuAffinitySet->apply();
34 }
35 }
36
37 void
38 CpuAffinityReconfigure()
39 {
40 if (TheCpuAffinitySet) {
41 TheCpuAffinitySet->undo();
42 delete TheCpuAffinitySet;
43 TheCpuAffinitySet = NULL;
44 }
45 CpuAffinityInit();
46 }
47
48 void
49 CpuAffinityCheck()
50 {
51 if (Config.cpuAffinityMap) {
52 Must(!Config.cpuAffinityMap->processes().empty());
53 const int maxProcess =
54 *std::max_element(Config.cpuAffinityMap->processes().begin(),
55 Config.cpuAffinityMap->processes().end());
56
57 // in no-deamon mode, there is one process regardless of squid.conf
58 const int numberOfProcesses = InDaemonMode() ? NumberOfKids() : 1;
59
60 if (maxProcess > numberOfProcesses) {
61 debugs(54, DBG_IMPORTANT, "WARNING: 'cpu_affinity_map' has "
62 "non-existing process number(s)");
63 }
64 }
65 }
66