public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Usage semantics of atomic_set ( )
@ 2008-01-11 22:57 Vineet Gupta
  2008-01-11 23:16 ` Roland Dreier
  2008-01-12  1:37 ` Chris Snook
  0 siblings, 2 replies; 4+ messages in thread
From: Vineet Gupta @ 2008-01-11 22:57 UTC (permalink / raw)
  To: linux-kernel

I'm trying to implement atomic ops for a CPU which has no inherent
support for Read-Modify-Write Ops. Instead of using a global spin lock
which protects all the atomic APIs, I want to use a spin lock per
instance of atomic_t. This works well when atomic_t is unitary and
statically initialized using ATOMIC_INIT (where I can reset the
spinlock_t as well). However if atomic_t var is embedded within a
bigger struct which is allocated dynamically how to I init the
embedded spin lock. atomic_set ( ) is the closest choice, however I
don't think it's current usage in kernel code qualifies it to be
"initializer only".

Doesn't that defeat the intended usage of atomic_t as a opaque type
which can be "effectively" used to hide other architecture specific
stuff.

Thanks,
Vineet

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

* Re: Usage semantics of atomic_set ( )
  2008-01-11 22:57 Usage semantics of atomic_set ( ) Vineet Gupta
@ 2008-01-11 23:16 ` Roland Dreier
  2008-01-12  1:37 ` Chris Snook
  1 sibling, 0 replies; 4+ messages in thread
From: Roland Dreier @ 2008-01-11 23:16 UTC (permalink / raw)
  To: Vineet Gupta; +Cc: linux-kernel

 > I'm trying to implement atomic ops for a CPU which has no inherent
 > support for Read-Modify-Write Ops. Instead of using a global spin lock
 > which protects all the atomic APIs, I want to use a spin lock per
 > instance of atomic_t. This works well when atomic_t is unitary and
 > statically initialized using ATOMIC_INIT (where I can reset the
 > spinlock_t as well). However if atomic_t var is embedded within a
 > bigger struct which is allocated dynamically how to I init the
 > embedded spin lock. atomic_set ( ) is the closest choice, however I
 > don't think it's current usage in kernel code qualifies it to be
 > "initializer only".

A simple way to handle this might be to use a separate array of
spinlocks and hash each atomic_t to one entry in the array.  You could
look in asm-parisc and arch/parisc to see an implementation of this
that is already in the kernel.

 - R.

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

* Re: Usage semantics of atomic_set ( )
  2008-01-11 22:57 Usage semantics of atomic_set ( ) Vineet Gupta
  2008-01-11 23:16 ` Roland Dreier
@ 2008-01-12  1:37 ` Chris Snook
  2008-01-12 18:36   ` Vineet Gupta
  1 sibling, 1 reply; 4+ messages in thread
From: Chris Snook @ 2008-01-12  1:37 UTC (permalink / raw)
  To: Vineet Gupta; +Cc: linux-kernel

Vineet Gupta wrote:
> I'm trying to implement atomic ops for a CPU which has no inherent
> support for Read-Modify-Write Ops. Instead of using a global spin lock
> which protects all the atomic APIs, I want to use a spin lock per
> instance of atomic_t.

What operations are you using to implement spinlocks?

A few architectures use arrays of spinlocks to implement atomic_t.  I believe 
sparc and parisc are among them.  Assuming your spinlock implementation is sound 
and efficient, the same technique should work for you.

	-- Chris

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

* Re: Usage semantics of atomic_set ( )
  2008-01-12  1:37 ` Chris Snook
@ 2008-01-12 18:36   ` Vineet Gupta
  0 siblings, 0 replies; 4+ messages in thread
From: Vineet Gupta @ 2008-01-12 18:36 UTC (permalink / raw)
  To: Chris Snook; +Cc: linux-kernel

> What operations are you using to implement spinlocks?

The cpu provides atomic exchange instruction (atomic Read/write
semantics) which forms the back end of spin lock code.
__raw_spin_trylock( ) atomically swaps the lock memory with a reg (set
to 1)

Using a pool of spinlocks rather that original idea of spinlock per
atomic_t anyways seems to be a better idea.
I really appreciate the responses. Thanks a lot

-Vineet

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

end of thread, other threads:[~2008-01-12 18:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-11 22:57 Usage semantics of atomic_set ( ) Vineet Gupta
2008-01-11 23:16 ` Roland Dreier
2008-01-12  1:37 ` Chris Snook
2008-01-12 18:36   ` Vineet Gupta

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