xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Boris Ostrovsky <boris.ostrovsky@oracle.com>
To: xen-devel@lists.xen.org
Cc: sstabellini@kernel.org, wei.liu2@citrix.com,
	George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com,
	ian.jackson@eu.citrix.com, jbeulich@suse.com, tim@xen.orgc,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>
Subject: [PATCH RFC 6/8] spinlock: Introduce _spin_lock_cond()
Date: Sun, 26 Feb 2017 19:22:38 -0500	[thread overview]
Message-ID: <1488154960-2826-7-git-send-email-boris.ostrovsky@oracle.com> (raw)
In-Reply-To: <1488154960-2826-1-git-send-email-boris.ostrovsky@oracle.com>

Because _spin_trylock() doesn't take lock ticket it may take a
long time until the lock is taken.

Add _spin_lock_cond() that waits for the lock while periodically
checking condition that may cause the lock request to be dropped.

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
---
 xen/common/spinlock.c      |   25 +++++++++++++++++++++++++
 xen/include/xen/spinlock.h |    3 +++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c
index 2a06406..4fd46e5 100644
--- a/xen/common/spinlock.c
+++ b/xen/common/spinlock.c
@@ -129,6 +129,31 @@ static always_inline u16 observe_head(spinlock_tickets_t *t)
     return read_atomic(&t->head);
 }
 
+int _spin_lock_cond(spinlock_t *lock, bool_t (*cond)(void *), void *data)
+{
+    spinlock_tickets_t tickets = SPINLOCK_TICKET_INC;
+    LOCK_PROFILE_VAR;
+
+    check_lock(&lock->debug);
+    tickets.head_tail = arch_fetch_and_add(&lock->tickets.head_tail,
+                                           tickets.head_tail);
+    while ( tickets.tail != observe_head(&lock->tickets) )
+    {
+        LOCK_PROFILE_BLOCK;
+        arch_lock_relax();
+        if ( cond && !cond(data) )
+        {
+            add_sized(&lock->tickets.head, 1);
+            arch_lock_signal();
+            return 0;
+        }
+    }
+    LOCK_PROFILE_GOT;
+    preempt_disable();
+    arch_lock_acquire_barrier();
+    return 1;
+}
+
 void _spin_lock(spinlock_t *lock)
 {
     spinlock_tickets_t tickets = SPINLOCK_TICKET_INC;
diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h
index c1883bd..b8bf72a 100644
--- a/xen/include/xen/spinlock.h
+++ b/xen/include/xen/spinlock.h
@@ -153,6 +153,7 @@ typedef struct spinlock {
 #define spin_lock_init(l) (*(l) = (spinlock_t)SPIN_LOCK_UNLOCKED)
 
 void _spin_lock(spinlock_t *lock);
+int _spin_lock_cond(spinlock_t *lock, bool_t (*cond)(void *), void *data);
 void _spin_lock_irq(spinlock_t *lock);
 unsigned long _spin_lock_irqsave(spinlock_t *lock);
 
@@ -169,6 +170,8 @@ void _spin_lock_recursive(spinlock_t *lock);
 void _spin_unlock_recursive(spinlock_t *lock);
 
 #define spin_lock(l)                  _spin_lock(l)
+#define spin_lock_cond(l, c, d)       _spin_lock_cond(l, c, d)
+#define spink_lock_kick(l)            arch_lock_signal()
 #define spin_lock_irq(l)              _spin_lock_irq(l)
 #define spin_lock_irqsave(l, f)                                 \
     ({                                                          \
-- 
1.7.1


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

  parent reply	other threads:[~2017-02-27  0:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-27  0:22 [PATCH RFC 0/8] Memory scrubbing from idle loop Boris Ostrovsky
2017-02-27  0:22 ` [PATCH RFC 1/8] mm: Separate free page chunk merging into its own routine Boris Ostrovsky
2017-02-27  0:22 ` [PATCH RFC 2/8] mm: Place unscrubbed pages at the end of pagelist Boris Ostrovsky
2017-02-27  0:22 ` [PATCH RFC 3/8] mm: Scrub pages in alloc_heap_pages() if needed Boris Ostrovsky
2017-02-27  0:22 ` [PATCH RFC 4/8] mm: Scrub memory from idle loop Boris Ostrovsky
2017-02-27  0:22 ` [PATCH RFC 5/8] mm: Do not discard already-scrubbed pages softirqs are pending Boris Ostrovsky
2017-02-27  0:22 ` Boris Ostrovsky [this message]
2017-02-27  0:22 ` [PATCH RFC 7/8] mm: Keep pages available for allocation while scrubbing Boris Ostrovsky
2017-02-27  0:22 ` [PATCH RFC 8/8] mm: Print number of unscrubbed pages in 'H' debug handler Boris Ostrovsky

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=1488154960-2826-7-git-send-email-boris.ostrovsky@oracle.com \
    --to=boris.ostrovsky@oracle.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.orgc \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.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 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).