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, tim@xen.org, jbeulich@suse.com,
Boris Ostrovsky <boris.ostrovsky@oracle.com>
Subject: [PATCH v1 6/9] spinlock: Introduce spin_lock_cb()
Date: Fri, 24 Mar 2017 13:05:01 -0400 [thread overview]
Message-ID: <1490375104-15450-7-git-send-email-boris.ostrovsky@oracle.com> (raw)
In-Reply-To: <1490375104-15450-1-git-send-email-boris.ostrovsky@oracle.com>
While waiting for a lock we may want to periodically run some
code. We could use spin_trylock() but since it doesn't take lock
ticket it may take a long time until the lock is taken.
Add spin_lock_cb() that allows us to execute a callback while waiting.
Also add spin_lock_kick() that will wake up the waiters.
Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
---
xen/common/spinlock.c | 20 ++++++++++++++++++++
xen/include/xen/spinlock.h | 3 +++
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c
index 2a06406..d1de3ca 100644
--- a/xen/common/spinlock.c
+++ b/xen/common/spinlock.c
@@ -129,6 +129,26 @@ static always_inline u16 observe_head(spinlock_tickets_t *t)
return read_atomic(&t->head);
}
+void _spin_lock_cb(spinlock_t *lock, void (*cb)(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;
+ if ( cb )
+ cb(data);
+ arch_lock_relax();
+ }
+ LOCK_PROFILE_GOT;
+ preempt_disable();
+ arch_lock_acquire_barrier();
+}
+
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..1cd91b7 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);
+void _spin_lock_cb(spinlock_t *lock, void (*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_cb(l, c, d) _spin_lock_cb(l, c, d)
+#define spin_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
next prev parent reply other threads:[~2017-03-24 17:05 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-24 17:04 [PATCH v1 0/9] Memory scrubbing from idle loop Boris Ostrovsky
2017-03-24 17:04 ` [PATCH v1 1/9] mm: Separate free page chunk merging into its own routine Boris Ostrovsky
2017-03-27 15:16 ` Wei Liu
2017-03-27 16:03 ` Jan Beulich
2017-03-27 16:28 ` Boris Ostrovsky
2017-03-28 7:27 ` Jan Beulich
2017-03-28 19:20 ` Wei Liu
2017-03-28 19:41 ` Boris Ostrovsky
2017-03-28 19:44 ` Wei Liu
2017-03-28 19:57 ` Boris Ostrovsky
2017-03-24 17:04 ` [PATCH v1 2/9] mm: Place unscrubbed pages at the end of pagelist Boris Ostrovsky
2017-03-28 19:27 ` Wei Liu
2017-03-28 19:46 ` Boris Ostrovsky
2017-03-24 17:04 ` [PATCH v1 3/9] mm: Scrub pages in alloc_heap_pages() if needed Boris Ostrovsky
2017-03-28 19:43 ` Wei Liu
2017-03-24 17:04 ` [PATCH v1 4/9] mm: Scrub memory from idle loop Boris Ostrovsky
2017-03-28 20:01 ` Wei Liu
2017-03-28 20:14 ` Boris Ostrovsky
2017-03-24 17:05 ` [PATCH v1 5/9] mm: Do not discard already-scrubbed pages if softirqs are pending Boris Ostrovsky
2017-03-29 10:22 ` Wei Liu
2017-03-24 17:05 ` Boris Ostrovsky [this message]
2017-03-29 10:28 ` [PATCH v1 6/9] spinlock: Introduce spin_lock_cb() Wei Liu
2017-03-29 13:47 ` Boris Ostrovsky
2017-03-29 14:07 ` Boris Ostrovsky
2017-03-24 17:05 ` [PATCH v1 7/9] mm: Keep pages available for allocation while scrubbing Boris Ostrovsky
2017-03-24 17:05 ` [PATCH v1 8/9] mm: Print number of unscrubbed pages in 'H' debug handler Boris Ostrovsky
2017-03-28 20:11 ` Wei Liu
2017-03-24 17:05 ` [PATCH v1 9/9] mm: Make sure pages are scrubbed Boris Ostrovsky
2017-03-29 10:39 ` Wei Liu
2017-03-29 16:25 ` Wei Liu
2017-03-29 16:35 ` Boris Ostrovsky
2017-03-29 16:45 ` Wei Liu
2017-03-29 17:12 ` 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=1490375104-15450-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.org \
--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).