unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: DJ Delorie <dj@redhat.com>
To: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Cc: libc-alpha@sourceware.org, nd@arm.com
Subject: Re: [PATCH] Add malloc micro benchmark
Date: Fri, 08 Feb 2019 14:37:18 -0500	[thread overview]
Message-ID: <xnd0o2cbrl.fsf@greed.delorie.com> (raw)
In-Reply-To: <DB5PR08MB1030A3EB64DA81DB604E140183920@DB5PR08MB1030.eurprd08.prod.outlook.com> (message from Wilco Dijkstra on Fri, 1 Feb 2019 16:27:34 +0000)


Looks good to me, although I'd like some additional comments in the test
code.

Wilco Dijkstra <Wilco.Dijkstra@arm.com> writes:
> -bench-malloc := malloc-thread
> +bench-malloc := malloc-thread malloc-simple

Adding a test, ok

> -$(objpfx)bench-malloc-thread: $(shared-thread-library)
> +$(addprefix $(objpfx)bench-,$(bench-malloc)): $(shared-thread-library)

Accepting a list of tests, ok

> -   malloc-thread
> +   malloc-thread malloc-simple

Adding a test, ok

>  bench-malloc: $(binaries-bench-malloc)
>  	for run in $^; do \
> +	  echo "$${run}"; \
> +	  if [ `basename $${run}` = "bench-malloc-thread" ]; then \
>  		for thr in 1 8 16 32; do \
>  			echo "Running $${run} $${thr}"; \
> -	  $(run-bench) $${thr} > $${run}-$${thr}.out; \
> -	  done;\
> +			$(run-bench) $${thr} > $${run}-$${thr}.out; \
> +		done;\
> +	  else \
> +		for thr in 8 16 32 64 128 256 512 1024 2048 4096; do \
> +		  echo "Running $${run} $${thr}"; \
> +		  $(run-bench) $${thr} > $${run}-$${thr}.out; \
> +		done;\
> +	  fi;\
>  	done

I wonder if this could be done more elegantly, but I'm OK with a simple
approach for now.  If we end up adding many more such tests we might
need to revisit this part.

> +/* Benchmark malloc and free functions.
> +   Copyright (C) 2018 Free Software Foundation, Inc.

2019

> +
> +#include <pthread.h>

I would like to see a comment block somewhere in this code that
describes, to the casual future reader, what this test is looking for
and why it's different than other tests.  I won't hold up my OK for it,
though.

> +#define NUM_ITERS 1000000
> +#define NUM_ALLOCS 4
> +#define MAX_ALLOCS 1600

How long does this test take to run, on average, compared to other
tests?  Do we have to worry about increasing timeouts for slow hosts?

> +static void
> +do_benchmark (malloc_args *args, int **arr)
> +{
> +  timing_t start, stop;
> +  size_t iters = args->iters;
> +  size_t size = args->size;
> +  int n = args->n;
> +
> +  TIMING_NOW (start);
> +
> +  for (int j = 0; j < iters; j++)
> +    {
> +      for (int i = 0; i < n; i++)
> +	arr[i] = malloc (size);
> +
> +      for (int i = 0; i < n; i++)
> +	free (arr[i]);
> +    }
> +
> +  TIMING_NOW (stop);
> +
> +  TIMING_DIFF (args->elapsed, start, stop);
> +}

Simple loop, but doesn't test for malloc returning NULL.

> +  /* Run benchmark single threaded in main_arena.  */
> +  for (int i = 0; i < NUM_ALLOCS; i++)
> +    do_benchmark (&tests[0][i], arr);
> +
> +  /* Run benchmark in a thread_arena.  */
> +  pthread_t t;
> +  pthread_create (&t, NULL, thread_test, (void*)arr);
> +  pthread_join (t, NULL);
> +
> +  /* Repeat benchmark in main_arena with SINGLE_THREAD_P == false.  */
> +  for (int i = 0; i < NUM_ALLOCS; i++)
> +    do_benchmark (&tests[1][i], arr);

So we repeat the "main thread" case but now the heap is "messy" from the
now-joined thread... ok.

  reply	other threads:[~2019-02-08 19:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-01 16:27 [PATCH] Add malloc micro benchmark Wilco Dijkstra
2019-02-08 19:37 ` DJ Delorie [this message]
2019-02-14 16:38   ` Wilco Dijkstra
2019-02-14 20:42     ` DJ Delorie
2019-02-28  4:52 ` Carlos O'Donell
2019-03-04 17:35   ` Wilco Dijkstra
2019-03-18 17:16     ` Wilco Dijkstra
2019-04-09  5:25       ` Carlos O'Donell
  -- strict thread matches above, loose matches on Subject: below --
2017-12-01 13:51 Wilco Dijkstra
2017-12-01 16:13 ` Carlos O'Donell
2017-12-18 15:18   ` Wilco Dijkstra
2017-12-18 16:32     ` Carlos O'Donell
2017-12-18 23:02     ` DJ Delorie
2017-12-28 14:09       ` Wilco Dijkstra
2017-12-28 19:01         ` DJ Delorie

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

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xnd0o2cbrl.fsf@greed.delorie.com \
    --to=dj@redhat.com \
    --cc=Wilco.Dijkstra@arm.com \
    --cc=libc-alpha@sourceware.org \
    --cc=nd@arm.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).