All of lore.kernel.org
 help / color / mirror / Atom feed
From: Waiman Long <waiman.long@hpe.com>
To: Pan Xinhui <xinhui@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, <linux-kernel@vger.kernel.org>,
	Scott J Norton <scott.norton@hpe.com>,
	Douglas Hatch <doug.hatch@hpe.com>
Subject: Re: [PATCH] locking/pvqspinlock: Add lock holder CPU argument to pv_wait()
Date: Thu, 14 Apr 2016 14:47:18 -0400	[thread overview]
Message-ID: <570FE5B6.50307@hpe.com> (raw)
In-Reply-To: <570FAA72.5090302@linux.vnet.ibm.com>

On 04/14/2016 10:34 AM, Pan Xinhui wrote:
> hello, Waiman
> I try your patch, thanks!
>
> also I do some improvement.
> below code diff has been tested, it works for me. :)
>
> diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c
> index ce2f75e..99f31e4 100644
> --- a/kernel/locking/qspinlock.c
> +++ b/kernel/locking/qspinlock.c
> @@ -248,7 +248,8 @@ static __always_inline void set_locked(struct qspinlock *lock)
>    */
>
>   static __always_inline void __pv_init_node(struct mcs_spinlock *node) { }
> -static __always_inline void __pv_wait_node(struct mcs_spinlock *node,
> +static __always_inline void __pv_wait_node(struct qspinlock *lock,
> +                                          struct mcs_spinlock *node,
>                                             struct mcs_spinlock *prev) { }
>   static __always_inline void __pv_kick_node(struct qspinlock *lock,
>                                             struct mcs_spinlock *node) { }
> @@ -407,7 +408,7 @@ queue:
>                  prev = decode_tail(old);
>                  WRITE_ONCE(prev->next, node);
>
> -               pv_wait_node(node, prev);
> +               pv_wait_node(lock, node, prev);
>                  arch_mcs_spin_lock_contended(&node->locked);
>
>                  /*
> diff --git a/kernel/locking/qspinlock_paravirt.h b/kernel/locking/qspinlock_paravirt.h
> index 01a6d16..75ccfd3 100644
> --- a/kernel/locking/qspinlock_paravirt.h
> +++ b/kernel/locking/qspinlock_paravirt.h
> @@ -255,6 +257,19 @@ static struct pv_node *pv_unhash(struct qspinlock *lock)
>          BUG();
>   }
>
> +static struct pv_node *pv_hash_lookup(struct qspinlock *lock)
> +{
> +       unsigned long offset, hash = hash_ptr(lock, pv_lock_hash_bits);
> +       struct pv_hash_entry *he;
> +
> +       for_each_hash_entry(he, offset, hash) {
> +               if (READ_ONCE(he->lock) == lock) {
> +                       return he->node;
> +               }
> +       }
> +       return NULL;
> +}
> +
>   /*
>    * Return true if when it is time to check the previous node which is not
>    * in a running state.
> @@ -287,14 +303,17 @@ static void pv_init_node(struct mcs_spinlock *node)
>    * pv_kick_node() is used to set _Q_SLOW_VAL and fill in hash table on its
>    * behalf.
>    */
> -static void pv_wait_node(struct mcs_spinlock *node, struct mcs_spinlock *prev)
> +static void pv_wait_node(struct qspinlock *lock, struct mcs_spinlock *node,
> +                       struct mcs_spinlock *prev)
>   {
>          struct pv_node *pn = (struct pv_node *)node;
>          struct pv_node *pp = (struct pv_node *)prev;
> +       struct pv_node *ph;
>          int waitcnt = 0;
>          int loop;
>          bool wait_early;
>
> +       pn->prev_cpu = pp->cpu;
>          /* waitcnt processing will be compiled out if !QUEUED_LOCK_STAT */
>          for (;; waitcnt++) {
>                  for (wait_early = false, loop = SPIN_THRESHOLD; loop; loop--) {
> @@ -322,7 +341,10 @@ static void pv_wait_node(struct mcs_spinlock *node, struct mcs_spinlock *prev)
>                          qstat_inc(qstat_pv_wait_node, true);
>                          qstat_inc(qstat_pv_wait_again, waitcnt);
>                          qstat_inc(qstat_pv_wait_early, wait_early);
> -                       pv_wait(&pn->state, vcpu_halted);
> +                       ph = pv_hash_lookup(lock);
> +                       if (!ph)
> +                               ph = pp;
> +                       pv_wait(&pn->state, vcpu_halted, ph->prev_cpu);
>                  }
>
>                  /*
>
> any comments are welcome. I put my patch here just for simplicity, or need I send it out in a new thread?
>
> thanks
> xinhui
>
>

I have sent out a v2 patch that incorporate your change with some minor 
twists.

Cheers,
Longman

      reply	other threads:[~2016-04-14 18:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-13 20:59 [PATCH] locking/pvqspinlock: Add lock holder CPU argument to pv_wait() Waiman Long
2016-04-14  0:21 ` Peter Zijlstra
2016-04-14  1:59   ` Waiman Long
2016-04-14  8:39   ` Pan Xinhui
2016-04-14  9:36 ` Pan Xinhui
2016-04-14 14:34   ` Pan Xinhui
2016-04-14 18:47     ` Waiman Long [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=570FE5B6.50307@hpe.com \
    --to=waiman.long@hpe.com \
    --cc=doug.hatch@hpe.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=scott.norton@hpe.com \
    --cc=xinhui@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 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.