fpu issue
I found the source of my fpu issue. A single kernel module with two tasks was also active. I noticed the failure occurred whenever sound would play. (This is one of the tasks.) It seems the problem is that the sound task doesn't use the FPU, so I didn't turn on T_FPU. The tone task (not in use at that time) does, so it has T_FPU. When I turned on T_FPU for the sound task, I never saw the problem again. With it off, if I played sound while running the program, I'd regularly see the corruption.
Here is the task code:
static void sound_func(void *data)
{
for (;;) //go until suspended or thread deletion
{
if (play==stop) //time to stop if this happens
{
unsigned long evt = 0;
play=stop=0; // just in case
rt_event_clear(&sound_event, SOUND, 0);
rt_task_set_periodic(&sound_task, TM_NOW, TM_INFINITE); /*disable periodic mode */
rt_event_wait(&sound_event, SOUND, &evt, EV_ALL,TM_INFINITE);
rt_task_set_periodic(&sound_task, TM_NOW,rt_timer_ns2ticks(ST_AUDIO_PERIOD));
}
#if BUFSIZE != 65536
if (play==BUFSIZE) play=0;
#endif
if(rt_task_wait_period(0)) rt_task_wait_period(0); //wait for
next tick and ignore overruns (do the best we can)
// Since the index is incrementd subtract 2 from the size before
comparing the index
outb(buf[play++], DAC_ADDRESS); //send the next byte to the dac
}
}
The buffer is filled with a linux userland process and an appropriate wait queue. This same code worked fine in RTAI without the FPU flag.
I've tested this for several minutes.
Any idea?
Steven
Quoted 77 lines · Steven Seeger
I found the source of my fpu issue. A single kernel module with two tasks was also active. I noticed the failure occurred whenever sound would play. (This is one of the tasks.) It seems the problem is that the sound task doesn't use the FPU, so I didn't turn on
T_FPU. The tone task (not in use at that time) does, so it hasT_FPU. When I turned onT_FPUfor the sound task, I never saw the problem again. With it off, if I played sound while running the program, I'd regularly see the corruption.Here is the task code:
static void
sound_func(void *data){
for (;;) //go until suspended or thread deletion { if (play==stop) //time to stop if this happens { unsigned long evt = 0; play=stop=0; // just in case rt_event_clear(&sound_event, SOUND, 0); rt_task_set_periodic(&sound_task, TM_NOW, TM_INFINITE); /*disable periodic mode */
rt_event_wait(&sound_event, SOUND, &evt,
EV_ALL,TM_INFINITE);rt_task_set_periodic(&sound_task,
TM_NOW,rt_timer_ns2ticks(ST_AUDIO_PERIOD));}#if BUFSIZE != 65536
if (play==BUFSIZE) play=0;#endif
if(rt_task_wait_period(0)) rt_task_wait_period(0); //wait fornext tick and ignore overruns (do the best we can)
// Since the index is incrementd subtract 2 from the size beforecomparing the index
outb(buf[play++], DAC_ADDRESS); //send the next byte to the dac}
}
The buffer is filled with a linux userland process and an appropriate wait queue. This same code worked fine in RTAI without the FPU flag.
Quoted 5 lines
I've tested this for several minutes.
Any idea?
An idea is to disassemble the kernel task code and the function it calls to see if FPU is really never used.
If this task really never calls any function using FPU, it would be nice if you could (as we always ask, you may have noticed) reduce your test case to a simple code where only FPU operations and every thing which causes task switches (blocking calls, and calls waking up other tasks) is kept.
Signature · 1 line
Gilles Chanteperdrix.
Quoted 1 line
An idea is to disassemble the kernel task code and the function it
calls
Quoted 3 lines
to see if FPU is really never used.
If this task really never calls any function using FPU, it would be
nice
Quoted 4 lines
if you could (as we always ask, you may have noticed) reduce your test case to a simple code where only FPU operations and every thing which causes task switches (blocking calls, and calls waking up other tasks) is kept.
My application has 12 threads most of which wait on queues. How am I going to reduce this to a simple case? Most of my threads are userspace except for 2.
I guess I'll see what I can do. I'll try the disassembler, too.
Steven
Quoted 6 lines · Steven Seeger
Quoted 1 line
An idea is to disassemble the kernel task code and the function it
calls
Quoted 3 lines
to see if FPU is really never used.
If this task really never calls any function using FPU, it would be
nice
Quoted 8 lines
Quoted 4 lines
if you could (as we always ask, you may have noticed) reduce your test case to a simple code where only FPU operations and every thing which causes task switches (blocking calls, and calls waking up other tasks) is kept.
My application has 12 threads most of which wait on queues. How am I going to reduce this to a simple case? Most of my threads are userspace except for 2.
You should start with an example having the 12 same threads as the real code, then try removing threads one by one and look if the bug is still there. If you need the 12 threads, then send us your example with the 12 threads.
Quoted 4 lines
I guess I'll see what I can do. I'll try the disassembler, too.
Steven
Signature · 1 line
Gilles Chanteperdrix.
Quoted 11 lines · Steven Seeger
Quoted 1 line
An idea is to disassemble the kernel task code and the function it
calls
Quoted 3 lines
to see if FPU is really never used.
If this task really never calls any function using FPU, it would be
nice
Quoted 4 lines
if you could (as we always ask, you may have noticed) reduce your test case to a simple code where only FPU operations and every thing which causes task switches (blocking calls, and calls waking up other tasks) is kept.
Quoted 5 lines
My application has 12 threads most of which wait on queues. How am I going to reduce this to a simple case? Most of my threads are userspace except for 2.
I guess I'll see what I can do. I'll try the disassembler, too.
It was a bad idea: if ever your task had used FPU without the FPU bit, Xenomai would have suspended this task, with a warning on the console.
Signature · 1 line
Gilles Chanteperdrix.