ros2_control - rolling
Classes | Typedefs | Functions | Variables
realtime_tools Namespace Reference

Classes

class  AsyncFunctionHandler
 Class to handle asynchronous function calls. AsyncFunctionHandler is a class that allows the user to have a asynchronous call to the parsed method and be able to set some thread specific parameters. More...
 
class  RealtimeBoxBase
 
class  RealtimeBuffer
 
class  RealtimeClock
 
class  RealtimePublisher
 
class  RealtimeServerGoalHandle
 

Typedefs

template<typename T , typename mutex_type = std::mutex>
using RealtimeBoxBestEffort = RealtimeBoxBase< T, mutex_type >
 
template<typename T >
using RealtimeBoxStandard = RealtimeBoxBase< T, std::mutex >
 
template<typename T >
using RealtimeBoxRecursive = RealtimeBoxBase< T, std::recursive_mutex >
 
template<typename T >
using RealtimeBox = RealtimeBoxStandard< T >
 
template<class MessageT >
using RealtimePublisherSharedPtr = std::shared_ptr< RealtimePublisher< MessageT > >
 

Functions

bool has_realtime_kernel ()
 
bool configure_sched_fifo (int priority)
 
bool lock_memory (std::string &message)
 
std::pair< bool, std::string > lock_memory ()
 
std::pair< bool, std::string > set_thread_affinity (NATIVE_THREAD_HANDLE thread, const std::vector< int > &cores)
 
std::pair< bool, std::string > set_thread_affinity (NATIVE_THREAD_HANDLE thread, int core)
 
std::pair< bool, std::string > set_thread_affinity (std::thread &thread, int core)
 
std::pair< bool, std::string > set_current_thread_affinity (int core)
 
std::pair< bool, std::string > set_current_thread_affinity (const std::vector< int > &cores)
 
int64_t get_number_of_available_processors ()
 

Variables

template<typename T >
constexpr auto is_ptr_or_smart_ptr = rcpputils::is_pointer<T>::value
 

Detailed Description

Author
Sai Kishor Kothakota
Stuart Glaser

Function Documentation

◆ configure_sched_fifo()

bool realtime_tools::configure_sched_fifo ( int  priority)

Configure SCHED_FIFO thread priority for the thread that calls this function

Parameters
[in]prioritythe priority of this thread from 0-99
Returns
true if configuring scheduler succeeded

◆ get_number_of_available_processors()

int64_t realtime_tools::get_number_of_available_processors ( )

Method to get the amount of available cpu cores https://man7.org/linux/man-pages/man3/sysconf.3.html https://stackoverflow.com/a/150971

Returns
The number of processors currently online (available)

◆ has_realtime_kernel()

bool realtime_tools::has_realtime_kernel ( )

Detect if realtime kernel is present.

Returns
true if realtime kernel is detected

◆ lock_memory() [1/2]

std::pair< bool, std::string > realtime_tools::lock_memory ( )

Locks the memory pages of the calling thread to prevent page faults. By calling this method, the programs locks all pages mapped into the address space of the calling process and future mappings. This means that the kernel will not swap out the pages to disk i.e., the pages are guaranteed to stay in RAM until later unlocked - which is important for realtime applications.

Parameters
[out]messagea message describing the result of the operation
Returns
a pair of a boolean indicating whether the operation succeeded or not and a message describing the result of the operation

◆ lock_memory() [2/2]

bool realtime_tools::lock_memory ( std::string &  message)

Locks the memory pages of the calling thread to prevent page faults. By calling this method, the programs locks all pages mapped into the address space of the calling process and future mappings. This means that the kernel will not swap out the pages to disk i.e., the pages are guaranteed to stay in RAM until later unlocked - which is important for realtime applications.

Parameters
[out]messagea message describing the result of the operation
Returns
true if memory locking succeeded, false otherwise.

◆ set_current_thread_affinity() [1/2]

std::pair< bool, std::string > realtime_tools::set_current_thread_affinity ( const std::vector< int > &  cores)

Configure the current thread affinity - Tell the scheduler to prefer a certain set of cores for the current thread.

Note
The threads created by the calling thread will inherit the affinity.
Parameters
[in]corethe cpu numbers of the core. If an empty vector is passed, the affinity is reset to the default.
Returns
a pair of a boolean indicating whether the operation succeeded or not and a message describing the result of the operation

◆ set_current_thread_affinity() [2/2]

std::pair< bool, std::string > realtime_tools::set_current_thread_affinity ( int  core)

Configure the current thread affinity - Tell the scheduler to prefer a certain core for the current thread.

Note
The threads created by the calling thread will inherit the affinity.
Parameters
[in]corethe cpu number of the core. If a negative number is passed, the affinity is reset to the default.
Returns
a pair of a boolean indicating whether the operation succeeded or not and a message describing the result of the operation

◆ set_thread_affinity() [1/3]

std::pair< bool, std::string > realtime_tools::set_thread_affinity ( NATIVE_THREAD_HANDLE  thread,
const std::vector< int > &  cores 
)

Configure the caller thread affinity - Tell the scheduler to prefer a certain set of cores for the given thread handle.

Note
The threads created by the calling thread will inherit the affinity.
Parameters
[in]threadthe thread handle of the thread
[in]corethe cpu numbers of the core. If an empty vector is passed, the affinity is reset to the default.
Returns
a pair of a boolean indicating whether the operation succeeded or not and a message describing the result of the operation

◆ set_thread_affinity() [2/3]

std::pair< bool, std::string > realtime_tools::set_thread_affinity ( NATIVE_THREAD_HANDLE  thread,
int  core 
)

Configure the caller thread affinity - Tell the scheduler to prefer a certain core for the given thread handle.

Note
The threads created by the calling thread will inherit the affinity.
Parameters
[in]threadthe thread handle of the thread
[in]corethe cpu number of the core. If a negative number is passed, the affinity is reset to the default.
Returns
a pair of a boolean indicating whether the operation succeeded or not and a message describing the result of the operation

◆ set_thread_affinity() [3/3]

std::pair< bool, std::string > realtime_tools::set_thread_affinity ( std::thread &  thread,
int  core 
)

Configure the caller thread affinity - Tell the scheduler to prefer a certain core for the given thread.

Note
The threads created by the calling thread will inherit the affinity.
Parameters
[in]threadthe reference of the thread
[in]corethe cpu number of the core. If a negative number is passed, the affinity is reset to the default.
Returns
a pair of a boolean indicating whether the operation succeeded or not and a message describing the result of the operation