NUMA++ 0.11.0
Loading...
Searching...
No Matches
numapolicies.cpp
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup numapp
4 * @copyright ESO 2024 - European Southern Observatory
5 *
6 * @brief Definition of numapp::NumaPolicies
7 */
9
10#include <ostream>
11
12namespace numapp {
13namespace thisThread {
14std::error_code Apply(NumaPolicies const& policies) noexcept {
15 if (auto pol = policies.GetMemPolicy(); pol) {
16 if (auto ec = thisThread::Apply(*pol); ec) {
17 return ec;
18 }
19 }
20
21 if (auto pol = policies.GetCpuAffinity(); pol) {
22 if (auto ec = thisThread::Apply(*pol); ec) {
23 return ec;
24 }
25 }
26
27 if (auto pol = policies.GetScheduler(); pol) {
28 if (auto ec = thisThread::Apply(*pol); ec) {
29 return ec;
30 }
31 }
32 return {};
33}
34} // namespace thisThread
35
36std::ostream& operator<<(std::ostream& os, NumaPolicies const& policies) {
37 auto mempolicy = policies.GetMemPolicy();
38 auto affinity = policies.GetCpuAffinity();
39 auto scheduler = policies.GetScheduler();
40
41 if (mempolicy) {
42 os << *mempolicy;
43 } else {
44 os << "MemPolicy: n/a";
45 }
46 os << ", ";
47 if (affinity) {
48 os << *affinity;
49 } else {
50 os << "CpuAffinity: n/a";
51 }
52 os << ", ";
53 if (scheduler) {
54 os << *scheduler;
55 } else {
56 os << "Scheduler: n/a";
57 }
58
59 return os;
60}
61
62} // 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.