All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] the exception saga - system hangs
@ 2008-11-06 10:21 Gabriele Moabiti
  2008-11-06 13:16 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 4+ messages in thread
From: Gabriele Moabiti @ 2008-11-06 10:21 UTC (permalink / raw)
  To: Xenomai help

[-- Attachment #1: Type: text/plain, Size: 3327 bytes --]


I was trying to do custom exceptions handling for a xenomai task but
I had problem of erratic hangs so I've done an example program to
reproduce the behaviour.
The user xenomai task causes an exception #13 when try to execute a
read in the eax of dr7 program register. The exception handler will
only change the ip to the next instruction.

All seems to work but after some loops (from 50 to 10000...
not predictable) system hangs. I can't figure the problem...
if the problem isn't in my code maybe the problem is in adeos.

[x86 32 bit - Xenomai 2.4.5 - Linux kernel `vanilla` 2.6.24-7, gcc 4.1.3]
-------------------------
 
User program
-------------------------
#include <stdio.h>
#include <sys/mman.h>
#include <native/task.h>
#include <rtdk.h>

#define MODULE_TASK_NAME    "xtask_user"
#define TASK_PRIO  99
#define TASK_MODE  T_FPU|T_CPU(0)
#define TASK_STKSZ 4096
#define FIXED_PERIOD 2000000          /* 2 ms */

RT_TASK task_desc;

void xeno_task(void *cookie)
{
  static long loop_count=0;
  for (;;loop_count++) {
    rt_task_wait_period(NULL);
    rt_printf("Loop number: %ld\n", loop_count);
    /* Let's raise an exception #13*/
    __asm__ __volatile__("nop; movl %dr7, %eax;nop");
  }
}
 
int main(int argc, char *argv[])
{
    mlockall(MCL_CURRENT|MCL_FUTURE);
    rt_print_auto_init(1);
    rt_task_create(&task_desc, MODULE_TASK_NAME, TASK_STKSZ, TASK_PRIO, TASK_MODE);
    rt_task_set_periodic(&task_desc, TM_NOW, rt_timer_ns2ticks(FIXED_PERIOD));
    rt_task_start(&task_desc,&xeno_task,NULL);
    pause();
    rt_task_delete(&task_desc);
}
-------------------------
 Kernel module
-------------------------
#include <linux/module.h>
#include <rtdm/rtdm_driver.h>
#include <native/task.h>
#include <native/timer.h>
#include <native/intr.h>

MODULE_AUTHOR(xxx");
MODULE_DESCRIPTION("xxx");
MODULE_LICENSE("GPL");                      

static rthal_trap_handler_t old_trap_handler;

static int custom_trap_fault(unsigned event, unsigned domid, void *data)
{
  volatile short *istr;
  struct pt_regs *regs=data;
  xnthread_t *thread;
  if (event==13) {
    if (!xnpod_active_p() ||
      (!xnpod_interrupt_p() && xnpod_idle_p()))
      goto xeno_handle;    
    if (!xnpod_shadow_p()) 
      goto xeno_handle;    
    if (!xnpod_userspace_p())
      goto xeno_handle;    
    thread = xnpod_current_thread();  
    if (!user_mode(regs)) /* not a user CS */
      goto xeno_handle;
    if (strcmp(thread->name,"xtask_user")!=0)
      goto xeno_handle;
    istr = (char *) (regs->x86reg_ip);
    if (*istr == 0x210f && (*(istr+1) & 0xFF) == 0xf8) {
      /* movl %dr7, %eax */
      regs->x86reg_ip+=3; 
      return RTHAL_EVENT_STOP;
    } 
  }
xeno_handle: /* Xenomai will handle the event */
    return ((rthal_trap_handler_t) old_trap_handler)(event, domid, data);
}

int __init init_mymodule(void)
{
  old_trap_handler = rthal_trap_catch(&custom_trap_fault);
  return 0; // OK, adesso ho fatto! 
}
void __exit cleanup_mymodule(void)
{
    rthal_trap_catch(old_trap_handler);
}
module_init(init_mymodule);
module_exit(cleanup_mymodule);


      Unisciti alla community di Io fotografo e video, il nuovo corso di fotografia di Gazzetta dello sport:
http://www.flickr.com/groups/iofotografoevideo

[-- Attachment #2: Type: text/html, Size: 4875 bytes --]

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

* Re: [Xenomai-help] the exception saga - system hangs
  2008-11-06 10:21 Gabriele Moabiti
@ 2008-11-06 13:16 ` Gilles Chanteperdrix
  2008-11-07 14:20   ` Gabriele Moabiti
  0 siblings, 1 reply; 4+ messages in thread
From: Gilles Chanteperdrix @ 2008-11-06 13:16 UTC (permalink / raw)
  To: Gabriele Moabiti; +Cc: Xenomai help

Gabriele Moabiti wrote:
>     __asm__ __volatile__("nop; movl %dr7, %eax;nop");

This piece of inline assembly is incorrect, you should mark as output
register the registers you clobber.

-- 
                                                 Gilles.


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

* Re: [Xenomai-help] the exception saga - system hangs
@ 2008-11-06 14:02 Gabriele Moabiti
  0 siblings, 0 replies; 4+ messages in thread
From: Gabriele Moabiti @ 2008-11-06 14:02 UTC (permalink / raw)
  To: Gilles Chanteperdrix; +Cc: Xenomai help

[-- Attachment #1: Type: text/plain, Size: 920 bytes --]


>>     __asm__ __volatile__("nop; movl %dr7, %eax;nop");
>
>This piece of inline assembly is incorrect, you should mark as output
>register the registers you clobber.

*ops* I'm not very skilled in Gnu asm
The user task asm istruction is used only to raise an exception (CPL=0 only),
but I can change the example:

insted of the that asm line i write 
__asm__ __volatile__(nop; clts;nop;);

and in the kernel module I change the check

- if (*istr == 0x210f && (*(istr+1) & 0xFF) == 0xf8) { // movl %dr7, %eax
-      regs->x86reg_ip+=3;
+if (*istr == 0x060f) { /* clts */
+    regs->x86reg_ip+=2;

the behaviour is always the same... after some loops system hang
(tested with turned on and off all debug options of xenomai)

 Gabriele


      Unisciti alla community di Io fotografo e video, il nuovo corso di fotografia di Gazzetta dello sport:
http://www.flickr.com/groups/iofotografoevideo

[-- Attachment #2: Type: text/html, Size: 1594 bytes --]

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

* Re: [Xenomai-help] the exception saga - system hangs
  2008-11-06 13:16 ` Gilles Chanteperdrix
@ 2008-11-07 14:20   ` Gabriele Moabiti
  0 siblings, 0 replies; 4+ messages in thread
From: Gabriele Moabiti @ 2008-11-07 14:20 UTC (permalink / raw)
  To: Gilles Chanteperdrix; +Cc: Xenomai help

[-- Attachment #1: Type: text/plain, Size: 315 bytes --]


Gilles, do you think the kernel code to catch and manage trap in the example is wrong?
The hang is strange due to erratic behaviour...

    Gabriele


      Unisciti alla community di Io fotografo e video, il nuovo corso di fotografia di Gazzetta dello sport:
http://www.flickr.com/groups/iofotografoevideo

[-- Attachment #2: Type: text/html, Size: 1351 bytes --]

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

end of thread, other threads:[~2008-11-07 14:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-06 14:02 [Xenomai-help] the exception saga - system hangs Gabriele Moabiti
  -- strict thread matches above, loose matches on Subject: below --
2008-11-06 10:21 Gabriele Moabiti
2008-11-06 13:16 ` Gilles Chanteperdrix
2008-11-07 14:20   ` Gabriele Moabiti

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.