All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai] delete a suspend rt_task xeno2<>xeno3
@ 2017-05-11 12:45 Hänel-Baas, Alexander
  0 siblings, 0 replies; 4+ messages in thread
From: Hänel-Baas, Alexander @ 2017-05-11 12:45 UTC (permalink / raw)
  To: Philippe Gerum (rpm@xenomai.org); +Cc: xenomai

Hi,

>What can I do to delete a suspend rt_task without the task will running in the loop, because the task descriptor was going invalid from delete() call?

I was looking into the xenomai source alchemy/task.c and copperplate/threadobj.c

When I call rt_task_delete() for an already  suspend rt_thread  the rt_thread was unlocked by: rt_task_delete() -> threadobj_cancel() ->cancel_sync()  -> request_cancel() ->threadobj_unlock().
So the rt_thread leaves rt_task_suspend() shows my printf() message (in my example) and entered rt_task_suspend() again.
But now in rt_task_suspend() the function find_alchemy_task_or_self() return NULL because the task descriptor is already deleted and we leaves the rt_task_suspend() function again. 
Shows my printf and entered rt_task_suspeng()...

And this loop demonstrate my short test example.
>Example
>rt_thread
>  for(;;){
>       rt_task_suspend(NULL);
>      printf("in loop\n");
>   }
>main:
>rt_task_spawn()
>. other stuff
>rt_task_delete()

My Solution:
In the rt_thread loop I call rt_task_self(). 
When I get NULL I know this thread was delete and I leave the rt_thread.

rt_thread
    for(;;){
        ret = rt_task_suspend(&rtTask);
        printf("--- %s in loop a: %d ret:%d -> %s\n",rt_task_info.name,a,ret,strerror(-ret));

        myrt = rt_task_self();
        if (myrt == NULL){
            goto exit;
        }
exit:
}

Any other solution for this?

Regards,
Alexander





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

* Re: [Xenomai] delete a suspend rt_task xeno2<>xeno3
  2017-05-09 12:52 ` Philippe Gerum
@ 2017-05-09 13:40   ` Hänel-Baas, Alexander
  0 siblings, 0 replies; 4+ messages in thread
From: Hänel-Baas, Alexander @ 2017-05-09 13:40 UTC (permalink / raw)
  To: Philippe Gerum; +Cc: xenomai

Hi Philippe,

Thank you for your prompt answer.

>Please provide a short and complete test code illustrating the issue, and what you want to achieve.
Yes gladly.
Example code:
---------------------------------------------
static void Alex_RT_Thread(void *)
{
    RT_TASK_INFO rt_task_info;
    struct timespec ts;
    volatile int a = 0;
    int ret;

    ts.tv_nsec=50000;
    ts.tv_sec=0;

    rt_task_inquire(NULL, &rt_task_info);
    printf("\n--- %s started\n",rt_task_info.name);

    for(;;){
        ret = rt_task_suspend(rt_task_self());
        printf("--- %s in loop a: %d ret:%d -> %s\n",rt_task_info.name,a,ret,strerror(-ret));

        nanosleep(&ts,NULL); //this is only a help to see what is going on. Normally we make mathematic calculation here.
        a++;
    }
}

int main(int argc, char * argv[])
{
  int ret;
  RT_TASK rtTask;

  printf("rt_task_spawn: Alex_rt\n");
  rt_task_spawn(&rtTask, "Alex_rt", 0, 40, 0 ,Alex_RT_Thread, NULL);

  printf("sleep \n");
  sleep(4);

  printf("rt_task_delete: Alex_rt\n");
  ret = rt_task_delete(&rtTask);
  printf("rt_task_delete: Alex_rt -> %s \n",  strerror(-ret));

  sleep(4);
  printf("main exit\n");
return 0;
}
-----------example code end ------------------------------------------------

Output from Xeno3:
###############################################
rt_task_spawn: Alex_rt

--- Alex_rt started
sleep
rt_task_delete: Alex_rt
--- Alex_rt in loop a: 0 ret:0 -> Success
--- Alex_rt in loop a: 1 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 2 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 3 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 4 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 5 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 6 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 7 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 8 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 9 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 10 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 11 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 12 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 13 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 14 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 15 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 16 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 17 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 18 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 19 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 20 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 21 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 22 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 23 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 24 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 25 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 26 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 27 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 28 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 29 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 30 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 31 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 32 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 33 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 34 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 35 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 36 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 37 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 38 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 39 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 40 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 41 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 42 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 43 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 44 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 45 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 46 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 47 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 48 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 49 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 50 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 51 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 52 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 53 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 54 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 55 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 56 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 57 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 58 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 59 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 60 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 61 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 62 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 63 ret:-1 -> Operation not permitted
--- Alex_rt in loop a: 64 ret:-1 -> Operation not permitted
rt_task_delete: Alex_rt -> Success
main exit

