41 std::string strbuf(256,
'\0');
42 int retval = evl_init();
44 strerror_r(errno, strbuf.data(), strbuf.size());
45 ERROR_MSG(
"RT::OS(EVL)::initiate : evl_init() : {}", strbuf);
50 struct sched_param param
53 param.sched_priority = 8;
54 retval = pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
56 ERROR_MSG(
"RT::OS(EVL)::initiate : Unable to set scheduling parameters");
60 int thread_fd = evl_attach_self(
"RTXI-RT-Thread:%d", getpid());
62 strerror_r(errno, strbuf.data(), strbuf.size());
63 ERROR_MSG(
"RT::OS(EVL)::initiate : evl_attach_self() : {}", strbuf);
74 int retval = evl_detach_self();
75 std::string strbuf(256,
'\0');
77 strerror_r(errno, strbuf.data(), strbuf.size());
78 ERROR_MSG(
"Unable to detach thread from evl core!");
79 ERROR_MSG(
"RT::OS(EVL)::shutdown : evl_detach_self() : {}", strbuf);
91 ERROR_MSG(
"RT::OS::createTask : Task cannot be created from rt context");
94 auto wrapper = [](
RT::OS::Task* tsk, void (*fn)(
void*),
void* args)
96 std::string strbuf(256,
'\0');
99 strerror_r(errno, strbuf.data(), strbuf.size());
100 ERROR_MSG(
"RT::OS::createTask : RT::OS::initiate() : {}", strbuf);
108 std::thread thread_obj(wrapper, task, func, arg);
109 if (thread_obj.joinable()) {
121 ERROR_MSG(
"RT::OS::createTask : Task cannot be deleted from rt context");
139 evl_read_clock(EVL_CLOCK_MONOTONIC, &tp);
162 if (task->
next_t < current_time) {
166 int64_t wakeup_time = task->
next_t;
172 evl_sleep_until(EVL_CLOCK_MONOTONIC, &ts);
181 if (pthread_setname_np(thread.native_handle(), name.c_str()) != 0) {
182 ERROR_MSG(
"RT::OS::renameOSThread : unable to set name to thread");
198 double cpu_percent = 0.0;
199 int64_t cpu_time_elapsed = 0;
200 int64_t proc_time_elapsed = 0;
202 timespec clock_time = {};
203 timespec proc_time = {};
206 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &proc_time);
207 clock_gettime(CLOCK_REALTIME, &clock_time);
213 if (cpu_time_elapsed <= 0) {
219 cpu_percent = 100.0 * (
static_cast<double>(proc_time_elapsed))
220 /
static_cast<double>(cpu_time_elapsed);
void ERROR_MSG(const std::string &errmsg, Args... args)
int createTask(Task *task, void(*func)(void *), void *arg)
int setPeriod(Task *task, int64_t period)
const int64_t SECONDS_TO_NANOSECONDS
void shutdown(RT::OS::Task *task)
void sleepTimestep(Task *task)
void renameOSThread(std::thread &thread, const std::string &name)
int initiate(RT::OS::Task *task)
void deleteTask(Task *task)
const int64_t DEFAULT_PERIOD
thread_local int64_t * RT_PERIOD
thread_local bool realtime_key