All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: malcolm.crossley@citrix.com
Cc: keir@xen.org, ian.campbell@citrix.com,
	george.dunlap@eu.citrix.com, andrew.cooper3@citrix.com,
	Marcos.Matsunaga@oracle.com, stefano.stabellini@citrix.com,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCHv2 1/3] rwlock: Add per-cpu reader-writer locks
Date: Thu, 26 Nov 2015 05:17:51 -0700	[thread overview]
Message-ID: <5657067F02000078000B9561@prv-mh.provo.novell.com> (raw)
In-Reply-To: <1448035423-24242-2-git-send-email-malcolm.crossley@citrix.com>

>>> On 20.11.15 at 17:03, <malcolm.crossley@citrix.com> wrote:
> --- a/xen/common/spinlock.c
> +++ b/xen/common/spinlock.c
> @@ -10,6 +10,8 @@
>  #include <asm/processor.h>
>  #include <asm/atomic.h>
>  
> +DEFINE_PER_CPU(cpumask_t, percpu_rwlock_readers);

static (and perhaps even local to _percpu_write_lock()).

> @@ -492,6 +494,42 @@ int _rw_is_write_locked(rwlock_t *lock)
>      return (lock->lock == RW_WRITE_FLAG); /* writer in critical section? */
>  }
>  
> +void _percpu_write_lock(percpu_rwlock_t **per_cpudata,
> +	        percpu_rwlock_t *percpu_rwlock)
> +{
> +    unsigned int cpu;
> +
> +    /* First take the write lock to protect against other writers. */

... or slow path readers.

> +    write_lock(&percpu_rwlock->rwlock);
> +
> +    /* Now set the global variable so that readers start using read_lock. */
> +    percpu_rwlock->writer_activating = 1;
> +    smp_mb();
> +
> +    /* Using a per cpu cpumask is only safe if there is no nesting. */
> +    ASSERT(!in_irq());
> +    this_cpu(percpu_rwlock_readers) = cpu_online_map;

cpumask_copy() please, to avoid copying perhaps half a kb on a
pretty small system.

> +    /* Check if there are any percpu readers in progress on this rwlock. */
> +    for ( ; ; )
> +    {
> +        for_each_cpu(cpu, &this_cpu(percpu_rwlock_readers))

No more than one this_cpu{,_ptr}() please within one function.

> +        {
> +            /* 
> +	     * Remove any percpu readers not contending on this rwlock
> +             * from our check mask.
> +	     */

Hard tabs.

> +            if ( per_cpu_ptr(per_cpudata, cpu) != percpu_rwlock )
> +                cpumask_clear_cpu(cpu, &this_cpu(percpu_rwlock_readers));

__cpumask_clear_cpu()

> +static inline void _percpu_read_lock(percpu_rwlock_t **per_cpudata,

const?

> +#define percpu_read_lock(percpu, lock) ( _percpu_read_lock( \
> +                                        &get_per_cpu_var(percpu), lock ) )
> +#define percpu_read_unlock(percpu, lock) ( _percpu_read_unlock( \
> +                                        &get_per_cpu_var(percpu), lock ) )
> +#define percpu_write_lock(percpu, lock) ( _percpu_write_lock( \
> +                                        &get_per_cpu_var(percpu), lock ) )
> +#define percpu_write_unlock(percpu, lock) ( _percpu_write_unlock( lock ) )

Perhaps easier to read as

#define percpu_read_lock(percpu, lock) \
    _percpu_read_lock(&get_per_cpu_var(percpu), lock)
#define percpu_read_unlock(percpu, lock) \
    _percpu_read_unlock(&get_per_cpu_var(percpu), lock)
#define percpu_write_lock(percpu, lock) \
    _percpu_write_lock(&get_per_cpu_var(percpu), lock)
#define percpu_write_unlock(percpu, lock) _percpu_write_unlock(lock)

But at the very least the stray blanks and parentheses should be
dropped.

Jan

  parent reply	other threads:[~2015-11-26 12:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-20 16:03 [PATCHv2 0/3] Implement per-cpu reader-writer locks Malcolm Crossley
2015-11-20 16:03 ` [PATCHv2 1/3] rwlock: Add " Malcolm Crossley
2015-11-25 11:12   ` George Dunlap
2015-11-26 12:17   ` Jan Beulich [this message]
2015-11-20 16:03 ` [PATCHv2 2/3] grant_table: convert grant table rwlock to percpu rwlock Malcolm Crossley
2015-11-25 12:35   ` Jan Beulich
2015-11-25 13:43     ` Malcolm Crossley
2015-11-25 13:53       ` Jan Beulich
2015-11-25 14:11         ` Malcolm Crossley
2015-11-20 16:03 ` [PATCHv2 3/3] p2m: " Malcolm Crossley
2015-11-25 12:00   ` George Dunlap
2015-11-25 12:38   ` Jan Beulich
2015-11-25 12:54     ` Malcolm Crossley
2015-11-24 18:16 ` [PATCHv2 0/3] Implement per-cpu reader-writer locks George Dunlap
2015-11-24 18:30   ` George Dunlap
2015-11-25  8:58     ` Malcolm Crossley
2015-11-25  9:49       ` George Dunlap
2015-11-26  9:48       ` Dario Faggioli
2015-11-24 18:32   ` Andrew Cooper

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=5657067F02000078000B9561@prv-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=Marcos.Matsunaga@oracle.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=keir@xen.org \
    --cc=malcolm.crossley@citrix.com \
    --cc=stefano.stabellini@citrix.com \
    --cc=xen-devel@lists.xenproject.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.