CpuAffinity.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2025 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/Stream.h"
17 #include "globals.h"
18 #include "SquidConfig.h"
19 #include "tools.h"
20 
21 #include <algorithm>
22 
24 
25 void
27 {
29  if (Config.cpuAffinityMap) {
30  const int processNumber = InDaemonMode() ? KidIdentifier : 1;
34  }
35 }
36 
37 void
39 {
40  if (TheCpuAffinitySet) {
42  delete TheCpuAffinitySet;
43  TheCpuAffinitySet = nullptr;
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 
int KidIdentifier
cpu affinity management for a single process
CpuAffinityMap * cpuAffinityMap
Definition: SquidConfig.h:522
CpuAffinitySet * calculateSet(const int targetProcess) const
calculate CPU set for this process
static CpuAffinitySet * TheCpuAffinitySet
Definition: CpuAffinity.cc:23
void CpuAffinityCheck()
check CPU affinity configuration and print warnings if needed
Definition: CpuAffinity.cc:49
void CpuAffinityInit()
set CPU affinity for this process on startup
Definition: CpuAffinity.cc:26
const std::vector< int > & processes() const
returns list of process numbers
#define Must(condition)
Definition: TextException.h:75
#define DBG_IMPORTANT
Definition: Stream.h:38
void undo()
undo CPU affinity changes for this process
int NumberOfKids()
number of Kid processes as defined in src/ipc/Kid.h
Definition: tools.cc:724
void apply()
set CPU affinity for this process
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
void CpuAffinityReconfigure()
reconfigure CPU affinity for this process
Definition: CpuAffinity.cc:38
class SquidConfig Config
Definition: SquidConfig.cc:12
bool InDaemonMode()
Whether we are running in daemon mode.
Definition: tools.cc:690

 

Introduction

Documentation

Support

Miscellaneous