Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: paulmck@linux.vnet.ibm.com (Paul E. McKenney)
Subject: [ltt-dev] [PATCH RFC] call_rcu() interface for userspace-rcu
Date: Mon, 1 Nov 2010 13:04:04 -0700	[thread overview]
Message-ID: <20101101200404.GC2664@linux.vnet.ibm.com> (raw)
In-Reply-To: <4CCBDE0B.8060102@redhat.com>

On Sat, Oct 30, 2010 at 10:57:47AM +0200, Paolo Bonzini wrote:
> >+static void *call_rcu_thread(void *arg)
> >+{
> >+		[...]
> >+		else {
> >+			call_rcu_lock(&crdp->mtx);
> >+			crdp->flags &= ~URCU_CALL_RCU_RUNNING;
> >+			if (&cbs->next != cbs_tail&&
> >+			    pthread_cond_wait(&crdp->cond,&crdp->mtx) != 0) {
> >+				perror("pthread_cond_wait");
> >+				exit(-1);
> >+			} else
> >+				poll(NULL, 0, 10);
> >+			crdp->flags |= URCU_CALL_RCU_RUNNING;
> >+			call_rcu_unlock(&crdp->mtx);
> >+		}
> >+	}
> >+	return NULL;  /* NOTREACHED */
> >+}
> 
> Given the way you handle URCU_CALL_RCU_RUNNING above, the flag will
> be reset in call_rcu iff call_rcu sees contention on the lock.

Doesn't pthread_cond_wait() release the mutex for the duration of the
wait?  Ah, are you worried about the poll() under the lock?  I am
moving this out from under the lock.

> >+		call_rcu_lock(&crdp->mtx);
> >+		if (!(crdp->flags&  URCU_CALL_RCU_RUNNING)) {
> >+			if (pthread_cond_signal(&crdp->cond) != 0) {
> >+				perror("pthread_cond_signal");
> >+				exit(-1);
> >+			}
> >+		}
> >+		call_rcu_unlock(&crdp->mtx);
> >+	}
> >+}
> 
> So, the mutex is basically unnecessary if some futex magic replaces
> the condition variable.  For example, in the thread:
> 
> 	else {
> 	   retry:
> 		flags = crdp->flags;
> 		if ((flags & URCU_CALL_RCU_REQUESTED))
> 			continue;
> 		if (cmpxchg (&crdp->flags, flags,
> 		             flags & ~URCU_CALL_RCU_RUNNING) != flags)
> 			goto retry;
> 
> 		futex_wait (&crdp->flags,
> 			    flags & ~URCU_CALL_RCU_RUNNING);
> 	}
> 
> and in call_rcu:
> 
> 	mb ();
> 	/* If the thread is not blocked, it will see our request.  */
> 	do {
> 		flags = crdp->flags;
> 		/* If there's already a request pending, no need to
> 		   wake up the process.  If the thread is running, no
> 		   need to do anything, it'll pick up our request.  */
> 		if (flags &
> 		    (URCU_CALL_RCU_REQUESTED | URCU_CALL_RCU_RUNNING))
> 			return;
> 	} while (cmpxchg (&crdp->flags, flags,
> 			  flags | URCU_CALL_RCU_REQUESTED) != flags);
> 	futex_wake (&crdp->flags, 1);

OK, sounds like a nice optimization, though a bit Linux-specific.
I will stick with the POSIX stuff for the moment, and once I am
convinced that it really is working, I might consider doing futexes
if running on Linux.

							Thanx, Paul




       reply	other threads:[~2010-11-01 20:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20101029162534.GA11742@linux.vnet.ibm.com>
     [not found] ` <4CCBDE0B.8060102@redhat.com>
2010-11-01 20:04   ` Paul E. McKenney [this message]
2010-11-01 20:25     ` Mathieu Desnoyers
2010-11-02 12:12       ` Paul E. McKenney
2010-11-11  8:44         ` Paolo Bonzini
2010-11-12  0:24           ` Paolo Bonzini
2010-11-16  0:16             ` Paul E. McKenney

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=20101101200404.GC2664@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox