blob: 9419b944220f6fc85f9b9593cce81639e7097cad [file] [log] [blame]
Hitoshi Mitake827f3b42009-11-18 00:20:09 +09001/*
2 * mem-memcpy.c
3 *
Ingo Molnar13839ec2015-10-19 10:04:17 +02004 * Simple memcpy() and memset() benchmarks
Hitoshi Mitake827f3b42009-11-18 00:20:09 +09005 *
6 * Written by Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
7 */
Hitoshi Mitake827f3b42009-11-18 00:20:09 +09008
9#include "../perf.h"
10#include "../util/util.h"
11#include "../util/parse-options.h"
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090012#include "../util/header.h"
Yann Droneaud57480d22014-06-30 22:28:47 +020013#include "../util/cloexec.h"
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090014#include "bench.h"
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +090015#include "mem-memcpy-arch.h"
Rabin Vincent5bce1a52014-12-02 16:50:40 +010016#include "mem-memset-arch.h"
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090017
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <sys/time.h>
22#include <errno.h>
23
24#define K 1024
25
Ingo Molnara69b4f72015-10-19 10:04:25 +020026static const char *size_str = "1MB";
Ingo Molnar2f211c82015-10-19 10:04:29 +020027static const char *function_str = "all";
Ingo Molnarb0d22e52015-10-19 10:04:28 +020028static int nr_loops = 1;
Ingo Molnarb14f2d32015-10-19 10:04:23 +020029static bool use_cycles;
30static int cycles_fd;
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090031
32static const struct option options[] = {
Ingo Molnarb0d22e52015-10-19 10:04:28 +020033 OPT_STRING('s', "size", &size_str, "1MB",
Ingo Molnara69b4f72015-10-19 10:04:25 +020034 "Specify the size of the memory buffers. "
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020035 "Available units: B, KB, MB, GB and TB (case insensitive)"),
36
Ingo Molnar2f211c82015-10-19 10:04:29 +020037 OPT_STRING('f', "function", &function_str, "all",
38 "Specify the function to run, \"all\" runs all available functions, \"help\" lists them"),
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020039
Ingo Molnarb0d22e52015-10-19 10:04:28 +020040 OPT_INTEGER('l', "nr_loops", &nr_loops,
41 "Specify the number of loops to run. (default: 1)"),
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020042
Ingo Molnarb14f2d32015-10-19 10:04:23 +020043 OPT_BOOLEAN('c', "cycles", &use_cycles,
44 "Use a cycles event instead of gettimeofday() to measure performance"),
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020045
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090046 OPT_END()
47};
48
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +090049typedef void *(*memcpy_t)(void *, const void *, size_t);
Rabin Vincent5bce1a52014-12-02 16:50:40 +010050typedef void *(*memset_t)(void *, int, size_t);
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +090051
Ingo Molnar2f211c82015-10-19 10:04:29 +020052struct function {
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090053 const char *name;
54 const char *desc;
Rabin Vincent308197b2014-12-02 16:50:39 +010055 union {
56 memcpy_t memcpy;
Rabin Vincent5bce1a52014-12-02 16:50:40 +010057 memset_t memset;
Rabin Vincent308197b2014-12-02 16:50:39 +010058 } fn;
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090059};
60
Hitoshi Mitake17d7a112012-07-02 22:46:17 +090061static struct perf_event_attr cycle_attr = {
Hitoshi Mitake12eac0b2009-11-20 12:37:17 +090062 .type = PERF_TYPE_HARDWARE,
63 .config = PERF_COUNT_HW_CPU_CYCLES
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090064};
65
Ingo Molnarb14f2d32015-10-19 10:04:23 +020066static void init_cycles(void)
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090067{
Ingo Molnarb14f2d32015-10-19 10:04:23 +020068 cycles_fd = sys_perf_event_open(&cycle_attr, getpid(), -1, -1, perf_event_open_cloexec_flag());
Hitoshi Mitake12eac0b2009-11-20 12:37:17 +090069
Ingo Molnarb14f2d32015-10-19 10:04:23 +020070 if (cycles_fd < 0 && errno == ENOSYS)
Hitoshi Mitake12eac0b2009-11-20 12:37:17 +090071 die("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
72 else
Ingo Molnarb14f2d32015-10-19 10:04:23 +020073 BUG_ON(cycles_fd < 0);
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090074}
75
Ingo Molnarb14f2d32015-10-19 10:04:23 +020076static u64 get_cycles(void)
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090077{
78 int ret;
79 u64 clk;
80
Ingo Molnarb14f2d32015-10-19 10:04:23 +020081 ret = read(cycles_fd, &clk, sizeof(u64));
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090082 BUG_ON(ret != sizeof(u64));
83
84 return clk;
85}
86
87static double timeval2double(struct timeval *ts)
88{
Ingo Molnar13839ec2015-10-19 10:04:17 +020089 return (double)ts->tv_sec + (double)ts->tv_usec / (double)1000000;
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090090}
91
Ingo Molnar6db175c2015-10-19 10:04:21 +020092#define print_bps(x) do { \
93 if (x < K) \
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020094 printf(" %14lf bytes/sec\n", x); \
Ingo Molnar6db175c2015-10-19 10:04:21 +020095 else if (x < K * K) \
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020096 printf(" %14lfd KB/sec\n", x / K); \
Ingo Molnar6db175c2015-10-19 10:04:21 +020097 else if (x < K * K * K) \
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020098 printf(" %14lf MB/sec\n", x / K / K); \
Ingo Molnar6db175c2015-10-19 10:04:21 +020099 else \
Ingo Molnar13b1fdc2015-10-19 10:04:26 +0200100 printf(" %14lf GB/sec\n", x / K / K / K); \
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900101 } while (0)
102
Rabin Vincent308197b2014-12-02 16:50:39 +0100103struct bench_mem_info {
Ingo Molnar2f211c82015-10-19 10:04:29 +0200104 const struct function *functions;
105 u64 (*do_cycles)(const struct function *r, size_t size);
106 double (*do_gettimeofday)(const struct function *r, size_t size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100107 const char *const *usage;
108};
109
Ingo Molnar2f211c82015-10-19 10:04:29 +0200110static void __bench_mem_function(struct bench_mem_info *info, int r_idx, size_t size, double size_total)
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900111{
Ingo Molnar2f211c82015-10-19 10:04:29 +0200112 const struct function *r = &info->functions[r_idx];
Ingo Molnar6db175c2015-10-19 10:04:21 +0200113 double result_bps = 0.0;
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200114 u64 result_cycles = 0;
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900115
Ingo Molnar2f211c82015-10-19 10:04:29 +0200116 printf("# function '%s' (%s)\n", r->name, r->desc);
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900117
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900118 if (bench_format == BENCH_FORMAT_DEFAULT)
Ingo Molnar13b1fdc2015-10-19 10:04:26 +0200119 printf("# Copying %s bytes ...\n\n", size_str);
Hitoshi Mitake12eac0b2009-11-20 12:37:17 +0900120
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200121 if (use_cycles) {
Ingo Molnara69b4f72015-10-19 10:04:25 +0200122 result_cycles = info->do_cycles(r, size);
Hitoshi Mitake12eac0b2009-11-20 12:37:17 +0900123 } else {
Ingo Molnara69b4f72015-10-19 10:04:25 +0200124 result_bps = info->do_gettimeofday(r, size);
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900125 }
126
127 switch (bench_format) {
128 case BENCH_FORMAT_DEFAULT:
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200129 if (use_cycles) {
Ingo Molnar13b1fdc2015-10-19 10:04:26 +0200130 printf(" %14lf cycles/byte\n", (double)result_cycles/size_total);
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900131 } else {
Ingo Molnar6db175c2015-10-19 10:04:21 +0200132 print_bps(result_bps);
133 }
134 break;
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900135
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900136 case BENCH_FORMAT_SIMPLE:
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200137 if (use_cycles) {
Ingo Molnara69b4f72015-10-19 10:04:25 +0200138 printf("%lf\n", (double)result_cycles/size_total);
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900139 } else {
Ingo Molnar6db175c2015-10-19 10:04:21 +0200140 printf("%lf\n", result_bps);
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900141 }
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900142 break;
Ingo Molnar6db175c2015-10-19 10:04:21 +0200143
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900144 default:
Ingo Molnar6db175c2015-10-19 10:04:21 +0200145 BUG_ON(1);
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900146 break;
147 }
Borislav Petkov515e23f2015-02-26 18:51:37 +0100148}
149
Ingo Molnar2946f592015-10-19 10:04:19 +0200150static int bench_mem_common(int argc, const char **argv, struct bench_mem_info *info)
Borislav Petkov515e23f2015-02-26 18:51:37 +0100151{
152 int i;
Ingo Molnara69b4f72015-10-19 10:04:25 +0200153 size_t size;
154 double size_total;
Borislav Petkov515e23f2015-02-26 18:51:37 +0100155
Ingo Molnar13839ec2015-10-19 10:04:17 +0200156 argc = parse_options(argc, argv, options, info->usage, 0);
Borislav Petkov515e23f2015-02-26 18:51:37 +0100157
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200158 if (use_cycles)
159 init_cycles();
Borislav Petkov515e23f2015-02-26 18:51:37 +0100160
Ingo Molnara69b4f72015-10-19 10:04:25 +0200161 size = (size_t)perf_atoll((char *)size_str);
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200162 size_total = (double)size * nr_loops;
Borislav Petkov515e23f2015-02-26 18:51:37 +0100163
Ingo Molnara69b4f72015-10-19 10:04:25 +0200164 if ((s64)size <= 0) {
165 fprintf(stderr, "Invalid size:%s\n", size_str);
Borislav Petkov515e23f2015-02-26 18:51:37 +0100166 return 1;
167 }
168
Ingo Molnar2f211c82015-10-19 10:04:29 +0200169 if (!strncmp(function_str, "all", 3)) {
170 for (i = 0; info->functions[i].name; i++)
171 __bench_mem_function(info, i, size, size_total);
Borislav Petkovdfecb952015-02-26 19:02:43 +0100172 return 0;
173 }
174
Ingo Molnar2f211c82015-10-19 10:04:29 +0200175 for (i = 0; info->functions[i].name; i++) {
176 if (!strcmp(info->functions[i].name, function_str))
Borislav Petkov515e23f2015-02-26 18:51:37 +0100177 break;
178 }
Ingo Molnar2f211c82015-10-19 10:04:29 +0200179 if (!info->functions[i].name) {
180 if (strcmp(function_str, "help") && strcmp(function_str, "h"))
181 printf("Unknown function: %s\n", function_str);
182 printf("Available functions:\n");
183 for (i = 0; info->functions[i].name; i++) {
Borislav Petkov515e23f2015-02-26 18:51:37 +0100184 printf("\t%s ... %s\n",
Ingo Molnar2f211c82015-10-19 10:04:29 +0200185 info->functions[i].name, info->functions[i].desc);
Borislav Petkov515e23f2015-02-26 18:51:37 +0100186 }
187 return 1;
188 }
189
Ingo Molnar2f211c82015-10-19 10:04:29 +0200190 __bench_mem_function(info, i, size, size_total);
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900191
192 return 0;
193}
Rabin Vincent308197b2014-12-02 16:50:39 +0100194
Ingo Molnara69b4f72015-10-19 10:04:25 +0200195static void memcpy_alloc_mem(void **dst, void **src, size_t size)
Rabin Vincent308197b2014-12-02 16:50:39 +0100196{
Ingo Molnara69b4f72015-10-19 10:04:25 +0200197 *dst = zalloc(size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100198 if (!*dst)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200199 die("memory allocation failed - maybe size is too large?\n");
Rabin Vincent308197b2014-12-02 16:50:39 +0100200
Ingo Molnara69b4f72015-10-19 10:04:25 +0200201 *src = zalloc(size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100202 if (!*src)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200203 die("memory allocation failed - maybe size is too large?\n");
Ingo Molnar13839ec2015-10-19 10:04:17 +0200204
205 /* Make sure to always prefault zero pages even if MMAP_THRESH is crossed: */
Ingo Molnara69b4f72015-10-19 10:04:25 +0200206 memset(*src, 0, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100207}
208
Ingo Molnar2f211c82015-10-19 10:04:29 +0200209static u64 do_memcpy_cycles(const struct function *r, size_t size)
Rabin Vincent308197b2014-12-02 16:50:39 +0100210{
211 u64 cycle_start = 0ULL, cycle_end = 0ULL;
212 void *src = NULL, *dst = NULL;
213 memcpy_t fn = r->fn.memcpy;
214 int i;
215
Ingo Molnara69b4f72015-10-19 10:04:25 +0200216 memcpy_alloc_mem(&dst, &src, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100217
Ingo Molnar6db175c2015-10-19 10:04:21 +0200218 /*
219 * We prefault the freshly allocated memory range here,
220 * to not measure page fault overhead:
221 */
Ingo Molnara69b4f72015-10-19 10:04:25 +0200222 fn(dst, src, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100223
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200224 cycle_start = get_cycles();
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200225 for (i = 0; i < nr_loops; ++i)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200226 fn(dst, src, size);
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200227 cycle_end = get_cycles();
Rabin Vincent308197b2014-12-02 16:50:39 +0100228
229 free(src);
230 free(dst);
231 return cycle_end - cycle_start;
232}
233
Ingo Molnar2f211c82015-10-19 10:04:29 +0200234static double do_memcpy_gettimeofday(const struct function *r, size_t size)
Rabin Vincent308197b2014-12-02 16:50:39 +0100235{
236 struct timeval tv_start, tv_end, tv_diff;
237 memcpy_t fn = r->fn.memcpy;
238 void *src = NULL, *dst = NULL;
239 int i;
240
Ingo Molnara69b4f72015-10-19 10:04:25 +0200241 memcpy_alloc_mem(&dst, &src, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100242
Ingo Molnar6db175c2015-10-19 10:04:21 +0200243 /*
244 * We prefault the freshly allocated memory range here,
245 * to not measure page fault overhead:
246 */
Ingo Molnara69b4f72015-10-19 10:04:25 +0200247 fn(dst, src, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100248
249 BUG_ON(gettimeofday(&tv_start, NULL));
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200250 for (i = 0; i < nr_loops; ++i)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200251 fn(dst, src, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100252 BUG_ON(gettimeofday(&tv_end, NULL));
253
254 timersub(&tv_end, &tv_start, &tv_diff);
255
256 free(src);
257 free(dst);
Ingo Molnar6db175c2015-10-19 10:04:21 +0200258
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200259 return (double)(((double)size * nr_loops) / timeval2double(&tv_diff));
Rabin Vincent308197b2014-12-02 16:50:39 +0100260}
261
Ingo Molnar2f211c82015-10-19 10:04:29 +0200262struct function memcpy_functions[] = {
Ingo Molnar5dd93302015-10-19 10:04:27 +0200263 { .name = "default",
264 .desc = "Default memcpy() provided by glibc",
265 .fn.memcpy = memcpy },
266
267#ifdef HAVE_ARCH_X86_64_SUPPORT
268# define MEMCPY_FN(_fn, _name, _desc) {.name = _name, .desc = _desc, .fn.memcpy = _fn},
269# include "mem-memcpy-x86-64-asm-def.h"
270# undef MEMCPY_FN
271#endif
272
Arnaldo Carvalho de Meloa4c6a3e2015-10-19 18:17:25 -0300273 { .name = NULL, }
Ingo Molnar5dd93302015-10-19 10:04:27 +0200274};
275
276static const char * const bench_mem_memcpy_usage[] = {
277 "perf bench mem memcpy <options>",
278 NULL
279};
280
Ingo Molnar2946f592015-10-19 10:04:19 +0200281int bench_mem_memcpy(int argc, const char **argv, const char *prefix __maybe_unused)
Rabin Vincent308197b2014-12-02 16:50:39 +0100282{
283 struct bench_mem_info info = {
Ingo Molnar2f211c82015-10-19 10:04:29 +0200284 .functions = memcpy_functions,
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200285 .do_cycles = do_memcpy_cycles,
Ingo Molnar13839ec2015-10-19 10:04:17 +0200286 .do_gettimeofday = do_memcpy_gettimeofday,
287 .usage = bench_mem_memcpy_usage,
Rabin Vincent308197b2014-12-02 16:50:39 +0100288 };
289
Ingo Molnar2946f592015-10-19 10:04:19 +0200290 return bench_mem_common(argc, argv, &info);
Rabin Vincent308197b2014-12-02 16:50:39 +0100291}
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100292
Ingo Molnara69b4f72015-10-19 10:04:25 +0200293static void memset_alloc_mem(void **dst, size_t size)
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100294{
Ingo Molnara69b4f72015-10-19 10:04:25 +0200295 *dst = zalloc(size);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100296 if (!*dst)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200297 die("memory allocation failed - maybe size is too large?\n");
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100298}
299
Ingo Molnar2f211c82015-10-19 10:04:29 +0200300static u64 do_memset_cycles(const struct function *r, size_t size)
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100301{
302 u64 cycle_start = 0ULL, cycle_end = 0ULL;
303 memset_t fn = r->fn.memset;
304 void *dst = NULL;
305 int i;
306
Ingo Molnara69b4f72015-10-19 10:04:25 +0200307 memset_alloc_mem(&dst, size);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100308
Ingo Molnar6db175c2015-10-19 10:04:21 +0200309 /*
310 * We prefault the freshly allocated memory range here,
311 * to not measure page fault overhead:
312 */
Ingo Molnara69b4f72015-10-19 10:04:25 +0200313 fn(dst, -1, size);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100314
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200315 cycle_start = get_cycles();
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200316 for (i = 0; i < nr_loops; ++i)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200317 fn(dst, i, size);
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200318 cycle_end = get_cycles();
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100319
320 free(dst);
321 return cycle_end - cycle_start;
322}
323
Ingo Molnar2f211c82015-10-19 10:04:29 +0200324static double do_memset_gettimeofday(const struct function *r, size_t size)
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100325{
326 struct timeval tv_start, tv_end, tv_diff;
327 memset_t fn = r->fn.memset;
328 void *dst = NULL;
329 int i;
330
Ingo Molnara69b4f72015-10-19 10:04:25 +0200331 memset_alloc_mem(&dst, size);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100332
Ingo Molnar6db175c2015-10-19 10:04:21 +0200333 /*
334 * We prefault the freshly allocated memory range here,
335 * to not measure page fault overhead:
336 */
Ingo Molnara69b4f72015-10-19 10:04:25 +0200337 fn(dst, -1, size);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100338
339 BUG_ON(gettimeofday(&tv_start, NULL));
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200340 for (i = 0; i < nr_loops; ++i)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200341 fn(dst, i, size);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100342 BUG_ON(gettimeofday(&tv_end, NULL));
343
344 timersub(&tv_end, &tv_start, &tv_diff);
345
346 free(dst);
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200347 return (double)(((double)size * nr_loops) / timeval2double(&tv_diff));
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100348}
349
350static const char * const bench_mem_memset_usage[] = {
351 "perf bench mem memset <options>",
352 NULL
353};
354
Ingo Molnar2f211c82015-10-19 10:04:29 +0200355static const struct function memset_functions[] = {
Ingo Molnar13839ec2015-10-19 10:04:17 +0200356 { .name = "default",
357 .desc = "Default memset() provided by glibc",
358 .fn.memset = memset },
359
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100360#ifdef HAVE_ARCH_X86_64_SUPPORT
Ingo Molnar13839ec2015-10-19 10:04:17 +0200361# define MEMSET_FN(_fn, _name, _desc) { .name = _name, .desc = _desc, .fn.memset = _fn },
362# include "mem-memset-x86-64-asm-def.h"
363# undef MEMSET_FN
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100364#endif
365
Arnaldo Carvalho de Meloa4c6a3e2015-10-19 18:17:25 -0300366 { .name = NULL, }
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100367};
368
Ingo Molnar13839ec2015-10-19 10:04:17 +0200369int bench_mem_memset(int argc, const char **argv, const char *prefix __maybe_unused)
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100370{
371 struct bench_mem_info info = {
Ingo Molnar2f211c82015-10-19 10:04:29 +0200372 .functions = memset_functions,
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200373 .do_cycles = do_memset_cycles,
Ingo Molnar13839ec2015-10-19 10:04:17 +0200374 .do_gettimeofday = do_memset_gettimeofday,
375 .usage = bench_mem_memset_usage,
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100376 };
377
Ingo Molnar2946f592015-10-19 10:04:19 +0200378 return bench_mem_common(argc, argv, &info);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100379}