public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Ingo Molnar <mingo@elte.hu>, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] sched: Introduce APIs for waiting multi events
Date: Thu, 16 Apr 2009 19:59:53 -0700	[thread overview]
Message-ID: <20090417025953.GA6885@linux.vnet.ibm.com> (raw)
In-Reply-To: <49E55218.1020208@cn.fujitsu.com>

On Wed, Apr 15, 2009 at 11:18:48AM +0800, Lai Jiangshan wrote:
> 
> Impact: make kernel has APIs for waiting multi events
> 
> Based on code in the RCU, the simple waiting-multi-events
> algorithm may do not serve RCU only.
> 
> Introduce 5 APIs for waiting multi events
> 
> start scheduling events:  ref_completion_get_init()
> schedule one event:       ref_completion_get()
> end scheduling events:    ref_completion_put_init()
> 
> any event is finished:    ref_completion_put()
> 
> waiting scheduled events: ref_completion_wait()

Interesting API!  What other uses for it have you found?

One question down below.

							Thanx, Paul

> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
> ---
> diff --git a/include/linux/completion.h b/include/linux/completion.h
> index 4a6b604..86c8236 100644
> --- a/include/linux/completion.h
> +++ b/include/linux/completion.h
> @@ -8,6 +8,7 @@
>   * See kernel/sched.c for details.
>   */
> 
> +#include <asm/atomic.h>
>  #include <linux/wait.h>
> 
>  /**
> @@ -98,5 +99,44 @@ extern void complete_all(struct completion *);
>   */
>  #define INIT_COMPLETION(x)	((x).done = 0)
> 
> +/*
> + * wait all references are put, or wait multi events finished in other words
> + * ref_completion_get_init() called before the struct is used or reused.
> + * ref_completion_put_init() called after all ref_completion_get()s called.
> + * ref_completion_wait()     waiting until all ref_completion_put()s and
> + *                           the ref_completion_put_init() are called.
> + */
> +struct ref_completion {
> +	atomic_t ref;
> +	struct completion wait;
> +};
> +
> +static inline void ref_completion_get_init(struct ref_completion *rc)
> +{
> +	atomic_set(&rc->ref, 1);
> +	init_completion(&rc->wait);
> +}
> +
> +static inline void ref_completion_get(struct ref_completion *rc)
> +{
> +	atomic_inc(&rc->ref);
> +}
> +
> +static inline void ref_completion_put(struct ref_completion *rc)
> +{
> +	if (atomic_dec_and_test(&rc->ref))
> +		complete_all(&rc->wait);
> +}
> +
> +static inline void ref_completion_put_init(struct ref_completion *rc)
> +{
> +	if (atomic_dec_and_test(&rc->ref))
> +		complete_all(&rc->wait);
> +}

Looks to me that ref_completion_put() and ref_completion_put_init() are
identical.  What is the story with that?

> +static inline void ref_completion_wait(struct ref_completion *rc)
> +{
> +	wait_for_completion(&rc->wait);
> +}
> 
>  #endif
> 
> 

      reply	other threads:[~2009-04-17  3:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-15  3:18 [PATCH 1/2] sched: Introduce APIs for waiting multi events Lai Jiangshan
2009-04-17  2:59 ` Paul E. McKenney [this message]

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=20090417025953.GA6885@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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