| 1 | #include <glib.h> |
| 2 | #include <string.h> |
| 3 | struct realtime * realtime_Init(int pid, long period_sec, long period_nsec, long running_time_sec, long running_time_nsec){ |
| 4 | struct realtime *this = (struct realtime *) g_malloc(sizeof(struct realtime)); |
| 5 | realtimeContext_Init(&this->_fsm, this); |
| 6 | this->pid = pid; |
| 7 | this->period_sec=period_sec; |
| 8 | this->period_nsec=period_nsec; |
| 9 | this->running_time_sec = running_time_sec; |
| 10 | this->running_time_nsec = running_time_nsec; |
| 11 | this->schedin_ts_sec=0;//needed for first event |
| 12 | this->schedin_ts_nsec=0; |
| 13 | return this; |
| 14 | } |
| 15 | void realtime_destroyfsm(struct realtime *this){ |
| 16 | //remove fsm from fsm_list |
| 17 | removefsm(this); |
| 18 | g_free(this); |
| 19 | } |
| 20 | void realtime_warning(struct realtime *this, long ts_sec, long ts_nsec){ |
| 21 | printf("WARNING: real-time process, pid %d was scheduled in after tolerable period @ %ld.%09ld.\n", this->pid, ts_sec, ts_nsec); |
| 22 | } |
| 23 | void realtime_report_insufficient_scheduling_time(struct realtime *this, long ts_sec, long ts_nsec){ |
| 24 | printf("WARNING: real-time process, pid %d was scheduled out early @%ld.%09ld.\n", this->pid, ts_sec, ts_nsec); |
| 25 | } |
| 26 | int latency(struct realtime *this, long ts_sec, long ts_nsec){ |
| 27 | //2 successive schedin are seperated by more than period |
| 28 | long delta_sec = ts_sec - this->schedin_ts_sec; |
| 29 | long delta_nsec = ts_nsec - this->schedin_ts_nsec; |
| 30 | if(delta_sec < this->period_sec) |
| 31 | return 0;//no latency |
| 32 | else if(delta_sec == this->period_sec) |
| 33 | if(delta_nsec < this->period_nsec) |
| 34 | return 0;//no latency |
| 35 | return 1; |
| 36 | } |
| 37 | int running_enough(struct realtime *this, long ts_sec, long ts_nsec){ |
| 38 | if(ts_sec - this->schedin_ts_sec > this->running_time_sec) |
| 39 | return 1; |
| 40 | else if(ts_sec - this->schedin_ts_sec == this->running_time_sec) |
| 41 | if(ts_nsec - this->running_time_nsec > this->running_time_nsec) |
| 42 | return 1; |
| 43 | return 0; |
| 44 | } |
| 45 | void realtime_save_ts(struct realtime *this, long ts_sec, long ts_nsec){ |
| 46 | this->schedin_ts_sec = ts_sec; |
| 47 | this->schedin_ts_nsec = ts_nsec; |
| 48 | } |
| 49 | |