Skip to contentSkip to conversation

xnpipe_recv and xntimer_get_timeout_periodic()

PATCH In review Dmitry Adamushko 2 participants 10 messages Aug 21, 2006 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xnpipe_recv and xntimer_get_timeout_periodic()

[ resent. subject was broken ]

------------------------------------

Hello,

[ pipe.c.patch ] update the "timeout" variable so that the remaining timeout is used in case of consequent xnsynch_sleep_on() calls.

As I understand that may indeed happen in case when another thread "steals" data while this one waits to be scheduled in.

[ timer.c.patch] xnticks_t is unsigned while (as I understand) "xntlholder_date(&timer->plink) - nkpod->jiffies" can be negative. In this case, some positive big number is returned and any code that relies on xnthread_timeout() or xntimer_get_timeout() and runs over periodic mode won't work properly (e.g. xnsynch_sleep_on() and xnpipe_recv() now). Not sure 1 should be returned in this case (so far I just did it the same way as xntimer_get_timeout_aperiodic()), I guess 0 would be better in both cases.

At least in theory, 1 may cause an (even) infinite loop in xnpipe_recv() as I don't like a check for "timeout > 1" to be placed there. It's something that should be decided at the timer layer - I mean, whether it's too late to sleep or not.

hope, I haven't overlooked anything this time :o)

Signature · 2 lines
Best regards,
Dmitry Adamushko
pipe.c renamed from pipe-SVN.c +3 -0
@@ -450,6 +450,9 @@ ssize_t xnpipe_recv(int minor, struct xn
 			ret = -EIDRM;
 			goto unlock_and_exit;
 		}
+
+		/* remaining timeout */		
+		timeout = xnthread_timeout(thread);
 	}
 
 	*pmh = link2mh(holder);
timer.c renamed from timer-SVN.c +6 -1
@@ -313,7 +313,12 @@ static xnticks_t xntimer_get_date_period
 
 static xnticks_t xntimer_get_timeout_periodic(xntimer_t *timer)
 {
-	return xntlholder_date(&timer->plink) - nkpod->jiffies;
+	xnticks_t now = nkpod->jiffies;
+	
+	if (xntlholder_date(&timer->plink) < now)
+		return 1;	/* Will elapse shortly. */
+	
+	return xntlholder_date(&timer->plink) - now;
 }
 
 static xnticks_t xntimer_get_raw_expiry_periodic(xntimer_t *timer)
#1 lore raw
Quoted 3 lines · Dmitry Adamushko

Not sure 1 should be returned in this case (so far I just did it the
same way as xntimer_get_timeout_aperiodic()), I guess 0 would be better in both cases.

Zero (XN_INFINITE) is reserved to indicate a non-running timer.

Signature · 1 line
Philippe.
#2 lore raw
In reply to Dmitry Adamushko
Quoted 2 lines · Dmitry Adamushko

[ timer.c.patch] xnticks_t is unsigned while (as I understand) "xntlholder_date(&timer->plink) - nkpod->jiffies" can be negative.

Well, normally, it should not. In periodic mode, each and every tick is processed by the timer handler which also maintains the time base (nkpod->jiffies), and as such, no timer should remain outstanding after its wakeup time has elapsed, otherwise, something is broken in the timer wheel management in the first place.

IOW, we should never miss a tick, and consequently, negative timeouts cannot exist, since a timer is either running (= 0), or scheduled to elapse in the future (> 0). On the contrary, aperiodic mode is based on some free running TSC value not controlled by the nucleus, and as such, we might well ask for the timeout value slightly before the related timer elapses, and end up reading the TSC a bit later than its timeout date.

Signature · 1 line
Philippe.
#3 lore raw
Quoted 5 lines · Philippe Gerum
Quoted 2 lines · Dmitry Adamushko

[ timer.c.patch] xnticks_t is unsigned while (as I understand) "xntlholder_date(&timer->plink) - nkpod->jiffies" can be negative.

ok, I somehow missed a check for xntimer_running_p() in xntimer_get_timeout(). I bet it was not there when I was looking at this part of code yesterday or maybe I just had too much ummmm wonderful belgium beer :o)

Actually xntimer_get_timeout() should be called with nklock held + irq off as it must be atomic. But anyway, this is how it's used in all places and it's probably not supposed to be used "as is" from any upper layer. So it's ok.

Signature · 2 lines
Best regards,
Dmitry Adamushko
#4 lore raw
Quoted 10 lines · Dmitry Adamushko

On 21/08/06, Philippe Gerum <[email protected]> wrote:

        On Mon, 2006-08-21 at 10:36 +0200, Dmitry Adamushko wrote:
        
        > [ timer.c.patch] xnticks_t is unsigned while (as I
        understand)
        > "xntlholder_date(&timer->plink) - nkpod->jiffies" can be
        negative.
Quoted 4 lines

ok, I somehow missed a check for xntimer_running_p() in xntimer_get_timeout(). I bet it was not there when I was looking at this part of code yesterday or maybe I just had too much ummmm wonderful belgium beer :o)

It's been there since the fusion times! Ok, it must be the beer... :o>

Quoted 6 lines

Actually xntimer_get_timeout() should be called with nklock held + irq off as it must be atomic. But anyway, this is how it's used in all places and it's probably not supposed to be used "as is" from any upper layer. So it's ok.

Indeed.

Quoted 5 lines
Signature · 3 lines
-- 
Best regards,
Dmitry Adamushko
Signature · 1 line
Philippe.
#5 lore raw
In reply to Dmitry Adamushko
Quoted 6 lines · Dmitry Adamushko

[ pipe.c.patch ] update the "timeout" variable so that the remaining timeout is used in case of consequent xnsynch_sleep_on() calls.

As I understand that may indeed happen in case when another thread "steals" data while this one waits to be scheduled in.

Indeed, but this case is already handled in xnsynch_sleep_on() (see the test for the XNROBBED bit).

Signature · 1 line
Philippe.
#6 lore raw

what about pipe-related change (I mean timeslice updating in xnpipe_recv()) ?

Signature · 2 lines
Best regards,
Dmitry Adamushko
#7 lore raw
Quoted 4 lines · Dmitry Adamushko

what about pipe-related change (I mean timeslice updating in xnpipe_recv()) ?

It's basically useless, since xnsynch_sleep_on() handles the resource stealing case internally, and the loop in xnpipe_recv is fake actually. Think of it as a goto statement in disguise.

Quoted 4 lines
Signature · 3 lines
-- 
Best regards,
Dmitry Adamushko
Signature · 1 line
Philippe.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

PATCH 1/1 xnpipe_recv and xntimer_get_timeout_periodic()

Quoted 8 lines · Dmitry Adamushko
Quoted 4 lines

what about pipe-related change (I mean timeslice updating in xnpipe_recv()) ?

It's basically useless, since xnsynch_sleep_on() handles the resource stealing case internally, and the loop in xnpipe_recv is fake actually. Think of it as a goto statement in disguise.

It has nothing to do with "resource stealing" (in terms of synch.c). The synch object is not PIP at all.

task1 : blocked in xnpipe_recv()

task2 : xnpipe_send() ---> wakes up task1 ---> task1 is waiting to be scheduled in

task3 [prio > task2.prio] : gets CPU and calls xnpipe_recv()

task3 gets a message so state->inq is empty now.

...

task2 : calls getq(&state->inq) which is NULL now (if there were no more messages)

calls xnsynch_sleep_on() again with the initial "timeout".

No?

Quoted 6 lines
Quoted 2 lines

--

Best regards,
Dmitry Adamushko

--
Philippe.

Signature · 2 lines
Best regards,
Dmitry Adamushko
#10 lore raw
Quoted 23 lines · Dmitry Adamushko

From:
Dmitry Adamushko
<[email protected]>

                               To: 

[email protected]
Subject:
[Xenomai-core] [patch, minor]
xnpipe_recv and
xntimer_get_timeout_periodic()
Date:
Mon, 21 Aug 2006 13:47:00 +0200

On Mon, 2006-08-21 at 12:47 +0200, Dmitry Adamushko wrote:
>
> what about pipe-related change (I mean timeslice updating in
> xnpipe_recv()) ?
>

Quoted 9 lines

It's basically useless, since xnsynch_sleep_on() handles the resource
stealing case internally, and the loop in xnpipe_recv is fake actually.
Think of it as a goto statement in disguise.

It has nothing to do with "resource stealing" (in terms of synch.c). The synch object is not PIP at all.

Ok, I thought we were discussing a more general issue about a new potential side-effect of the resource stealing feature.

Quoted 7 lines

task1 : blocked in xnpipe_recv()

task2 : xnpipe_send() ---> wakes up task1 ---> task1 is waiting to be scheduled in

task3 [prio > task2.prio] : gets CPU and calls xnpipe_recv()

Quoted 9 lines

task3 gets a message so state->inq is empty now.

...

task2 : calls getq(&state->inq) which is NULL now (if there were no more messages)

calls xnsynch_sleep_on() again with the initial "timeout".

Definitely, yes. Please ignore my previous comment. I'll apply this one, thanks.

Signature · 1 line
Philippe.