[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v1 6/9] spinlock: Introduce spin_lock_cb()
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@xxxxxxxxxx> --- 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@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |