mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* atomic_inc and spin_lock_irq
@ 2014-12-18 21:07 Rogelio M. Serrano Jr.
  2014-12-18 22:04 ` Mihai Donțu
  2014-12-23  2:08 ` PaX Team
  0 siblings, 2 replies; 3+ messages in thread
From: Rogelio M. Serrano Jr. @ 2014-12-18 21:07 UTC (permalink / raw)
  To: linux-kernel, PaX Team

whats the difference between:

atomic_inc(&port->count);

and

spin_lock_irq(&port->lock);
++port->count;
spin_unlock_irq(&port->lock);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: atomic_inc and spin_lock_irq
  2014-12-18 21:07 atomic_inc and spin_lock_irq Rogelio M. Serrano Jr.
@ 2014-12-18 22:04 ` Mihai Donțu
  2014-12-23  2:08 ` PaX Team
  1 sibling, 0 replies; 3+ messages in thread
From: Mihai Donțu @ 2014-12-18 22:04 UTC (permalink / raw)
  To: Rogelio M. Serrano Jr.; +Cc: linux-kernel, pageexec

On Thu, 18 Dec 2014 21:07:46 +0000 Rogelio M. Serrano Jr. wrote:
> whats the difference between:
> 
> atomic_inc(&port->count);

It is intended to atomically increment a variable of a standard size
(int/long). See [1] for more information.

> and
> 
> spin_lock_irq(&port->lock);
> ++port->count;
> spin_unlock_irq(&port->lock);

These are intended to be used when larger changes are to be made in an
atomic fashion (not just increments). See [2] for details and [3] for
an example.

[1] https://en.wikipedia.org/wiki/Fetch-and-add
[2] http://lxr.free-electrons.com/source/include/linux/spinlock_api_smp.h#L104
[3] http://lxr.free-electrons.com/source/arch/x86/mm/mmio-mod.c#L265

-- 
Mihai Donțu

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: atomic_inc and spin_lock_irq
  2014-12-18 21:07 atomic_inc and spin_lock_irq Rogelio M. Serrano Jr.
  2014-12-18 22:04 ` Mihai Donțu
@ 2014-12-23  2:08 ` PaX Team
  1 sibling, 0 replies; 3+ messages in thread
From: PaX Team @ 2014-12-23  2:08 UTC (permalink / raw)
  To: linux-kernel, rogelio.serrano

On 18 Dec 2014 at 21:07, Rogelio M. Serrano Jr. wrote:

> whats the difference between:
> 
> atomic_inc(&port->count);
> 
> and
> 
> spin_lock_irq(&port->lock);
> ++port->count;
> spin_unlock_irq(&port->lock);

in PaX this kind of change brings the ->count accesses under the coverage
of the REFCOUNT feature. if the kernel had a non-atomic refcount type and
corresponding accessors, they'd be used here instead.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-12-23  2:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-18 21:07 atomic_inc and spin_lock_irq Rogelio M. Serrano Jr.
2014-12-18 22:04 ` Mihai Donțu
2014-12-23  2:08 ` PaX Team

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®