Skip to contentSkip to conversation

Application crash

Xenomai-help Fabien MAHOT 3 participants 24 messages Mar 17, 2008 – Apr 9, 2008

lore
Share & tools
lore
#0 lore raw

Hello,

I ve got a problem with my application. I use the Xenomai 2.3.4 kernel (disable priority coupling option -> deactivate).
I wrote a test program to show you the problem.

There are T1 thread with the highest priority and T2 thread. T1 thread sleeps during 5ms and uses the console function to display its current state.
T2 uses the console function to display its current state. To use the console function, the threads need lockConsole mutex.

#include <sys/mman.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/time.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdarg.h>
#include <semaphore.h>

// Console
pthread_mutex_t lockConsole;
unsigned char bufferConsole[2048];
// Start of tasks
pthread_cond_t start_signal;
pthread_mutex_t main_start_lock;

void console(char * chaine,...)

{
    if (pthread_mutex_lock(&lockConsole)!=0)
    {
       printf("Error:pthread_mutex_lock\n");
    }
    pthread_t p0;
    va_list ArgConsole;
    va_start(ArgConsole, chaine);
    vsprintf((char *)bufferConsole,chaine,ArgConsole);
    if (write(2, (char*)bufferConsole, strlen((char *)bufferConsole)) == -1)
    {
       printf("Error:write\n");
    }
    pthread_mutex_unlock(&lockConsole);
}

int func(volatile int* i)

{
	return (*i)++;
}

/************************ tasks ****************************/

void* thread1(void * cookie) {
    volatile int i=0;
    volatile int result;

    pthread_mutex_lock(&main_start_lock);
    pthread_cond_wait(&start_signal, &main_start_lock);
    pthread_mutex_unlock(&main_start_lock);

    while (i < 10) {
        usleep(5000);
        result = func(&i);
        console ("T1 : %d \n",result);
    }

    return NULL;
}
void* thread2(void * cookie) {
    volatile int i=0;
    volatile int result;

    pthread_mutex_lock(&main_start_lock);
    pthread_cond_wait(&start_signal, &main_start_lock);
    pthread_mutex_unlock(&main_start_lock);

    while (i < 200) {
        result = func(&i);
        console ("T2 : %d \n",result);
    }

    return NULL;
}

/************************** main *****************************/

int main(int argc, char** argv) {
    pthread_attr_t attr;
    pthread_mutexattr_t attr_proto;
    struct sched_param sch;
    pthread_t p1;
    pthread_t p2;

    mlockall(MCL_CURRENT|MCL_FUTURE);

    pthread_mutexattr_init(&attr_proto);
    pthread_mutexattr_setprotocol(&attr_proto,PTHREAD_PRIO_INHERIT);
    pthread_mutex_init(&lockConsole, &attr_proto);

    pthread_cond_init(&start_signal, NULL);
    pthread_mutex_init(&main_start_lock, NULL);

    pthread_attr_init(&attr);
    pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED);
    pthread_attr_setschedpolicy(&attr, SCHED_FIFO);

    // creation of task 1
    sch.sched_priority = 80;
    pthread_attr_setschedparam(&attr, &sch);
    pthread_create(&p1, &attr, thread1, NULL);

    // creation of task 2
    sch.sched_priority = 75;
    pthread_attr_setschedparam(&attr, &sch);
    pthread_create(&p2, &attr, thread2, NULL);

    // Start of tasks
    pthread_mutex_lock(&main_start_lock);
    pthread_cond_broadcast(&start_signal);
    pthread_mutex_unlock(&main_start_lock);

    pthread_attr_destroy(&attr);

    while (1){
        sleep(500);
    }

    return 0;
}

Result in Xenomai environment(Xenomai 2.3.4 kernel) :
T2 : 0
T2 : 1
T2 : 2
T2 : 3
T2 : 4
T2 : 5
T2 : 6
T2 : 7
T2 : 8
T2 : 9

And the application crashes without error message.
When the application crashes, I think that T1 thread runs in the console function and it will be put in hold (mutex or write). Thanks to an other test program, I saw that there is a wait in the write function

So, there is a preemption possibility.

I try different configurations :
- When I delete the console call in T1, my application doesn't crash.
- When I use a clock thread which sleeps during 5ms and wakes up T1 thanks to a semaphore, my application doesn't crash. (T1 doesn't call usleep)

So there is something strange. I think there is a problem when a thread changes of domain (Xenomai to linux) after time out function use (when you use these functions, is there a signal emission when the time out is finished? maybe, this signal crashes my application...)

I would like to know why I ve got this problem. If you ve got an idea, please , give me your opinion.

Thanks a lot.

#1 lore raw
Quoted 3 lines · Fabien MAHOT

Hello,

I ve got a problem with my application. I use the Xenomai 2.3.4 kernel

Do you get the same problem with the latest stable release of Xenomai, i.e 2.4.2 ?

Signature · 1 line
					    Gilles Chanteperdrix.
#2 lore raw
Quoted 5 lines
Quoted 3 lines · Fabien MAHOT

Hello,

I ve got a problem with my application. I use the Xenomai 2.3.4 kernel

Quoted 8 lines

Do you get the same problem with the latest stable release of Xenomai, i.e 2.4.2 ?

--

Gilles Chanteperdrix.

Today, I try with Xenomai 2.4.1 and 2.4.2. I ve got the same result, my application crashes.

#3 lore raw
In reply to Fabien MAHOT
Quoted 11 lines · Fabien MAHOT

Hello,

I ve got a problem with my application. I use the Xenomai 2.3.4 kernel (disable priority coupling option -> deactivate).
I wrote a test program to show you the problem.

There are T1 thread with the highest priority and T2 thread. T1 thread sleeps during 5ms and uses the console function to display its current state.
T2 uses the console function to display its current state. To use the console function, the threads need lockConsole mutex.

Except the fact that your program relies on correct priorities ordering for starting up tasks, which does not always work if priority coupling is disabled, your program runs just fine on ARM.

On what platform are you testing this program ? What does getconf GNU_LIBPTHREAD_VERSION
returns on your platform ?
Could you send me the .config of the kernel you are using ?

Signature · 1 line
					    Gilles.
#4 lore raw
Quoted 8 lines

Except the fact that your program relies on correct priorities ordering for starting up tasks, which does not always work if priority coupling is disabled, your program runs just fine on ARM.

On what platform are you testing this program ? What does getconf GNU_LIBPTHREAD_VERSION
returns on your platform ?
Could you send me the .config of the kernel you are using ?

Thanks for your answers,

My platform is Geode AMD Processor i586.
(I use Adeos-ipipe-2.6.23-i386-1.12-03 patch of Xenomai-2.4.2)

getconf GNU_LIBPTHREAD_VERSION returns NPTL 2.5

And , there is the .config of my kernel in attached files.

#5 lore raw
Quoted 9 lines · Fabien MAHOT
Quoted 8 lines

Except the fact that your program relies on correct priorities ordering for starting up tasks, which does not always work if priority coupling is disabled, your program runs just fine on ARM.

On what platform are you testing this program ? What does getconf GNU_LIBPTHREAD_VERSION
returns on your platform ?
Could you send me the .config of the kernel you are using ?

Quoted 8 lines

Thanks for your answers,

My platform is Geode AMD Processor i586.
(I use Adeos-ipipe-2.6.23-i386-1.12-03 patch of Xenomai-2.4.2)

getconf GNU_LIBPTHREAD_VERSION returns NPTL 2.5

And , there is the .config of my kernel in attached files.

Are you sure this is the right .config ? I see that priority coupling is enabled.

Signature · 1 line
 Gilles
#6 lore raw
Quoted 2 lines

Are you sure this is the right .config ? I see that priority coupling is enabled.

I want the priority coupling be enabled. (I have a problem when it was disabled : I have a main thread with highest priority which creates other threads. When all the threads are created, the main thread reduces its priority at the minimum, broadcats a condition and unlock the associated mutex to start the other threads . But, after that main thread unlocks the mutex, it stays a short while in execution in spite of its priority)

With my first configuration (linux 2.6.20 with xenomai-2.3.4), the priority coupling option was called "disable priority coupling", so in .config, there was : # CONFIG_XENO_OPT_RPIDISABLE is not set. So, the priority coupling was enabled.

Now, with linux 2.6.23 and xenomai-2.4.2, the priority coupling option is called "Priority coupling support". To activate it, you must put mark. In .config, there is : CONFIG_XENO_OPT_PRIOCPL=y

#7 lore raw
In reply to Gilles Chanteperdrix
Quoted 9 lines
Quoted 2 lines

Are you sure this is the right .config ? I see that priority coupling is enabled.

I want the priority coupling be enabled. (I have a problem when it was disabled : I have a main thread with highest priority which creates other threads. When all the threads are created, the main thread reduces its priority at the minimum, broadcats a condition and unlock the associated mutex to start the other threads . But, after that main thread unlocks the mutex, it stays a short while in execution in spite of its priority)

---> I make a mistake, when Main thread reduces its priority at the minimum (with pthread_setschedparam), it's not preempted by a thread which has an higher priority and which is ready to run.

Could you try to run my program on your arm with enabled priority coupling, please?

#8 lore raw
Quoted 10 lines · Fabien MAHOT
Quoted 9 lines
Quoted 2 lines

Are you sure this is the right .config ? I see that priority coupling is enabled.

I want the priority coupling be enabled. (I have a problem when it was disabled : I have a main thread with highest priority which creates other threads. When all the threads are created, the main thread reduces its priority at the minimum, broadcats a condition and unlock the associated mutex to start the other threads . But, after that main thread unlocks the mutex, it stays a short while in execution in spite of its priority)

Quoted 7 lines

---> I make a mistake, when Main thread reduces its priority at the minimum (with pthread_setschedparam), it's not preempted by a thread which has an higher priority and which is ready to run.

Could you try to run my program on your arm with enabled priority coupling, please?

I see that you have the interrupt shield enabled, could you try and disable it ? The thread "thread2" never suspends, with the interrupt shield enabled, it means that Linux will never heandle its IRQs.

Signature · 1 line
					    Gilles.
#9 lore raw
Quoted 16 lines · Gilles Chanteperdrix
Quoted 15 lines · Fabien MAHOT
Quoted 9 lines
Quoted 2 lines

Are you sure this is the right .config ? I see that priority coupling is enabled.

I want the priority coupling be enabled. (I have a problem when it was disabled : I have a main thread with highest priority which creates other threads. When all the threads are created, the main thread reduces its priority at the minimum, broadcats a condition and unlock the associated mutex to start the other threads . But, after that main thread unlocks the mutex, it stays a short while in execution in spite of its priority)

---> I make a mistake, when Main thread reduces its priority at the minimum (with pthread_setschedparam), it's not preempted by a thread which has an higher priority and which is ready to run.

Quoted 6 lines
Quoted 2 lines

Could you try to run my program on your arm with enabled priority coupling, please?

I see that you have the interrupt shield enabled, could you try and disable it ? The thread "thread2" never suspends, with the interrupt shield enabled, it means that Linux will never heandle its IRQs.

That said, the interrupt shield should not enter in action since the shield bit is not armed for any thread. And indeed, your program runs fine with the same configuration as you (including interrupt shield) on ARM.

I tend to think about an hardware or configuration issue. I will now try to run your example on an x86 with the same configuration as you, to see if it is a configuration issue.

The only thing that bothers me when reading your configuration is that you select 586MMX whereas you have a Geode. You should really select Geode, this would let the kernel enable any quirk needed for this platform. Another question: do xenomai various tests run normally on your platform ? The Geode has (or had ?) known issues with stopping tsc and SMIs, but I do not know the current status of these issues with recent kernels. Maybe someone with more experience on Geodes can comment ?

Signature · 1 line
					    Gilles.
#10 lore raw
Quoted 24 lines · Gilles Chanteperdrix
Quoted 16 lines · Gilles Chanteperdrix
Quoted 15 lines · Fabien MAHOT
Quoted 9 lines
Quoted 2 lines

Are you sure this is the right .config ? I see that priority coupling is enabled.

I want the priority coupling be enabled. (I have a problem when it was disabled : I have a main thread with highest priority which creates other threads. When all the threads are created, the main thread reduces its priority at the minimum, broadcats a condition and unlock the associated mutex to start the other threads . But, after that main thread unlocks the mutex, it stays a short while in execution in spite of its priority)

---> I make a mistake, when Main thread reduces its priority at the minimum (with pthread_setschedparam), it's not preempted by a thread which has an higher priority and which is ready to run.

Quoted 6 lines
Quoted 2 lines

Could you try to run my program on your arm with enabled priority coupling, please?

I see that you have the interrupt shield enabled, could you try and disable it ? The thread "thread2" never suspends, with the interrupt shield enabled, it means that Linux will never heandle its IRQs.

Quoted 8 lines

That said, the interrupt shield should not enter in action since the shield bit is not armed for any thread. And indeed, your program runs fine with the same configuration as you (including interrupt shield) on ARM.

I tend to think about an hardware or configuration issue. I will now try to run your example on an x86 with the same configuration as you, to see if it is a configuration issue.

I have now tested your configuration on a PC. Your example works fine. So, it is now official, you have an hardware issue. This may be a peculiarity of Geode hardware, or some missing stuff in Xenomai.

Signature · 1 line
					    Gilles.
#11 lore raw

Hello,

thank you very much for your answers !

I tried several configurations with my AMD ETX module... Interrupt shield enable/disable, with GeodeLX

or Pentium-MMX processor. My application always crashed. However when the priority coupling was

disabled, my application worked correctly. (but it must be enabled)

You said to me that I ve got an hardware issue. So, I tried with an other ETX module. A Kontron with

celeron processor. With or Without the interrupt shield, my application crashed. I also try with a PC

with a celeron processor, that's the same result.

Maybe, I ve got a problem with my c libraries, but as I ve got a good beahaviour when the priority

coupling is disabled.What is your libraries version, please ?

So, I am almost sure that it's not a hardware problem. But a problem with my xenomai environment

#12 lore raw
Quoted 18 lines · Fabien MAHOT

Hello,

thank you very much for your answers !

I tried several configurations with my AMD ETX module... Interrupt shield enable/disable, with GeodeLX

or Pentium-MMX processor. My application always crashed. However when the priority coupling was

disabled, my application worked correctly. (but it must be enabled)

You said to me that I ve got an hardware issue. So, I tried with an other ETX module. A Kontron with

celeron processor. With or Without the interrupt shield, my application crashed. I also try with a PC

Quoted 6 lines

with a celeron processor, that's the same result.

Maybe, I ve got a problem with my c libraries, but as I ve got a good beahaviour when the priority

coupling is disabled.What is your libraries version, please ?

I have tested with Xenomai trunk and version 2.4.2 (same version as you). What do you mean by crash anyway ? Box lockup, application dying ? Is there no message on the console ? Did you try running your application inside gdb ?

Quoted 3 lines

So, I am almost sure that it's not a hardware problem. But a problem with my xenomai environment

If you suspect your xenomai environment, the best thing to do is to remove any trace of Xenomai on your test box, and recompile Xenomai from scratch, using the same version of Xenomai tarball for kernel-space support and user-space support.

Signature · 1 line
 Gilles
#13 lore raw
Quoted 13 lines
Quoted 4 lines

Result in Xenomai environment(Xenomai 2.3.4 kernel) :
___ # ./test
T2 : 0
T2 : 1

Quoted 8 lines

T2 : 2
T2 : 3
T2 : 4
T2 : 5
T2 : 6
T2 : 7
T2 : 8
T2 : 9

Quoted 5 lines

I have tested with Xenomai trunk and version 2.4.2 (same version as you). What do you mean by crash anyway ? Box lockup, application dying ? Is there no message on the console ? Did you try running your application inside gdb ?

Hello,

In my opinion, crash means that my application is frozen. On my console, I ve got the T2 traces and when T1 must display its trace, my application freezes.
As I use Xenomai threads with the highest priority, I cannot stop my application with CTRL+C or a call to kill with my other console (Ethernet -- ssh). I just can reset my ETX module.

I tried with gdb. If I didn't put breakpoints, my application froze. With breakpoints, I hadn't got the crash but the thread behaviour is totally different.

Quoted 6 lines

If you suspect your xenomai environment, the best thing to do is to remove any trace of Xenomai on your test box, and recompile Xenomai from scratch, using the same version of Xenomai tarball for kernel-space support and user-space support.

I m going to try this.

thanks

#14 lore raw
Quoted 21 lines · Fabien MAHOT
Quoted 15 lines
Quoted 13 lines

Result in Xenomai environment(Xenomai 2.3.4 kernel) :
___ # ./test

T2 : 0
T2 : 1
T2 : 2
T2 : 3
T2 : 4
T2 : 5
T2 : 6
T2 : 7
T2 : 8
T2 : 9

Quoted 5 lines

I have tested with Xenomai trunk and version 2.4.2 (same version as you). What do you mean by crash anyway ? Box lockup, application dying ? Is there no message on the console ? Did you try running your application inside gdb ?

Quoted 8 lines

Hello,

In my opinion, crash means that my application is frozen. On my console, I ve got the T2 traces and when T1 must display its trace, my application freezes.
As I use Xenomai threads with the highest priority, I cannot stop my application with CTRL+C or a call to kill with my other console (Ethernet -- ssh). I just can reset my ETX module.

It's a lockup then. Could you try enabling the Xenomai watchdog ?

