public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh@gotplt.org>
To: Gabriel Staples <ercaguy@gmail.com>, libc-alpha@sourceware.org
Subject: Re: [PATCH] bench-malloc-thread.c: add assert that malloc() is never out of memory
Date: Tue, 6 Jul 2021 19:02:12 +0530	[thread overview]
Message-ID: <5f9dd99f-8d5c-ce19-cde7-0813cebb4188@gotplt.org> (raw)
In-Reply-To: <20210703045845.1610215-1-ercaguy@gmail.com>

On 7/3/21 10:28 AM, Gabriel Staples via Libc-alpha wrote:
> ...so we get realistic speed tests. Also add units to the results
> variables. And Replace tabs w/spaces for consistency, since the file
> was mixed format.

Thanks for helping clean up the benchtests.  I don't know if it's 
mentioned in the guidelines, but the compression of 8 spaces into tabs 
is ubiquitous in the glibc sources so I'd suggest keeping them as is. 
This change is not too large and so should be OK without an FSF 
copyright assignment.

> @@ -137,7 +138,14 @@ malloc_benchmark_loop (void **ptr_arr)
>   
>         free (ptr_arr[next_idx]);
>   
> -      ptr_arr[next_idx] = malloc (next_block);
> +      void* ptr = malloc (next_block);
> +      // allocation time isn't realistic if out of memory, so ensure all allocations succeed
> +      if (ptr == NULL)
> +      {
> +          printf ("Out of memory\n");
> +          assert (ptr != NULL);
> +      }
> +      ptr_arr[next_idx] = ptr;

Instead of the assert, please terminate the test with exit 
(EXIT_FAILURE).  Also, please write the error to stderr and not stdout; 
stdout is for json output.

>   
>         iters++;
>       }
> @@ -199,24 +207,24 @@ do_benchmark (size_t num_threads, size_t *iters)
>         *iters = 0;
>   
>         for (size_t i = 0; i < num_threads; i++)
> -	{
> -	  args[i].working_set = working_set[i];
> -	  pthread_create(&threads[i], NULL, benchmark_thread, &args[i]);
> -	}
> +        {
> +          args[i].working_set = working_set[i];
> +          pthread_create(&threads[i], NULL, benchmark_thread, &args[i]);
> +        }
>   
>         for (size_t i = 0; i < num_threads; i++)
> -	{
> -	  pthread_join(threads[i], NULL);
> -	  TIMING_ACCUM (elapsed, args[i].elapsed);
> -	  *iters += args[i].iters;
> -	}
> +        {
> +          pthread_join(threads[i], NULL);
> +          TIMING_ACCUM (elapsed, args[i].elapsed);
> +          *iters += args[i].iters;
> +        }
>       }
>     return elapsed;
>   }
>   
> -static void usage(const char *name)
> +static void usage(const char *executable_name)
>   {
> -  fprintf (stderr, "%s: <num_threads>\n", name);
> +  fprintf (stderr, "Usage: %s: <num_threads>\n", executable_name);
>     exit (1);
>   }
>   
> @@ -239,7 +247,7 @@ main (int argc, char **argv)
>         ret = strtol(argv[1], NULL, 10);
>   
>         if (errno || ret == 0)
> -	usage(argv[0]);
> +        usage(argv[0]);
>   
>         num_threads = ret;
>       }
> @@ -275,14 +283,18 @@ main (int argc, char **argv)
>     d_total_s = cur;
>     d_total_i = iters;
>   
> -  json_attr_double (&json_ctx, "duration", d_total_s);
> +  // Units for x86 processors are "clock cycles"
> +  json_attr_double (&json_ctx, "duration_clock_cycles", d_total_s);
> +  // each iteration is equal to 1 free + 1 malloc
>     json_attr_double (&json_ctx, "iterations", d_total_i);
> -  json_attr_double (&json_ctx, "time_per_iteration", d_total_s / d_total_i);
> -  json_attr_double (&json_ctx, "max_rss", usage.ru_maxrss);
> -
> -  json_attr_double (&json_ctx, "threads", num_threads);
> -  json_attr_double (&json_ctx, "min_size", MIN_ALLOCATION_SIZE);
> -  json_attr_double (&json_ctx, "max_size", MAX_ALLOCATION_SIZE);
> +  // Units for x86 processors are "clock cycles"
> +  json_attr_double (&json_ctx, "time_per_iteration_clock_cycles", d_total_s / d_total_i);
> +  // Maximum resident set size (in kilobytes)
> +  json_attr_double (&json_ctx, "max_rss_kb", usage.ru_maxrss);
> +
> +  json_attr_double (&json_ctx, "num_threads", num_threads);
> +  json_attr_double (&json_ctx, "min_allocation_size_bytes)", MIN_ALLOCATION_SIZE);
> +  json_attr_double (&json_ctx, "max_allocation_size_bytes)", MAX_ALLOCATION_SIZE);
>     json_attr_double (&json_ctx, "random_seed", RAND_SEED);
>   
>     json_attr_object_end (&json_ctx);
> 

Renaming the size is OK to disambiguate, but the time ones are not; 
there may be architectures where the time unit is not clock cycles.

Thanks,
Siddhesh

      reply	other threads:[~2021-07-06 13:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-03  4:58 Gabriel Staples
2021-07-06 13:32 ` Siddhesh Poyarekar [this message]

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

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

  git send-email \
    --in-reply-to=5f9dd99f-8d5c-ce19-cde7-0813cebb4188@gotplt.org \
    --to=siddhesh@gotplt.org \
    --cc=ercaguy@gmail.com \
    --cc=libc-alpha@sourceware.org \
    /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).