From: Peter Zijlstra <peterz@infradead.org>
To: Vineet Gupta <Vineet.Gupta1@synopsys.com>
Cc: lkml <linux-kernel@vger.kernel.org>, arc-linux-dev@synopsys.com
Subject: Re: [PATCH 3/6] ARC: LLOCK/SCOND based spin_lock
Date: Mon, 3 Aug 2015 13:29:30 +0200 [thread overview]
Message-ID: <20150803112930.GI25159@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1438596188-10875-4-git-send-email-vgupta@synopsys.com>
On Mon, Aug 03, 2015 at 03:33:05PM +0530, Vineet Gupta wrote:
> EX causes the cache line to be in Exclusive state and if done
> concurrently by multiple cores, it keeps bouncing around.
> In LLOCK/SCOND regime, spinning only involves LLOCK which doesn't
> change the line state hence better solution.
Maybe write like:
"The EXchange instruction forces the cacheline into exclusive state
(because of the modify) and concurrent loops with it will bounce the
cacheline between the cores
Instead use LLOCK/SCOND to form the test-and-set lock implementation
since LLOCK can keep the line in shared state."
Because it wasn't clear to me what EX meant, and surely a LOAD must
change the cacheline state of it previously was in exclusive on another
core. Its just that shared is a whole lot better to spin on than
exclusive.
Also, since you're using LL/SC now, a slightly more complex lock is
trivial to implement, might I suggest you look at implementing ticket
locks next?
> Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
> Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
> ---
> arch/arc/include/asm/spinlock.h | 76 +++++++++++++++++++++++++++++++++++++----
> 1 file changed, 69 insertions(+), 7 deletions(-)
>
> diff --git a/arch/arc/include/asm/spinlock.h b/arch/arc/include/asm/spinlock.h
> index e1651df6a93d..4f6c90a0a68a 100644
> --- a/arch/arc/include/asm/spinlock.h
> +++ b/arch/arc/include/asm/spinlock.h
> @@ -18,9 +18,68 @@
> #define arch_spin_unlock_wait(x) \
> do { while (arch_spin_is_locked(x)) cpu_relax(); } while (0)
>
> +#ifdef CONFIG_ARC_HAS_LLSC
> +
> +static inline void arch_spin_lock(arch_spinlock_t *lock)
> +{
> + unsigned int val;
> +
> + smp_mb();
I'm still puzzled by your need of this one ...
> +
> + __asm__ __volatile__(
> + "1: llock %[val], [%[slock]] \n"
> + " breq %[val], %[LOCKED], 1b \n" /* spin while LOCKED */
> + " scond %[LOCKED], [%[slock]] \n" /* acquire */
> + " bnz 1b \n"
> + " \n"
> + : [val] "=&r" (val)
> + : [slock] "r" (&(lock->slock)),
> + [LOCKED] "r" (__ARCH_SPIN_LOCK_LOCKED__)
> + : "memory", "cc");
> +
> + smp_mb();
> +}
> +
> +/* 1 - lock taken successfully */
> +static inline int arch_spin_trylock(arch_spinlock_t *lock)
> +{
> + unsigned int val, got_it = 0;
> +
> + smp_mb();
Idem.
> +
> + __asm__ __volatile__(
> + "1: llock %[val], [%[slock]] \n"
> + " breq %[val], %[LOCKED], 4f \n" /* already LOCKED, just bail */
> + " scond %[LOCKED], [%[slock]] \n" /* acquire */
> + " bnz 1b \n"
> + " mov %[got_it], 1 \n"
> + "4: \n"
> + " \n"
> + : [val] "=&r" (val),
> + [got_it] "+&r" (got_it)
> + : [slock] "r" (&(lock->slock)),
> + [LOCKED] "r" (__ARCH_SPIN_LOCK_LOCKED__)
> + : "memory", "cc");
> +
> + smp_mb();
> +
> + return got_it;
> +}
> +
> +static inline void arch_spin_unlock(arch_spinlock_t *lock)
> +{
> + smp_mb();
> +
> + lock->slock = __ARCH_SPIN_LOCK_UNLOCKED__;
> +
> + smp_mb();
Idem.
> +}
> +
> +#else /* !CONFIG_ARC_HAS_LLSC */
next prev parent reply other threads:[~2015-08-03 11:29 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-03 10:03 [PATCH 0/6] ARC: spinlocks/atomics rework Vineet Gupta
2015-08-03 10:03 ` [PATCH 1/6] Revert "ARCv2: STAR 9000837815 workaround hardware exclusive transactions livelock" Vineet Gupta
2015-08-03 10:03 ` [PATCH 2/6] ARC: refactor atomic inline asm operands with symbolic names Vineet Gupta
2015-08-03 10:03 ` [PATCH 3/6] ARC: LLOCK/SCOND based spin_lock Vineet Gupta
2015-08-03 11:29 ` Peter Zijlstra [this message]
2015-08-03 11:44 ` Vineet Gupta
2015-08-03 10:03 ` [PATCH 4/6] ARC: LLOCK/SCOND based rwlock Vineet Gupta
2015-08-03 11:33 ` Peter Zijlstra
2015-08-03 11:51 ` Vineet Gupta
2015-08-03 10:03 ` [PATCH 5/6] ARCv2: spinlock/rwlock/atomics: Delayed retry of failed SCOND with exponential backoff Vineet Gupta
2015-08-03 11:41 ` Peter Zijlstra
2015-08-03 13:01 ` Vineet Gupta
2015-08-03 13:50 ` Vineet Gupta
2015-08-03 14:08 ` Peter Zijlstra
2015-08-03 11:50 ` Peter Zijlstra
2015-08-03 13:02 ` Vineet Gupta
2015-08-03 13:06 ` Peter Zijlstra
2015-08-03 10:03 ` [PATCH 6/6] ARCv2: spinlock/rwlock: Reset retry delay when starting a new spin-wait cycle Vineet Gupta
2015-08-03 11:43 ` Peter Zijlstra
2015-08-03 14:40 ` Vineet Gupta
2015-08-03 14:42 ` Peter Zijlstra
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=20150803112930.GI25159@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=Vineet.Gupta1@synopsys.com \
--cc=arc-linux-dev@synopsys.com \
--cc=linux-kernel@vger.kernel.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