From: Josh Triplett on
On Mon, Apr 05, 2010 at 03:10:57PM -0400, Mathieu Desnoyers wrote:
> * Randy Dunlap (randy.dunlap(a)oracle.com) wrote:
> > On Mon, 5 Apr 2010 13:57:37 -0400 Mathieu Desnoyers wrote:
> > > +/*
> > > + * sys_membarrier - issue memory barrier on current process running threads
> > > + * @flags: One of these must be set:
> > > + * MEMBARRIER_EXPEDITED
> > > + * Adds some overhead, fast execution (few microseconds)
> > > + * MEMBARRIER_DELAYED
> > > + * Low overhead, but slow execution (few milliseconds)
> > > + *
> > > + * MEMBARRIER_QUERY
> > > + * This optional flag can be set to query if the kernel supports
> > > + * a set of flags.
> > > + *
> > > + * return values: Returns -EINVAL if the flags are incorrect. Testing for kernel
> > > + * sys_membarrier support can be done by checking for -ENOSYS return value.
> > > + * Return values >= 0 indicate success. For a given set of flags on a given
> > > + * kernel, this system call will always return the same value. It is therefore
> > > + * correct to check the return value only once at library load, passing the
> >
> > library load assumes caller is a library? does the kernel care about that?
>
> Nope, it doesn't. Will rephrase:
>
> ... It is therefore
> * correct to check the return value only once during a process lifetime,
> * passing the MEMBARRIER_QUERY flag in addition to only check if the flags are
> * supported, without performing any synchronization.

Technically you can optimize even more than "process lifetime", since as
you said the results hold "For a given set of flags on a given kernel".
So you could check once and use the results as long as you remain on the
same running system. (Craziness like live process migration and
checkpoint/restart aside. :) )

- Josh Triplett
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Paul E. McKenney on
On Mon, Apr 05, 2010 at 01:23:55PM -0700, Randy Dunlap wrote:
> Paul E. McKenney wrote:
> > On Mon, Apr 05, 2010 at 03:10:57PM -0400, Mathieu Desnoyers wrote:
> >> * Randy Dunlap (randy.dunlap(a)oracle.com) wrote:
> >>> On Mon, 5 Apr 2010 13:57:37 -0400 Mathieu Desnoyers wrote:
> >
> > [ . . . ]
> >
> >>>> +#else /* #ifdef CONFIG_SMP */
> >>> I don't know that we have a known convention for that, but I would use:
> >>>
> >>> #else /* not CONFIG_SMP */
> >>>
> >>> or
> >>>
> >>> #else /* !CONFIG_SMP */
> >>>
> >>>> +
> >>>> +SYSCALL_DEFINE1(membarrier, unsigned int, flags)
> >>>> +{
> >>>> + return 0;
> >>>> +}
> >>>> +
> >>>> +#endif /* #else #ifdef CONFIG_SMP */
>
> or just:
>
> #endif /* #else #ifdef CONFIG_SMP : tell the reader that the #else part of the #ifdef CONFIG_SMP just ended */
>
> ad nauseum.

You lost me on this one.

> >>> and:
> >>>
> >>> #endif /* CONFIG_SMP */
> >>>
> >>> The "#else #ifdef" is both ugly and too wordy IMO.
> >
> > The extra words make it very clear that we are in at the end of the #else
> > clause of a #ifdef with the given condition. With "#endif /* CONFIG_SMP
> > */", is the immediately preceding code compiled under CONFIG_SMP or
> > !CONFIG_SMP? You have to dig back and see whether or not there is a
> > #else clause.
> >
> > But there is no accounting for taste. ;-)
>
> IYHO.

Indeed, in both directions.

Thanx, Paul
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/