All of lore.kernel.org
 help / color / mirror / Atom feed
From: Malcolm Crossley <malcolm.crossley@citrix.com>
To: Jan Beulich <JBeulich@suse.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 2/3] grant_table: convert grant table rwlock to percpu rwlock
Date: Wed, 25 Nov 2015 14:11:49 +0000	[thread overview]
Message-ID: <5655C1A5.7000909@citrix.com> (raw)
In-Reply-To: <5655CB6402000078000B906C@prv-mh.provo.novell.com>

On 25/11/15 13:53, Jan Beulich wrote:
>>>> On 25.11.15 at 14:43, <malcolm.crossley@citrix.com> wrote:
>> On 25/11/15 12:35, Jan Beulich wrote:
>>>>>> On 20.11.15 at 17:03, <malcolm.crossley@citrix.com> wrote:
>>>> @@ -208,8 +210,6 @@ active_entry_acquire(struct grant_table *t, grant_ref_t 
>> e)
>>>>  {
>>>>      struct active_grant_entry *act;
>>>>  
>>>> -    ASSERT(rw_is_locked(&t->lock));
>>>
>>> Even if not covering all cases, I don't think this should be dropped,
>>> just like you don't drop rw_is_write_locked() asserts. Would properly
>>> replacing this be rather expensive?
>>
>> I could add a percpu_rw_is_locked function but it will be racy because I 
>> can't
>> set the local lock barrier variable ( set/clearing that would race with real
>> users of the write lock ) Therefore I would be left polling the percpu 
>> readers
>> which is not reliable without the local barrier variable. Should I still add
>> the function if it won't reliably detect the locked condition?
> 
> Iiuc that would then risk the ASSERT() producing false positives,
> which clearly is a no-go. In which case I'd still like you to leave in
> some sort of comment (perhaps just the current code converted
> to a comment) to document the requirement.

After checking the grant table code itself, it looks like the lock is always
taken by the local CPU so we should not get ASSERT false positives.

A generic percpu_rw_is_locked function would still be racy, maybe I should

> 
>>>> @@ -3180,7 +3178,7 @@ grant_table_create(
>>>>          goto no_mem_0;
>>>>  
>>>>      /* Simple stuff. */
>>>> -    rwlock_init(&t->lock);
>>>> +    percpu_rwlock_resource_init(&t->lock);
>>>
>>> Considering George's general comment (on patch 1), would it perhaps
>>> make sense to store (in debug builds) the per-CPU variable's offset
>>> in the lock structure, having percpu_{read,write}_lock() verify it? Or
>>> at the very least have gt_{read,write}_lock() wrappers, thus
>>> avoiding the need to explicitly pass grant_rwlock at each use site? I
>>> certainly agree with George that we should make it as hard as
>>> possible for someone to get using these constructs wrong.
>>
>> I can add storing the "per-CPU variable" owner in the local lock structure for
>> debug builds and have the percpu_{read,write} verify it at runtime.
>>
>> The downsides is that the size of structures will vary between debug and non-debug
>> builds and that perhaps users may be confused what the per-CPU variables are 
>> used for.
> 
> I'm not sure what confusion might arise here.

I was thinking there's a chance users might believe the per-CPU data are all somehow
stored in the percpu_rwlock_t itself. It's not a problem and I will implement it as
described above.
> 
>> I'll add the wrappers to for the grant table but will this make it harder to
>> determine how the locking works?
> 
> Why would it? At the call sites we don't really care about the
> mechanism. But perhaps I'm not seeing what you're thinking of...

I was thinking along the lines that it might appear the lock is for all usages in the
grant table code. I.E. We won't want people using the wrappers for locking of the
maptrack table itself. Ideally we want separate percpu variables for each "type" of
resource so that we don't get nested percpu locking of the different "types" which will
harm performance. Again, It's a major problem and I'm happy to add the wrappers.

Malcolm

> 
> Jan
> 

  reply	other threads:[~2015-11-25 14:11 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
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 [this message]
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=5655C1A5.7000909@citrix.com \
    --to=malcolm.crossley@citrix.com \
    --cc=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=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.