Output from Xeno2:
###############################################
rt_task_spawn: Alex_rt

--- Alex_rt started
sleep
rt_task_delete: Alex_rt
rt_task_delete: Alex_rt -> Success
main exit

So, you can see Xeno3 runs across the rt_task_suspend() function with an error.
Xeno2 delete the thread "friendly".

In the Xenomai 3 case my problem is that some rt_threads are high prior and will consume the
whole cpu time. And the application can't go down.

I hope you can identify my problem.

Greetings
Alexander

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

* Re: [Xenomai] delete a suspend rt_task xeno2<>xeno3
  2017-05-09 11:53 Hänel-Baas, Alexander
@ 2017-05-09 12:52 ` Philippe Gerum
  2017-05-09 13:40   ` Hänel-Baas, Alexander
  0 siblings, 1 reply; 4+ messages in thread
From: Philippe Gerum @ 2017-05-09 12:52 UTC (permalink / raw)
  To: Hänel-Baas, Alexander, xenomai

On 05/09/2017 01:53 PM, Hänel-Baas, Alexander wrote:
> Hi,
> i'm porting our application from Xeno2 (linux 3.14) to Xeno3(Linux 4.4).
> 
> Under Xeno3:
> When I delete a suspend task, the suspend task will begin to run.
> Under Xeno2 :
> The suspend task is deleted successfully, without that the suspend thread will begin to run.
>  
> Example
> rt_thread
>    for(;;){
>        rt_task_suspend(NULL);
>       printf("in loop\n");
>    }
> main:
> rt_task_spawn()
> . other stuff
> rt_task_delete()
> 
> So, in Xenomai 2 i have never seen the string "in loop" when we delete the task, but under Xenomai 3
> after the rt_task_delete() call, i get many "in loop" messages.
> 
> I notice the return value from rt_task_suspend is "operation not permitted", because i
> have delete successful the task descriptor with rt_task_delete(). 
> Right?
> Or is there a mistake in my Xenomai installation?
> 
> When this point is different to xenomai2 comes here my problem:
> This was only a test example. 
> In the real application the rt_task_suspend() call came from another task, and not directly from rt_thread loop self.
> And so rt_task_suspend() is called at the right time, return "successfully" and the rt_thrad stops fine. 
> Now, when we  want shut down the application we calling rt_task_delete(), and then the rt_thread begins to run
> and we can't delete it. 
> 
> What can I do to delete a suspend rt_task without the task will running in the loop, because the task descriptor was going invalid from delete() call?
> 
> 

Please provide a short and complete test code illustrating the issue,
and what you want to achieve.

-- 
Philippe.


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

* [Xenomai] delete a suspend rt_task xeno2<>xeno3
@ 2017-05-09 11:53 Hänel-Baas, Alexander
  2017-05-09 12:52 ` Philippe Gerum
  0 siblings, 1 reply; 4+ messages in thread
From: Hänel-Baas, Alexander @ 2017-05-09 11:53 UTC (permalink / raw)
  To: xenomai

Hi,
i'm porting our application from Xeno2 (linux 3.14) to Xeno3(Linux 4.4).

Under Xeno3:
When I delete a suspend task, the suspend task will begin to run.
Under Xeno2 :
The suspend task is deleted successfully, without that the suspend thread will begin to run.
 
Example
rt_thread
   for(;;){
       rt_task_suspend(NULL);
      printf("in loop\n");
   }
main:
rt_task_spawn()
. other stuff
rt_task_delete()

So, in Xenomai 2 i have never seen the string "in loop" when we delete the task, but under Xenomai 3
after the rt_task_delete() call, i get many "in loop" messages.

I notice the return value from rt_task_suspend is "operation not permitted", because i
have delete successful the task descriptor with rt_task_delete(). 
Right?
Or is there a mistake in my Xenomai installation?

When this point is different to xenomai2 comes here my problem:
This was only a test example. 
In the real application the rt_task_suspend() call came from another task, and not directly from rt_thread loop self.
And so rt_task_suspend() is called at the right time, return "successfully" and the rt_thrad stops fine. 
Now, when we  want shut down the application we calling rt_task_delete(), and then the rt_thread begins to run
and we can't delete it. 

What can I do to delete a suspend rt_task without the task will running in the loop, because the task descriptor was going invalid from delete() call?


With best regards,
Alexander 




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

end of thread, other threads:[~2017-05-11 12:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-11 12:45 [Xenomai] delete a suspend rt_task xeno2<>xeno3 Hänel-Baas, Alexander
  -- strict thread matches above, loose matches on Subject: below --
2017-05-09 11:53 Hänel-Baas, Alexander
2017-05-09 12:52 ` Philippe Gerum
2017-05-09 13:40   ` Hänel-Baas, Alexander

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.