NUMA++ 0.12.0
Loading...
Searching...
No Matches
numapolicies.cpp
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup numapp
4 * @brief Definition of numapp::NumaPolicies
5 * @copyright
6 * SPDX-FileCopyrightText: 2020-2023 European Southern Observatory (ESO)
7 *
8 * SPDX-License-Identifier: LGPL-3.0-only
9 */
11
12#include <ostream>
13
14namespace numapp {
15namespace thisThread {
16std::error_code Apply(NumaPolicies const& policies) noexcept {
17 if (auto pol = policies.GetMemPolicy(); pol) {
18 if (auto ec = thisThread::Apply(*pol); ec) {
19 return ec;
20 }
21 }
22
23 if (auto pol = policies.GetCpuAffinity(); pol) {
24 if (auto ec = thisThread::Apply(*pol); ec) {
25 return ec;
26 }
27 }
28
29 if (auto pol = policies.GetScheduler(); pol) {
30 if (auto ec = thisThread::Apply(*pol); ec) {
31 return ec;
32 }
33 }
34 return {};
35}
36} // namespace thisThread
37
38std::ostream& operator<<(std::ostream& os, NumaPolicies const& policies) {
39 auto mempolicy = policies.GetMemPolicy();
40 auto affinity = policies.GetCpuAffinity();
41 auto scheduler = policies.GetScheduler();
42
43 if (mempolicy) {
44 os << *mempolicy;
45 } else {
46 os << "MemPolicy: n/a";
47 }
48 os << ", ";
49 if (affinity) {
50 os << *affinity;
51 } else {
52 os << "CpuAffinity: n/a";
53 }
54 os << ", ";
55 if (scheduler) {
56 os << *scheduler;
57 } else {
58 os << "Scheduler: n/a";
59 }
60
61 return os;
62}
63
64} // namespace numapp
Combines the the available NUMA policy types in one object.
std::optional< MemPolicy > GetMemPolicy() const noexcept
Get memory policy.
std::optional< Scheduler > GetScheduler() const noexcept
Get scheduler.
std::optional< CpuAffinity > GetCpuAffinity() const noexcept
Get CPU affinity.
std::error_code Apply(CpuAffinity const &affinity) noexcept
Apply policy to calling thread.
Contains declarations for NumaPolicies.