CpuAffinityMap.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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/Stream.h"
16
17bool
18CpuAffinityMap::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
36CpuAffinityMap::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 = nullptr;
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
#define Must(condition)
Definition: TextException.h:75
CpuAffinitySet * calculateSet(const int targetProcess) const
calculate CPU set for this process
bool add(const std::vector< int > &aProcesses, const std::vector< int > &aCores)
append cpu_affinity_map option
std::vector< int > theProcesses
list of process numbers
std::vector< int > theCores
list of cores
cpu affinity management for a single process
void set(const cpu_set_t &aCpuSet)
set CPU affinity mask
#define CPU_SET(cpunum, cpuset)
Definition: cpu.h:38
#define CPU_ZERO(set)
Definition: cpu.h:34
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define DBG_CRITICAL
Definition: Stream.h:37
Definition: cpu.h:21

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors