#include #include #include #include #include #include void *Task( void * ) { float prec, prec_max=0.; long long work_tm, cur_tm; int per = 100000000; //s struct timespec get_tm; //Calc next work time and sleep clock_gettime(CLOCK_REALTIME,&get_tm); work_tm = (long long)get_tm.tv_sec*1000000000+get_tm.tv_nsec; for(int i=0; true/*i < 1000*/; i++) { char buf[100], name[31]; float val; FILE *fp = popen("mbmon -r -c 1","r"); if( fp == NULL ) return NULL; while(fgets(buf,sizeof(buf),fp)) { if( sscanf(buf, "%31s : %f", name, &val) != 2 ) continue; printf("%s : %f\n",name,val); } pclose(fp); work_tm=work_tm+per; get_tm.tv_sec = work_tm/1000000000; get_tm.tv_nsec = work_tm%1000000000; clock_nanosleep(CLOCK_REALTIME,TIMER_ABSTIME,&get_tm,NULL); clock_gettime(CLOCK_REALTIME,&get_tm); cur_tm = (long long)get_tm.tv_sec*1000000000+get_tm.tv_nsec; prec = (float)(cur_tm-work_tm)/1000000.; if(prec>prec_max) prec_max=prec; printf("Precission %f ms; max %f\n",prec,prec_max); } } int main( int argc, char **argv ) { pthread_t pthrid; pthread_attr_t pthr_attr; pthread_attr_init(&pthr_attr); struct sched_param prior; pthread_attr_setschedpolicy(&pthr_attr,SCHED_RR); //pthread_attr_setschedpolicy(&pthr_attr,SCHED_OTHER); prior.__sched_priority=10; pthread_attr_setschedparam(&pthr_attr,&prior); pthread_create(&pthrid,&pthr_attr,Task,NULL); pthread_attr_destroy(&pthr_attr); while(true) sleep(100); return 0; }