xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spinlock: improve spin_is_locked() for recursive locks
@ 2016-03-24 11:30 Jan Beulich
  2016-03-24 14:19 ` Dario Faggioli
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Jan Beulich @ 2016-03-24 11:30 UTC (permalink / raw)
  To: xen-devel; +Cc: Keir Fraser, Ian Jackson, Tim Deegan

[-- Attachment #1: Type: text/plain, Size: 776 bytes --]

Recursive locks know their current owner, and since we use the function
solely to determine whether a particular lock is being held by the
current CPU (which so far has been an imprecise check), make actually
check the owner for recusrively acquired locks.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/common/spinlock.c
+++ b/xen/common/spinlock.c
@@ -188,7 +188,9 @@ void _spin_unlock_irqrestore(spinlock_t
 int _spin_is_locked(spinlock_t *lock)
 {
     check_lock(&lock->debug);
-    return lock->tickets.head != lock->tickets.tail;
+    return lock->recurse_cpu == SPINLOCK_NO_CPU
+           ? lock->tickets.head != lock->tickets.tail
+           : lock->recurse_cpu == smp_processor_id();
 }
 
 int _spin_trylock(spinlock_t *lock)




[-- Attachment #2: spin-is-locked.patch --]
[-- Type: text/plain, Size: 828 bytes --]

spinlock: improve spin_is_locked() for recursive locks

Recursive locks know their current owner, and since we use the function
solely to determine whether a particular lock is being held by the
current CPU (which so far has been an imprecise check), make actually
check the owner for recusrively acquired locks.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/common/spinlock.c
+++ b/xen/common/spinlock.c
@@ -188,7 +188,9 @@ void _spin_unlock_irqrestore(spinlock_t
 int _spin_is_locked(spinlock_t *lock)
 {
     check_lock(&lock->debug);
-    return lock->tickets.head != lock->tickets.tail;
+    return lock->recurse_cpu == SPINLOCK_NO_CPU
+           ? lock->tickets.head != lock->tickets.tail
+           : lock->recurse_cpu == smp_processor_id();
 }
 
 int _spin_trylock(spinlock_t *lock)

[-- Attachment #3: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] spinlock: improve spin_is_locked() for recursive locks
  2016-03-24 11:30 [PATCH] spinlock: improve spin_is_locked() for recursive locks Jan Beulich
@ 2016-03-24 14:19 ` Dario Faggioli
  2016-03-24 14:38 ` Andrew Cooper
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Dario Faggioli @ 2016-03-24 14:19 UTC (permalink / raw)
  To: Jan Beulich, xen-devel; +Cc: Ian Jackson, Keir Fraser, Tim Deegan


[-- Attachment #1.1: Type: text/plain, Size: 723 bytes --]

On Thu, 2016-03-24 at 05:30 -0600, Jan Beulich wrote:
> Recursive locks know their current owner, and since we use the
> function
> solely to determine whether a particular lock is being held by the
> current CPU (which so far has been an imprecise check), make actually
> check the owner for recusrively acquired locks.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com>

Regards,
Dario
-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)


[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] spinlock: improve spin_is_locked() for recursive locks
  2016-03-24 11:30 [PATCH] spinlock: improve spin_is_locked() for recursive locks Jan Beulich
  2016-03-24 14:19 ` Dario Faggioli
@ 2016-03-24 14:38 ` Andrew Cooper
  2016-03-24 15:55 ` David Vrabel
  2016-03-25 10:19 ` Xu, Quan
  3 siblings, 0 replies; 8+ messages in thread
From: Andrew Cooper @ 2016-03-24 14:38 UTC (permalink / raw)
  To: Jan Beulich, xen-devel; +Cc: Ian Jackson, Keir Fraser, Tim Deegan

On 24/03/16 11:30, Jan Beulich wrote:
> Recursive locks know their current owner, and since we use the function
> solely to determine whether a particular lock is being held by the
> current CPU (which so far has been an imprecise check), make actually
> check the owner for recusrively acquired locks.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] spinlock: improve spin_is_locked() for recursive locks
  2016-03-24 11:30 [PATCH] spinlock: improve spin_is_locked() for recursive locks Jan Beulich
  2016-03-24 14:19 ` Dario Faggioli
  2016-03-24 14:38 ` Andrew Cooper
@ 2016-03-24 15:55 ` David Vrabel
  2016-03-24 16:19   ` Jan Beulich
  2016-03-25 10:19 ` Xu, Quan
  3 siblings, 1 reply; 8+ messages in thread
