Brise

latency 측정 소스 본문

Linux

latency 측정 소스

naudhizb 2014. 10. 14. 19:05
반응형

#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/mman.h>
#include <rtdm/rtdm.h>
#include <xenomai/native/task.h>
#include <xenomai/native/sem.h>
#include <xenomai/native/mutex.h>
#include <xenomai/native/timer.h>
#include <rtdk.h>
#include <pthread.h>
#include <rtdm/rtdm.h>
#include <xenomai/native/task.h>
#include <xenomai/native/timer.h>



RT_TASK my_task;

int run=0;
int i;
static unsigned int cycle_ns;
#define TASK_PERIOD_NS 500000
void my_task_proc(void *arg);
RTIME *time_test;

int main(int argc,char **argv)
{
    int ret;
    cycle_ns = TASK_PERIOD_NS;
    mlockall(MCL_CURRENT | MCL_FUTURE);
    rt_print_auto_init(1);
    time_test =(RTIME *)malloc(sizeof(RTIME)*120000);
    ret = rt_task_create(&my_task,"my_task",0,20,T_JOINABLE);
    fprintf(stdout,"starting my_task\n");
    ret = rt_task_start(&my_task, &my_task_proc,NULL);
    while(run)
    {
        sched_yield();
    }
    rt_task_join(&my_task);
    rt_task_delete(&my_task);

    printf("End of Program\n");
    return 0;

}

void my_task_proc(void *arg)
{
    int ret;
    int index_1 = 0;
    RTIME now, previous;
    run =1;
    ret = rt_task_set_mode(0,T_CONFORMING,NULL);
    rt_task_set_periodic(NULL, TM_NOW, cycle_ns);
    previous = rt_timer_read();
    while(index_1<120000)
    {
        rt_task_wait_period(NULL);
        now = rt_timer_read();
        *(time_test+index_1) =(now - previous);
        rt_printf("present time is %llu \n",*(time_test+index_1));
        previous = now ;
        index_1++;
    }
    index_1=0;
     FILE *opt;
     opt = fopen("test.txt","w");
     while(index_1<120000)
    {
             fprintf(opt,"%llu \n",*(time_test+index_1));
             index_1++;
    }
    fclose(opt);
}

반응형
Comments