All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] rt_task_bind() and timeout values
@ 2008-07-14 17:22 Stefan Kisdaroczi
  2008-07-14 17:50 ` Philippe Gerum
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Kisdaroczi @ 2008-07-14 17:22 UTC (permalink / raw)
  To: xenomai


[-- Attachment #1.1: Type: text/plain, Size: 768 bytes --]

Hi all,

If I call rt_task_bind() with a timeout value other than TM_NONBLOCK or TM_INFINITE
it works not as expected (by me).

System: Debian Lenny with Xenomai 2.4.3 and Kernel 2.6.24.

The attached example calls 3 times rt_task_bind() for a nonexistent task:

1. dont wait: rt_task_bind(&task,"SomeTaskName",TM_NONBLOCK)
   -> returns -11 (EWOULDBLOCK) -> OK

2. wait 5 secs: rt_task_bind(&task,"SomeTaskName",5000000000LL);
   -> returns immediately -13 (EACCES) without waiting -> ?
   -> I expected ETIMEDOUT after 5 seconds

3. wait forever: rt_task_bind(&task,"SomeTaskName",TM_INFINITE);
   -> blocks a expected -> OK

I have the same problem with rt_queue_bind() calls.

Do i expect something wrong?

Thanks for your help!

kisda


[-- Attachment #1.2: bind_task.c --]
[-- Type: text/plain, Size: 780 bytes --]

#include <sys/mman.h>
#include <native/task.h>

RT_TASK mtask,task;

int main (int argc, char *argv[])

{
    int err;

    mlockall(MCL_CURRENT|MCL_FUTURE);

    err = rt_task_shadow(&mtask, NULL, 10, 0);

    if (err)
        fprintf(stderr,"rt_task_shadow failed, code %d\n",err);

    // 1. dont wait
    err = rt_task_bind(&task,"SomeTaskName",TM_NONBLOCK);

    if (err)
        fprintf(stderr,"bind (1) failed, code %d\n",err);

    // 2. wait 5 secs
    err = rt_task_bind(&task,"SomeTaskName",5000000000LL);

    if (err)
        fprintf(stderr,"bind (2) failed, code %d\n",err);

    // 3. wait forever
    err = rt_task_bind(&task,"SomeTaskName",TM_INFINITE);

    if (err)
        fprintf(stderr,"bind (3) failed, code %d\n",err);
}

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

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

* Re: [Xenomai-help] rt_task_bind() and timeout values
  2008-07-14 17:22 [Xenomai-help] rt_task_bind() and timeout values Stefan Kisdaroczi
@ 2008-07-14 17:50 ` Philippe Gerum
  2008-07-14 19:03   ` Stefan Kisdaroczi
  0 siblings, 1 reply; 11+ messages in thread
From: Philippe Gerum @ 2008-07-14 17:50 UTC (permalink / raw)
  To: Stefan Kisdaroczi; +Cc: xenomai

Stefan Kisdaroczi wrote:
> Hi all,
> 
> If I call rt_task_bind() with a timeout value other than TM_NONBLOCK or
> TM_INFINITE
> it works not as expected (by me).
> 
> System: Debian Lenny with Xenomai 2.4.3 and Kernel 2.6.24.
> 
> The attached example calls 3 times rt_task_bind() for a nonexistent task:
> 
> 1. dont wait: rt_task_bind(&task,"SomeTaskName",TM_NONBLOCK)
>   -> returns -11 (EWOULDBLOCK) -> OK
> 
> 2. wait 5 secs: rt_task_bind(&task,"SomeTaskName",5000000000LL);
>   -> returns immediately -13 (EACCES) without waiting -> ?
>   -> I expected ETIMEDOUT after 5 seconds
> 

"SomeTaskName" was found in the registry, but suddenly disappeared while in the
process of returning its handle (we do post-validation after binding). That task
has probably exited prematurely.

> 3. wait forever: rt_task_bind(&task,"SomeTaskName",TM_INFINITE);
>   -> blocks a expected -> OK
> 
> I have the same problem with rt_queue_bind() calls.
> 
> Do i expect something wrong?
> 
> Thanks for your help!
> 
> kisda
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help


-- 
Philippe.


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

* Re: [Xenomai-help] rt_task_bind() and timeout values
  2008-07-14 17:50 ` Philippe Gerum
@ 2008-07-14 19:03   ` Stefan Kisdaroczi
  2008-07-14 20:35     ` Philippe Gerum
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Kisdaroczi @ 2008-07-14 19:03 UTC (permalink / raw)
  To: rpm; +Cc: xenomai

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

Hi Philippe,

