public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Antoine Tenart <antoine.tenart@free-electrons.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 01/10] arm: add atomic functions with return support
Date: Thu, 27 Oct 2016 15:28:45 +0200	[thread overview]
Message-ID: <20161027132845.2i3dn4iqnb72epp4@kwain> (raw)
In-Reply-To: <20161026151354.GA22713@leverpostej>

HI Mark,

On Wed, Oct 26, 2016 at 04:14:31PM +0100, Mark Rutland wrote:
> On Wed, Oct 26, 2016 at 02:10:24PM +0200, Antoine Tenart wrote:
> > Implement three atomic functions to allow making an atomic operation
> > that returns the value. Adds: atomic_add_return(), atomic_sub_return(),
> > atomic_inc_return() and atomic_dec_return().
> > 
> > Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
> 
> In the cover letter, you mentioned that these are needed for SMP
> systems (for managing common suspend entry/exit management).
> 
> The below operations are *not* atomic in SMP systems, and can only work
> in UP. The same is true of all the existing code in the same file.

That's what I feared...

> > +static inline int atomic_add_return(int i, volatile atomic_t *v)
> > +{
> > +	unsigned long flags = 0;
> > +	int ret;
> > +
> > +	local_irq_save(flags);
> > +	ret = (v->counter += i);
> > +	local_irq_restore(flags);
> > +
> > +	return ret;
> > +}
> 
> local_irq_{save,restore}() won't serialize two CPUs. Consider two CPUs
> executing this in parallel (assuming the compiler chooses a register rX
> as a temporary):
> 
> 	CPU0				CPU1
> 
> 	local_irq_save()		local_irq_save()
> 	rX = v->counter			rX = v->counter
> 	rX += i				rX += i
> 	v->counter = rX
> 					v->counter = rX
> 	local_irq_restore()		local_irq_restore()
> 
> At the end of this, CPU0's increment of v->counter is lost.
> 
> If you need atomics on SMP, you'll need to use the
> {load,store}-exclusive instructions, which come with a number of
> additional requirements (e.g. the memory being operated on must be
> mapped as write-back cacheable, the entire retry loop needs to be
> writtten in asm, etc).

Thanks a lot for the review and for the explanation.

So I need to do something like what's done in the kernel, at
http://lxr.free-electrons.com/source/arch/arm/include/asm/atomic.h#L60
for ARM; by using ldrex and strex.

Thanks,

Antoine

-- 
Antoine T?nart, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161027/baec227b/attachment.sig>

  reply	other threads:[~2016-10-27 13:28 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-26 12:10 [U-Boot] [PATCH v3 00/10] sunxi: sun5/7i: add the psci suspend function Antoine Tenart
2016-10-26 12:10 ` [U-Boot] [PATCH v3 01/10] arm: add atomic functions with return support Antoine Tenart
2016-10-26 15:14   ` Mark Rutland
2016-10-27 13:28     ` Antoine Tenart [this message]
2016-10-26 12:10 ` [U-Boot] [PATCH v3 02/10] ARM: add the ARM_GIC configuration option Antoine Tenart
2016-10-26 12:10 ` [U-Boot] [PATCH v3 03/10] sunxi: select ARM_GIC for sun[6789]i Antoine Tenart
2016-10-26 12:10 ` [U-Boot] [PATCH v3 04/10] ARM: select ARM_GIC for SoCs having a psci implementation Antoine Tenart
2016-10-26 12:10 ` [U-Boot] [PATCH v3 05/10] exynos: select ARM_GIC for TARGET_ARNDALE Antoine Tenart
2016-10-26 12:10 ` [U-Boot] [PATCH v3 06/10] tegra: select ARM_GIC for Tegra TK1s Antoine Tenart
2016-10-26 14:55   ` Stephen Warren
2016-10-26 14:59     ` Antoine Tenart
2016-10-26 15:01       ` Stephen Warren
2016-10-27 13:13         ` Antoine Tenart
2016-10-26 12:10 ` [U-Boot] [PATCH v3 07/10] ARM: PSCI: protect GIC specific code with ARM_GIC Antoine Tenart
2016-10-26 12:10 ` [U-Boot] [PATCH v3 08/10] sun5/7i: add an implementation of the psci suspend function Antoine Tenart
2016-10-26 12:38   ` Maxime Ripard
2016-10-27 13:10     ` Antoine Tenart
2016-10-27 13:20       ` Maxime Ripard
2016-10-27 13:32         ` Antoine Tenart
2016-10-27 13:21       ` Chen-Yu Tsai
2016-10-27 13:41         ` Antoine Tenart
2016-10-27 13:56           ` Chen-Yu Tsai
2016-10-26 12:10 ` [U-Boot] [PATCH v3 09/10] sun5i: add defines used by the PSCI code Antoine Tenart
2016-10-26 12:34   ` Maxime Ripard
2016-10-27 13:04     ` Antoine Tenart
2016-10-26 12:10 ` [U-Boot] [PATCH v3 10/10] sun5i: boot in non-secure mode by default Antoine Tenart

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=20161027132845.2i3dn4iqnb72epp4@kwain \
    --to=antoine.tenart@free-electrons.com \
    --cc=u-boot@lists.denx.de \
    /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