JayBeams
0.1
Another project to have fun coding.
|
A wrapper for the Linux CPU_SET data structure. More...
#include <cpu_set.hpp>
Public Member Functions | |
cpu_set () | |
std::size_t | capacity () const |
Return the number of CPUs that can be stored in the cpu set. More... | |
bool | status (int cpu) const |
Returns true if cpu is included in the cpu set. More... | |
int | count () const |
Return the number of cpus included in the cpu set. More... | |
cpu_set & | reset () |
Remove all cpus from the cpu set. More... | |
cpu_set & | set (int cpu) |
Add cpu to the cpu set. More... | |
cpu_set & | clear (int cpu) |
Remove cpu from the cpu set. More... | |
cpu_set & | set (int cpulo, int cpuhi) |
Add all the cpus in the [cpulo,cpuhi] range to the set. More... | |
cpu_set & | clear (int cpulo, int cpuhi) |
Remove all the cpus in the [cpulo,cpuhi] range from the set. More... | |
std::string | as_list_format () const |
Return the set in the list format representation. More... | |
Implement bitwise operations for cpu sets. | |
void | operator &= (cpu_set const &rhs) |
void | operator|= (cpu_set const &rhs) |
void | operator^= (cpu_set const &rhs) |
Comparison operators for cpu sets. | |
bool | operator== (cpu_set const &rhs) const |
bool | operator!= (cpu_set const &rhs) const |
Access the native implementation. | |
cpu_set_t * | native_handle () |
cpu_set_t const * | native_handle () const |
Static Public Member Functions | |
static cpu_set | parse (std::string const &value) |
Interpret value as a cpu set in list format. More... | |
Private Member Functions | |
void | check_range (int cpu, char const *op) const |
Check that cpu is in range. More... | |
void | check_range (int cpulo, int cpuhi, char const *op) const |
Check that [cpulo,cpuhi] is in range. More... | |
Static Private Member Functions | |
static void | parse_error (std::string const &value) |
Raise an exception because the input to parse() is invalid. More... | |
Private Attributes | |
cpu_set_t | set_ |
A wrapper for the Linux CPU_SET data structure.
Setting CPU affinity can help improve the predictability of our system. Typically different threads are assigned to different processors and in extreme cases no threads share the same core. The cpu sets are also typically configured using the "List Format" as described in cpuset(7). Briefly this format is:
cpuset ::= range[,cpuset] range ::= (number|number-number) number ::= a positive integer
So one can specify a cpu_set as "1,2,3" (cpus 1, 2 and 3), or "1-15" (cpus from 1 to 15), or "0-4,10,12-14" (cpus 0 to 4, 10 and 12 to 14).
The iostream operators (used for tests, and conversions everywhere) use this format.
TODO(#151) this is a portability problem. Many platforms can specify cpu affinity, but they all use different constructs for it. TODO(#152) we only support up to CPU_SETSIZE cpus, it is possible to control more CPUs in Linux, but the application that has access to more than 1024 cpus is rare indeed.
Definition at line 37 of file cpu_set.hpp.
|
inline |
Definition at line 39 of file cpu_set.hpp.
References set_.
std::string jb::cpu_set::as_list_format | ( | ) | const |
Return the set in the list format representation.
Definition at line 55 of file cpu_set.cpp.
References capacity(), and status().
Referenced by YAML::convert< jb::cpu_set >::encode(), operator!=(), and jb::operator<<().
|
inline |
Return the number of CPUs that can be stored in the cpu set.
Definition at line 45 of file cpu_set.hpp.
Referenced by as_list_format(), BOOST_AUTO_TEST_CASE(), and check_range().
|
private |
Check that cpu is in range.
std::out_of_range | if the argument is out of range. |
Definition at line 75 of file cpu_set.cpp.
References capacity().
Referenced by clear(), native_handle(), and set().
|
private |
Check that [cpulo,cpuhi] is in range.
std::out_of_range | if the arguments are out of range. |
Definition at line 85 of file cpu_set.cpp.
References capacity().
|
inline |
Remove cpu from the cpu set.
Definition at line 73 of file cpu_set.hpp.
References check_range(), and set_.
Referenced by BOOST_AUTO_TEST_CASE().
jb::cpu_set & jb::cpu_set::clear | ( | int | cpulo, |
int | cpuhi | ||
) |
Remove all the cpus in the [cpulo,cpuhi] range from the set.
Definition at line 16 of file cpu_set.cpp.
References check_range(), and set_.
|
inline |
Return the number of cpus included in the cpu set.
Definition at line 55 of file cpu_set.hpp.
References set_.
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Definition at line 127 of file cpu_set.hpp.
References set_.
|
inline |
Definition at line 130 of file cpu_set.hpp.
References check_range(), parse_error(), and set_.
|
inline |
Definition at line 89 of file cpu_set.hpp.
References set_.
|
inline |
Definition at line 108 of file cpu_set.hpp.
References as_list_format(), and parse().
|
inline |
Definition at line 104 of file cpu_set.hpp.
References set_.
|
inline |
Definition at line 95 of file cpu_set.hpp.
References set_.
|
inline |
Definition at line 92 of file cpu_set.hpp.
References set_.
|
static |
Interpret value as a cpu set in list format.
Definition at line 24 of file cpu_set.cpp.
References parse_error(), set(), and jb::strtonum().
Referenced by BOOST_AUTO_TEST_CASE(), YAML::convert< jb::cpu_set >::decode(), operator!=(), and jb::operator>>().
|
staticprivate |
Raise an exception because the input to parse() is invalid.
Definition at line 94 of file cpu_set.cpp.
Referenced by native_handle(), and parse().
|
inline |
|
inline |
Add cpu to the cpu set.
Definition at line 66 of file cpu_set.hpp.
References check_range(), and set_.
Referenced by BOOST_AUTO_TEST_CASE(), and parse().
jb::cpu_set & jb::cpu_set::set | ( | int | cpulo, |
int | cpuhi | ||
) |
Add all the cpus in the [cpulo,cpuhi] range to the set.
Definition at line 8 of file cpu_set.cpp.
References check_range(), and set_.
|
inline |
Returns true if cpu is included in the cpu set.
Definition at line 50 of file cpu_set.hpp.
References set_.
Referenced by as_list_format(), and BOOST_AUTO_TEST_CASE().
|
private |
Definition at line 156 of file cpu_set.hpp.
Referenced by clear(), count(), cpu_set(), native_handle(), operator &=(), operator==(), operator^=(), operator|=(), reset(), set(), and status().