NUMA++ 0.11.0
Loading...
Searching...
No Matches
lowlevel.hpp
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup numapp_ll
4 * @copyright ESO 2024 - European Southern Observatory
5 *
6 * @brief Contains low-level functions
7 */
8#ifndef NUMAPP_LOWLEVEL_HPP_
9#define NUMAPP_LOWLEVEL_HPP_
10#include "config.hpp"
11
12#include <sched.h>
13#include <system_error>
14#include <variant>
15
16#include "cpumask.hpp"
17#include "nodemask.hpp"
18
19namespace numapp {
20/**
21 * @brief Defines lowlevel functions that should not be used directly.
22 * @ingroup numapp_ll
23 */
24namespace ll {
25/**
26 * A low-level, and error prone function to set policy.
27 *
28 * Prefer to use the @ref numapp::Apply() functions instead.
29 *
30 * @ingroup numapp_ll
31 */
32std::error_code
33SetSchedulerPolicy(pid_t pid, int policy, int static_priority, int dynamic_priority) NUMAPP_NOEXCEPT;
34
35/**
36 * A low-level, and error prone function to get policy.
37 *
38 * Prefer to use the @c numapp::Scheduler instead.
39 *
40 * @ingroup numapp_ll
41 */
42std::error_code
43GetSchedulerPolicy(pid_t pid, int* policy, int* static_priority, int* dynamic_priority) NUMAPP_NOEXCEPT;
44
45/**
46 * Get CPU affinity.
47 *
48 * @param ttid Thread id to get the affinity from.
49 * @param[out] mask
50 * @return error code.
51 *
52 * @manpages
53 * @manpage{numa,3}
54 *
55 * @ingroup numapp_ll
56 */
57std::error_code GetCpuAffinity(pid_t ttid, Cpumask& mask) NUMAPP_NOEXCEPT;
58
59/**
60 * Set CPU affinity.
61 *
62 * @param ttid Thread id to apply the affinity to.
63 * @param mask CPU mask describing the desired affinity.
64 * @return error code.
65 *
66 * @manpages
67 * @manpage{numa,3}
68 *
69 * @ingroup numapp_ll
70 */
71std::error_code SetCpuAffinity(pid_t ttid, Cpumask const& mask) NUMAPP_NOEXCEPT;
72
73
74/**
75 * Convert NUMA node number to corresponding CPU mask.
76 *
77 * @param node NUMA node number to get mask for.
78 * @param [out] mask Destination CPU mask.
79 *
80 * @ingroup numapp_ll
81 */
82std::error_code NumaNodeToCpumask(int node, Cpumask& mask) NUMAPP_NOEXCEPT;
83
84
85/**
86 * Get memory policy for calling thread or an address.
87 *
88 * See manpage for details.
89 *
90 * @manpages
91 * @manpage{get_mempolicy,2}
92 *
93 * @param [out] mode memory policy.
94 * @param [out] mask The output nodemask.
95 * @param [in] addr Address to get policy for.
96 * @param [in] flags Determines operation.
97 * @return errors from get_mempolicy.
98 *
99 * @ingroup numapp_ll
100 */
101std::error_code GetMemPolicy(int& mode, Nodemask& mask, void* addr, unsigned flags) NUMAPP_NOEXCEPT;
102
103/**
104 * Set active memory policy for calling thread.
105 *
106 * @param mode memory policy.
107 * @param mask the input nodemask.
108 * @return errors from get_mempolicy.
109 *
110 * @ingroup numapp_ll
111 */
112std::error_code SetMemPolicy(int mode, Nodemask const& mask) NUMAPP_NOEXCEPT;
113
114/**
115 * Set memory policy for memory range.
116 *
117 * @param addr starting address.
118 * @param len memory range length.
119 * @param mode memory policy.
120 * @param mask the input nodemask.
121 * @param flags combination of MPOL_MF_* flags
122 * @return errors from mbind.
123 *
124 * @ingroup numapp_ll
125 */
126std::error_code
127SetMemPolicy(void* addr, std::size_t len, int mode, Nodemask const& mask, unsigned flags)
128 NUMAPP_NOEXCEPT;
129
130} // namespace ll
131
132} // namespace numapp
133
134#endif
Type-safe CPU mask.
Definition cpumask.hpp:25
NUMA++ configuration.
Contains declarations for CpumaskTrait.
Defines lowlevel functions that should not be used directly.
Definition lowlevel.hpp:24
std::error_code GetCpuAffinity(pid_t ttid, Cpumask &mask) noexcept
Get CPU affinity.
std::error_code SetMemPolicy(int mode, Nodemask const &mask) noexcept
Set active memory policy for calling thread.
std::error_code SetSchedulerPolicy(pid_t pid, int policy, int static_priority, int dynamic_priority) noexcept
A low-level, and error prone function to set policy.
std::error_code GetMemPolicy(int &mode, Nodemask &mask, void *addr, unsigned flags) noexcept
Get memory policy for calling thread or an address.
std::error_code NumaNodeToCpumask(int node, Cpumask &mask) noexcept
Convert NUMA node number to corresponding CPU mask.
std::error_code GetSchedulerPolicy(pid_t pid, int *policy, int *static_priority, int *dynamic_priority) noexcept
A low-level, and error prone function to get policy.
std::error_code SetCpuAffinity(pid_t ttid, Cpumask const &mask) noexcept
Set CPU affinity.
Contains declarations for Nodemask.
Type-safe NUMA node mask.
Definition nodemask.hpp:23