Blame benchtests/bench-memmove-walk.c

Packit Service 82fcde
/* Measure memmove function combined throughput for different alignments.
Packit Service 82fcde
   Copyright (C) 2017-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
/* This microbenchmark measures the throughput of memmove for various sizes from
Packit Service 82fcde
   1 byte to 32MiB, doubling every iteration and then misaligning by 0-15
Packit Service 82fcde
   bytes.  The copies are done from source to destination and then back and the
Packit Service 82fcde
   source walks forward across the array and the destination walks backward by
Packit Service 82fcde
   one byte each, thus measuring misaligned accesses as well.  The idea is to
Packit Service 82fcde
   avoid caching effects by copying a different string and far enough from each
Packit Service 82fcde
   other, walking in different directions so that we can measure prefetcher
Packit Service 82fcde
   efficiency (software or hardware) more closely than with a loop copying the
Packit Service 82fcde
   same data over and over, which eventually only gives us L1 cache
Packit Service 82fcde
   performance.  */
Packit Service 82fcde
Packit Service 82fcde
#ifndef MEMMOVE_RESULT
Packit Service 82fcde
# define MEMMOVE_RESULT(dst, len) dst
Packit Service 82fcde
# define START_SIZE 128
Packit Service 82fcde
# define MIN_PAGE_SIZE (getpagesize () + 32 * 1024 * 1024)
Packit Service 82fcde
# define TEST_MAIN
Packit Service 82fcde
# define TEST_NAME "memmove"
Packit Service 82fcde
# define TIMEOUT (20 * 60)
Packit Service 82fcde
# include "bench-string.h"
Packit Service 82fcde
Packit Service 82fcde
IMPL (memmove, 1)
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
#include "json-lib.h"
Packit Service 82fcde
Packit Service 82fcde
typedef char *(*proto_t) (char *, const char *, size_t);
Packit Service 82fcde
Packit Service 82fcde
static void
Packit Service 82fcde
do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, char *src,
Packit Service 82fcde
	     size_t len)
Packit Service 82fcde
{
Packit Service 82fcde
  size_t i = 0;
Packit Service 82fcde
  timing_t start, stop, cur;
Packit Service 82fcde
Packit Service 82fcde
  char *dst_end = dst + MIN_PAGE_SIZE - len;
Packit Service 82fcde
  char *src_end = src + MIN_PAGE_SIZE - len;
Packit Service 82fcde
Packit Service 82fcde
  TIMING_NOW (start);
Packit Service 82fcde
  /* Copy the entire buffer backwards, LEN at a time.  */
Packit Service 82fcde
  for (; src_end >= src && dst <= dst_end; dst += len, src_end -= len, i++)
Packit Service 82fcde
    CALL (impl, dst, src_end, len);
Packit Service 82fcde
  TIMING_NOW (stop);
Packit Service 82fcde
Packit Service 82fcde
  TIMING_DIFF (cur, start, stop);
Packit Service 82fcde
Packit Service 82fcde
  /* Get time taken per function call.  */
Packit Service 82fcde
  json_element_double (json_ctx, (double) cur / i);
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
static void
Packit Service 82fcde
do_test (json_ctx_t *json_ctx, size_t len, bool overlap)
Packit Service 82fcde
{
Packit Service 82fcde
  json_element_object_begin (json_ctx);
Packit Service 82fcde
  json_attr_uint (json_ctx, "length", (double) len);
Packit Service 82fcde
  json_array_begin (json_ctx, "timings");
Packit Service 82fcde
Packit Service 82fcde
  if (overlap)
Packit Service 82fcde
    buf2 = buf1;
Packit Service 82fcde
Packit Service 82fcde
  FOR_EACH_IMPL (impl, 0)
Packit Service 82fcde
    do_one_test (json_ctx, impl, (char *) buf2, (char *) buf1, len);
Packit Service 82fcde
Packit Service 82fcde
  json_array_end (json_ctx);
Packit Service 82fcde
  json_element_object_end (json_ctx);
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
int
Packit Service 82fcde
test_main (void)
Packit Service 82fcde
{
Packit Service 82fcde
  json_ctx_t json_ctx;
Packit Service 82fcde
Packit Service 82fcde
  test_init ();
Packit Service 82fcde
Packit Service 82fcde
  json_init (&json_ctx, 0, stdout);
Packit Service 82fcde
Packit Service 82fcde
  json_document_begin (&json_ctx);
Packit Service 82fcde
  json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
Packit Service 82fcde
Packit Service 82fcde
  json_attr_object_begin (&json_ctx, "functions");
Packit Service 82fcde
  json_attr_object_begin (&json_ctx, "memmove");
Packit Service 82fcde
  json_attr_string (&json_ctx, "bench-variant", "walk");
Packit Service 82fcde
Packit Service 82fcde
  json_array_begin (&json_ctx, "ifuncs");
Packit Service 82fcde
  FOR_EACH_IMPL (impl, 0)
Packit Service 82fcde
    json_element_string (&json_ctx, impl->name);
Packit Service 82fcde
  json_array_end (&json_ctx);
Packit Service 82fcde
Packit Service 82fcde
  json_array_begin (&json_ctx, "results");
Packit Service 82fcde
  /* Non-overlapping buffers.  */
Packit Service 82fcde
  for (size_t i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
Packit Service 82fcde
    {
Packit Service 82fcde
      /* Test length alignments from 0-16 bytes.  */
Packit Service 82fcde
      for (int j = 0; j < 8; j++)
Packit Service 82fcde
	{
Packit Service 82fcde
	  do_test (&json_ctx, i + j, false);
Packit Service 82fcde
	  do_test (&json_ctx, i + 16 - j, false);
Packit Service 82fcde
	}
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  /* Overlapping buffers.  */
Packit Service 82fcde
  for (size_t i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
Packit Service 82fcde
    {
Packit Service 82fcde
      /* Test length alignments from 0-16 bytes.  */
Packit Service 82fcde
      for (int j = 0; j < 8; j++)
Packit Service 82fcde
	{
Packit Service 82fcde
	  do_test (&json_ctx, i + j, true);
Packit Service 82fcde
	  do_test (&json_ctx, i + 16 - j, true);
Packit Service 82fcde
	}
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  json_array_end (&json_ctx);
Packit Service 82fcde
  json_attr_object_end (&json_ctx);
Packit Service 82fcde
  json_attr_object_end (&json_ctx);
Packit Service 82fcde
  json_document_end (&json_ctx);
Packit Service 82fcde
Packit Service 82fcde
  return ret;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
#include <support/test-driver.c>