From: David Vrabel @ 2016-03-24 15:55 UTC (permalink / raw)
  To: Jan Beulich, xen-devel; +Cc: Ian Jackson, Keir Fraser, Tim Deegan

On 24/03/16 11:30, Jan Beulich wrote:
> Recursive locks know their current owner, and since we use the function
> solely to determine whether a particular lock is being held by the
> current CPU (which so far has been an imprecise check), make actually
> check the owner for recusrively acquired locks.

What's the expected behaviour of _spin_is_locked() if the lock is held
by another CPU?

Before it may return true if it is held by another CPU, now it will
always return false in this case.

David

> --- a/xen/common/spinlock.c
> +++ b/xen/common/spinlock.c
> @@ -188,7 +188,9 @@ void _spin_unlock_irqrestore(spinlock_t
>  int _spin_is_locked(spinlock_t *lock)
>  {
>      check_lock(&lock->debug);
> -    return lock->tickets.head != lock->tickets.tail;
> +    return lock->recurse_cpu == SPINLOCK_NO_CPU
> +           ? lock->tickets.head != lock->tickets.tail
> +           : lock->recurse_cpu == smp_processor_id();
>  }
>  
>  int _spin_trylock(spinlock_t *lock)
> 
> 
> 
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
> 


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] spinlock: improve spin_is_locked() for recursive locks
  2016-03-24 15:55 ` David Vrabel
@ 2016-03-24 16:19   ` Jan Beulich
  2016-03-29 10:36     ` George Dunlap
  0 siblings, 1 reply; 8+ messages in thread
From: Jan Beulich @ 2016-03-24 16:19 UTC (permalink / raw)
  To: David Vrabel; +Cc: xen-devel, Keir Fraser, Ian Jackson, TimDeegan

>>> On 24.03.16 at 16:55, <david.vrabel@citrix.com> wrote:
> On 24/03/16 11:30, Jan Beulich wrote:
>> Recursive locks know their current owner, and since we use the function
>> solely to determine whether a particular lock is being held by the
>> current CPU (which so far has been an imprecise check), make actually
>> check the owner for recusrively acquired locks.
> 
> What's the expected behaviour of _spin_is_locked() if the lock is held
> by another CPU?
> 
> Before it may return true if it is held by another CPU, now it will
> always return false in this case.

Correct - hence the reference to this only being used for a limited
set of cases (read: ASSERT()s and alike).

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] spinlock: improve spin_is_locked() for recursive locks
  2016-03-24 11:30 [PATCH] spinlock: improve spin_is_locked() for recursive locks Jan Beulich
                   ` (2 preceding siblings ...)
  2016-03-24 15:55 ` David Vrabel
@ 2016-03-25 10:19 ` Xu, Quan
  3 siblings, 0 replies; 8+ messages in thread
From: Xu, Quan @ 2016-03-25 10:19 UTC (permalink / raw)
  To: Jan Beulich, xen-devel; +Cc: Ian Jackson, Keir Fraser, Tim Deegan

