Skip to contentSkip to conversation

task not being scheduled

Xenomai-help Jeff Weber 4 participants 15 messages Feb 27, 2007 – Mar 8, 2007

lore
Share & tools
lore

Jeff Weber

author
#0 lore raw

I have system where a 100Hz periodic task is occasionally over running it's periodic task wakeup by 10s of msec. To debug the problem, I froze an ipipe verbose trace upon an -ETIMEDOUT error return from rt_task_wait_period(). A filtered output of the trace appears below. This trace includes every occurence of the task, which is pid 7380.

:|  # [ 7380] -<?>-   35 -25252+   5.587  xnpod_resume_thread+0x59 [xeno_nucleus ] (xnthread_periodic_handler+0x31 [xeno_nucleus])
:|  # [ 7380] -<?>-   35 -24820+   4.214  xnpod_schedule+0x6c0 [xeno_nucleus] (x npod_suspend_thread+0x118 [xeno_nucleus])
:|  # [ 7380] -<?>-   35 -24734+   1.501  xnpod_schedule+0x97 [xeno_nucleus] (xn intr_irq_handler+0x9a [xeno_nucleus])
:|  # [ 7380] -<?>-   35 -24589+   1.218  xnpod_schedule+0x6c0 [xeno_nucleus] (x nintr_irq_handler+0x9a [xeno_nucleus])
:   + func               -24587    0.493  __rt_task_wait_period+0x11 [xeno_native] (hisyscall_event+0x162 [xeno_nucleus])
:   + func               -24586    0.485  rt_task_wait_period+0xb [xeno_native] (__rt_task_wait_period+0x3f [xeno_native])
:   + func               -24586    0.464  xnpod_wait_thread_period+0xe [xeno_nucleus] (rt_task_wait_period+0x4b [xeno_native])
:|  + begin   0x80000001 -24586    0.718  xnpod_wait_thread_period+0x1ed [xeno_nucleus] (rt_task_wait_period+0x4b [xeno_native])
:|  # func               -24585    0.621  xnpod_suspend_thread+0xe [xeno_nucleus] (xnpod_wait_thread_period+0x91 [xeno_nucleus])
:|  # func               -24584    0.558  xnpod_schedule+0xe [xeno_nucleus] (xnpod_suspend_thread+0x118 [xeno_nucleus])
:|  # [ 7380] -<?>-   35 -24584    0.847  xnpod_schedule+0x97 [xeno_nucleus] (xn pod_suspend_thread+0x118 [xeno_nucleus])
:|  # [    0] -<?>-   -1 -10630    0.916  xnpod_schedule+0x6c0 [xeno_nucleus] (xnintr_irq_handler+0x9a [xeno_nucleus])
:|  # [    0] -<?>-   -1 -4632    0.886  xnpod_schedule+0x6c0 [xeno_nucleus] (xnintr_irq_handler+0x9a [xeno_nucleus])
:|  # [ 7380] -<?>-   35  -609+   1.747  xnpod_resume_thread+0x59 [xeno_nucleus] (xnthread_periodic_handler+0x31 [xeno_nucleus])
:|  # [ 7380] -<?>-   35  -186+   4.288  xnpod_schedule+0x6c0 [xeno_nucleus] (xn pod_suspend_thread+0x118 [xeno_nucleus])
:|  # [ 7380] -<?>-   35  -143+   1.554  xnpod_schedule+0x97 [xeno_nucleus] (xni ntr_irq_handler+0x9a [xeno_nucleus])
:|  # [ 7380] -<?>-   35    -6+   1.211  xnpod_schedule+0x6c0 [xeno_nucleus] (xn intr_irq_handler+0x9a [xeno_nucleus])
<   + freeze  0x00000007     0    0.929  xnshadow_sys_trace+0x8b [xeno_nucleus] (hisyscall_event+0x162 [xeno_nucleus])

At time -24587 usec, the task calls rt_task_wait_period(), presumable to sleep for approx 10msec. So, I would expect to see the task resumed at approx clock -14587. However, the task is not resumed until clock -609, and not run until time -186. So, the task wasn't sheduled for over 14msec. During this time, the ROOT task, presumably pid=0 priority=-1, ran 61 times. I included a 2 samples of this in the above trace.
Thus a worse priority task ran many times, when my better priority task was not being scheduled.

I am new to interpreting ipipe traces, and may be overlooking some of the details. I would appreciate help understanding this problem, and how to fix it.

config:
arch = x86
Linux 2.6.17.14
Xenomai-2.2.4
ipipe 1.5-00

TIA,
Jeff

#1 lore raw
Quoted 5 lines · Jeff Weber

I have system where a 100Hz periodic task is occasionally over running it's periodic task wakeup by 10s of msec. To debug the problem, I froze an ipipe verbose trace upon an -ETIMEDOUT error return from rt_task_wait_period(). A filtered output of the trace appears below. This trace includes every occurence of the task, which is pid 7380.

Please post the unfiltered (but compressed) trace. It's not yet obvious from the excerpt below what happens.

Quoted 40 lines
:|  # [ 7380] -<?>-   35 -25252+   5.587  xnpod_resume_thread+0x59 [xeno_nucleus ] (xnthread_periodic_handler+0x31 [xeno_nucleus])
:|  # [ 7380] -<?>-   35 -24820+   4.214  xnpod_schedule+0x6c0 [xeno_nucleus] (x npod_suspend_thread+0x118 [xeno_nucleus])
:|  # [ 7380] -<?>-   35 -24734+   1.501  xnpod_schedule+0x97 [xeno_nucleus] (xn intr_irq_handler+0x9a [xeno_nucleus])
:|  # [ 7380] -<?>-   35 -24589+   1.218  xnpod_schedule+0x6c0 [xeno_nucleus] (x nintr_irq_handler+0x9a [xeno_nucleus])
:   + func               -24587    0.493  __rt_task_wait_period+0x11 [xeno_native] (hisyscall_event+0x162 [xeno_nucleus])
:   + func               -24586    0.485  rt_task_wait_period+0xb [xeno_native] (__rt_task_wait_period+0x3f [xeno_native])
:   + func               -24586    0.464  xnpod_wait_thread_period+0xe [xeno_nucleus] (rt_task_wait_period+0x4b [xeno_native])
:|  + begin   0x80000001 -24586    0.718  xnpod_wait_thread_period+0x1ed [xeno_nucleus] (rt_task_wait_period+0x4b [xeno_native])
:|  # func               -24585    0.621  xnpod_suspend_thread+0xe [xeno_nucleus] (xnpod_wait_thread_period+0x91 [xeno_nucleus])
:|  # func               -24584    0.558  xnpod_schedule+0xe [xeno_nucleus] (xnpod_suspend_thread+0x118 [xeno_nucleus])
:|  # [ 7380] -<?>-   35 -24584    0.847  xnpod_schedule+0x97 [xeno_nucleus] (xn pod_suspend_thread+0x118 [xeno_nucleus])
:|  # [    0] -<?>-   -1 -10630    0.916  xnpod_schedule+0x6c0 [xeno_nucleus] (xnintr_irq_handler+0x9a [xeno_nucleus])
:|  # [    0] -<?>-   -1 -4632    0.886  xnpod_schedule+0x6c0 [xeno_nucleus] (xnintr_irq_handler+0x9a [xeno_nucleus])
:|  # [ 7380] -<?>-   35  -609+   1.747  xnpod_resume_thread+0x59 [xeno_nucleus] (xnthread_periodic_handler+0x31 [xeno_nucleus])
:|  # [ 7380] -<?>-   35  -186+   4.288  xnpod_schedule+0x6c0 [xeno_nucleus] (xn pod_suspend_thread+0x118 [xeno_nucleus])
:|  # [ 7380] -<?>-   35  -143+   1.554  xnpod_schedule+0x97 [xeno_nucleus] (xni ntr_irq_handler+0x9a [xeno_nucleus])
:|  # [ 7380] -<?>-   35    -6+   1.211  xnpod_schedule+0x6c0 [xeno_nucleus] (xn intr_irq_handler+0x9a [xeno_nucleus])
<   + freeze  0x00000007     0    0.929  xnshadow_sys_trace+0x8b [xeno_nucleus] (hisyscall_event+0x162 [xeno_nucleus])

At time -24587 usec, the task calls rt_task_wait_period(), presumable to sleep for approx 10msec. So, I would expect to see the task resumed at approx clock -14587. However, the task is not resumed until clock -609, and not run until time -186. So, the task wasn't sheduled for over 14msec. During this time, the ROOT task, presumably pid=0 priority=-1, ran 61 times. I included a 2 samples of this in the above trace.
Thus a worse priority task ran many times, when my better priority task was not being scheduled.

I am new to interpreting ipipe traces, and may be overlooking some of the details. I would appreciate help understanding this problem, and how to fix it.

config:
arch = x86
Linux 2.6.17.14
Xenomai-2.2.4
ipipe 1.5-00

Quoted 3 lines

TIA,
Jeff

Jan

#2 lore raw
Quoted 10 lines · Jan Kiszka
Quoted 5 lines · Jeff Weber

I have system where a 100Hz periodic task is occasionally over running it's periodic task wakeup by 10s of msec. To debug the problem, I froze an ipipe verbose trace upon an -ETIMEDOUT error return from rt_task_wait_period(). A filtered output of the trace appears below. This trace includes every occurence of the task, which is pid 7380.

Please post the unfiltered (but compressed) trace. It's not yet obvious from the excerpt below what happens.

...and include your .config as well, please.

Thanks,
Jan

author
#3 lore raw
In reply to Jan Kiszka

trace and .config attached.
The board has a single 750MHz VIA Nehemiah CPU.

Jeff

Quoted 6 lines · Jan Kiszka
Quoted 1 line · Jeff Weber

I have system where a 100Hz periodic task is occasionally over running

Please post the unfiltered (but compressed) trace. It's not yet obvious from the excerpt below what happens.

#4 lore raw
Quoted 1 line · Jeff Weber

trace and .config attached.

OK. Sorry for not believing in the first place :), but there are actually timer events missing for your 10-ms-period task.

I saw in the .config that you are using the heap timer list. Already tried the classic linked list as well? Maybe we see in issue related to this queue implementation.

Gilles, I think the heap was your contribution. If it turns out to bite us here, any idea where to look, what to instrument (xntrace_special[_u64]...)?

Jan

#5 lore raw
Quoted 6 lines · Jan Kiszka
Quoted 1 line · Jeff Weber

trace and .config attached.

OK. Sorry for not believing in the first place :), but there are actually timer events missing for your 10-ms-period task.

Quoted 7 lines

I saw in the .config that you are using the heap timer list. Already tried the classic linked list as well? Maybe we see in issue related to this queue implementation.

Gilles, I think the heap was your contribution. If it turns out to bite us here, any idea where to look, what to instrument (xntrace_special[_u64]...)?

I used a dumper that I called at any time when I wanted to inspect the contents of a binary heap. Here it comes, it probably needs to be re-adapted.

Signature · 1 line
					    Gilles Chanteperdrix.

#ifndef AHEAP_DUMP_H
#define AHEAP_DUMP_H

#ifndef __KERNEL__

#include <stdlib.h>             /* For NULL */
#include <errno.h>              /* For EINVAL, EBUSY */
#include <string.h>             /* For memset */

#endif /* __KERNEL__ */

#if DUMPER && !defined(__KERNEL__)

#define flnz(word)                              \
({                                              \
    unsigned long out;                          \
    /* Derived from bitops.h's ffs() */         \
    __asm__ ("bsrl %1, %0"                      \
             : "=r" (out)                       \
             : "mr"  (word));                   \
    out;                                        \

})

static inline void
aheap_dumper_visit (FILE *file,
aheap_t *heap,
aheaph_t *node,
int (*prn)(char *, size_t, const aheaph_t *const), const char *blank,
unsigned blank_sz,
char *buf,
unsigned indent,
unsigned len)

{
    aheaph_t *left, *right;

    right = aheaph_child(heap, node, 1);
    if(right) {
        if(blank_sz >= (unsigned) (buf-blank)) {
            snprintf(buf, len+2, "%*s\n", (int) len+1, "bug!");
            fputs(buf-blank_sz, file);
        } else
            aheap_dumper_visit(file, heap, right, prn, blank,
                               blank_sz+indent, buf, indent, len);
    }
    
    (*prn)(buf, len+1, node);
    buf[len] = '\n';
    buf[len+1] = '\0';
    
    fputs(buf-blank_sz, file);

    left = aheaph_child(heap, node, 0);    
    if(left) {
        if(blank_sz >= (unsigned) (buf-blank)) {
            snprintf(buf, len+2, "%*s\n", (int) len+1, "bug!");
            fputs(buf-blank_sz, file);
        } else
            aheap_dumper_visit(file, heap, left, prn, blank,
                               blank_sz+indent, buf, indent, len);
    }
}

static inline void
aheap_dump (FILE *file,
aheap_t *heap,
int (*prn)(char *, size_t, const aheaph_t *const), unsigned indent,
unsigned len)

{
    aheaph_t *holder = aheap_gethead(heap);

    putc('\n', file);
    if (!holder)
        fputs("Empty.\n", file);
    else {
        size_t blank_sz = (flnz(heap->last - 1) + 1) * indent;
        char buffer[blank_sz+len+2];
        memset(buffer, ' ', blank_sz);

        aheap_dumper_visit(file, heap, holder, prn, buffer, 0,
                           buffer+blank_sz, indent, len);
    }
}

#else /* !DUMPER || __KERNEL__ */

#define aheap_dump(file, heap, prn, indent, len) do { } while(0)

#endif /* !DUMPER || __KERNEL__ */

#endif /* AHEAP_DUMP_H */

author
#6 lore raw
In reply to Jan Kiszka

I will try the CONFIG_XENO_OPT_TIMER_LIST. I have about 18 RT tasks, of which only a few are ever runnable at the same time.

Jeff

Quoted 9 lines · Jan Kiszka
Quoted 1 line · Jeff Weber

trace and .config attached.

OK. Sorry for not believing in the first place :), but there are actually timer events missing for your 10-ms-period task.

I saw in the .config that you are using the heap timer list. Already tried the classic linked list as well? Maybe we see in issue related to this queue implementation.

#7 lore raw
Quoted 2 lines · Jeff Weber

I will try the CONFIG_XENO_OPT_TIMER_LIST. I have about 18 RT tasks, of which only a few are ever runnable at the same time.

The thing that matters for selecting the timer list data structure is the number of pending timers.

Signature · 1 line
					    Gilles Chanteperdrix.
author
#8 lore raw
In reply to Jan Kiszka

Switching to the linked timer list from the heap list fixed it.

thanks,
Jeff

Quoted 3 lines · Jan Kiszka

I saw in the .config that you are using the heap timer list. Already tried the classic linked list as well? Maybe we see in issue related to this queue implementation.

#9 lore raw
Quoted 2 lines · Jeff Weber

Switching to the linked timer list from the heap list fixed it.

Ok people, that's a showstopper for v2.3.1.

Quoted 12 lines

thanks,
Jeff

Quoted 3 lines · Jan Kiszka

I saw in the .config that you are using the heap timer list. Already tried the classic linked list as well? Maybe we see in issue related to this queue implementation.

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Signature · 1 line
Philippe.
#10 lore raw
In reply to Jeff Weber
Quoted 2 lines · Jeff Weber

Switching to the linked timer list from the heap list fixed it.

OK, good to know.

Gilles, could you provide some ready-to-apply instrumentation patch?

Jeff, you have the ultimate test case now. Will you have some time to run that test on your box so that we can quickly find and resolve the bug?

Jan

#11 lore raw
Quoted 9 lines · Jan Kiszka
Quoted 2 lines · Jeff Weber

Switching to the linked timer list from the heap list fixed it.

OK, good to know.

Gilles, could you provide some ready-to-apply instrumentation patch?

Yes, the mail with attached patch did not make it to the list, but I just finished my work on the ARM patch for Linux 2.6.19, so, I have time to spend on this issue.

Quoted 3 lines

Jeff, you have the ultimate test case now. Will you have some time to run that test on your box so that we can quickly find and resolve the bug?

Is it possible to get a simplified version of the application you are running with only timer-related events ? Some kind of model that I could quietly run in the simulator ?

Signature · 1 line
                                                 Gilles Chanteperdrix
author
#12 lore raw
Quoted 5 lines · Gilles Chanteperdrix
Quoted 3 lines · Jan Kiszka

Jeff, you have the ultimate test case now. Will you have some time to run that test on your box so that we can quickly find and resolve the bug?

Yes. I've rebuilt my kernel with the linked list scheduler, but I've saved the previous heap scheduler config. I will recreate the bug config, and await a patch or instrumentation.

Quoted 4 lines

Is it possible to get a simplified version of the application you are running with only timer-related events ? Some kind of model that I could quietly run in the simulator ?

That will be more difficult. The application requires a custom kernel module, and has many dependencies upon our hardware. Further, the app is written in C++, which I understand is not compatible with the simulator.

Let me know if you would like to move this discussion off the xenomai-help list, to xenomai-core, or a private email discussion.

And again, thanks for taking the time to look at my trace, config and recommend a solution. It was causing considerable frustration on this end.

Jeff

