X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=contrib%2Ffsm_checker%2FRT_CHECK%2Frealtime.c;fp=contrib%2Ffsm_checker%2FRT_CHECK%2Frealtime.c;h=2c60a91ab1e3880fb0d3556d42899ae09c0ea5f2;hb=e09e518ebf18d490dbeb72c6358968af7d05d675;hp=0000000000000000000000000000000000000000;hpb=58f53b56557577b64911d0e7a2bba3fbb521d71d;p=lttv.git diff --git a/contrib/fsm_checker/RT_CHECK/realtime.c b/contrib/fsm_checker/RT_CHECK/realtime.c new file mode 100755 index 00000000..2c60a91a --- /dev/null +++ b/contrib/fsm_checker/RT_CHECK/realtime.c @@ -0,0 +1,49 @@ +#include +#include +struct realtime * realtime_Init(int pid, long period_sec, long period_nsec, long running_time_sec, long running_time_nsec){ + struct realtime *this = (struct realtime *) g_malloc(sizeof(struct realtime)); + realtimeContext_Init(&this->_fsm, this); + this->pid = pid; + this->period_sec=period_sec; + this->period_nsec=period_nsec; + this->running_time_sec = running_time_sec; + this->running_time_nsec = running_time_nsec; + this->schedin_ts_sec=0;//needed for first event + this->schedin_ts_nsec=0; + return this; +} +void realtime_destroyfsm(struct realtime *this){ + //remove fsm from fsm_list + removefsm(this); + g_free(this); +} +void realtime_warning(struct realtime *this, long ts_sec, long ts_nsec){ + printf("WARNING: real-time process, pid %d was scheduled in after tolerable period @ %ld.%09ld.\n", this->pid, ts_sec, ts_nsec); +} +void realtime_report_insufficient_scheduling_time(struct realtime *this, long ts_sec, long ts_nsec){ + printf("WARNING: real-time process, pid %d was scheduled out early @%ld.%09ld.\n", this->pid, ts_sec, ts_nsec); +} +int latency(struct realtime *this, long ts_sec, long ts_nsec){ + //2 successive schedin are seperated by more than period + long delta_sec = ts_sec - this->schedin_ts_sec; + long delta_nsec = ts_nsec - this->schedin_ts_nsec; + if(delta_sec < this->period_sec) + return 0;//no latency + else if(delta_sec == this->period_sec) + if(delta_nsec < this->period_nsec) + return 0;//no latency + return 1; +} +int running_enough(struct realtime *this, long ts_sec, long ts_nsec){ + if(ts_sec - this->schedin_ts_sec > this->running_time_sec) + return 1; + else if(ts_sec - this->schedin_ts_sec == this->running_time_sec) + if(ts_nsec - this->running_time_nsec > this->running_time_nsec) + return 1; + return 0; +} +void realtime_save_ts(struct realtime *this, long ts_sec, long ts_nsec){ + this->schedin_ts_sec = ts_sec; + this->schedin_ts_nsec = ts_nsec; +} +