]>
Commit | Line | Data |
---|---|---|
96c2bb61 | 1 | /* |
bbc27441 | 2 | * Copyright (C) 1996-2014 The Squid Software Foundation and contributors |
96c2bb61 | 3 | * |
bbc27441 AJ |
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. | |
96c2bb61 AR |
7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 54 Interprocess Communication */ |
10 | ||
f7f3304a | 11 | #include "squid.h" |
96c2bb61 AR |
12 | #include "base/TextException.h" |
13 | #include "CpuAffinityMap.h" | |
14 | #include "CpuAffinitySet.h" | |
15 | #include "Debug.h" | |
16 | ||
96c2bb61 | 17 | bool |
c8ea3cc0 | 18 | CpuAffinityMap::add(const std::vector<int> &aProcesses, const std::vector<int> &aCores) |
96c2bb61 AR |
19 | { |
20 | if (aProcesses.size() != aCores.size()) | |
21 | return false; | |
22 | ||
23 | for (size_t i = 0; i < aProcesses.size(); ++i) { | |
24 | const int process = aProcesses[i]; | |
25 | const int core = aCores[i]; | |
26 | if (process <= 0 || core <= 0) | |
27 | return false; | |
28 | theProcesses.push_back(process); | |
29 | theCores.push_back(core); | |
30 | } | |
31 | ||
32 | return true; | |
33 | } | |
34 | ||
35 | CpuAffinitySet * | |
36 | CpuAffinityMap::calculateSet(const int targetProcess) const | |
37 | { | |
38 | Must(theProcesses.size() == theCores.size()); | |
39 | int core = 0; | |
40 | for (size_t i = 0; i < theProcesses.size(); ++i) { | |
41 | const int process = theProcesses[i]; | |
212af65c | 42 | if (process == targetProcess) { |
96c2bb61 AR |
43 | if (core > 0) { |
44 | debugs(54, DBG_CRITICAL, "WARNING: conflicting " | |
45 | "'cpu_affinity_map' for process number " << process << | |
46 | ", using the last core seen: " << theCores[i]); | |
47 | } | |
48 | core = theCores[i]; | |
49 | } | |
50 | } | |
51 | CpuAffinitySet *cpuAffinitySet = NULL; | |
52 | if (core > 0) { | |
53 | cpuAffinitySet = new CpuAffinitySet; | |
54 | cpu_set_t cpuSet; | |
55 | CPU_ZERO(&cpuSet); | |
56 | CPU_SET(core - 1, &cpuSet); | |
57 | cpuAffinitySet->set(cpuSet); | |
58 | } | |
59 | return cpuAffinitySet; | |
60 | } |