CpuAffinityMap.cc
Go to the documentation of this file.
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 "CpuAffinityMap.h"
14 #include "CpuAffinitySet.h"
15 #include "Debug.h"
16 
17 bool
18 CpuAffinityMap::add(const std::vector<int> &aProcesses, const std::vector<int> &aCores)
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 
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];
42  if (process == targetProcess) {
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 }
61 
int i
Definition: membanger.c:49
#define CPU_ZERO(set)
Definition: cpu.h:35
#define DBG_CRITICAL
Definition: Debug.h:44
CpuAffinitySet * calculateSet(const int targetProcess) const
calculate CPU set for this process
#define CPU_SET(cpu, set)
Definition: cpu.h:39
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
std::vector< int > theProcesses
list of process numbers
#define Must(cond)
Definition: TextException.h:89
cpu affinity management for a single process
bool add(const std::vector< int > &aProcesses, const std::vector< int > &aCores)
append cpu_affinity_map option
Definition: cpu.h:22
std::vector< int > theCores
list of cores
void set(const cpu_set_t &aCpuSet)
set CPU affinity mask
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors