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