Philippe Gerum schrieb:
> Stefan Kisdaroczi wrote:
>> Hi all,
>>
>> If I call rt_task_bind() with a timeout value other than TM_NONBLOCK or
>> TM_INFINITE
>> it works not as expected (by me).
>>
>> System: Debian Lenny with Xenomai 2.4.3 and Kernel 2.6.24.
>>
>> The attached example calls 3 times rt_task_bind() for a nonexistent task:
>>
>> 1. dont wait: rt_task_bind(&task,"SomeTaskName",TM_NONBLOCK)
>>   -> returns -11 (EWOULDBLOCK) -> OK
>>
>> 2. wait 5 secs: rt_task_bind(&task,"SomeTaskName",5000000000LL);
>>   -> returns immediately -13 (EACCES) without waiting -> ?
>>   -> I expected ETIMEDOUT after 5 seconds
>>
> 
> "SomeTaskName" was found in the registry, but suddenly disappeared while in the
> process of returning its handle (we do post-validation after binding). That task
> has probably exited prematurely.

There was and is no task with this name. This happens on a freshly rebooted box
with any name i choose. Can someone please try my small example from the first
mail on his box. Thank you.

>> 3. wait forever: rt_task_bind(&task,"SomeTaskName",TM_INFINITE);
>>   -> blocks a expected -> OK
>>
>> I have the same problem with rt_queue_bind() calls.
>>
>> Do i expect something wrong?
>>
>> Thanks for your help!
>>
>> kisda
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Xenomai-help mailing list
>> Xenomai-help@domain.hid
>> https://mail.gna.org/listinfo/xenomai-help
> 
> 



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

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

* Re: [Xenomai-help] rt_task_bind() and timeout values
  2008-07-14 19:03   ` Stefan Kisdaroczi
@ 2008-07-14 20:35     ` Philippe Gerum
  2008-07-15  0:38       ` Stefan Kisdaroczi
  0 siblings, 1 reply; 11+ messages in thread
From: Philippe Gerum @ 2008-07-14 20:35 UTC (permalink / raw)
  To: Stefan Kisdaroczi; +Cc: xenomai

Stefan Kisdaroczi wrote:
> Hi Philippe,
> 
> Philippe Gerum schrieb:
>> Stefan Kisdaroczi wrote:
>>> Hi all,
>>>
>>> If I call rt_task_bind() with a timeout value other than TM_NONBLOCK or
>>> TM_INFINITE
>>> it works not as expected (by me).
>>>
>>> System: Debian Lenny with Xenomai 2.4.3 and Kernel 2.6.24.
>>>
>>> The attached example calls 3 times rt_task_bind() for a nonexistent
>>> task:
>>>
>>> 1. dont wait: rt_task_bind(&task,"SomeTaskName",TM_NONBLOCK)
>>>   -> returns -11 (EWOULDBLOCK) -> OK
>>>
>>> 2. wait 5 secs: rt_task_bind(&task,"SomeTaskName",5000000000LL);
>>>   -> returns immediately -13 (EACCES) without waiting -> ?
>>>   -> I expected ETIMEDOUT after 5 seconds
>>>
>>
>> "SomeTaskName" was found in the registry, but suddenly disappeared
>> while in the
>> process of returning its handle (we do post-validation after binding).
>> That task
>> has probably exited prematurely.
> 
> There was and is no task with this name. This happens on a freshly
> rebooted box
> with any name i choose. Can someone please try my small example from the
> first
> mail on his box. Thank you.
>

Can't test right now, unfortunately, and I'll be travelling tomorrow.

I suspect some weird issue with xnregistry_bind(). Please make sure to disable
CONFIG_XENO_OPT_NATIVE_REGISTRY, and apply this trivial trace point. The only
reason to get EACCES would be to receive a success code from xnregistry_bind(),
which we should not. I'd be interested to know the result codes for each call
your snippet does. TIA,

--- ksrc/nucleus/registry.c	(revision 4044)
+++ ksrc/nucleus/registry.c	(working copy)
@@ -776,6 +776,8 @@

 	xnlock_put_irqrestore(&nklock, s);

+	printk(KERN_INFO "%s: ret=%d\n", __FUNCTION__, err);
+
 	return err;
 }


>>> 3. wait forever: rt_task_bind(&task,"SomeTaskName",TM_INFINITE);
>>>   -> blocks a expected -> OK
>>>
>>> I have the same problem with rt_queue_bind() calls.
>>>
>>> Do i expect something wrong?
>>>
>>> Thanks for your help!
>>>
>>> kisda
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> Xenomai-help mailing list
>>> Xenomai-help@domain.hid
>>> https://mail.gna.org/listinfo/xenomai-help
>>
>>
> 
> 


-- 
Philippe.


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

* Re: [Xenomai-help] rt_task_bind() and timeout values
  2008-07-14 20:35     ` Philippe Gerum