On March 24, 2016 7:31pm, <jbeulich@suse.com> wrote:
> Recursive locks know their current owner, and since we use the function solely
> to determine whether a particular lock is being held by the current CPU (which
> so far has been an imprecise check), make actually check the owner for
> recusrively acquired locks.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> --- a/xen/common/spinlock.c
> +++ b/xen/common/spinlock.c
> @@ -188,7 +188,9 @@ void _spin_unlock_irqrestore(spinlock_t
>  int _spin_is_locked(spinlock_t *lock)
>  {
>      check_lock(&lock->debug);
> -    return lock->tickets.head != lock->tickets.tail;
> +    return lock->recurse_cpu == SPINLOCK_NO_CPU
> +           ? lock->tickets.head != lock->tickets.tail
> +           : lock->recurse_cpu == smp_processor_id();
>  }
> 
>  int _spin_trylock(spinlock_t *lock)
> 
> 

Reviewed-by: Quan Xu <quan.xu@intel.com>

Thanks for your enhancement. I am not aware of this case in my previous patch set.
Quan



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] spinlock: improve spin_is_locked() for recursive locks
  2016-03-24 16:19   ` Jan Beulich
@ 2016-03-29 10:36     ` George Dunlap
  2016-03-29 10:45       ` Jan Beulich
  0 siblings, 1 reply; 8+ messages in thread
From: George Dunlap @ 2016-03-29 10:36 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Ian Jackson, xen-devel, Keir Fraser, David Vrabel, TimDeegan

On Thu, Mar 24, 2016 at 4:19 PM, Jan Beulich <JBeulich@suse.com> wrote:
>>>> On 24.03.16 at 16:55, <david.vrabel@citrix.com> wrote:
>> On 24/03/16 11:30, Jan Beulich wrote:
>>> Recursive locks know their current owner, and since we use the function
>>> solely to determine whether a particular lock is being held by the
>>> current CPU (which so far has been an imprecise check), make actually
>>> check the owner for recusrively acquired locks.
>>
>> What's the expected behaviour of _spin_is_locked() if the lock is held
>> by another CPU?
>>
>> Before it may return true if it is held by another CPU, now it will
>> always return false in this case.
>
> Correct - hence the reference to this only being used for a limited
> set of cases (read: ASSERT()s and alike).

A bunch of the mm locks add "_by_me" at the end of the function.  Did
spin_is_locked() used to have that as well?

In any case I suppose "spin_is_locked_by_someone()" is really pretty
useless information.

 -George

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] spinlock: improve spin_is_locked() for recursive locks
  2016-03-29 10:36     ` George Dunlap
@ 2016-03-29 10:45       ` Jan Beulich
  0 siblings, 0 replies; 8+ messages in thread
From: Jan Beulich @ 2016-03-29 10:45 UTC (permalink / raw)
  To: George Dunlap
  Cc: xen-devel, Keir Fraser, Ian Jackson, David Vrabel, TimDeegan

>>> On 29.03.16 at 12:36, <George.Dunlap@eu.citrix.com> wrote:
> On Thu, Mar 24, 2016 at 4:19 PM, Jan Beulich <JBeulich@suse.com> wrote:
>>>>> On 24.03.16 at 16:55, <david.vrabel@citrix.com> wrote:
>>> On 24/03/16 11:30, Jan Beulich wrote:
>>>> Recursive locks know their current owner, and since we use the function
>>>> solely to determine whether a particular lock is being held by the
>>>> current CPU (which so far has been an imprecise check), make actually
>>>> check the owner for recusrively acquired locks.
>>>
>>> What's the expected behaviour of _spin_is_locked() if the lock is held
>>> by another CPU?
>>>
>>> Before it may return true if it is held by another CPU, now it will
>>> always return false in this case.
>>
>> Correct - hence the reference to this only being used for a limited
>> set of cases (read: ASSERT()s and alike).
> 
> A bunch of the mm locks add "_by_me" at the end of the function.  Did
> spin_is_locked() used to have that as well?

I don't think it did. And I think the only other readily visible use
case of spin_is_locked() (testing whether a spin lock could be
acquired without delay) is bogus anyway, as it would better be
performed by doing a try-lock.

> In any case I suppose "spin_is_locked_by_someone()" is really pretty
> useless information.

Indeed, hence I didn't want to alter the functions' names.

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-03-29 10:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-24 11:30 [PATCH] spinlock: improve spin_is_locked() for recursive locks Jan Beulich
2016-03-24 14:19 ` Dario Faggioli
2016-03-24 14:38 ` Andrew Cooper
2016-03-24 15:55 ` David Vrabel
2016-03-24 16:19   ` Jan Beulich
2016-03-29 10:36     ` George Dunlap
2016-03-29 10:45       ` Jan Beulich
2016-03-25 10:19 ` Xu, Quan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).