[cpp-threads] Belated comments on dependency-based orderingproposal

Lawrence Crowl Lawrence at Crowl.org
Thu Sep 20 01:18:05 BST 2007


On 9/19/07, Paul E. McKenney <paulmck at linux.vnet.ibm.com> wrote:
> On Wed, Sep 19, 2007 at 03:38:10PM -0700, Lawrence Crowl wrote:
> > On 9/19/07, Paul E. McKenney <paulmck at linux.vnet.ibm.com> wrote:
> > >         In this
> > >         case, the called function would have annotated its return value,
> > >         and it seems to me that the compiler would have to distinguish
> > >         between these two cases, terminating the dependency chain if
> > >         the head of the chain is an atomic load that is lexically within
> > >         the function, and propagating it (via explicit memory fence if
> > >         need be) if the local head of the chain is instead an annotated
> > >         return value from a called function.
> >
> > Things got fuzzy on me here.  In f(h(a)) where f and h have annotated
> > arguments and h has an annotated return, you are worried that there
> > might be an implicit conversion, and the actual code is f(g(h(a))) where
> > g has neither annotation.  Why doesn't the code get protected by a
> > fence before the call to g?
> >
> > (I admit that we have a subtle performance implication here, but that
> > is more the result of implicit conversions than of the dependences.)
>
> We are thinking of different cases.  Here is what I was considering:
>
>         [[dependency_propagate]] foo_t *h(void)
>         {
>                 return x.load(memory_order_dependency);
>         }
>
>         int f(void)
>         {
>                 implicitly_converted_from_foo_t *p;
>
>                 p = h();
>                 return(p->data);
>         }

Isn't the principle the same?  The argument for the unannotated
function forces a fence.

>
> The compiler would convert the assignment in f() to something like:
>
>         p = implicit_conversion_from_foo_t(h());
>
> If the conversion was a library function, then I am advocating that the
> compiler do the following transformation instead, given that it can see
> the return-value annotation:
>
>         foo_t temp1 = h();
>         atomic_fence(memory_order_acquire);
>         p = implicit_conversion_from_foo_t(temp1);
>
> Of course, if the conversion function were annotated, there would
> be no need for the fence, since the conversion function would then
> be known to preserve dependency chains.
>
> Seem reasonable?

Yes, though I note that we've lost the object we're supposed to do
the fence upon.  I don't know how much if any of a problem that
imposes given that the fence is implicit.

> And I presume that I should get new document numbers from Clark
> and revise to suit?

Probably, but we might want to wait on submitting a revision until
we've had time to sit in the same room and talk through a few
examples.

-- 
Lawrence Crowl



More information about the cpp-threads mailing list