Quoted 18 lines

I tried with gdb. If I didn't put breakpoints, my application froze. With breakpoints, I hadn't got the crash but the thread behaviour is totally different.

Quoted 6 lines

If you suspect your xenomai environment, the best thing to do is to remove any trace of Xenomai on your test box, and recompile Xenomai from scratch, using the same version of Xenomai tarball for kernel-space support and user-space support.

I m going to try this.

thanks

Signature · 1 line
 Gilles
#15 lore raw
Quoted 2 lines

It's a lockup then. Could you try enabling the Xenomai watchdog ?

yes, but no thread is killed. my application stays frozen

#16 lore raw
Quoted 4 lines · Fabien MAHOT
Quoted 2 lines

It's a lockup then. Could you try enabling the Xenomai watchdog ?

yes, but no thread is killed. my application stays frozen

And you do not get any message on the console ?

Signature · 1 line
					    Gilles.
#17 lore raw
Quoted 8 lines
Quoted 4 lines · Fabien MAHOT
Quoted 2 lines

It's a lockup then. Could you try enabling the Xenomai watchdog ?

yes, but no thread is killed. my application stays frozen

And you do not get any message on the console ?

Hello !

Yes, I don't get messages on the console.

but, I tried my test program with a xenomai 2.3.4 kernel directly on my pc (gentoo distribution). And I haven't got the crash like you !

When my application crashes, I try my program on the target (ETX module) from a flash card. In my gentoo distribution on my PC, I create a new gentoo xenomai environment in order to generate it on my flash card.

So, my new xenomai environement contains errors.

thank you very much for your help !

#18 lore raw
In reply to Gilles Chanteperdrix

Hello,

I found the solution for my application crash. The "Queue Debugging Support" kernel option was enabled. When this option is disabled, my program works perfectly.

I m not sure that is really the origin of the problem, but without this option, I think that thread scheduling is more "clean" (overhead problem...)?

bye !

#19 lore raw

[Xenomai-help] Posix timers increase

In reply to Gilles Chanteperdrix

Hello,

I ve got an application in which I create a lot of posix timers (with timer_create). After a while timer_create returns an error. There is no available timer. I would like to increase the timer amount. How can I do this ? there is a link with "Size of the system heap" kernel configuration option ?

thanks a lot

#20 lore raw

Re: [Xenomai-help] Posix timers increase

Quoted 10 lines

Hello,

I ve got an application in which I create a lot of posix timers (with timer_create). After a while timer_create returns an error. There is no available timer. I would like to increase the timer amount. How can I do this ? there is a link with "Size of the system heap" kernel configuration option ?

thanks a lot

folder xenomai : ksrc/skins/posix/timer.c : #define PSE51_TIMER_MAX 128

#21 lore raw

Re: [Xenomai-help] Posix timers increase

Quoted 8 lines · Fabien MAHOT
Quoted 8 lines

Hello,

I ve got an application in which I create a lot of posix timers (with timer_create). After a while timer_create returns an error. There is no available timer. I would like to increase the timer amount. How can I do this ? there is a link with "Size of the system heap" kernel configuration option ?

Quoted 5 lines
Quoted 2 lines

thanks a lot

folder xenomai : ksrc/skins/posix/timer.c : #define PSE51_TIMER_MAX 128

Beware: posix timers use signals, and signals in user-space cause the target thread to switch to secondary mode. So, timers are or little use in user-space. You would better use clock_nanosleep, or pthread_make_periodic_np/pthread_wait_np.

Signature · 1 line
					    Gilles.
#22 lore raw

Re: [Xenomai-help] Posix timers increase

Hi all, I'm trying to embed the
linux-2.6.24 with xenomai-2.4.3 on powerpc processor. Although when I try to execute
/scripts/prepare-kernel.sh on xenomai directory I unfortunately get the message at the end :

patching file Makefile
patching file arch/powerpc/Kconfig
patching file arch/powerpc/boot/Makefile
patching file arch/powerpc/kernel/Makefile
patching file arch/powerpc/kernel/asm-offsets.c
patching file arch/powerpc/kernel/cputable.c
Hunk #1 succeeded at 1333 (offset -79 lines).
Hunk #2 succeeded at 1380 (offset -79 lines).
patching file arch/powerpc/kernel/entry_32.S

......

Unable to patch kernel 2.6.24.4 with adeos-ipipe....

Have you seen this problem? Could you give me some tips?

Thanks,

Breno