All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
Cc: xenomai-core <xenomai@xenomai.org>
Subject: Re: [Xenomai-core] [RFC][PATCH] Factor out xnsynch_acquire/release
Date: Mon, 22 Sep 2008 10:09:30 +0200	[thread overview]
Message-ID: <48D752BA.3000403@domain.hid> (raw)
In-Reply-To: <48D69A7A.7090302@domain.hid>

Gilles Chanteperdrix wrote:
> Jan Kiszka wrote:
> 
>> [1]http://thread.gmane.org/gmane.linux.real-time.xenomai.devel/5412/focus=5405
>>
> always-put-xnthread-base-into-registry.patch:
> 	I understand the need, but I will cowardly let Philippe decide whether
> he likes the implementation details.
> 
> handle-base-xn_sys_current-1.patch:
> 	In some places (pse51_mutex_timedlock_inner for instances) you use
> XN_NO_HANDLE, in others (pse51_mutex_timedlock for instances) you use
> NULL, are the two equivalents ? If yes, should not we always use the
> same consistently ? Otherwise looks ok.

I fail to find the NULL spots - which pse51_mutex_timedlock do you mean?

> 
> remove-xnarch_atomic_intptr.patch:
> 	Ok.
> 
> spread-xeno_set_current.patch:
> 	Ok. This is even a bug fix.
> 
> xnsynch refactoring:
> 	things have moved too much to see what has really changed in
> xnsynch_wakeup_one_sleeper and xnsynch_sleep_on. But is not there a
> common behaviour between the old and new services that could be factored
> ? But otherwise I agree with the general idea of the patch, this is what
> we had discussed with Philippe.

Yes, the diff is unfortunate due to a reordering of the function within
synch.c. Here is a direct diff of both services:

