Motorcortex Core
version: 2.7.6
|
6 #ifndef CONTAINER_CT_TASK_H
7 #define CONTAINER_CT_TASK_H
9 #include "cmdline_task.h"
10 #include "ct_tasksched.h"
12 #include "ps_parameter.h"
13 #include "utl_realtime.h"
20 namespace mcx::container {
89 void add(
const std::vector<Module*>& modules);
120 void start(uint64_t cycle_time_micro_s, TaskSched task_sched,
const std::vector<uint32_t>& cpu_affinity_list = {},
121 uint32_t priority = 0);
189 bool setCpuAffinity(
const std::vector<uint32_t>& cpu_affinity_list);
202 struct TimeStatistics {
213 timespec prepare(pthread_attr_t& gattr);
217 static void* runHelper(
void* context);
219 struct timespec syncToIdealTime(struct timespec t_ideal);
221 static inline void fillCycleTime(TimeStatistics* cycle_time, uint64_t time, uint64_t cycle);
223 const char* policyToStr(uint32_t policy)
const;
225 std::atomic<State> state_{State::OFF};
226 std::atomic<bool> is_running_{
false};
227 std::string task_name_{
"Undefined"};
229 struct timespec desired_cycle_time_ {};
230 TimeStatistics actual_cycle_time_{};
232 int32_t reset_absolute_max_time_micro_s_{};
233 uint64_t absolute_max_time_micro_s_{};
234 uint64_t desired_cycle_time_micro_s_{1000};
235 std::atomic<uint64_t> nr_of_cycles_{};
236 TimeStatistics utilization_percent_{};
238 double secaligned_{0.1};
239 int32_t startop_[2]{};
241 std::vector<uint32_t> cpu_affinity_list_{};
242 sched_param sched_priority_{};
243 pthread_t task_thread_id_{};
244 uint32_t sched_policy_{};
246 uint64_t stack_size_{};
249 #pragma clang diagnostic push
250 #pragma clang diagnostic ignored "-Wunused-private-field"
252 utils::PageFaults page_faults_{};
254 #pragma clang diagnostic pop
257 std::vector<ModuleInfo> modules_;
258 parameter_server::Parameter local_branch_;
263 inline void Task::fillCycleTime(TimeStatistics* cycle_time, uint64_t time, uint64_t cycle) {
264 cycle_time->actual = time;
266 cycle_time->max = cycle_time->actual;
268 cycle_time->max = cycle_time->actual > cycle_time->max ? cycle_time->actual : cycle_time->max;
274 #endif // CONTAINER_CT_TASK_H
const std::vector< uint32_t > & getCpuAffinity() const
Gets list of CPUs to which task is bound.
Definition: ct_task.cpp:489
void setStackSize(uint64_t size_bytes)
Sets stack size of the task bytes.
Definition: ct_task.cpp:74
uint32_t getSchedPolicy() const
Gets task scheduler policy.
Definition: ct_task.cpp:448
void stop()
Stops Operation Phase of the task.
Definition: ct_task.cpp:121
Definition: ps_parameter.h:45
void add(Module *module)
Adds module to the task.
Definition: ct_task.cpp:78
Task & operator=(Task &orig)=delete
Copy constructors are deleted.
void setName(const char *name)
Sets the name of the task.
Definition: ct_task.cpp:65
Event loop and concurrency primitive for Motorcortex modules.
Definition: ct_task.h:31
uint64_t getNrOfCycles() const
Gets number of execution cycles.
Definition: ct_task.cpp:421
Definition: cmdline_task.h:16
int getSchedPriority() const
Gets task scheduler priority.
Definition: ct_task.cpp:470
Task()=delete
Default constructor is deleted.
double getCycleTimeS() const
Gets cycle time of the event-loop of the task in seconds.
Definition: ct_task.cpp:425
bool setSchedPriority(int priority)
Sets task scheduler priority.
Definition: ct_task.cpp:450
uint64_t getStackSize() const
Returns stack size of the task im bytes.
Definition: ct_task.cpp:76
void start(uint64_t cycle_time_micro_s, TaskSched task_sched, const std::vector< uint32_t > &cpu_affinity_list={}, uint32_t priority=0)
Starts Operation Phase of the task.
Definition: ct_task.cpp:101
bool setCpuAffinity(const std::vector< uint32_t > &cpu_affinity_list)
Binds task to the list of CPUs.
Definition: ct_task.cpp:472
void configure()
Starts Configuration Phase of the task.
Definition: ct_task.cpp:89
const char * getName() const
Returns the name of the task.
Definition: ct_task.cpp:70
Task(Task &orig)=delete
Copy constructors are deleted.
bool setSchedPolicy(uint32_t policy)
Sets task scheduler policy.
Definition: ct_task.cpp:427
A building block of the Motorcortex components.
Definition: ct_module.h:64
uint64_t getCycleMicroS() const
Gets cycle time of the event-loop of the task in microseconds.
Definition: ct_task.cpp:423
void setCycleTimeMicroS(uint64_t cycle_time_micro_s)
Sets a cycle time of the event-loop of the task.
Definition: ct_task.cpp:413
bool running() const
Returns true if task is running.
Definition: ct_task.cpp:72
virtual ~Task()
Destructor brings all the task modules to a destroy phase.
Definition: ct_task.cpp:57