NUMA++ 0.11.0
Loading...
Searching...
No Matches
numapolicies.hpp
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup numapp
4 * @copyright ESO 2024 - European Southern Observatory
5 *
6 * @brief Contains declarations for NumaPolicies
7 */
8#ifndef NUMAPP_NUMAPOLICIES_HPP_
9#define NUMAPP_NUMAPOLICIES_HPP_
10#include <iosfwd>
11
13#include <numapp/mempolicy.hpp>
14#include <numapp/scheduler.hpp>
15
16namespace numapp {
17
18class NumaPolicies;
19
20namespace thisThread {
21/**
22 * @name Apply Policies to Current Thread
23 *
24 * Applies specified policies to calling thread.
25 */
26/// @{
27
28/**
29 * Apply the set policies to current thread.
30 *
31 * If any failure occurs the function will stop applying policies and return error.
32 * This means the policies can be partially applied.
33 *
34 * @param policies The set of policies to apply.
35 * @returns system error code if policies fails to apply.
36 *
37 * @relatesalso numapp::NumaPolicies
38 */
39std::error_code Apply(NumaPolicies const& policies) noexcept;
40/// @}
41
42} // namespace thisThread
43
44/**
45 * Combines the the available NUMA policy types in one object.
46 *
47 * @ingroup numapp
48 */
49class NumaPolicies {
50public:
51 NumaPolicies() noexcept = default;
52 NumaPolicies(MemPolicy const& policy) : m_mempolicy(policy) {};
53 NumaPolicies(CpuAffinity const& policy) : m_affinity(policy) {};
54 NumaPolicies(Scheduler const& policy) : m_scheduler(policy) {};
55 NumaPolicies(NumaPolicies&&) noexcept = default;
56 NumaPolicies& operator=(NumaPolicies&&) noexcept = default;
57
58 NumaPolicies(NumaPolicies const& rhs) = default;
59 NumaPolicies& operator=(NumaPolicies const& rhs) noexcept = default;
60
61 /**
62 * Set CPU affinity.
63 */
64 inline void SetCpuAffinity(std::optional<CpuAffinity> affinity) noexcept;
65
66 /**
67 * Get CPU affinity.
68 */
69 inline std::optional<CpuAffinity> GetCpuAffinity() const noexcept;
70
71 /**
72 * Swap CPU affinity.
73 */
74 inline void SwapCpuAffinity(std::optional<CpuAffinity>& affinity) noexcept;
75
76 /**
77 * Set scheduler.
78 */
79 inline void SetScheduler(std::optional<Scheduler> scheduler) noexcept;
80
81 /**
82 * Get scheduler.
83 */
84 inline std::optional<Scheduler> GetScheduler() const noexcept;
85
86 /**
87 * Swap scheduler.
88 */
89 inline void SwapScheduler(std::optional<Scheduler>& scheduler) noexcept;
90
91 /**
92 * Set memory policy.
93 */
94 inline void SetMemPolicy(std::optional<MemPolicy> policy) noexcept;
95
96
97 /**
98 * Get memory policy.
99 */
100 inline std::optional<MemPolicy> GetMemPolicy() const noexcept;
101
102 /**
103 * Swap memory policy.
104 */
105 inline void SwapMemPolicy(std::optional<MemPolicy>& mempol) noexcept ;
106
107private:
108 std::optional<CpuAffinity> m_affinity;
109 std::optional<MemPolicy> m_mempolicy;
110 std::optional<Scheduler> m_scheduler;
111};
112
113// Inlines
114void NumaPolicies::SetCpuAffinity(std::optional<CpuAffinity> affinity) noexcept {
115 m_affinity.swap(affinity);
116}
117
118std::optional<CpuAffinity> NumaPolicies::GetCpuAffinity() const noexcept {
119 return m_affinity;
120}
121
122void NumaPolicies::SwapCpuAffinity(std::optional<CpuAffinity>& affinity) noexcept {
123 m_affinity.swap(affinity);
124}
125
126void NumaPolicies::SetScheduler(std::optional<Scheduler> scheduler) noexcept {
127 m_scheduler.swap(scheduler);
128}
129
130std::optional<Scheduler> NumaPolicies::GetScheduler() const noexcept {
131 return m_scheduler;
132}
133
134void NumaPolicies::SwapScheduler(std::optional<Scheduler>& scheduler) noexcept {
135 m_scheduler.swap(scheduler);
136}
137
138void NumaPolicies::SetMemPolicy(std::optional<MemPolicy> policy) noexcept {
139 m_mempolicy.swap(policy);
140}
141
142std::optional<MemPolicy> NumaPolicies::GetMemPolicy() const noexcept {
143 return m_mempolicy;
144}
145
146void NumaPolicies::SwapMemPolicy(std::optional<MemPolicy>& mempol) noexcept {
147 m_mempolicy.swap(mempol);
148}
149
150/**
151 * Formats @a policies and inserts it to @a os.
152 *
153 * @param os output stream to insert into.
154 * @param policies policy to format.
155 * @returns @a os
156 */
157std::ostream& operator<<(std::ostream& os, NumaPolicies const& policies);
158
159} // namespace numapp
160#endif // NUMAPP_NUMAPOLICIES_HPP_
Create CPU affinity and apply to current thread.
Class representing a memory policy that can be modified and used to apply to the current thread or a ...
Combines the the available NUMA policy types in one object.
void SwapScheduler(std::optional< Scheduler > &scheduler) noexcept
Swap scheduler.
void SwapMemPolicy(std::optional< MemPolicy > &mempol) noexcept
Swap memory policy.
void SetCpuAffinity(std::optional< CpuAffinity > affinity) noexcept
Set CPU affinity.
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.
void SwapCpuAffinity(std::optional< CpuAffinity > &affinity) noexcept
Swap CPU affinity.
void SetMemPolicy(std::optional< MemPolicy > policy) noexcept
Set memory policy.
void SetScheduler(std::optional< Scheduler > scheduler) noexcept
Set scheduler.
A sum-type of all supported schedulers.
Contains declarations for CpuAffinity.
std::error_code Apply(CpuAffinity const &affinity) noexcept
Apply policy to calling thread.
Contains declarations for numapp::MemPolicy.
Contains scheduler declarations.