/* *If a constant has the U suffix, its data type will be the first of the following that can accommodate its value: unsigned short, unsigned int, unsigned long int. If a constant has the L suffix, its data type will be the first of the following that can accommodate its value: long int, unsigned long int. If a constant has both L and U suffixes, (LU or UL), its data type will be unsigned long int. If a constant has the LL, its data type will be long long. If a constant has the ULL, its data type will be unsigned long long. * */ #include //registra la evolucion del tiempo en relojes local y remoto //optimizar en velocidad //https://docs.redhat.com/de/documentation/red_hat_enterprise_linux_for_real_time/8/html-single/optimizing_rhel_8_for_real_time_for_low_latency_operation/index#ref_interpreting-hardware-and-firmware-latency-test-results_assembly_running-and-interpreting-hardware-and-firmware-latency-tests //https://man7.org/linux/man-pages/man7/sched.7.html #include void high_priority(void){ //ajusta schedulle, falla sin privilegios //alta prioridad, no es interrumpido hasta retorna struct sched_param x; int pid=0; x.sched_priority=99; sched_setscheduler(pid, SCHED_FIFO, &x); } //https://linux.die.net/man/3/clock_gettime //https://man7.org/linux/man-pages/man2/nanosleep.2.html #include #include #define u64 uint64_t #define u32 uint32_t u64 clock2(void){ struct timespec x; clock_gettime(CLOCK_MONOTONIC,&x); int64_t a; a=(int64_t)(x.tv_sec) * (int64_t)1000000000 + (int64_t)(x.tv_nsec); return a; } void nanosleep2(u64 t){ struct timespec x; x.tv_sec =t/(u64)1E9; x.tv_nsec=t%(u64)1E9; nanosleep(&x,NULL); } u64 a,ae,b,be,c,ce,d=0; u64 diff; const u64 periode=(u64)(1q*60*1E9); char str[1024]; FILE *fo; int n=0; //cada 5 minutos int main(void){ printf("reloj local,remoto\n"); high_priority(); c=clock2(); loop: a=clock2(); //query_ntp(); //hora remota ae=clock2(); b=clock2(); nanosleep2(10E9); //ruido_conmutacion_tareas_cada_10ms be=clock2(); if(d==0)d=c;else d=ce; sprintf(str,"%d %lld %lld 0 %lld %lld 0 %lld \n",n++, a,ae, b,be, d); fputs(str,stdout); lectura remota via wget // /var/www/localhost/htdocs/users/hub fo=fopen("clock_lr.dat","a"); fputs(str,fo); fclose(fo); //me duermo con precision ce=clock2(); diff=(ce-c)%periode; diff=periode-diff; nanosleep2(diff); goto loop; }