public inbox for libc-ports@sourceware.org
 help / color / mirror / Atom feed
From: Maxim Kuvyrkov <maxim@codesourcery.com>
To: Torvald Riegel <triegel@redhat.com>
Cc: Roland McGrath <roland@hack.frob.com>,
	Andrew Haley <aph@redhat.com>,	David Miller <davem@davemloft.net>,
	"Joseph S. Myers"	<joseph@codesourcery.com>,
	Richard Sandiford <rdsandiford@googlemail.com>,
	<libc-ports@sourceware.org>,
	GLIBC Devel <libc-alpha@sourceware.org>,
	Chris Metcalf <cmetcalf@tilera.com>
Subject: Re: [PATCH] Unify pthread_spin_[try]lock implementations.
Date: Wed, 22 Aug 2012 23:16:00 -0000	[thread overview]
Message-ID: <47032406-D3C9-4383-BD8E-0DC1E92E10BA@codesourcery.com> (raw)
In-Reply-To: <1345112457.3083.217.camel@triegel.csb>

On 16/08/2012, at 10:20 PM, Torvald Riegel wrote:

> On Wed, 2012-08-15 at 15:16 +1200, Maxim Kuvyrkov wrote:
>> On 26/07/2012, at 6:13 AM, Roland McGrath wrote: 
>>> /* Machine-dependent rationale about the selection of this value.  */
>>> #define SPIN_LOCK_READS_BETWEEN_CMPXCHG 1000
> 
> This looks like an arbitrary choice.

It is.

>  I don't want to complain about
> this patch (whose goal is to just unify similar code), but let me use it
> as an example.
> Elsewhere in the thread, you (IIRC) mentioned that the assumption is
> that a CAS is 100x slower than a load. IMO, this is a flawed assumption.
> First, this has more dimensions than one instruction being slower than
> another one: cache architecture, what other threads are doing and where
> in the cache hierarchy/graph they are, the CAS HW implementation, etc.
> Second, it's not really about the slow-down for the current thread when
> executing a CAS; it's about what the CAS might do in terms of caching
> and the latency at which you detect a free lock on ARM, as Andrew Haley
> pointed out.  Third, not all machines in an architecture are similar; a
> P4 cmpxchg performs much differently to a cmpxchg on a recent x86 CPU.
> Fourth, there's no test for this assumption.

This are good arguments.

> 
> So, we will have to make such assumptions, but how do we make sure that
> they are reasonable, and remain reasonable over time?  If we don't,
> these will bit-rot, and performance might degrade over time (assuming
> that the assumptions were initially correct, which might be hard in the
> first place).  Is there a plan for this yet, or discussion about this?

The usual way how this kind of problem is solved in a free software project is that the current [arbitrary] constant causes a bottleneck on some application.  Then someone who cares about that application will investigate the problem and come to the mailing list with specific measurements and specific arguments why this constant should change.  If those arguments are reasonable and general enough, then the community will accept the change.  Then the cycle will continue.

In my opinion, really solving the heck out of a problem such as this one is not worthwhile.  I'm happy with the approximate solution that we arrived to, but I certainly encourage anyone who thinks that this is not good enough to step up and fix it for real and forever.

> 
>>> while Teil will use -1.
> 
> Is there a plan to include a back-off component in this generic spin
> lock?  (-1 would spin forever, but not do back-off.)

No.

Thank you,

--
Maxim Kuvyrkov
CodeSourcery / Mentor Graphics

  parent reply	other threads:[~2012-08-22 23:16 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-14  4:36 [PATCH 2/3, MIPS] Rewrite MIPS' pthread_spin_[try]lock using __atomic_* builtins Maxim Kuvyrkov
2012-06-28 23:10 ` Joseph S. Myers
2012-07-11  5:58   ` [PATCH] Unify pthread_spin_[try]lock implementations Maxim Kuvyrkov
2012-07-11  8:15     ` Roland McGrath
2012-07-11  8:25       ` David Miller
2012-07-11  8:44         ` Andrew Haley
2012-07-11  8:54           ` Maxim Kuvyrkov
2012-07-11  9:02             ` Andrew Haley
2012-07-11  9:05               ` Maxim Kuvyrkov
2012-07-11 11:22                 ` Roland McGrath
2012-07-11 14:52                   ` Chris Metcalf
2012-07-11 22:16                   ` Maxim Kuvyrkov
2012-07-25 18:13                     ` Roland McGrath
2012-07-25 19:04                       ` Chris Metcalf
2012-07-25 20:22                         ` Roland McGrath
2012-07-25 20:29                           ` Chris Metcalf
2012-07-25 20:43                             ` Roland McGrath
2012-08-15  3:17                       ` Maxim Kuvyrkov
2012-08-15 16:27                         ` Roland McGrath
2012-08-15 16:39                           ` Maxim Kuvyrkov
2012-08-15 16:44                             ` Roland McGrath
2012-08-15 16:53                               ` Maxim Kuvyrkov
2012-08-15 16:56                                 ` Roland McGrath
2012-08-15 17:05                                   ` Maxim Kuvyrkov
2012-08-15 17:05                             ` Jeff Law
2012-08-15 17:11                               ` Roland McGrath
2012-08-15 17:24                                 ` Jeff Law
2012-08-15 16:40                         ` Joseph S. Myers
2012-08-15 16:43                         ` Carlos O'Donell
2012-08-15 22:00                         ` Andreas Schwab
2012-08-16 10:21                         ` Torvald Riegel
2012-08-16 12:40                           ` Chris Metcalf
2012-08-22 23:16                           ` Maxim Kuvyrkov [this message]
2012-07-11  8:26       ` Maxim Kuvyrkov

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=47032406-D3C9-4383-BD8E-0DC1E92E10BA@codesourcery.com \
    --to=maxim@codesourcery.com \
    --cc=aph@redhat.com \
    --cc=cmetcalf@tilera.com \
    --cc=davem@davemloft.net \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=libc-ports@sourceware.org \
    --cc=rdsandiford@googlemail.com \
    --cc=roland@hack.frob.com \
    --cc=triegel@redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).