Skip to contentSkip to conversation

Switch mode with x86

Xenomai-help Nicolas BLANCHARD 2 participants 2 messages Nov 28, 2006

lore
Share & tools
lore
#0 lore raw

Hi !

I'm newbie in xenomai world,
I've write an application which make a lot of switch mode (Primary->secondary ...)
and sometime tasks are block in secondary mode (/proc/xenomai/sched -> stat X).
(no watchod message in dmesg, it's block in secondary mode).

I use xenomai 2.2.5, adeos 1.5.02 (same probleme with 2.2.3 et adeos 1.4)
It' run on x86 (486 vortex 166Mhz).
So, i've write an litle example that failed. It failed on my x86 (in less than 2 minutes),
but this example run corectly with a pentium 4 or an Amd processor :

#include <sys/mman.h>
#include <stdio.h>
#include <signal.h>
#include <native/task.h>
#include <string.h>

static int iStop = 0;
RT_TASK Task_1, Task_2; //----------------------------------------------------------------------THREAD 1
void thread_1(void *arg)

{
	while(1)
	{
		unsigned long overruns;
		int iErr;

		iErr = rt_task_wait_period(&overruns);
		if (iErr || overruns)
			printf("Echec wait_period task_1 err %d,

overruns: %lu\n",iErr,overruns);

		//iErr = rt_task_set_mode(T_PRIMARY, 0, NULL);
		if(iErr)
			printf("Echec set_mod Secondary task_1\n");
printf("r\n");
		if(iStop == 1)
		{
			iErr = rt_task_delete(&Task_1);
			if (iErr ) 
				printf("Echec delete task_1 err %d\n",
iErr);
			break;
		}
	}
}
//----------------------------------------------------------------------THREAD
2
void thread_2(void *arg)
{
	while(1)
	{
		unsigned long overruns;
		int iErr;

		iErr = rt_task_wait_period(&overruns);
		if (iErr || overruns)
			printf("Echec wait_period task_2 err %d,

overruns: %lu\n",iErr,overruns);

		//iErr = rt_task_set_mode(T_PRIMARY, 0, NULL);
		if(iErr)
			printf("Echec set_mod Secondary task_2\n");

printf("u\n");

		if(iStop == 1)
		{
			iErr = rt_task_delete(&Task_2);
			if (iErr ) 
				printf("Echec delete task_2 %d\n",
iErr);
			break;
		}
	}
}
//----------------------------------------------------------------------CLEANUP
UPON SIG
void cleanup_upon_sig(int sig)
{
	iStop = 1;
}
//----------------------------------------------------------------------MAIN
int main(int argc, char *argv[]) 
{
	sigset_t mask, oldmask;
	int iErr;

	mlockall(MCL_CURRENT | MCL_FUTURE);

	sigemptyset(&mask);
	sigaddset(&mask, SIGINT);
	signal(SIGINT, cleanup_upon_sig);
	sigaddset(&mask, SIGTERM);
	signal(SIGTERM, cleanup_upon_sig);
	sigaddset(&mask, SIGHUP);
	signal(SIGHUP, cleanup_upon_sig);

	pthread_sigmask(SIG_BLOCK, &mask, &oldmask);

		// Task 1 *******************************
	iErr = rt_task_create(&Task_1,"TASK1", 0, 99, 0);
	if(iErr)
		printf("Echec create Task_1
%d\n",iErr);			
	iErr = rt_task_set_periodic(
&Task_1,rt_timer_read()+100*1000000llu,rt_timer_ns2ticks(10*1000000llu)
); //period 10 ms
	if(iErr)
		printf("Echec set_periodic Task_1 %d\n",iErr);
	iErr = rt_task_start(&Task_1,(void *)thread_1,NULL);
	if(iErr)
		printf("Echec start Task_1 %d\n", iErr);

		// Task 2 ******************************
	iErr = rt_task_create(&Task_2,"TASK2", 0, 0, 0);
	if(iErr)
		printf("Echec create task_2
%d\n",iErr);			
	iErr = rt_task_set_periodic(
&Task_2,rt_timer_read()+100*1000000llu,rt_timer_ns2ticks(11*1000000llu)
); //period 11 ms
	if(iErr)
		printf("Echec set_periodic task_2 %d\n", iErr);
	iErr = rt_task_start(&Task_2,(void *)thread_2,NULL);
	if(iErr)
		printf("Echec start task_2 %d\n", iErr);

	sigsuspend(&oldmask);
	return 0;
}

If thoses two task have the same priority it looks to not failed, perhaps a problem
with the scheduler in secondary mode when two task comes from primary mode ?
Is it a know probleme with x86 ?
Or perhaps a big error in my example ...

Have you an idea ?
thanks in advance

nicolas blanchard

#1 lore raw
Quoted 9 lines · Nicolas BLANCHARD

Hi !

I'm newbie in xenomai world,
I've write an application which make a lot of switch mode (Primary->secondary ...)
and sometime tasks are block in secondary mode (/proc/xenomai/sched -> stat X).
(no watchod message in dmesg, it's block in secondary mode).

Quoted 6 lines

I use xenomai 2.2.5, adeos 1.5.02 (same probleme with 2.2.3 et adeos 1.4)
It' run on x86 (486 vortex 166Mhz).
So, i've write an litle example that failed. It failed on my x86 (in less than 2 minutes),
but this example run corectly with a pentium 4 or an Amd processor :

How does it fail precisely? Which tasks are stuck? Attach /proc/xenomai/sched output e.g. Already tried to attach gdb to that process after the lock-up?

One difference of vortex vs. P4 might be (besides speed) that for the former Xenomai uses TSC emulation, for the latter the CPU already comes with this support. You can force the high-end systems into that mode by compiling the kernel with CONFIG_M586. Or did you use the same kernel images on all systems?

Your .config would be interesting. You can already check if CONFIG_INPUT_PCSPKR is set. Must be off for TSC emulation (Xenomai 2.2 doesn't check for this conflict, 2.3 will do so).

Quoted 21 lines

#include <sys/mman.h>
#include <stdio.h>
#include <signal.h>
#include <native/task.h>
#include <string.h>

static int iStop = 0;
RT_TASK Task_1, Task_2; //----------------------------------------------------------------------THREAD 1
void thread_1(void *arg)

{
	while(1)
	{
		unsigned long overruns;
		int iErr;

		iErr = rt_task_wait_period(&overruns);
		if (iErr || overruns)
			printf("Echec wait_period task_1 err %d,
Quoted 1 line

overruns: %lu\n",iErr,overruns);

Would have been better to attach the program instead of inlining it. :)

Quoted 14 lines
		//iErr = rt_task_set_mode(T_PRIMARY, 0, NULL);
		if(iErr)
			printf("Echec set_mod Secondary task_1\n");
printf("r\n");
		if(iStop == 1)
		{
			iErr = rt_task_delete(&Task_1);
			if (iErr ) 
				printf("Echec delete task_1 err %d\n",
iErr);
			break;
		}
	}

There is no mode switch in this thread and the second one. Is this not required to cause the lock-up???

...

Quoted 6 lines

If thoses two task have the same priority it looks to not failed, perhaps a problem
with the scheduler in secondary mode when two task comes from primary mode ?
Is it a know probleme with x86 ?

Nope. Fairly unusual. Does the switchtest from the Xenomai test-suite fail as well?

Quoted 1 line

Or perhaps a big error in my example ...

Nothing I can see.

Quoted 6 lines

Have you an idea ?
thanks in advance

nicolas blanchard

Jan