3 #include "cpu_timer.hpp"
4 #include "error_util.hpp"
5 #include "phonebook.hpp"
7 #include "record_logger.hpp"
8 #include "stoplight.hpp"
20 const record_header __threadloop_iteration_header{
21 "threadloop_iteration",
23 {
"plugin_id",
typeid(std::size_t)},
24 {
"iteration_no",
typeid(std::size_t)},
25 {
"skips",
typeid(std::size_t)},
26 {
"cpu_time_start",
typeid(std::chrono::nanoseconds)},
27 {
"cpu_time_stop",
typeid(std::chrono::nanoseconds)},
28 {
"wall_time_start",
typeid(std::chrono::high_resolution_clock::time_point)},
29 {
"wall_time_stop",
typeid(std::chrono::high_resolution_clock::time_point)},
60 _m_thread = std::thread(std::bind(&threadloop::thread_main,
this));
61 assert(!_m_stoplight->check_should_stop());
62 assert(_m_thread.joinable());
71 assert(_m_stoplight->check_should_stop());
72 assert(_m_thread.joinable());
82 _m_internal_stop.store(
true);
86 assert(_m_stoplight->check_should_stop());
87 assert(!_m_thread.joinable());
91 std::size_t iteration_no = 0;
92 std::size_t skip_no = 0;
96 record_coalescer it_log{record_logger_};
102 _m_stoplight->wait_for_ready();
110 std::this_thread::yield();
117 auto iteration_start_cpu_time = thread_cpu_time();
118 auto iteration_start_wall_time = std::chrono::high_resolution_clock::now();
124 it_log.log(record{__threadloop_iteration_header,
129 {iteration_start_cpu_time},
131 {iteration_start_wall_time},
132 {std::chrono::high_resolution_clock::now()},
145 [[maybe_unused]]
int cpp_requires_a_statement_after_a_label_plz_optimize_me_away;
189 return _m_internal_stop.load();
193 std::atomic<bool> _m_internal_stop{
false};
194 std::thread _m_thread;
195 std::shared_ptr<const Stoplight> _m_stoplight;
Start/stop synchronization for the whole application.
Definition: stoplight.hpp:106
A service locator for ILLIXR.
Definition: phonebook.hpp:68
std::shared_ptr< specific_service > lookup_impl() const
Look up an implementation of specific_service, which should be registered first.
Definition: phonebook.hpp:122
A dynamically-loadable plugin for Spindle.
Definition: plugin.hpp:32
virtual void start()
A method which Spindle calls when it starts the component.
Definition: plugin.hpp:41
A reusable threadloop for plugins.
Definition: threadloop.hpp:39
virtual void _p_thread_setup()
Gets called at setup time, from the new thread.
Definition: threadloop.hpp:174
skip_option
Definition: threadloop.hpp:149
@ run
Run iteration NOW. Only then does CPU timer begin counting.
@ skip_and_spin
AKA "busy wait". Skip but try again very quickly.
virtual void internal_stop()
Stops the thread.
Definition: threadloop.hpp:81
virtual void _p_one_iteration()=0
Override with the computation the thread does every loop.
bool should_terminate()
Whether the thread has been asked to terminate.
Definition: threadloop.hpp:188
void stop() override
Joins the thread.
Definition: threadloop.hpp:70
virtual skip_option _p_should_skip()
Gets called in a tight loop, to gate the invocation of _p_one_iteration()
Definition: threadloop.hpp:167
void start() override
Starts the thread.
Definition: threadloop.hpp:58
RAC_ERRNO_MSG.
Definition: data_format.hpp:15