From: peterz@infradead.org
To: Guo Ren <guoren@kernel.org>
Cc: Ren Guo <ren_guo@c-sky.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
linux-csky@vger.kernel.org, mathieu.desnoyers@efficios.com,
Will Deacon <will@kernel.org>
Subject: Re: csky: smp_mb__after_spinlock
Date: Fri, 7 Aug 2020 10:12:53 +0200 [thread overview]
Message-ID: <20200807081253.GD2674@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <CAJF2gTRqi-HuxJsMOjHTpaf33f1L9LypF-FkWo8OZm4SP12Hnw@mail.gmail.com>
On Fri, Aug 07, 2020 at 08:22:36AM +0800, Guo Ren wrote:
> Hi Peter,
>
> On Thu, Aug 6, 2020 at 3:53 AM <peterz@infradead.org> wrote:
> >
> > Hi,
> >
> > While doing an audit of smp_mb__after_spinlock, I found that csky
> > defines it, why?
> >
> > CSKY only has smp_mb(), it doesn't override __atomic_acquire_fence or
> > otherwise special cases it's atomic*_acquire() primitives. It has an
> > explicit smp_mb() in its arch_spin_lock().
>
> Yes, csky didn't implement ACQUIRE/RELEASE in spinlock.h. So it is a
> redundant and side-effect wrong macro, we should remove it to fixup.
>
> TODO:
> - implement csky's ACQUIRE/RELEASE barrier
Fair enough; please Cc me when you get to it.
> > Also, why have two implementations of all the locking?
>
> I just kept my baby's codes :P. Now, we could remove it and just keep
> the ticket's one.
>
> BTW, I want to change the spinlock to qspinlock, but csky only has
> 32-bit atomic operation in hardware.
Yeah, that's okay, you can do 'short' atomics using wider RmW.
> Any plan to deal with this in spinlock?
>
> Maybe for the embedded scenario, qspinlock seems a bit heavy,
I tend to agree, qspinlock only really makes sense when you have
multiple cache domains and NUMA makes it shine.
> are any
> tickets-like comm spinlock infrastructures in the plan?
No. ticket locks are 'simple' and their implementation fairly straight
forward. Also, since the generic code only has cmpxchg, a generic ticket
lock would be sub-optimal on LL/SC (or even x86 for that matter).
It would look something like this, which I think is pretty terrible for
just about any arch compared to what you can do with inline asm.
struct ticket_lock {
union {
atomic_t val;
struct {
#ifdef __LITTLE_ENDIAN
u16 head;
u16 tail;
#else
u16 tail;
u16 head;
#endif
};
};
};
void ticket_lock(struct ticket_lock *lock)
{
unsigned int val = atomic_read(&lock->val);
struct ticket_lock lock;
do {
lock.val = ATOMIC_INIT(val);
lock.head++;
} while (!atomic_try_cmpxchg_relaxed(&lock->lock, &val, lock.val));
atomic_cond_read_acquire(&lock->val, (VAL >> 16) == lock.head);
}
void ticket_unlock(struct ticket_lock *lock)
{
atomic_fetch_inc_release(&lock->val);
}
prev parent reply other threads:[~2020-08-07 8:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-05 10:41 csky: smp_mb__after_spinlock peterz
2020-08-05 10:44 ` peterz
2020-08-07 0:23 ` Guo Ren
2020-08-07 0:22 ` Guo Ren
2020-08-07 8:12 ` peterz [this message]
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=20200807081253.GD2674@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=guoren@kernel.org \
--cc=linux-csky@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=ren_guo@c-sky.com \
--cc=will@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