--- a	2008-09-22 10:06:56.000000000 +0200
+++ b	2008-09-22 10:07:39.000000000 +0200
@@ -1,112 +1,47 @@
 void xnsynch_sleep_on(xnsynch_t *synch, xnticks_t timeout,
 		      xntmode_t timeout_mode)
 {
-	xnthread_t *thread = xnpod_current_thread(), *owner;
+	xnthread_t *thread = xnpod_current_thread();
 	spl_t s;
 
+	XENO_BUGON(NUCLEUS, testbits(synch->status, XNSYNCH_OWNER));
+
 	xnlock_get_irqsave(&nklock, s);
 
 	trace_mark(xn_nucleus_synch_sleepon,
 		   "thread %p thread_name %s synch %p",
 		   thread, xnthread_name(thread), synch);
 
-	if (!testbits(synch->status, XNSYNCH_PRIO)) { /* i.e. FIFO */
+	if (!testbits(synch->status, XNSYNCH_PRIO)) /* i.e. FIFO */
 		appendpq(&synch->pendq, &thread->plink);
-		xnpod_suspend_thread(thread, XNPEND, timeout, timeout_mode, synch);
-		goto unlock_and_exit;
-	}
-
-	if (!testbits(synch->status, XNSYNCH_PIP)) { /* i.e. no ownership */
-		insertpqf(&synch->pendq, &thread->plink, thread->cprio);
-		xnpod_suspend_thread(thread, XNPEND, timeout, timeout_mode, synch);
-		goto unlock_and_exit;
-	}
-
-redo:
-	owner = synch->owner;
-
-	if (!owner) {
-		synch->owner = thread;
-		xnthread_clear_info(thread, XNRMID | XNTIMEO | XNBREAK);
-		goto unlock_and_exit;
-	}
-
-	if (thread->cprio > owner->cprio) {
-		if (xnthread_test_info(owner, XNWAKEN) && owner->wwake == synch) {
-			/* Ownership is still pending, steal the resource. */
-			synch->owner = thread;
-			xnthread_clear_info(thread, XNRMID | XNTIMEO | XNBREAK);
-			xnthread_set_info(owner, XNROBBED);
-			goto unlock_and_exit;
-		}
-
-		if (!xnthread_test_state(owner, XNBOOST)) {
-			owner->bprio = owner->cprio;
-			xnthread_set_state(owner, XNBOOST);
-		}
-
-		if (testbits(synch->status, XNSYNCH_CLAIMED))
-			removepq(&owner->claimq, &synch->link);
-		else
-			__setbits(synch->status, XNSYNCH_CLAIMED);
-
-		insertpqf(&owner->claimq, &synch->link, thread->cprio);
-		insertpqf(&synch->pendq, &thread->plink, thread->cprio);
-		xnsynch_renice_thread(owner, thread->cprio);
-	} else
+	else /* i.e. priority-sorted */
 		insertpqf(&synch->pendq, &thread->plink, thread->cprio);
 
 	xnpod_suspend_thread(thread, XNPEND, timeout, timeout_mode, synch);
 
-	if (xnthread_test_info(thread, XNRMID | XNTIMEO | XNBREAK))
-		goto unlock_and_exit;
-
-	if (xnthread_test_info(thread, XNROBBED)) {
-		/* Somebody stole us the ownership while we were ready
-		   to run, waiting for the CPU: we need to wait again
-		   for the resource. */
-		if (timeout_mode != XN_RELATIVE || timeout == XN_INFINITE)
-			goto redo;
-		timeout = xntimer_get_timeout_stopped(&thread->rtimer);
-		if (timeout > 1) /* Otherwise, it's too late. */
-			goto redo;
-		xnthread_set_info(thread, XNTIMEO);
-	}
-
-      unlock_and_exit:
-
-	thread->wwake = NULL;
-	xnthread_clear_info(thread, XNWAKEN);
-
 	xnlock_put_irqrestore(&nklock, s);
 }
 
 xnthread_t *xnsynch_wakeup_one_sleeper(xnsynch_t *synch)
 {
-	xnthread_t *thread = NULL, *lastowner;
+	xnthread_t *thread = NULL;
 	xnpholder_t *holder;
 	spl_t s;
 
+	XENO_BUGON(NUCLEUS, testbits(synch->status, XNSYNCH_OWNER));
+
 	xnlock_get_irqsave(&nklock, s);
 
-	lastowner = synch->owner;
 	holder = getpq(&synch->pendq);
 
 	if (holder) {
 		thread = link2thread(holder, plink);
 		thread->wchan = NULL;
-		thread->wwake = synch;
-		synch->owner = thread;
-		xnthread_set_info(thread, XNWAKEN);
 		trace_mark(xn_nucleus_synch_wakeup_one,
 			   "thread %p thread_name %s synch %p",
 			   thread, xnthread_name(thread), synch);
 		xnpod_resume_thread(thread, XNPEND);
-	} else
-		synch->owner = NULL;
-
-	if (testbits(synch->status, XNSYNCH_CLAIMED))
-		xnsynch_clear_boost(synch, lastowner);
+	}
 
 	xnlock_put_irqrestore(&nklock, s);
 

Jan

-- 
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux


  reply	other threads:[~2008-09-22  8:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-15 15:14 [Xenomai-core] [RFC][PATCH] Factor out xnsynch_acquire/release Jan Kiszka
2008-09-15 17:10 ` Jan Kiszka
2008-09-16 17:15   ` Philippe Gerum
2008-09-21 10:24 ` Jan Kiszka
2008-09-21 17:48   ` Gilles Chanteperdrix
2008-09-21 18:07     ` Jan Kiszka
2008-09-21 19:03       ` Gilles Chanteperdrix
2008-09-22  8:09         ` Jan Kiszka [this message]
2008-09-22  8:18           ` Gilles Chanteperdrix
2008-09-22  8:57             ` Jan Kiszka
2008-09-22 18:41               ` Gilles Chanteperdrix
2008-09-23  8:44                 ` Jan Kiszka
2008-09-23  8:45                   ` Gilles Chanteperdrix
2008-09-23  9:01                     ` Jan Kiszka
2008-09-22  8:19         ` Philippe Gerum
2008-09-23 14:59           ` Jan Kiszka

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=48D752BA.3000403@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=gilles.chanteperdrix@xenomai.org \
    --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.