[PATCH v2 2/5] benchtests: Add memset zero fill benchtest
Noah Goldstein
goldstein.w.n@gmail.com
Mon Jul 26 17:22:11 GMT 2021
On Mon, Jul 26, 2021 at 4:39 AM naohirot@fujitsu.com <naohirot@fujitsu.com>
wrote:
> Hi Noah,
>
> > I see. I think 16 for the inner loop makes sense. From the x86_64
> > perspective this
> > will keep the loop from running out of the LSD which is necessary for
> > accurate
> > benchmarking. I guess then somewhere between [2, 8] is reasonable for the
> > outer
> > loop?
> >
> >
> > > #define START_SIZE (16 * 1024)
> > > ...
> > > static void
> > > __attribute__((noinline, noclone))
> > > do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
> > > int c1 __attribute ((unused)), int c2 __attribute
> ((unused)),
> > > size_t n)
> > > {
> > > size_t i, j, iters = INNER_LOOP_ITERS; // 32;
> > > timing_t start, stop, cur, latency = 0;
> > >
> > > for (i = 0; i < 512; i++) // for (i = 0; i < 2; i++)
> > > {
> > >
> > > CALL (impl, s, c1, n * 16);
> > > TIMING_NOW (start);
> > > for (j = 0; j < 16; j++)
> > > CALL (impl, s + n * j, c2, n);
> > > TIMING_NOW (stop);
> > > TIMING_DIFF (cur, start, stop);
> > > TIMING_ACCUM (latency, cur);
> > > }
> > >
> > This looks good. But as you said, a much smaller value for outer loop.
>
> I made one improvement that replaced
> CALL (impl, s, c1, n * 16);
> to
> __builtin_memset (s, c1, n * 16);
> and tentatively chose outer loop two times such as the followings:
>
> -----
> static void
> __attribute__((noinline, noclone))
> do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
> int c1 __attribute ((unused)), int c2 __attribute ((unused)),
> size_t n)
> {
> size_t i, j, iters = 32;
> timing_t start, stop, cur, latency = 0;
>
> for (i = 0; i < 2; i++)
> {
> __builtin_memset (s, c1, n * 16);
> TIMING_NOW (start);
> for (j = 0; j < 16; j++)
> CALL (impl, s + n * j, c2, n);
> TIMING_NOW (stop);
> TIMING_DIFF (cur, start, stop);
> TIMING_ACCUM (latency, cur);
> }
>
> json_element_double (json_ctx, (double) latency / (double) iters);
> }
>
Looks good!
> -----
>
In case of __memset_generic on a64fx, execution of outer loop 8times
> and 2times took as follows:
>
> 8times
> real 0m26.236s
> user 0m18.806s
> sys 0m6.562s
>
> 2times
> real 0m12.956s
> user 0m5.081s
> sys 0m6.594s
>
> The performance difference is shown in a comparison graph [1],
> there is a difference at 16KB.
> This difference would not be critical if we use the performance data
> mainly to compare "before" with "after" such as master version of
> memset with patched version of memset.
>
>
> This graph[1] can be drawn as the following:
>
> $ cat 2times/bench-memset-zerofill.out 8times/bench-memset-zerofill.out | \
> > merge_strings4graph.sh __memset_generic 2times 8times | \
> > plot_strings.py -l -p thru -v -
>
>
> In order to use __builtin_memset() and create the comparison graph [1],
> I submitted two ground work patches [2][3].
>
> [1]
> https://drive.google.com/file/d/1vD1VE3pdHLoYdaAMWXtImvDlGFDHYkyx/view?usp=sharing
> [2] https://sourceware.org/pipermail/libc-alpha/2021-July/129459.html
> [3] https://sourceware.org/pipermail/libc-alpha/2021-July/129460.html
>
> Thanks.
> Naohiro
>
More information about the Libc-alpha
mailing list