#include #include #include #include #include #include #include #include #include #include "returncode.h" #include "ts.h" #include "monano.h" #include "monano_data.h" #include "configure.h" #include "monano_constraints.h" bool pthread_static_constraints_architecture1(pthread_monano_t* t) { return (t->static_constraints[MONANO_STATIC_CONSTRAINTS_MONOCORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PARTITIONED]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_FIXED_PRIORITY]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PRECEDENCE_CONSTRAINTS]); } bool pthread_static_constraints_architecture2(pthread_monano_t* t) { return (t->static_constraints[MONANO_STATIC_CONSTRAINTS_MONOCORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PARTITIONED]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_FIXED_PRIORITY]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_NON_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_INDEPENDENT_TASKS]); } bool pthread_static_constraints_architecture3(pthread_monano_t* t) { return (t->static_constraints[MONANO_STATIC_CONSTRAINTS_MONOCORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PARTITIONED]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_DEADLINE_MONOTONIC]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_NON_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SHARED_RESOURCES]); } bool pthread_static_constraints_architecture4(pthread_monano_t* t) { return (t->static_constraints[MONANO_STATIC_CONSTRAINTS_MONOCORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PARTITIONED]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_EDF_SCHEDULING]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_NON_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_ASYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_INDEPENDENT_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SELF_SUSPENSION_TASKS]); } bool pthread_static_constraints_architecture5(pthread_monano_t* t) { return (t->static_constraints[MONANO_STATIC_CONSTRAINTS_MONOCORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PARTITIONED]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_EDF_SCHEDULING]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_ASYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_INDEPENDENT_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PREEMPTION_DELAY_TASKS]); } bool pthread_static_constraints_architecture6(pthread_monano_t* t) { return (t->static_constraints[MONANO_STATIC_CONSTRAINTS_MONOCORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PARTITIONED]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_DEADLINE_MONOTONIC]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_ASYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_INDEPENDENT_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PREEMPTION_DELAY_TASKS]); } bool pthread_static_constraints_architecture7(pthread_monano_t* t) { return (t->static_constraints[MONANO_STATIC_CONSTRAINTS_MONOCORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PARTITIONED]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_RATE_MONOTONIC]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_ASYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_INDEPENDENT_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PREEMPTION_DELAY_TASKS]); } bool pthread_static_constraints_architecture8(pthread_monano_t* t) { return (t->static_constraints[MONANO_STATIC_CONSTRAINTS_MULTICORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_GLOBAL]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_FIXED_PRIORITY]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_INDEPENDENT_TASKS]); } bool pthread_static_constraints_architecture9(pthread_monano_t* t) { return ( t->static_constraints[MONANO_STATIC_CONSTRAINTS_MULTICORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_GLOBAL]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_FIXED_PRIORITY]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_NON_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PRECEDENCE_CONSTRAINTS]); } bool pthread_static_constraints_architecture10(pthread_monano_t* t) { return ( t->static_constraints[MONANO_STATIC_CONSTRAINTS_MULTICORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PARTITIONED]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_FIXED_PRIORITY]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_NON_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SHARED_RESOURCES]); } bool pthread_static_constraints_architecture11(pthread_monano_t* t) { return ( t->static_constraints[MONANO_STATIC_CONSTRAINTS_MONOCORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PARTITIONED]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_FIXED_PRIORITY]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SHARED_RESOURCES]); } bool pthread_static_constraints_architecture12(pthread_monano_t* t) { return ( t->static_constraints[MONANO_STATIC_CONSTRAINTS_MONOCORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PARTITIONED]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_FIXED_PRIORITY]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SUSPENDED_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SHARED_RESOURCES]); } bool pthread_static_constraints_architecture13(pthread_monano_t* t) { return ( t->static_constraints[MONANO_STATIC_CONSTRAINTS_MONOCORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PARTITIONED]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_FIXED_PRIORITY]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_INDEPENDENT_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SUSPENDED_TASKS]); } bool pthread_static_constraints_architecture14(pthread_monano_t* t) { return ( t->static_constraints[MONANO_STATIC_CONSTRAINTS_MULTICORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_GLOBAL]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_DEADLINE_MONOTONIC]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_NON_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_INDEPENDENT_TASKS]); } bool pthread_static_constraints_architecture15(pthread_monano_t* t) { return ( t->static_constraints[MONANO_STATIC_CONSTRAINTS_MULTICORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PARTITIONED]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_RATE_MONOTONIC]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_SYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_INDEPENDENT_TASKS]); } bool pthread_static_constraints_architecture16(pthread_monano_t* t) { return ( t->static_constraints[MONANO_STATIC_CONSTRAINTS_MULTICORE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_GLOBAL]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_EDF_SCHEDULING]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PREEMPTIVE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_ASYNCHRONOUS_RELEASE]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_PERIODIC_TASKS]&& t->static_constraints[MONANO_STATIC_CONSTRAINTS_INDEPENDENT_TASKS]); } int pthread_monano_verify_static_constraints_reduce_execution_time(pthread_monano_t* t) { if ( pthread_static_constraints_architecture1(t)|| pthread_static_constraints_architecture2(t)|| pthread_static_constraints_architecture3(t)|| pthread_static_constraints_architecture4(t)|| pthread_static_constraints_architecture5(t)|| pthread_static_constraints_architecture6(t)|| pthread_static_constraints_architecture7(t)|| pthread_static_constraints_architecture8(t) || pthread_static_constraints_architecture9(t)|| pthread_static_constraints_architecture10(t)) return 1 ; else return 0; } int pthread_monano_verify_static_constraints_precedence_constraint_change(pthread_monano_t* t) { if ( pthread_static_constraints_architecture1(t)|| pthread_static_constraints_architecture9(t) ) return 1 ; else return 0; } int pthread_monano_verify_static_constraints_processor_speed_increase(pthread_monano_t* t) { if ( pthread_static_constraints_architecture2(t)|| pthread_static_constraints_architecture11(t) ) return 1 ; else return 0; } int pthread_monano_verify_static_constraints_period_change(pthread_monano_t* t) { if ( pthread_static_constraints_architecture8(t)|| pthread_static_constraints_architecture14(t)|| pthread_static_constraints_architecture15(t)|| pthread_static_constraints_architecture16(t) ) return 1 ; else return 0 ; } int pthread_monano_verify_static_constraints_priority_change(pthread_monano_t* t) { if ( pthread_static_constraints_architecture1(t)|| pthread_static_constraints_architecture9(t) ) return 1 ; else return 0; } int pthread_monano_verify_static_constraints_processor_number_increase(pthread_monano_t* t) { if ( pthread_static_constraints_architecture9(t) ) return 1 ; else return 0; } int pthread_monano_verify_static_constraints_delay_execution_time(pthread_monano_t* t) { if ( pthread_static_constraints_architecture12(t)|| pthread_static_constraints_architecture13(t)) return 1 ; else return 0; } int pthread_monano_verify_static_constraints_reduce_preemption_delay(pthread_monano_t* t) { if ( pthread_static_constraints_architecture5(t)|| pthread_static_constraints_architecture6(t) || pthread_static_constraints_architecture7(t)) return 1 ; else return 0; } int pthread_monano_verify_static_constraints_increase_deadline(pthread_monano_t* t) { if ( pthread_static_constraints_architecture5(t)) return 1 ; else return 0; } int pthread_monano_verify_static_constraints_reduce_self_suspension(pthread_monano_t* t) { if ( pthread_static_constraints_architecture4(t)) return 1 ; else return 0; } /* Called by the monitored application to verify if the thread have miss its deadline */ int pthread_monano_verify_missed_deadline(pthread_monano_t* t, pthread_monano_id_t id){ int result=0; if (ts_compare(ts_substract(t->attr[id].end_time, t->attr[id].last_release_time),t->attr[id].deadline)==1){ // struct timespec fin = ts_substract(t->attr[id].end_time, t->attr[id].last_release_time); // printf("temps d'exĂ©cution du thread %x depuis son reveil fin = %d : %d ", pthread_self(), (int)fin.tv_sec, (int)fin.tv_nsec); printf("missed deadline of thread number %d \n", id); result=1; pthread_monano_stop(t); } return result; } /* Called by a thread to verify if the thread had change its priority level */ int pthread_monano_verify_priority_change(pthread_monano_t* t, pthread_monano_id_t id) { int policy, status; struct sched_param param; status=pthread_getschedparam(pthread_self(), &policy, ¶m); if (status<0) returncode("pthread_getschedparam",status); if (t->attr[id].priority!=param.sched_priority){ t->callback(PRIORITY_ANOMALY, id); } return 0; } /* Called by the monitored application to verify if execution time of a thread have been reduce */ int pthread_monano_verify_reduce_execution_time(pthread_monano_t* t, pthread_monano_id_t id){ int status; // printf("dans verify reduce execution_time de %x : id = %d: %d:%d \n", pthread_self(), id, (int)t->attr[id].current_execution_time.tv_sec, (int)t->attr[id].current_execution_time.tv_nsec); status=pthread_monano_verify_missed_deadline(t,id); if (status<0) returncode("pthread_monano_verify_missed_deadline",status); else if (status==1) if (ts_compare(t->attr[id].current_execution_time, t->attr[id].wcet) <0) t->callback(REDUCE_WCET_ANOMALY, id); return 0; } /* Called by the monitored application to signal if the precedence constraint of thread has been modified */ int pthread_monano_verify_precedence_constraint_change(pthread_monano_t* t, pthread_monano_id_t id){ int i; for(i=0; inb_precedencies; i++) { if(t->pthread_precedencies[i].destination==id) { if(pthread_monano_search_thread(dependencies_list,t->pthread_precedencies[i].source)==NULL) t->callback(DEPENDENCY_ANOMALY, i); } } return 0; } /* Called by the monitored application to signal to MONANO that the processor speed has change */ int pthread_monano_verify_processor_speed_increase(pthread_monano_t* t, pthread_monano_id_t id) { if (ts_compare(ts_substract(t->attr[id].end_time,t->attr[id].start_time), ts_divide(t->attr[id].wcet, 2)) < 0) processor_speed_list= pthread_monano_add_thread(processor_speed_list,id); if (pthread_monano_count_thread(processor_speed_list)==t->nb_thread) t->callback(SPEED_PROCESSOR_ANOMALY, id); return 0; } /* Called by the monitored application to verify if the thread had change its period */ int pthread_monano_verify_period_change(pthread_monano_t* t, pthread_monano_attr_t attr, pthread_monano_id_t id) { if(t->attr[id].change_period ==1) t->callback(PERIOD_ANOMALY, id); return 0; } /* Called by the monitored application to verify if its processor number has been change */ int pthread_monano_verify_processor_number_increase(pthread_monano_t* t) { if(t->change_nb_processors ==1) t->callback(NUMBER_PROCESSOR_ANOMALY, t->change_nb_processors); return 0; } /* Called by the monitored application to verify if delay time of a thread have been reduce */ int pthread_monano_verify_reduce_suspending_time(pthread_monano_t* t, pthread_monano_id_t id) { printf("execution_time de %x : id = %d: %d:%d \n", pthread_self(), id, (int)t->attr[id].selfsuspending_time.tv_sec, (int)t->attr[id].selfsuspending_time.tv_nsec); pthread_monano_verify_missed_deadline(t,id); if (ts_compare(t->attr[id].selfsuspending_time, t->attr[id].delay) < 0) t->callback(DELAY_WCET_ANOMALY, id); return 0; }