All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: barbalace@domain.hid
Cc: xenomai-help <xenomai@xenomai.org>, adeos-main@gna.org
Subject: Re: [Xenomai-help] Re: [Adeos-main] [PATCH] ppc mvme5500
Date: Mon, 11 Dec 2006 19:10:33 +0100	[thread overview]
Message-ID: <457D9F19.3050807@domain.hid> (raw)
In-Reply-To: <1165859722.457d9b8a9b097@domain.hid>

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

barbalace@domain.hid wrote:
> Quoting Jan Kiszka <jan.kiszka@domain.hid>:
>> Antonio, please use a recent Xenomai version (e.g. 2.2.5) to avoid that
>> we may hunt old issues.
>  Ok, could be the right solution.

Your issue is independent of the version, still 2.2.5 contains a lot of
fixes.

> 
>> Next post a simple demo code to xenomai-help,
>> showing the misbehaviour. We could then check if other archs are
>> involved, if it's reproducible on further PPC boards, or if some mistake
>> might have slipped into the code.
>> From your description I wonder if you lock the mutex in line 2 from the
>> correct context (a Xenomai thread). If you call that lock from main,
>> don't forget to invoke rt_task_shadow first.
> 
> A simplified version of the code (in the original code there is an hw DAQ and I
> understand that the same code run 2-times, here one could use a buffer to write
> for example a u(->for unlocking) and a l(->for locking) ):
> 
> /* -- START CODE HERE ---------- demo.c --------------------------------------*/
> #include <linux/config.h>
> #include <linux/version.h>
> #include <linux/module.h>
> #include <linux/moduleparam.h>
> 
> #include <native/task.h>
> #include <native/intr.h>
> #include <native/mutex.h>
> #include <native/sem.h>
> 
> 
> #define TASK_PRIO 99
> #define TASK_MODE (T_FPU | T_CPU(0))
> #define TASK_STKSZ 4096
> 
> RT_INTR intr_desc;
> RT_TASK task_desc;
> RT_MUTEX mutex_desc;
> 
> int demo_finalize;
> 
> #define INTR_IRQ 76
> 
> static irqreturn_t demo_irqhandler(void)
> {
>         rt_mutex_unlock(&mutex_desc);                        // IPC handling

You cannot unlock a mutex from a non-task context like the IRQ handler
is. Actually, the return value of that call should be EPERM, indicating
the misuse.

> 
>         return RT_INTR_HANDLED;
> }
> 
> 
> 
> void rt_handler(void *data){
> 
>         printk(KERN_ERR"entered in RT task\n");                // ok I know is
> not right use printk

There is actually no problem (except growing log files), printk is safe
from RT context under Xenomai.

>         rt_mutex_lock(&mutex_desc, TM_INFINITE);
> 
>         for(;;){
>                 rt_mutex_lock(&mutex_desc, TM_INFINITE);
> 
>                 if(demo_finalize == 1)
>                         break;
>                 /* doing something */
>         }
> 
>         return;
> }
> 
> static int demo_init(void)
> {
>         int result;
>         // initialize MUTEX
>         int err;
>         err = rt_mutex_create(&mutex_desc, "demo_mutex");
>         printk(KERN_ERR"mutex created and locked\n");
> 
>         demo_finalize = 0;
> 
>         // create the real-time task waiting for data
>         err = rt_task_create(&task_desc, "demo_acq", TASK_STKSZ, TASK_PRIO,
> TASK_MODE);
>         if (!err) {
>                 rt_task_start(&task_desc, &rt_handler, NULL);
>                 printk(KERN_ERR"RT task started!\n");
>         } else
>                 printk(KERN_ERR"can't start RT thread!!!\n");
> 
>         result = rt_intr_create(&intr_desc, "demo_intr", INTR_IRQ,
> demo_irqhandler, 0,
> 0);
> 
>         return (0);
> }
> 
> static void demo_exit(void)
> {
>         rt_intr_delete(&intr_desc);
> 
>         demo_finalize = 1;
>         rt_mutex_unlock(&mutex_desc);
> 
> 
>         rt_task_delete(&task_desc);
>         printk(KERN_ERR"demo: RT task destroyed\n");
> 
>         return;
> }
> 
> module_init(demo_init);
> module_exit(demo_exit);
> 
> /* --- END CODE HERE ---------------------------------------------------------*/
> 
> With this code and Xenomai 2.2.0 you lose the machine control... I resolve this
> using semaphores.

Using a semaphore to wake the blocked RT task up is actually the Right
Thing. Why not a mutex? A locked mutex always has an owner, which is the
task that successfully acquired it. That owner is ought to release the
mutex again - NO ONE ELSE. And having an owner allows do thing like
inheriting the priority of a waiter to the current owner - or to analyse
who forgot to release it...

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

      reply	other threads:[~2006-12-11 18:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-08  0:28 [Adeos-main] [PATCH] ppc mvme5500 barbalace
2006-12-08 11:57 ` Wolfgang Grandegger
2006-12-08 16:35   ` barbalace
2006-12-08 20:38     ` Wolfgang Grandegger
     [not found]       ` <1165665886.457aa65e2c26e@domain.hid>
     [not found]         ` <457AAEB9.20403@domain.hid>
     [not found]           ` <1165834501.457d390514d36@domain.hid>
     [not found]             ` <457D57B4.3000802@domain.hid>
     [not found]               ` <1165843368.457d5ba8692bd@domain.hid>
2006-12-11 13:43                 ` [Xenomai-help] " Wolfgang Grandegger
2006-12-11 14:32                   ` Jan Kiszka
2006-12-11 17:55                     ` barbalace
2006-12-11 18:10                       ` Jan Kiszka [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=457D9F19.3050807@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=adeos-main@gna.org \
    --cc=barbalace@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.