@ 2008-07-15  0:38       ` Stefan Kisdaroczi
  2008-07-15  6:25         ` Philippe Gerum
  2008-07-15 14:28         ` Stefan Kisdaroczi
  0 siblings, 2 replies; 11+ messages in thread
From: Stefan Kisdaroczi @ 2008-07-15  0:38 UTC (permalink / raw)
  To: rpm; +Cc: xenomai


[-- Attachment #1.1: Type: text/plain, Size: 2631 bytes --]

Hi Philippe,

the attached patch fixed the problem for me.
However, i think that in the "break case" still EACCES is returned.
Can the break be replaced with a "return ETIMEDOUT" ?

kisda

Philippe Gerum schrieb:
> Stefan Kisdaroczi wrote:
>> Hi Philippe,
>>
>> Philippe Gerum schrieb:
>>> Stefan Kisdaroczi wrote:
>>>> Hi all,
>>>>
>>>> If I call rt_task_bind() with a timeout value other than TM_NONBLOCK or
>>>> TM_INFINITE
>>>> it works not as expected (by me).
>>>>
>>>> System: Debian Lenny with Xenomai 2.4.3 and Kernel 2.6.24.
>>>>
>>>> The attached example calls 3 times rt_task_bind() for a nonexistent
>>>> task:
>>>>
>>>> 1. dont wait: rt_task_bind(&task,"SomeTaskName",TM_NONBLOCK)
>>>>   -> returns -11 (EWOULDBLOCK) -> OK
>>>>
>>>> 2. wait 5 secs: rt_task_bind(&task,"SomeTaskName",5000000000LL);
>>>>   -> returns immediately -13 (EACCES) without waiting -> ?
>>>>   -> I expected ETIMEDOUT after 5 seconds
>>>>
>>> "SomeTaskName" was found in the registry, but suddenly disappeared
>>> while in the
>>> process of returning its handle (we do post-validation after binding).
>>> That task
>>> has probably exited prematurely.
>> There was and is no task with this name. This happens on a freshly
>> rebooted box
>> with any name i choose. Can someone please try my small example from the
>> first
>> mail on his box. Thank you.
>>
> 
> Can't test right now, unfortunately, and I'll be travelling tomorrow.
> 
> I suspect some weird issue with xnregistry_bind(). Please make sure to disable
> CONFIG_XENO_OPT_NATIVE_REGISTRY, and apply this trivial trace point. The only
> reason to get EACCES would be to receive a success code from xnregistry_bind(),
> which we should not. I'd be interested to know the result codes for each call
> your snippet does. TIA,
> 
> --- ksrc/nucleus/registry.c	(revision 4044)
> +++ ksrc/nucleus/registry.c	(working copy)
> @@ -776,6 +776,8 @@
> 
>  	xnlock_put_irqrestore(&nklock, s);
> 
> +	printk(KERN_INFO "%s: ret=%d\n", __FUNCTION__, err);
> +
>  	return err;
>  }
> 
> 
>>>> 3. wait forever: rt_task_bind(&task,"SomeTaskName",TM_INFINITE);
>>>>   -> blocks a expected -> OK
>>>>
>>>> I have the same problem with rt_queue_bind() calls.
>>>>
>>>> Do i expect something wrong?
>>>>
>>>> Thanks for your help!
>>>>
>>>> kisda
>>>>
>>>>
>>>> ------------------------------------------------------------------------
>>>>
>>>> _______________________________________________
>>>> Xenomai-help mailing list
>>>> Xenomai-help@domain.hid
>>>> https://mail.gna.org/listinfo/xenomai-help
>>>
>>
> 
> 


[-- Attachment #1.2: xenomai-bind-timeout.patch --]
[-- Type: text/plain, Size: 398 bytes --]

--- xenomai/nucleus/registry.c.old	2008-07-15 00:36:10.000000000 +0200
+++ xenomai/nucleus/registry.c	2008-07-15 01:51:13.000000000 +0200
@@ -733,7 +733,7 @@ int xnregistry_bind(const char *key, xnt
 		if (timeout != XN_INFINITE) {
 			xnticks_t now = xntbase_get_time(tbase);
 
-			if (stime + timeout >= now)
+			if (stime + timeout <= now)
 				break;
 
 			timeout -= (now - stime);

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

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

* Re: [Xenomai-help] rt_task_bind() and timeout values
  2008-07-15  0:38       ` Stefan Kisdaroczi
@ 2008-07-15  6:25         ` Philippe Gerum
  2008-07-16 10:25           ` Stefan Kisdaroczi
  2008-07-15 14:28         ` Stefan Kisdaroczi
  1 sibling, 1 reply; 11+ messages in thread
From: Philippe Gerum @ 2008-07-15  6:25 UTC (permalink / raw)
  To: Stefan Kisdaroczi; +Cc: xenomai

Stefan Kisdaroczi wrote:
> Hi Philippe,
> 
> the attached patch fixed the problem for me.

Good spot. Now it's official, since four years that feature exists or so, nobody
actually used registry timeouts... Oh, well...

> However, i think that in the "break case" still EACCES is returned.
> Can the break be replaced with a "return ETIMEDOUT" ?
>

Yes, normally we should do that along with your patch. Actually, the most
appropriate fix would be to use an absolute timeout value internally, since the
nucleus allows it.

--- ksrc/nucleus/registry.c	(revision 4044)
+++ ksrc/nucleus/registry.c	(working copy)
@@ -711,7 +711,6 @@
 	xnobject_t *object;
 	xnthread_t *thread;
 	xntbase_t *tbase;
-	xnticks_t stime;
 	int err = 0;
 	spl_t s;

@@ -723,7 +722,8 @@

 	xnlock_get_irqsave(&nklock, s);

-	stime = xntbase_get_time(tbase);
+	if (timeout != TM_NONBLOCK && timeout != TM_INFINITE)
+		timeout += xntbase_get_time(tbase);

 	for (;;) {
 		object = registry_hash_find(key);
@@ -738,18 +738,8 @@
 			goto unlock_and_exit;
 		}

-		if (timeout != XN_INFINITE) {
-			xnticks_t now = xntbase_get_time(tbase);
-
-			if (stime + timeout >= now)
-				break;
-
-			timeout -= (now - stime);
-			stime = now;
-		}
-
 		thread->registry.waitkey = key;
-		xnsynch_sleep_on(&registry_hash_synch, timeout, XN_RELATIVE);
+		xnsynch_sleep_on(&registry_hash_synch, timeout, XN_ABSOLUTE);

 		if (xnthread_test_info(thread, XNTIMEO)) {
 			err = -ETIMEDOUT;
 --
Philippe.



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

* Re: [Xenomai-help] rt_task_bind() and timeout values
  2008-07-15  0:38       ` Stefan Kisdaroczi
  2008-07-15  6:25         ` Philippe Gerum
@ 2008-07-15 14:28         ` Stefan Kisdaroczi
  1 sibling, 0 replies; 11+ messages in thread
From: Stefan Kisdaroczi @ 2008-07-15 14:28 UTC (permalink / raw)
  To: rpm; +Cc: xenomai


[-- Attachment #1.1: Type: text/plain, Size: 518 bytes --]

Hi,

Stefan Kisdaroczi schrieb:
> Hi Philippe,
> 
> the attached patch fixed the problem for me.
> However, i think that in the "break case" still EACCES is returned.
> Can the break be replaced with a "return ETIMEDOUT" ?
> [...]

I have tried it. A new patch is attached. I tested it first without changing
the ">=" to "<=", and the call returned immediately as expected but now with
ETIMEDOUT instead of EACCESS. After changing the ">=" to "<=" it seems to
work like it should.

best regards
kisda

[-- Attachment #1.2: xnregistry_bind_timeout.patch --]
[-- Type: text/plain, Size: 465 bytes --]

--- xenomai/nucleus/registry.c.old	2008-07-15 00:36:10.000000000 +0200
+++ xenomai/nucleus/registry.c	2008-07-15 15:28:23.000000000 +0200
@@ -733,8 +733,10 @@ int xnregistry_bind(const char *key, xnt
 		if (timeout != XN_INFINITE) {
 			xnticks_t now = xntbase_get_time(tbase);
 
-			if (stime + timeout >= now)
-				break;
+			if (stime + timeout <= now) {
+				err = -ETIMEDOUT;
+				goto unlock_and_exit;
+			}		
 
 			timeout -= (now - stime);
 			stime = now;

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

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

* Re: [Xenomai-help] rt_task_bind() and timeout values
  2008-07-15  6:25         ` Philippe Gerum
@ 2008-07-16 10:25           ` Stefan Kisdaroczi
  2008-07-16 21:17             ` Philippe Gerum
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Kisdaroczi @ 2008-07-16 10:25 UTC (permalink / raw)
  To: rpm; +Cc: xenomai

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

Hi,

your patch didnt work. The bind_calls are now blocking infinite (at least much too long, still waiting...)
To compile i had to change following line in your patch:
-	if (timeout != TM_NONBLOCK && timeout != TM_INFINITE)
+	if (timeout != XN_NONBLOCK && timeout != XN_INFINITE)

I will use following patch for the moment, this works.

--- xenomai/nucleus/registry.c.old	2008-07-15 00:36:10.000000000 +0200
+++ xenomai/nucleus/registry.c	2008-07-15 15:28:23.000000000 +0200
@@ -733,8 +733,10 @@ int xnregistry_bind(const char *key, xnt
  		if (timeout != XN_INFINITE) {
  			xnticks_t now = xntbase_get_time(tbase);

-			if (stime + timeout >= now)
-				break;
+			if (stime + timeout <= now) {
+				err = -ETIMEDOUT;
+				goto unlock_and_exit;
+			}		

  			timeout -= (now - stime);
  			stime = now;


Philippe Gerum schrieb:
> Stefan Kisdaroczi wrote:
>> Hi Philippe,
>>
>> the attached patch fixed the problem for me.
> 
> Good spot. Now it's official, since four years that feature exists or so, nobody
> actually used registry timeouts... Oh, well...
> 
>> However, i think that in the "break case" still EACCES is returned.
>> Can the break be replaced with a "return ETIMEDOUT" ?
>>
> 
> Yes, normally we should do that along with your patch. Actually, the most
> appropriate fix would be to use an absolute timeout value internally, since the
> nucleus allows it.
> 
> --- ksrc/nucleus/registry.c	(revision 4044)
> +++ ksrc/nucleus/registry.c	(working copy)
> @@ -711,7 +711,6 @@
>  	xnobject_t *object;
>  	xnthread_t *thread;
>  	xntbase_t *tbase;
> -	xnticks_t stime;
>  	int err = 0;
>  	spl_t s;
> 
> @@ -723,7 +722,8 @@
> 
>  	xnlock_get_irqsave(&nklock, s);
> 
> -	stime = xntbase_get_time(tbase);
> +	if (timeout != TM_NONBLOCK && timeout != TM_INFINITE)
> +		timeout += xntbase_get_time(tbase);
> 
>  	for (;;) {
>  		object = registry_hash_find(key);
> @@ -738,18 +738,8 @@
>  			goto unlock_and_exit;
>  		}
> 
> -		if (timeout != XN_INFINITE) {
> -			xnticks_t now = xntbase_get_time(tbase);
> -
> -			if (stime + timeout >= now)
> -				break;
> -
> -			timeout -= (now - stime);
> -			stime = now;
> -		}
> -
>  		thread->registry.waitkey = key;
> -		xnsynch_sleep_on(&registry_hash_synch, timeout, XN_RELATIVE);
> +		xnsynch_sleep_on(&registry_hash_synch, timeout, XN_ABSOLUTE);
> 
>  		if (xnthread_test_info(thread, XNTIMEO)) {
>  			err = -ETIMEDOUT;
>  --
> Philippe.
> 
> 



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

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

* Re: [Xenomai-help] rt_task_bind() and timeout values
  2008-07-16 10:25           ` Stefan Kisdaroczi
@ 2008-07-16 21:17             ` Philippe Gerum
  2008-07-17 11:01               ` Stefan Kisdaroczi
  0 siblings, 1 reply; 11+ messages in thread
From: Philippe Gerum @ 2008-07-16 21:17 UTC (permalink / raw)
  To: Stefan Kisdaroczi; +Cc: xenomai

Stefan Kisdaroczi wrote:
> Hi,
> 
> your patch didnt work. The bind_calls are now blocking infinite (at
> least much too long, still waiting...)
> To compile i had to change following line in your patch:
> -    if (timeout != TM_NONBLOCK && timeout != TM_INFINITE)
> +    if (timeout != XN_NONBLOCK && timeout != XN_INFINITE)
>

Ok, fair enough. This one has been tested. No kidding.

--- ksrc/nucleus/registry.c	(revision 4050)
+++ ksrc/nucleus/registry.c	(revision 4051)
@@ -711,7 +711,6 @@
 	xnobject_t *object;
 	xnthread_t *thread;
 	xntbase_t *tbase;
-	xnticks_t stime;
 	int err = 0;
 	spl_t s;

@@ -723,7 +722,8 @@

 	xnlock_get_irqsave(&nklock, s);

-	stime = xntbase_get_time(tbase);
+	if (timeout != XN_INFINITE && timeout != XN_NONBLOCK)
+		timeout += xntbase_get_time(tbase);

 	for (;;) {
 		object = registry_hash_find(key);
@@ -738,18 +738,8 @@
 			goto unlock_and_exit;
 		}

-		if (timeout != XN_INFINITE) {
-			xnticks_t now = xntbase_get_time(tbase);
-
-			if (stime + timeout >= now)
-				break;
-
-			timeout -= (now - stime);
-			stime = now;
-		}
-
 		thread->registry.waitkey = key;
-		xnsynch_sleep_on(&registry_hash_synch, timeout, XN_RELATIVE);
+		xnsynch_sleep_on(&registry_hash_synch, timeout, XN_REALTIME);

 		if (xnthread_test_info(thread, XNTIMEO)) {
 			err = -ETIMEDOUT;

> I will use following patch for the moment, this works.
> 
> --- xenomai/nucleus/registry.c.old    2008-07-15 00:36:10.000000000 +0200
> +++ xenomai/nucleus/registry.c    2008-07-15 15:28:23.000000000 +0200
> @@ -733,8 +733,10 @@ int xnregistry_bind(const char *key, xnt
>          if (timeout != XN_INFINITE) {
>              xnticks_t now = xntbase_get_time(tbase);
> 
> -            if (stime + timeout >= now)
> -                break;
> +            if (stime + timeout <= now) {
> +                err = -ETIMEDOUT;
> +                goto unlock_and_exit;
> +            }       
> 
>              timeout -= (now - stime);
>              stime = now;
> 
> 
> Philippe Gerum schrieb:
>> Stefan Kisdaroczi wrote:
>>> Hi Philippe,
>>>
>>> the attached patch fixed the problem for me.
>>
>> Good spot. Now it's official, since four years that feature exists or
>> so, nobody
>> actually used registry timeouts... Oh, well...
>>
>>> However, i think that in the "break case" still EACCES is returned.
>>> Can the break be replaced with a "return ETIMEDOUT" ?
>>>
>>
>> Yes, normally we should do that along with your patch. Actually, the most
>> appropriate fix would be to use an absolute timeout value internally,
>> since the
>> nucleus allows it.
>>
>> --- ksrc/nucleus/registry.c    (revision 4044)
>> +++ ksrc/nucleus/registry.c    (working copy)
>> @@ -711,7 +711,6 @@
>>      xnobject_t *object;
>>      xnthread_t *thread;
>>      xntbase_t *tbase;
>> -    xnticks_t stime;
>>      int err = 0;
>>      spl_t s;
>>
>> @@ -723,7 +722,8 @@
>>
>>      xnlock_get_irqsave(&nklock, s);
>>
>> -    stime = xntbase_get_time(tbase);
>> +    if (timeout != TM_NONBLOCK && timeout != TM_INFINITE)
>> +        timeout += xntbase_get_time(tbase);
>>
>>      for (;;) {
>>          object = registry_hash_find(key);
>> @@ -738,18 +738,8 @@
>>              goto unlock_and_exit;
>>          }
>>
>> -        if (timeout != XN_INFINITE) {
>> -            xnticks_t now = xntbase_get_time(tbase);
>> -
>> -            if (stime + timeout >= now)
>> -                break;
>> -
>> -            timeout -= (now - stime);
>> -            stime = now;
>> -        }
>> -
>>          thread->registry.waitkey = key;
>> -        xnsynch_sleep_on(&registry_hash_synch, timeout, XN_RELATIVE);
>> +        xnsynch_sleep_on(&registry_hash_synch, timeout, XN_ABSOLUTE);
>>
>>          if (xnthread_test_info(thread, XNTIMEO)) {
>>              err = -ETIMEDOUT;
>>  --
>> Philippe.
>>
>>
> 
> 


-- 
Philippe.


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

* Re: [Xenomai-help] rt_task_bind() and timeout values
  2008-07-16 21:17             ` Philippe Gerum
@ 2008-07-17 11:01               ` Stefan Kisdaroczi
  2008-07-17 21:58                 ` Philippe Gerum
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Kisdaroczi @ 2008-07-17 11:01 UTC (permalink / raw)
  To: rpm; +Cc: xenomai

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

your new patch works with TM_NONBLOCK und user timeouts,
but bind now fails for TM_INFINITE: it returns immediately with ETIMEDOUT...

Philippe Gerum schrieb:
> Stefan Kisdaroczi wrote:
>> Hi,
>>
>> your patch didnt work. The bind_calls are now blocking infinite (at
>> least much too long, still waiting...)
>> To compile i had to change following line in your patch:
>> -    if (timeout != TM_NONBLOCK && timeout != TM_INFINITE)
>> +    if (timeout != XN_NONBLOCK && timeout != XN_INFINITE)
>>
> 
> Ok, fair enough. This one has been tested. No kidding.
> 
> --- ksrc/nucleus/registry.c	(revision 4050)
> +++ ksrc/nucleus/registry.c	(revision 4051)
> @@ -711,7 +711,6 @@
>  	xnobject_t *object;
>  	xnthread_t *thread;
>  	xntbase_t *tbase;
> -	xnticks_t stime;
>  	int err = 0;
>  	spl_t s;
> 
> @@ -723,7 +722,8 @@
> 
>  	xnlock_get_irqsave(&nklock, s);
> 
> -	stime = xntbase_get_time(tbase);
> +	if (timeout != XN_INFINITE && timeout != XN_NONBLOCK)
> +		timeout += xntbase_get_time(tbase);
> 
>  	for (;;) {
>  		object = registry_hash_find(key);
> @@ -738,18 +738,8 @@
>  			goto unlock_and_exit;
>  		}
> 
> -		if (timeout != XN_INFINITE) {
> -			xnticks_t now = xntbase_get_time(tbase);
> -
> -			if (stime + timeout >= now)
> -				break;
> -
> -			timeout -= (now - stime);
> -			stime = now;
> -		}
> -
>  		thread->registry.waitkey = key;
> -		xnsynch_sleep_on(&registry_hash_synch, timeout, XN_RELATIVE);
> +		xnsynch_sleep_on(&registry_hash_synch, timeout, XN_REALTIME);
> 
>  		if (xnthread_test_info(thread, XNTIMEO)) {
>  			err = -ETIMEDOUT;
> 
>> I will use following patch for the moment, this works.
>>
>> --- xenomai/nucleus/registry.c.old    2008-07-15 00:36:10.000000000 +0200
>> +++ xenomai/nucleus/registry.c    2008-07-15 15:28:23.000000000 +0200
>> @@ -733,8 +733,10 @@ int xnregistry_bind(const char *key, xnt
>>          if (timeout != XN_INFINITE) {
>>              xnticks_t now = xntbase_get_time(tbase);
>>
>> -            if (stime + timeout >= now)
>> -                break;
>> +            if (stime + timeout <= now) {
>> +                err = -ETIMEDOUT;
>> +                goto unlock_and_exit;
>> +            }       
>>
>>              timeout -= (now - stime);
>>              stime = now;
>>
>>
>> Philippe Gerum schrieb:
>>> Stefan Kisdaroczi wrote:
>>>> Hi Philippe,
>>>>
>>>> the attached patch fixed the problem for me.
>>> Good spot. Now it's official, since four years that feature exists or
>>> so, nobody
>>> actually used registry timeouts... Oh, well...
>>>
>>>> However, i think that in the "break case" still EACCES is returned.
>>>> Can the break be replaced with a "return ETIMEDOUT" ?
>>>>
>>> Yes, normally we should do that along with your patch. Actually, the most
>>> appropriate fix would be to use an absolute timeout value internally,
>>> since the
>>> nucleus allows it.
>>>
>>> --- ksrc/nucleus/registry.c    (revision 4044)
>>> +++ ksrc/nucleus/registry.c    (working copy)
>>> @@ -711,7 +711,6 @@
>>>      xnobject_t *object;
>>>      xnthread_t *thread;
>>>      xntbase_t *tbase;
>>> -    xnticks_t stime;
>>>      int err = 0;
>>>      spl_t s;
>>>
>>> @@ -723,7 +722,8 @@
>>>
>>>      xnlock_get_irqsave(&nklock, s);
>>>
>>> -    stime = xntbase_get_time(tbase);
>>> +    if (timeout != TM_NONBLOCK && timeout != TM_INFINITE)
>>> +        timeout += xntbase_get_time(tbase);
>>>
>>>      for (;;) {
>>>          object = registry_hash_find(key);
>>> @@ -738,18 +738,8 @@
>>>              goto unlock_and_exit;
>>>          }
>>>
>>> -        if (timeout != XN_INFINITE) {
>>> -            xnticks_t now = xntbase_get_time(tbase);
>>> -
>>> -            if (stime + timeout >= now)
>>> -                break;
>>> -
>>> -            timeout -= (now - stime);
>>> -            stime = now;
>>> -        }
>>> -
>>>          thread->registry.waitkey = key;
>>> -        xnsynch_sleep_on(&registry_hash_synch, timeout, XN_RELATIVE);
>>> +        xnsynch_sleep_on(&registry_hash_synch, timeout, XN_ABSOLUTE);
>>>
>>>          if (xnthread_test_info(thread, XNTIMEO)) {
>>>              err = -ETIMEDOUT;
>>>  --
>>> Philippe.
>>>
>>>
>>
> 
> 



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

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

* Re: [Xenomai-help] rt_task_bind() and timeout values
  2008-07-17 11:01               ` Stefan Kisdaroczi
@ 2008-07-17 21:58                 ` Philippe Gerum
  0 siblings, 0 replies; 11+ messages in thread
From: Philippe Gerum @ 2008-07-17 21:58 UTC (permalink / raw)
  To: Stefan Kisdaroczi; +Cc: xenomai

Stefan Kisdaroczi wrote:
> your new patch works with TM_NONBLOCK und user timeouts,
> but bind now fails for TM_INFINITE: it returns immediately with
> ETIMEDOUT...
>

Yeah, I should not be working at night. The nucleus does not like the idea of an
infinite timeout value in absolute mode. I need to think a bit about the
consequences of allowing this at core level, so we would not have to expect the
same issue with any interface converting relative timeouts to absolute ones.

The work around for the registry issue is this one, but I don't like it actually:

-        xnsynch_sleep_on(&registry_hash_synch, timeout, XN_REALTIME);
+        xnsynch_sleep_on(&registry_hash_synch, timeout, timeout == XN_INFINITE
? XN_RELATIVE : XN_REALTIME);

More later.

> Philippe Gerum schrieb:
>> Stefan Kisdaroczi wrote:
>>> Hi,
>>>
>>> your patch didnt work. The bind_calls are now blocking infinite (at
>>> least much too long, still waiting...)
>>> To compile i had to change following line in your patch:
>>> -    if (timeout != TM_NONBLOCK && timeout != TM_INFINITE)
>>> +    if (timeout != XN_NONBLOCK && timeout != XN_INFINITE)
>>>
>>
>> Ok, fair enough. This one has been tested. No kidding.
>>
>> --- ksrc/nucleus/registry.c    (revision 4050)
>> +++ ksrc/nucleus/registry.c    (revision 4051)
>> @@ -711,7 +711,6 @@
>>      xnobject_t *object;
>>      xnthread_t *thread;
>>      xntbase_t *tbase;
>> -    xnticks_t stime;
>>      int err = 0;
>>      spl_t s;
>>
>> @@ -723,7 +722,8 @@
>>
>>      xnlock_get_irqsave(&nklock, s);
>>
>> -    stime = xntbase_get_time(tbase);
>> +    if (timeout != XN_INFINITE && timeout != XN_NONBLOCK)
>> +        timeout += xntbase_get_time(tbase);
>>
>>      for (;;) {
>>          object = registry_hash_find(key);
>> @@ -738,18 +738,8 @@
>>              goto unlock_and_exit;
>>          }
>>
>> -        if (timeout != XN_INFINITE) {
>> -            xnticks_t now = xntbase_get_time(tbase);
>> -
>> -            if (stime + timeout >= now)
>> -                break;
>> -
>> -            timeout -= (now - stime);
>> -            stime = now;
>> -        }
>> -
>>          thread->registry.waitkey = key;
>> -        xnsynch_sleep_on(&registry_hash_synch, timeout, XN_RELATIVE);
>> +        xnsynch_sleep_on(&registry_hash_synch, timeout, XN_REALTIME);
>>
>>          if (xnthread_test_info(thread, XNTIMEO)) {
>>              err = -ETIMEDOUT;
>>
>>> I will use following patch for the moment, this works.
>>>
>>> --- xenomai/nucleus/registry.c.old    2008-07-15 00:36:10.000000000
>>> +0200
>>> +++ xenomai/nucleus/registry.c    2008-07-15 15:28:23.000000000 +0200
>>> @@ -733,8 +733,10 @@ int xnregistry_bind(const char *key, xnt
>>>          if (timeout != XN_INFINITE) {
>>>              xnticks_t now = xntbase_get_time(tbase);
>>>
>>> -            if (stime + timeout >= now)
>>> -                break;
>>> +            if (stime + timeout <= now) {
>>> +                err = -ETIMEDOUT;
>>> +                goto unlock_and_exit;
>>> +            }      
>>>              timeout -= (now - stime);
>>>              stime = now;
>>>
>>>
>>> Philippe Gerum schrieb:
>>>> Stefan Kisdaroczi wrote:
>>>>> Hi Philippe,
>>>>>
>>>>> the attached patch fixed the problem for me.
>>>> Good spot. Now it's official, since four years that feature exists or
>>>> so, nobody
>>>> actually used registry timeouts... Oh, well...
>>>>
>>>>> However, i think that in the "break case" still EACCES is returned.
>>>>> Can the break be replaced with a "return ETIMEDOUT" ?
>>>>>
>>>> Yes, normally we should do that along with your patch. Actually, the
>>>> most
>>>> appropriate fix would be to use an absolute timeout value internally,
>>>> since the
>>>> nucleus allows it.
>>>>
>>>> --- ksrc/nucleus/registry.c    (revision 4044)
>>>> +++ ksrc/nucleus/registry.c    (working copy)
>>>> @@ -711,7 +711,6 @@
>>>>      xnobject_t *object;
>>>>      xnthread_t *thread;
>>>>      xntbase_t *tbase;
>>>> -    xnticks_t stime;
>>>>      int err = 0;
>>>>      spl_t s;
>>>>
>>>> @@ -723,7 +722,8 @@
>>>>
>>>>      xnlock_get_irqsave(&nklock, s);
>>>>
>>>> -    stime = xntbase_get_time(tbase);
>>>> +    if (timeout != TM_NONBLOCK && timeout != TM_INFINITE)
>>>> +        timeout += xntbase_get_time(tbase);
>>>>
>>>>      for (;;) {
>>>>          object = registry_hash_find(key);
>>>> @@ -738,18 +738,8 @@
>>>>              goto unlock_and_exit;
>>>>          }
>>>>
>>>> -        if (timeout != XN_INFINITE) {
>>>> -            xnticks_t now = xntbase_get_time(tbase);
>>>> -
>>>> -            if (stime + timeout >= now)
>>>> -                break;
>>>> -
>>>> -            timeout -= (now - stime);
>>>> -            stime = now;
>>>> -        }
>>>> -
>>>>          thread->registry.waitkey = key;
>>>> -        xnsynch_sleep_on(&registry_hash_synch, timeout, XN_RELATIVE);
>>>> +        xnsynch_sleep_on(&registry_hash_synch, timeout, XN_ABSOLUTE);
>>>>
>>>>          if (xnthread_test_info(thread, XNTIMEO)) {
>>>>              err = -ETIMEDOUT;
>>>>  --
>>>> Philippe.
>>>>
>>>>
>>>
>>
>>
> 
> 


-- 
Philippe.


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

end of thread, other threads:[~2008-07-17 21:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-14 17:22 [Xenomai-help] rt_task_bind() and timeout values Stefan Kisdaroczi
2008-07-14 17:50 ` Philippe Gerum
2008-07-14 19:03   ` Stefan Kisdaroczi
2008-07-14 20:35     ` Philippe Gerum
2008-07-15  0:38       ` Stefan Kisdaroczi
2008-07-15  6:25         ` Philippe Gerum
2008-07-16 10:25           ` Stefan Kisdaroczi
2008-07-16 21:17             ` Philippe Gerum
2008-07-17 11:01               ` Stefan Kisdaroczi
2008-07-17 21:58                 ` Philippe Gerum
2008-07-15 14:28         ` Stefan Kisdaroczi

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.