Find the answer to your Linux question:
Results 1 to 2 of 2
I'm aware of the existence of RTLinux patch, but still I want to test the real time capabilities of a non-realtime Ubuntu distribution. For this, I have written a simple ...
  1. #1
    Just Joined!
    Join Date
    Aug 2011
    Posts
    2

    Real Time in Ubuntu

    I'm aware of the existence of RTLinux patch, but still I want to test the real time capabilities of a non-realtime Ubuntu distribution. For this, I have written a simple program which has a function I want to call every 100ms, using an interval timer (setitimer). The strange thing I can't figure out is that my function is called very precisely every 100ms but a weird 1 sec periodic delay appears when you see the csv log the program generates. Any idea of what task can be producing such periodic delay?Some hardware interrupt? RTC maybe? Thanks in advance.

    The log file is attached.


    Code:
    void tick(int n)
    {
    	static long elapsed=0;
    	static long past=0;
    
    	t++;
    
    	if(t>=50)
    	{
    		t=0;
    		clock_gettime(CLOCK_REALTIME, &start);
    		elapsed=start.tv_nsec-past;
    		past=start.tv_nsec;
    		fprintf(fprof,"%f,%f\n",(float)elapsed/1000000000.,0.1-(float)elapsed/1000000000.);
    	}
    
    }
    
    int main(void) {
    	int realtime=1;
    	struct itimerval tout_val;
        int i,j;
    
    	pid=getpid();
    
    	fprof=fopen("fprof.csv","w");
    
        tout_val.it_interval.tv_sec = 0;
        tout_val.it_interval.tv_usec = 2000;
    
    	tout_val.it_value.tv_sec = 0;
    	tout_val.it_value.tv_usec = 2000;
    
    	signal(SIGINT, SigProc);
    
    	if(realtime)
    	{
    		setitimer(ITIMER_REAL, &tout_val,0);
    		signal(SIGALRM,tick);
    	}
    	else
    	{
    		while(1)
    		{
    			tick(0);
    			for(i=0;i<150000;i++) //try some hardcoded delay if not real time
    				j=0;
    		}
    	}
    
    	while(1);
    
    	return EXIT_SUCCESS;
    }
    Attached Files Attached Files
    Last edited by IgnacioC; 08-15-2011 at 08:10 PM. Reason: Bad english

  2. #2
    Just Joined!
    Join Date
    Aug 2011
    Posts
    2
    Stupid mistake, wasn't taking into account the overflow of start.tv_nsec... Timing behaves pretty good now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...