This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] benchtests: Add pthread_once common-case test.
- From: Will Newton <will dot newton at linaro dot org>
- To: Siddhesh Poyarekar <siddhesh at redhat dot com>
- Cc: Torvald Riegel <triegel at redhat dot com>, GLIBC Devel <libc-alpha at sourceware dot org>
- Date: Mon, 31 Mar 2014 10:21:24 +0100
- Subject: Re: [PATCH] benchtests: Add pthread_once common-case test.
- Authentication-results: sourceware.org; auth=none
- References: <1381266586 dot 18547 dot 1130 dot camel at triegel dot csb> <20131009020406 dot GQ3178 at spoyarek dot pnq dot redhat dot com>
On 9 October 2013 03:04, Siddhesh Poyarekar <siddhesh@redhat.com> wrote:
> On Wed, Oct 09, 2013 at 12:09:46AM +0300, Torvald Riegel wrote:
>> This adds a benchtest for the common-case scenario for pthread_once.
>>
>> We have a single thread that runs a no-op initialization once and then
>> repeatedly runs checks of the initialization (i.e., an acquire load and
>> conditional jump) in a tight loop. This gives us, on average, the
>> best-case latency of pthread_once (the initialization is the
>> exactly-once slow path, and we're not looking at initialization-related
>> synchronization overheads in this case). I'm adding this to investigate
>> whether we still need the x86-custom pthread_once version written in
>> assembler, or whether we can use the generic version without a
>> performance loss (both use the same algorithm).
>>
>> This needs the other patch that adds the include-sources directive to
>> scripts/bench.pl.
>>
>> OK?
>
>> commit a26cb3d5ffd621b756a951a53bd160811d0f3fae
>> Author: Torvald Riegel <triegel@redhat.com>
>> Date: Tue Oct 8 14:17:01 2013 +0300
>>
>> benchtests: Add pthread_once common-case test.
>>
>> * benchtests/pthread_once-inputs: New file.
>> * benchtests/pthread_once-source.c: New file.
>> * benchtests/README: Update documentation.
>>
>> diff --git a/ChangeLog b/ChangeLog
>> index 1acd57c..61da75c 100644
>> --- a/ChangeLog
>> +++ b/ChangeLog
>> @@ -1,5 +1,11 @@
>> 2013-10-08 Torvald Riegel <triegel@redhat.com>
>>
>> + * benchtests/pthread_once-inputs: New file.
>> + * benchtests/pthread_once-source.c: New file.
>> + * benchtests/README: Update documentation.
>> +
>> +2013-10-08 Torvald Riegel <triegel@redhat.com>
>> +
>> * scripts/bench.pl: Add include-sources directive.
>> * benchtests/README: Update documentation.
>>
>
> You don't need to post ChangeLog diffs here. Also, if you have back
> to back changes on the same day, you could merge the entries by
> leaving a blank line between the change sets like this:
>
> 2013-10-08 Torvald Riegel <triegel@redhat.com>
>
> * benchtests/pthread_once-inputs: New file.
> * benchtests/pthread_once-source.c: New file.
> * benchtests/README: Update documentation.
>
> * scripts/bench.pl: Add include-sources directive.
> * benchtests/README: Update documentation.
>
>> diff --git a/benchtests/Makefile b/benchtests/Makefile
>> index aec395a..2eb1393 100644
>> --- a/benchtests/Makefile
>> +++ b/benchtests/Makefile
>> @@ -20,8 +20,8 @@
>> # Add benchmark functions in alphabetical order.
>>
>> subdir := benchtests
>> -bench := acos acosh asin asinh atan atanh cos cosh exp log modf pow rint sin \
>> - sincos sinh tan tanh
>> +bench := acos acosh asin asinh atan atanh cos cosh exp log modf pow \
>> + pthread_once rint sin sincos sinh tan tanh
>>
>> # String function benchmarks.
>> string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
>> @@ -45,6 +45,7 @@ LDLIBS-bench-cosh = -lm
>> LDLIBS-bench-exp = -lm
>> LDLIBS-bench-log = -lm
>> LDLIBS-bench-pow = -lm
>> +LDLIBS-bench-pthread_once = -lpthread
>> LDLIBS-bench-rint = -lm
>> LDLIBS-bench-sin = -lm
>> LDLIBS-bench-sinh = -lm
>> diff --git a/benchtests/README b/benchtests/README
>> index 0c643a6..9dcbc53 100644
>> --- a/benchtests/README
>> +++ b/benchtests/README
>> @@ -57,6 +57,8 @@ one to add `foo' to the bench tests:
>> - include-sources: This should be assigned a comma-separated list of source
>> files that need to be included to provide definitions of global variables
>> and functions (specifically, this includes using "#include "source").
>> + See pthread_once-inputs and pthreads_once-source.c for an example of how
>> + to use this to benchmark a function that needs state across several calls.
>> - name: See following section for instructions on how to use this directive.
>>
>> Lines beginning with a single hash '#' are treated as comments. See
>> diff --git a/benchtests/pthread_once-inputs b/benchtests/pthread_once-inputs
>> new file mode 100644
>> index 0000000..040bc5c
>> --- /dev/null
>> +++ b/benchtests/pthread_once-inputs
>> @@ -0,0 +1,10 @@
>> +# This tests the common-case scenario for pthread_once.
>> +# We have a single thread that runs a no-op initialization once and then
>> +# repeatedly runs checks of the initialization (i.e., an acquire load and
>> +# conditional jump) in a tight loop.
>> +# scripts/bench.pl doesn't handle function pointers, so we just use void *:
>> +## args: pthread_once_t *:void *
>> +## ret: void
>> +## includes: pthread.h
>> +## include-sources: pthread_once-source.c
>> +&once, once_handler
>> diff --git a/benchtests/pthread_once-source.c b/benchtests/pthread_once-source.c
>> new file mode 100644
>> index 0000000..04e70d6
>> --- /dev/null
>> +++ b/benchtests/pthread_once-source.c
>> @@ -0,0 +1,23 @@
>> +/* Copyright (C) 2013 Free Software Foundation, Inc.
>> + This file is part of the GNU C Library.
>> +
>> + The GNU C Library is free software; you can redistribute it and/or
>> + modify it under the terms of the GNU Lesser General Public
>> + License as published by the Free Software Foundation; either
>> + version 2.1 of the License, or (at your option) any later version.
>> +
>> + The GNU C Library is distributed in the hope that it will be useful,
>> + but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>> + Lesser General Public License for more details.
>> +
>> + You should have received a copy of the GNU Lesser General Public
>> + License along with the GNU C Library; if not, see
>> + <http://www.gnu.org/licenses/>. */
>> +
>> +static pthread_once_t once = PTHREAD_ONCE_INIT;
>> +
>> +static void
>> +once_handler (void)
>> +{
>> +}
>
> I am OK with this patch, but please wait for another review before you
> check this in.
This patch fails to build for me:
/home/will/glibc-build/benchtests/bench-pthread_once.c:34:22: error:
variable or field 'ret' declared void
static void volatile ret;
Removing the "ret" line from the inputs fixes the problem.
--
Will Newton
Toolchain Working Group, Linaro