public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* clock_nanosleep: cyclic POSIX thread freezes during time setting
@ 2009-10-05 13:20 Mehlan, Markus
  2009-10-05 18:57 ` Thomas Gleixner
  0 siblings, 1 reply; 8+ messages in thread
From: Mehlan, Markus @ 2009-10-05 13:20 UTC (permalink / raw)
  To: linux-kernel

Hi All,

I have the following problem on a MPC5200b customer board,
tested with linux-2.6.24.7-rt11 and 2.6.26.8-rt16.

I start the test application. Every 200ms I can see a new 
line on the console ("ping"). Then I set the time with "date
100509152009" a few times on
a second console. The effect is that the output on the first console
freezes and if I check
the time with "date", the time doesn't progress during the "freeze
time". After the 
"freeze time" the time makes a jump of several seconds.

In the real application the "ping" should reset the watchdog-timer. The
freezing causes
an elapsing of the watchdog-timer and finally a reboot.

Has someone an idea?

With friendly regards,
Markus Mehlan

---------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <time.h>
#include <sys/time.h>
#include <pthread.h>
#include <sys/mman.h>

#define CTRL_TASK_PRIORITY		5
#define USEC_PER_SEC   1000000
#define NSEC_PER_SEC   1000000000


static void tsnorm(struct timespec *ts)
{
	while (ts->tv_nsec >= NSEC_PER_SEC)
	{
		ts->tv_nsec -= NSEC_PER_SEC;
		ts->tv_sec++;       
	}
}

void *PingTask()
{
	static unsigned long ulHwWdgTime = 0;			
	struct itimerspec timer;
	int i;
	unsigned long ulInterval = 1000; // = 1ms
	
	if(clock_gettime(CLOCK_MONOTONIC, &timer.it_value) < 0)
	{
		perror("TimerTask: clock_gettime() failed\n");
		//return -1;
	}
	
	timer.it_interval.tv_nsec = ulInterval % USEC_PER_SEC;
	timer.it_interval.tv_nsec *= 1000;
	timer.it_interval.tv_sec = ulInterval / USEC_PER_SEC;
	
	while(1) {
		// 1ms-Task
		timer.it_value.tv_sec += timer.it_interval.tv_sec;
		timer.it_value.tv_nsec += timer.it_interval.tv_nsec;
		tsnorm(&timer.it_value);
		
		if (ulHwWdgTime == 0)
		{
			ulHwWdgTime = 200; // 200ms		
			clock_gettime(CLOCK_MONOTONIC,
&timer2.it_value);
			printf("ping\n");
		}	
		ulHwWdgTime--;
		
		clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME,
&timer.it_value, NULL);
	}	
}

int main(int argc, char **argv)
{
	pthread_attr_t attr;
	pthread_t	threadHandle;
	void *thread_result;
	struct sched_param sched_param;
	int res;
	unsigned char byPriority = CTRL_TASK_PRIORITY;
	  
	pthread_attr_init(&attr);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
	   
 	if (pthread_create(&threadHandle, &attr, PingTask, NULL) != 0)
    {	
    	printf("Fehler pthread_create\n");
    	if (fd_drv_wdg)	
    		close(fd_drv_wdg);
    	return -3;
    }
    
	sched_param.sched_priority =
max(0,sched_get_priority_max(SCHED_FIFO) - (int)byPriority);
	if ((res=pthread_setschedparam
((pthread_t)threadHandle,SCHED_FIFO,&sched_param)))
	{
		printf("SysTaskSetPriority->pthread_setschedparam()
failed:%s\n",strerror(res));
		if (fd_drv_wdg)	
			close(fd_drv_wdg);
		return -4;
	}
  	pthread_attr_destroy(&attr);
  	  	
  	printf("Ende\n");
  	getchar();
	
	if (fd_drv_wdg)				
		close(fd_drv_wdg);
	return 0;
}

Sitz der Gesellschaft: Oberhausen
Handelsregister Amtsgericht Duisburg HRB-Nr. 17168 UST ID-Nr. DE 814009849
Geschaftsfuehrer: Manfred A. Wagner und Dr. Uwe Baader


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-10-07 14:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-05 13:20 clock_nanosleep: cyclic POSIX thread freezes during time setting Mehlan, Markus
2009-10-05 18:57 ` Thomas Gleixner
2009-10-06  9:00   ` AW: " Mehlan, Markus
2009-10-06  9:13     ` Thomas Gleixner
2009-10-06  9:56       ` AW: " Mehlan, Markus
2009-10-06 10:04         ` Thomas Gleixner
2009-10-06 10:09           ` AW: " Mehlan, Markus
2009-10-07 14:13           ` Mehlan, Markus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox