public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Brian Gerst <bgerst@didntduck.org>
To: "Tillier, Fabian" <ftillier@infiniconsys.com>
Cc: Greg KH <greg@kroah.com>, "Randy.Dunlap" <rddunlap@osdl.org>,
	sean.hefty@intel.com, linux-kernel@vger.kernel.org,
	hozer@hozed.org, woody@co.intel.com, bill.magro@intel.com,
	woody@jf.intel.com, infiniband-general@lists.sourceforge.net
Subject: Re: [Infiniband-general] Getting an Infiniband access layer in theLinux kernel
Date: Thu, 05 Feb 2004 17:56:37 -0500	[thread overview]
Message-ID: <4022CA25.8070507@didntduck.org> (raw)
In-Reply-To: <08628CA53C6CBA4ABAFB9E808A5214CB01DB96FA@mercury.infiniconsys.com>

Tillier, Fabian wrote:
> Greg,
> 
> I'm not arguing about the spinlocks here, and never have.  I'm arguing
> about the atomic abstraction for the x86 platforms.  My last question
> was not a yes/no question so I'm not sure what you're answering with
> your "No" - your reply makes no sense.  To clarify, the answer to a
> "chose one of two things" question is not "No".  Basic XOR logic is all
> that's needed here.  I'm not sure what you're asking about with the
> whole quotations thing.
> 
> Having atomic operations return a value allows one to do something like
> test for zero when decrementing an atomic variable such as a reference
> count, to determine whether final cleanup should proceed.  This removes
> the need for an actual spinlock protecting the reference count.  As you
> know, reading the value post-decrement does not guarantee that said
> value reflects the result of only that decrement operation.  It would be
> catastrophic if two threads checked the value of a reference count
> without proper synchronization - they could both end up running the
> cleanup code with undesired (and perhaps catastrophic) results.
> 
> I'll try a simple example for you assuming atomic_dec returns the
> decremented value:
> 
> if( atomic_dec( x ) == 0 )
> {
>     cleanup();
> }

I guess you missed this then:
/**
  * atomic_dec_and_test - decrement and test
  * @v: pointer of type atomic_t
  *
  * Atomically decrements @v by 1 and
  * returns true if the result is 0, or false for all other
  * cases.  Note that the guaranteed
  * useful range of an atomic_t is only 24 bits.
  */

There is also atomic_dec_and_lock():
/*
  * This is an architecture-neutral, but slow,
  * implementation of the notion of "decrement
  * a reference count, and return locked if it
  * decremented to zero".
  *
  * NOTE NOTE NOTE! This is _not_ equivalent to
  *
  *      if (atomic_dec_and_test(&atomic)) {
  *              spin_lock(&lock);
  *              return 1;
  *      }
  *      return 0;
  *
  * because the spin-lock and the decrement must be
  * "atomic".
  *
  * This slow version gets the spinlock unconditionally,
  * and releases it if it isn't needed. Architectures
  * are encouraged to come up with better approaches,
  * this is trivially done efficiently using a load-locked
  * store-conditional approach, for example.
  */

--
				Brian Gerst

  reply	other threads:[~2004-02-05 22:57 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-05 22:17 [Infiniband-general] Getting an Infiniband access layer in theLinux kernel Tillier, Fabian
2004-02-05 22:56 ` Brian Gerst [this message]
2004-02-05 22:58 ` Bernd Petrovitsch
  -- strict thread matches above, loose matches on Subject: below --
2004-02-24 17:55 Woodruff, Robert J
2004-02-24 18:03 ` Greg KH
     [not found] <mailman.1076018705.12618.linux-kernel2news@redhat.com>
2004-02-09  1:51 ` Pete Zaitcev
2004-02-08 23:43 Arnd Bergmann
2004-02-08 21:36 Woodruff, Robert J
2004-02-06 16:42 Hefty, Sean
2004-02-06 17:05 ` Richard B. Johnson
2004-02-06 17:23   ` Roland Dreier
2004-02-06 18:00     ` Richard B. Johnson
2004-02-06 18:12       ` Måns Rullgård
2004-02-06 18:13       ` Chris Friesen
2004-02-06 18:22       ` Valdis.Kletnieks
2004-02-06 18:50         ` Richard B. Johnson
2004-02-06 19:02           ` Matti Aarnio
2004-02-06 19:11           ` Petr Vandrovec
2004-02-07  3:05             ` Jamie Lokier
2004-02-06 18:54         ` Måns Rullgård
2004-02-06 19:01     ` somenath
2004-02-06 17:27 ` Troy Benjegerdes
2004-02-06 18:51 ` Greg KH
2004-02-08  8:31   ` Fab Tillier
2004-02-08 16:29     ` Greg KH
2004-02-08 16:51       ` Fab Tillier
2004-02-09  2:55         ` Troy Benjegerdes
2004-02-09  2:57         ` Greg KH
2004-02-06  4:07 Perez-Gonzalez, Inaky
2004-02-05 23:09 Woodruff, Robert J
2004-02-05 22:55 Woodruff, Robert J
2004-02-05 22:54 ` Randy.Dunlap
2004-02-05 22:26 Hefty, Sean
2004-02-05 22:40 ` Christoph Hellwig
2004-02-05 22:39   ` Randy.Dunlap
2004-02-05 23:19 ` Greg KH
2004-02-06  1:10 ` Troy Benjegerdes
2004-02-05 22:02 Tillier, Fabian
2004-02-06  1:57 ` Troy Benjegerdes
2004-02-05 20:32 Tillier, Fabian
2004-02-05 21:27 ` Greg KH
2004-02-05 21:56   ` Chris Friesen
2004-02-06 20:22 ` Bill Davidsen
2004-02-05 19:26 Tillier, Fabian
2004-02-05 20:27 ` Greg KH

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=4022CA25.8070507@didntduck.org \
    --to=bgerst@didntduck.org \
    --cc=bill.magro@intel.com \
    --cc=ftillier@infiniconsys.com \
    --cc=greg@kroah.com \
    --cc=hozer@hozed.org \
    --cc=infiniband-general@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rddunlap@osdl.org \
    --cc=sean.hefty@intel.com \
    --cc=woody@co.intel.com \
    --cc=woody@jf.intel.com \
    /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