53 unsigned long RTStackSize,
58 const std::string& LogProcName)
60 RTStackSize, bRTAllowNonRoot, RTCpuMap),
63 LogProcName(LogProcName),
75 ASSERT(!bRTlog || !LogProcName.empty());
81 rtmbdyn_rt_mbx_delete(&
mbxlog);
97 out <<
"period, time step, " <<
lRTPeriod;
109 out <<
", allow nonroot";
117 out <<
", hard realtime";
121 out <<
", realtime log, \"" <<
LogProcName <<
"\"";
132 rtmbdyn_rt_allow_nonroot_hrt();
135 ASSERT(::rtmbdyn_rtai_task == 0);
138 if (rtmbdyn_rt_task_init(
"MBDTSK", 1, 0, 0,
RTCpuMap,
139 &::rtmbdyn_rtai_task))
141 silent_cerr(
"RTAISolver: unable to init RTAI task" << std::endl);
151 if (!rtmbdyn_rt_is_hard_timer_running()) {
153 silent_cout(
"RTAISolver: Hard timer is started by MBDyn"
155 rtmbdyn_rt_set_oneshot_mode();
156 rtmbdyn_start_rt_timer(rtmbdyn_nano2count(1000000));
166 long long t = rtmbdyn_rt_get_time();
172 silent_cout(
"RTAISolver: Task: " << ::rtmbdyn_rtai_task
180 r = rtmbdyn_rt_task_make_periodic(::rtmbdyn_rtai_task,
184 silent_cerr(
"RTAISolver: "
185 "rtmbdyn_rt_task_make_periodic() failed "
186 "(" << r <<
")" << std::endl);
198 r = rtmbdyn_rt_sem_init(
"MBDSMI", 0, &
RTSemPtr_in);
200 silent_cerr(
"rt_sem_init() failed ("
201 << r <<
")" << std::endl);
211 silent_cerr(
"rt_sem_init() failed ("
212 << r <<
")" << std::endl);
220 silent_cout(
"RTAISolver: MBDyn starts overruns monitor "
224 const char *mbxlogname =
"logmb";
225 if (rtmbdyn_rt_mbx_init(mbxlogname,
sizeof(
msg)*16, &
mbxlog)) {
227 silent_cerr(
"RTAISolver: cannot init log mailbox "
228 "\"" << mbxlogname <<
"\""
232 const char *nonroot =
237 char LogCpuMap[] =
"0xFF";
242 snprintf(LogCpuMap,
sizeof(LogCpuMap),
248 "MBDTSK", mbxlogname,
249 LogCpuMap, nonroot, NULL) == 0)
255 silent_cout(
"RTAISolver: cannot start "
258 "using default" << std::endl);
266 char *origpath = getenv(
"PATH");
269 setenv(
"PATH",
".:" BINPATH, 1);
272 std::string newpath =
".:" BINPATH
":";
274 setenv(
"PATH", newpath.c_str(), 1);
276 #endif // HAVE_SETENV
279 if (execlp(
"logproc",
"logproc",
"MBDTSK",
280 mbxlogname, LogCpuMap, nonroot, NULL)
283 silent_cout(
"RTAISolver: cannot start default "
284 "log procedure \"logproc\""
293 silent_cerr(
"Cannot init log procedure" << std::endl);
298 rtmbdyn_rt_sleep(rtmbdyn_nano2count(1000000000));
323 rtmbdyn_rt_make_soft_real_time();
331 silent_cout(
"total overruns: " <<
or_counter << std::endl
332 <<
"total overrun time: " <<
t_tot <<
" micros" << std::endl);
341 t1 = rtmbdyn_rt_get_time();
350 rtmbdyn_RT_mbx_send_if(0, 0,
mbxlog, &
msg,
sizeof(
msg));
355 rtmbdyn_rt_task_wait_period();
364 t0 = rtmbdyn_rt_get_time();
368 rtmbdyn_rt_make_hard_real_time();
380 unsigned long lRTPeriod;
381 unsigned long RTStackSize;
382 bool bRTAllowNonRoot;
384 ReadRTParams(pS, HP, eRTMode, lRTPeriod, RTStackSize, bRTAllowNonRoot, RTCpuMap);
386 bool bRTHard =
false;
387 if (HP.
IsKeyWord(
"hard" "real" "time")) {
392 std::string LogProcName;
397 silent_cerr(
"RTAISolver: unable to get "
398 "log process name (\"file name\") "
407 LogProcName =
"logproc";
416 RTStackSize, bRTAllowNonRoot, RTCpuMap,
417 bRTHard, bRTlog, LogProcName));
#define MBDYN_EXCEPT_ARGS
unsigned long RTStackSize
virtual const char * GetFileName(enum Delims Del=DEFAULTDELIM)
RTSolverBase * ReadRTAISolver(Solver *pS, MBDynParser &HP)
virtual bool IsKeyWord(const char *sKeyWord)
bool RTSemWait(void) const
bool RTWaitPeriod(void) const
#define ASSERT(expression)
RTAISolver(Solver *pS, RTMode eRTMode, long long lRTPeriod, unsigned long RTStackSize, bool bRTAllowNonRoot, int RTCpuMap, bool bRTHard, bool bRTlog, const std::string &LogProcName)
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
void ReadRTParams(Solver *pS, MBDynParser &HP, RTSolverBase::RTMode &eRTMode, unsigned long &lRTPeriod, unsigned long &RTStackSize, bool &bRTAllowNonRoot, int &RTCpuMap)
const std::string LogProcName
std::ostream & Restart(std::ostream &out) const
bool IsStopCommanded(void)
virtual HighParser::ErrOut GetLineData(void) const