LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* atomic_t and atomic_inc
@ 2004-04-22 18:58 Al Niessner
  2004-04-22 20:50 ` Richard B. Johnson
  0 siblings, 1 reply; 3+ messages in thread
From: Al Niessner @ 2004-04-22 18:58 UTC (permalink / raw)
  To: linux-kernel


First, I am not subscribed to this list so please reply to me directly
if you wish a timely response to any questions. In any case, I will lurk
in the archives for responses.

I am using atomic_t to count interrupts from some piece of hardware.
These interrupts come at a fairly high rate -- 10 KHz and higher. The
problem is, will I get increment problem at the limit of atomic_t or
will it wrap around without error? I read the docs (man pages, on-line
api docs, this list and other stuff) and none of them talk about the
behavior of atomic_t at the boundaries. Furthermore, am I guaranteed of
any boundary behavior across platforms?

Thank you in advance for any and all help.

-- 
Al Niessner <Al.Niessner@jpl.nasa.gov>
Jet Propulsion Laboratory

All opinions stated above are mine and do not necessarily reflect 
those of JPL or NASA.

 ----
| dS | >= 0
 ----


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

* Re: atomic_t and atomic_inc
  2004-04-22 18:58 atomic_t and atomic_inc Al Niessner
@ 2004-04-22 20:50 ` Richard B. Johnson
  2004-05-15 22:54   ` Jamie Lokier
  0 siblings, 1 reply; 3+ messages in thread
From: Richard B. Johnson @ 2004-04-22 20:50 UTC (permalink / raw)
  To: Al Niessner; +Cc: linux-kernel

On Thu, 22 Apr 2004, Al Niessner wrote:

>
> First, I am not subscribed to this list so please reply to me directly
> if you wish a timely response to any questions. In any case, I will lurk
> in the archives for responses.
>
> I am using atomic_t to count interrupts from some piece of hardware.
> These interrupts come at a fairly high rate -- 10 KHz and higher. The
> problem is, will I get increment problem at the limit of atomic_t or
> will it wrap around without error? I read the docs (man pages, on-line
> api docs, this list and other stuff) and none of them talk about the
> behavior of atomic_t at the boundaries. Furthermore, am I guaranteed of
> any boundary behavior across platforms?
>
> Thank you in advance for any and all help.

Type atomic_t is an integer that can be accessed in memory
with an uninterruptible instruction. This limits the atomic_t
type in 32-bit machines to 32-bits, in 64-bit machines to 64-bits,
etc. It has nothing to do with wrap-around. If you increment
0xffffffff it becomes 0 even it it's an atomic type.

In an ISR, the code won't be interrupted until you enable interrupts,
which you shouldn't do anyway. This means that even non-atomic types
are safe, even in SMP machines if the increment is after a spin-lock.

So, you can use 'long long' types for interrupt counters and no
information will be lost until you wrap 0xffffffffffffffff, which
will take quite some time. The problem remains, however, in
reading this value. You need to either read it under a spinlock
or read several times until you get the same value twice in a row.

Spin-locks are easier.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5557.45 BogoMips).
            Note 96.31% of all statistics are fiction.



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

* Re: atomic_t and atomic_inc
  2004-04-22 20:50 ` Richard B. Johnson
@ 2004-05-15 22:54   ` Jamie Lokier
  0 siblings, 0 replies; 3+ messages in thread
From: Jamie Lokier @ 2004-05-15 22:54 UTC (permalink / raw)
  To: Richard B. Johnson; +Cc: Al Niessner, linux-kernel

Richard B. Johnson wrote:
> Type atomic_t is an integer that can be accessed in memory
> with an uninterruptible instruction. This limits the atomic_t
> type in 32-bit machines to 32-bits, in 64-bit machines to 64-bits,
> etc. It has nothing to do with wrap-around. If you increment
> 0xffffffff it becomes 0 even it it's an atomic type.

Note that atomic_t used to be 24 bits on Sparc.  It isn't any more, though.

-- Jame

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

end of thread, other threads:[~2004-05-15 22:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-22 18:58 atomic_t and atomic_inc Al Niessner
2004-04-22 20:50 ` Richard B. Johnson
2004-05-15 22:54   ` Jamie Lokier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).