CpuAffinity.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 "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
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
39 {
40  if (TheCpuAffinitySet) {
41  TheCpuAffinitySet->undo();
42  delete TheCpuAffinitySet;
43  TheCpuAffinitySet = NULL;
44  }
46 }
47 
48 void
50 {
51  if (Config.cpuAffinityMap) {
52  Must(!Config.cpuAffinityMap->processes().empty());
53  const int maxProcess =
54  *std::max_element(Config.cpuAffinityMap->processes().begin(),
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 
CpuAffinityMap * cpuAffinityMap
Definition: SquidConfig.h:522
CpuAffinitySet * calculateSet(const int targetProcess) const
calculate CPU set for this process
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
#define DBG_IMPORTANT
Definition: Debug.h:45
int NumberOfKids()
number of Kid processes as defined in src/ipc/Kid.h
Definition: tools.cc:686
void CpuAffinityInit()
set CPU affinity for this process on startup
Definition: CpuAffinity.cc:26
#define Must(cond)
Definition: TextException.h:89
void CpuAffinityReconfigure()
reconfigure CPU affinity for this process
Definition: CpuAffinity.cc:38
bool InDaemonMode()
Whether we are running in daemon mode.
Definition: tools.cc:652
int KidIdentifier
cpu affinity management for a single process
static CpuAffinitySet * TheCpuAffinitySet
Definition: CpuAffinity.cc:23
void apply()
set CPU affinity for this process
const std::vector< int > & processes() const
returns list of process numbers
void undo()
undo CPU affinity changes for this process
class SquidConfig Config
Definition: SquidConfig.cc:12
#define NULL
Definition: types.h:166
void CpuAffinityCheck()
check CPU affinity configuration and print warnings if needed
Definition: CpuAffinity.cc:49

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors