|
Packit Service |
82fcde |
/* Measure string and memory functions.
|
|
Packit Service |
82fcde |
Copyright (C) 2013-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 |
#include <getopt.h>
|
|
Packit Service |
82fcde |
#include <sys/cdefs.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* We are compiled under _ISOMAC, so libc-symbols.h does not do this
|
|
Packit Service |
82fcde |
for us. */
|
|
Packit Service |
82fcde |
#include "config.h"
|
|
Packit Service |
82fcde |
#ifdef HAVE_CC_INHIBIT_LOOP_TO_LIBCALL
|
|
Packit Service |
82fcde |
# define inhibit_loop_to_libcall \
|
|
Packit Service |
82fcde |
__attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns")))
|
|
Packit Service |
82fcde |
#else
|
|
Packit Service |
82fcde |
# define inhibit_loop_to_libcall
|
|
Packit Service |
82fcde |
#endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
typedef struct
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
const char *name;
|
|
Packit Service |
82fcde |
void (*fn) (void);
|
|
Packit Service |
82fcde |
long test;
|
|
Packit Service |
82fcde |
} impl_t;
|
|
Packit Service |
82fcde |
extern impl_t __start_impls[], __stop_impls[];
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define IMPL(name, test) \
|
|
Packit Service |
82fcde |
impl_t tst_ ## name \
|
|
Packit Service |
82fcde |
__attribute__ ((section ("impls"), aligned (sizeof (void *)))) \
|
|
Packit Service |
82fcde |
= { __STRING (name), (void (*) (void))name, test };
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#ifdef TEST_MAIN
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
# ifndef _GNU_SOURCE
|
|
Packit Service |
82fcde |
# define _GNU_SOURCE
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
# undef __USE_STRING_INLINES
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
# include <stdio.h>
|
|
Packit Service |
82fcde |
# include <stdlib.h>
|
|
Packit Service |
82fcde |
# include <string.h>
|
|
Packit Service |
82fcde |
# include <sys/mman.h>
|
|
Packit Service |
82fcde |
# include <sys/param.h>
|
|
Packit Service |
82fcde |
# include <unistd.h>
|
|
Packit Service |
82fcde |
# include <fcntl.h>
|
|
Packit Service |
82fcde |
# include <error.h>
|
|
Packit Service |
82fcde |
# include <errno.h>
|
|
Packit Service |
82fcde |
# include <time.h>
|
|
Packit Service |
82fcde |
# include <ifunc-impl-list.h>
|
|
Packit Service |
82fcde |
# define GL(x) _##x
|
|
Packit Service |
82fcde |
# define GLRO(x) _##x
|
|
Packit Service |
82fcde |
# include "bench-timing.h"
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
# define TEST_FUNCTION test_main
|
|
Packit Service |
82fcde |
# ifndef TIMEOUT
|
|
Packit Service |
82fcde |
# define TIMEOUT (4 * 60)
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
# define OPT_ITERATIONS 10000
|
|
Packit Service |
82fcde |
# define OPT_RANDOM 10001
|
|
Packit Service |
82fcde |
# define OPT_SEED 10002
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
# define INNER_LOOP_ITERS 64
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
unsigned char *buf1, *buf2;
|
|
Packit Service |
82fcde |
int ret, do_srandom;
|
|
Packit Service |
82fcde |
unsigned int seed;
|
|
Packit Service |
82fcde |
size_t page_size;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
# ifndef ITERATIONS
|
|
Packit Service |
82fcde |
size_t iterations = 100000;
|
|
Packit Service |
82fcde |
# define ITERATIONS_OPTIONS \
|
|
Packit Service |
82fcde |
{ "iterations", required_argument, NULL, OPT_ITERATIONS },
|
|
Packit Service |
82fcde |
# define ITERATIONS_PROCESS \
|
|
Packit Service |
82fcde |
case OPT_ITERATIONS: \
|
|
Packit Service |
82fcde |
iterations = strtoul (optarg, NULL, 0); \
|
|
Packit Service |
82fcde |
break;
|
|
Packit Service |
82fcde |
# define ITERATIONS iterations
|
|
Packit Service |
82fcde |
# else
|
|
Packit Service |
82fcde |
# define ITERATIONS_OPTIONS
|
|
Packit Service |
82fcde |
# define ITERATIONS_PROCESS
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
# define CMDLINE_OPTIONS ITERATIONS_OPTIONS \
|
|
Packit Service |
82fcde |
{ "random", no_argument, NULL, OPT_RANDOM }, \
|
|
Packit Service |
82fcde |
{ "seed", required_argument, NULL, OPT_SEED },
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static void __attribute__ ((used))
|
|
Packit Service |
82fcde |
cmdline_process_function (int c)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
switch (c)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
ITERATIONS_PROCESS
|
|
Packit Service |
82fcde |
case OPT_RANDOM:
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
int fdr = open ("/dev/urandom", O_RDONLY);
|
|
Packit Service |
82fcde |
if (fdr < 0 || read (fdr, &seed, sizeof(seed)) != sizeof (seed))
|
|
Packit Service |
82fcde |
seed = time (NULL);
|
|
Packit Service |
82fcde |
if (fdr >= 0)
|
|
Packit Service |
82fcde |
close (fdr);
|
|
Packit Service |
82fcde |
do_srandom = 1;
|
|
Packit Service |
82fcde |
break;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
case OPT_SEED:
|
|
Packit Service |
82fcde |
seed = strtoul (optarg, NULL, 0);
|
|
Packit Service |
82fcde |
do_srandom = 1;
|
|
Packit Service |
82fcde |
break;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
# define CMDLINE_PROCESS cmdline_process_function
|
|
Packit Service |
82fcde |
# define CALL(impl, ...) \
|
|
Packit Service |
82fcde |
(* (proto_t) (impl)->fn) (__VA_ARGS__)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
# ifdef TEST_NAME
|
|
Packit Service |
82fcde |
/* Increase size of FUNC_LIST if assert is triggered at run-time. */
|
|
Packit Service |
82fcde |
static struct libc_ifunc_impl func_list[32];
|
|
Packit Service |
82fcde |
static int func_count;
|
|
Packit Service |
82fcde |
static int impl_count = -1;
|
|
Packit Service |
82fcde |
static impl_t *impl_array;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
# define FOR_EACH_IMPL(impl, notall) \
|
|
Packit Service |
82fcde |
impl_t *impl; \
|
|
Packit Service |
82fcde |
int count; \
|
|
Packit Service |
82fcde |
if (impl_count == -1) \
|
|
Packit Service |
82fcde |
{ \
|
|
Packit Service |
82fcde |
impl_count = 0; \
|
|
Packit Service |
82fcde |
if (func_count != 0) \
|
|
Packit Service |
82fcde |
{ \
|
|
Packit Service |
82fcde |
int f; \
|
|
Packit Service |
82fcde |
impl_t *skip = NULL, *a; \
|
|
Packit Service |
82fcde |
for (impl = __start_impls; impl < __stop_impls; ++impl) \
|
|
Packit Service |
82fcde |
if (strcmp (impl->name, TEST_NAME) == 0) \
|
|
Packit Service |
82fcde |
skip = impl; \
|
|
Packit Service |
82fcde |
else \
|
|
Packit Service |
82fcde |
impl_count++; \
|
|
Packit Service |
82fcde |
a = impl_array = malloc ((impl_count + func_count) * \
|
|
Packit Service |
82fcde |
sizeof (impl_t)); \
|
|
Packit Service |
82fcde |
for (impl = __start_impls; impl < __stop_impls; ++impl) \
|
|
Packit Service |
82fcde |
if (impl != skip) \
|
|
Packit Service |
82fcde |
*a++ = *impl; \
|
|
Packit Service |
82fcde |
for (f = 0; f < func_count; f++) \
|
|
Packit Service |
82fcde |
if (func_list[f].usable) \
|
|
Packit Service |
82fcde |
{ \
|
|
Packit Service |
82fcde |
a->name = func_list[f].name; \
|
|
Packit Service |
82fcde |
a->fn = func_list[f].fn; \
|
|
Packit Service |
82fcde |
a->test = 1; \
|
|
Packit Service |
82fcde |
a++; \
|
|
Packit Service |
82fcde |
} \
|
|
Packit Service |
82fcde |
impl_count = a - impl_array; \
|
|
Packit Service |
82fcde |
} \
|
|
Packit Service |
82fcde |
else \
|
|
Packit Service |
82fcde |
{ \
|
|
Packit Service |
82fcde |
impl_count = __stop_impls - __start_impls; \
|
|
Packit Service |
82fcde |
impl_array = __start_impls; \
|
|
Packit Service |
82fcde |
} \
|
|
Packit Service |
82fcde |
} \
|
|
Packit Service |
82fcde |
impl = impl_array; \
|
|
Packit Service |
82fcde |
for (count = 0; count < impl_count; ++count, ++impl) \
|
|
Packit Service |
82fcde |
if (!notall || impl->test)
|
|
Packit Service |
82fcde |
# else /* !TEST_NAME */
|
|
Packit Service |
82fcde |
# define FOR_EACH_IMPL(impl, notall) \
|
|
Packit Service |
82fcde |
for (impl_t *impl = __start_impls; impl < __stop_impls; ++impl) \
|
|
Packit Service |
82fcde |
if (!notall || impl->test)
|
|
Packit Service |
82fcde |
# endif /* !TEST_NAME */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
# ifndef BUF1PAGES
|
|
Packit Service |
82fcde |
# define BUF1PAGES 1
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static void
|
|
Packit Service |
82fcde |
alloc_bufs (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
page_size = 2 * getpagesize ();
|
|
Packit Service |
82fcde |
# ifdef MIN_PAGE_SIZE
|
|
Packit Service |
82fcde |
if (page_size < MIN_PAGE_SIZE)
|
|
Packit Service |
82fcde |
page_size = MIN_PAGE_SIZE;
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
buf1 = mmap (0, (BUF1PAGES + 1) * page_size, PROT_READ | PROT_WRITE,
|
|
Packit Service |
82fcde |
MAP_PRIVATE | MAP_ANON, -1, 0);
|
|
Packit Service |
82fcde |
if (buf1 == MAP_FAILED)
|
|
Packit Service |
82fcde |
error (EXIT_FAILURE, errno, "mmap failed for buf1");
|
|
Packit Service |
82fcde |
if (mprotect (buf1 + BUF1PAGES * page_size, page_size, PROT_NONE))
|
|
Packit Service |
82fcde |
error (EXIT_FAILURE, errno, "mprotect failed for buf1");
|
|
Packit Service |
82fcde |
buf2 = mmap (0, 2 * page_size, PROT_READ | PROT_WRITE,
|
|
Packit Service |
82fcde |
MAP_PRIVATE | MAP_ANON, -1, 0);
|
|
Packit Service |
82fcde |
if (buf2 == MAP_FAILED)
|
|
Packit Service |
82fcde |
error (EXIT_FAILURE, errno, "mmap failed for buf2");
|
|
Packit Service |
82fcde |
if (mprotect (buf2 + page_size, page_size, PROT_NONE))
|
|
Packit Service |
82fcde |
error (EXIT_FAILURE, errno, "mprotect failed for buf2");
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static void
|
|
Packit Service |
82fcde |
__attribute__ ((unused))
|
|
Packit Service |
82fcde |
realloc_bufs (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
int ret = 0;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (buf1)
|
|
Packit Service |
82fcde |
ret = munmap (buf1, (BUF1PAGES + 1) * page_size);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (ret != 0)
|
|
Packit Service |
82fcde |
error (EXIT_FAILURE, errno, "munmap failed for buf1");
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (buf2)
|
|
Packit Service |
82fcde |
ret = munmap (buf2, 2 * page_size);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (ret != 0)
|
|
Packit Service |
82fcde |
error (EXIT_FAILURE, errno, "munmap failed for buf2");
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
alloc_bufs ();
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static void
|
|
Packit Service |
82fcde |
test_init (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
# ifdef TEST_NAME
|
|
Packit Service |
82fcde |
func_count = __libc_ifunc_impl_list (TEST_NAME, func_list,
|
|
Packit Service |
82fcde |
(sizeof func_list
|
|
Packit Service |
82fcde |
/ sizeof func_list[0]));
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
alloc_bufs ();
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (do_srandom)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
printf ("Setting seed to 0x%x\n", seed);
|
|
Packit Service |
82fcde |
srandom (seed);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#endif /* TEST_MAIN */
|