#13 lore raw
Quoted 22 lines · Jeff Weber
Quoted 6 lines · Gilles Chanteperdrix
Quoted 3 lines · Jan Kiszka

Jeff, you have the ultimate test case now. Will you have some time to run that test on your box so that we can quickly find and resolve the bug?

Yes. I've rebuilt my kernel with the linked list scheduler, but I've saved the previous heap scheduler config. I will recreate the bug config, and await a patch or instrumentation.

Quoted 3 lines

Is it possible to get a simplified version of the application you are running with only timer-related events ? Some kind of model that I could quietly run in the simulator ?

That will be more difficult. The application requires a custom kernel module, and has many dependencies upon our hardware. Further, the app is written in C++, which I understand is not compatible with the simulator.

Quoted 5 lines

Let me know if you would like to move this discussion off the xenomai-help list, to xenomai-core, or a private email discussion.

And again, thanks for taking the time to look at my trace, config and recommend a solution. It was causing considerable frustration on this end.

Ok. Following up on xenomai-core. Find attached a not too subtle instrumentation that saves the state of the heap after each elementary operation. This history is then dumped with printk on xntrace freeze.

Signature · 1 line
                                                 Gilles Chanteperdrix
nucleus/bheap.h +15 -0
Index: include/nucleus/bheap.h
===================================================================
@@ -25,6 +25,12 @@
 
 /* Priority queue implementation, using a binary heap. */
 
+typedef enum {
+	BHEAP_INSERT,
+	BHEAP_DELETE,
+	BHEAP_GETHEAD,
+} bheap_op_t;
+ 
 typedef unsigned long long bheap_key_t;
 
 typedef struct bheaph {
@@ -66,11 +72,18 @@
     __internal_bheap_gethead(_bheap);           \
 })
 
+void bheap_s_init(void);
+
+void bheap_save_push(bheap_t *q, bheap_op_t op, bheaph_t *elem);
+
+void bheap_ops_dump(void);
+
 static inline bheaph_t *__internal_bheap_gethead(bheap_t *heap)
 {
     if (heap->last == 1)
         return NULL;
 
+    bheap_save_push(heap, BHEAP_GETHEAD, heap->elems[1]);
     return heap->elems[1];
 }
 
@@ -158,6 +171,7 @@
     bheaph_pos(holder) = heap->last;
     ++heap->last;
     bheap_up(heap, holder);
+    bheap_save_push(heap, BHEAP_INSERT, holder);
     return 0;
 }
 
@@ -182,6 +196,7 @@
         bheaph_pos(lasth) = bheaph_pos(holder);
         bheap_down(heap, lasth);
     }
+    bheap_save_push(heap, BHEAP_DELETE, holder);
 
     return 0;
 }
nucleus/timer.c +166 -0

175 lines not on this page · raw message

nucleus/shadow.c +3 -0
Index: ksrc/nucleus/shadow.c
===================================================================
@@ -1330,6 +1330,9 @@
 		break;
 
 	case __xntrace_op_user_freeze:
+#if defined(CONFIG_XENO_OPT_TIMER_HEAP)
+		bheap_ops_dump();
+#endif
 		err = xnarch_trace_user_freeze(__xn_reg_arg2(regs),
 					       __xn_reg_arg3(regs));
 		break;
#14 lore raw
In reply to Jeff Weber
Quoted 19 lines · Jeff Weber
Quoted 5 lines · Gilles Chanteperdrix
Quoted 3 lines · Jan Kiszka

Jeff, you have the ultimate test case now. Will you have some time to run that test on your box so that we can quickly find and resolve the bug?

Yes. I've rebuilt my kernel with the linked list scheduler, but I've saved the previous heap scheduler config. I will recreate the bug config, and await a patch or instrumentation.

Quoted 4 lines

Is it possible to get a simplified version of the application you are running with only timer-related events ? Some kind of model that I could quietly run in the simulator ?

That will be more difficult. The application requires a custom kernel module, and has many dependencies upon our hardware. Further, the app is written in C++, which I understand is not compatible with the simulator.

Quoted 5 lines

Let me know if you would like to move this discussion off the xenomai-help list, to xenomai-core, or a private email discussion.

And again, thanks for taking the time to look at my trace, config and recommend a solution. It was causing considerable frustration on this end.

Thank you Jeff for helping. The issue should now be resolved by commit #2280 in trunk and #2281 in branch 2.3.

Signature · 1 line
					    Gilles Chanteperdrix.