blob: 9235b76501be81c71bcdc9ee36bfd3f286a2a205 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Hitoshi Mitake827f3b42009-11-18 00:20:09 +09002/*
3 * mem-memcpy.c
4 *
Ingo Molnar13839ec2015-10-19 10:04:17 +02005 * Simple memcpy() and memset() benchmarks
Hitoshi Mitake827f3b42009-11-18 00:20:09 +09006 *
7 * Written by Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
8 */
Hitoshi Mitake827f3b42009-11-18 00:20:09 +09009
Arnaldo Carvalho de Meloc2a218c2016-04-26 13:27:23 -030010#include "debug.h"
Arnaldo Carvalho de Melo91854f92019-08-29 14:59:50 -030011#include "../perf-sys.h"
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -060012#include <subcmd/parse-options.h>
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090013#include "../util/header.h"
Yann Droneaud57480d22014-06-30 22:28:47 +020014#include "../util/cloexec.h"
Arnaldo Carvalho de Meloa0675582017-04-17 16:51:59 -030015#include "../util/string2.h"
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090016#include "bench.h"
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +090017#include "mem-memcpy-arch.h"
Rabin Vincent5bce1a52014-12-02 16:50:40 +010018#include "mem-memset-arch.h"
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090019
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
Arnaldo Carvalho de Melo91854f92019-08-29 14:59:50 -030023#include <unistd.h>
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090024#include <sys/time.h>
25#include <errno.h>
Arnaldo Carvalho de Melof2b91be2016-08-08 14:59:21 -030026#include <linux/time64.h>
Arnaldo Carvalho de Melo7f7c5362019-07-04 11:32:27 -030027#include <linux/zalloc.h>
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090028
29#define K 1024
30
Ingo Molnara69b4f72015-10-19 10:04:25 +020031static const char *size_str = "1MB";
Ingo Molnar2f211c82015-10-19 10:04:29 +020032static const char *function_str = "all";
Ingo Molnarb0d22e52015-10-19 10:04:28 +020033static int nr_loops = 1;
Ingo Molnarb14f2d32015-10-19 10:04:23 +020034static bool use_cycles;
35static int cycles_fd;
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090036
37static const struct option options[] = {
Ingo Molnarb0d22e52015-10-19 10:04:28 +020038 OPT_STRING('s', "size", &size_str, "1MB",
Ingo Molnara69b4f72015-10-19 10:04:25 +020039 "Specify the size of the memory buffers. "
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020040 "Available units: B, KB, MB, GB and TB (case insensitive)"),
41
Ingo Molnar2f211c82015-10-19 10:04:29 +020042 OPT_STRING('f', "function", &function_str, "all",
43 "Specify the function to run, \"all\" runs all available functions, \"help\" lists them"),
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020044
Ingo Molnarb0d22e52015-10-19 10:04:28 +020045 OPT_INTEGER('l', "nr_loops", &nr_loops,
46 "Specify the number of loops to run. (default: 1)"),
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020047
Ingo Molnarb14f2d32015-10-19 10:04:23 +020048 OPT_BOOLEAN('c', "cycles", &use_cycles,
49 "Use a cycles event instead of gettimeofday() to measure performance"),
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020050
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090051 OPT_END()
52};
53
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +090054typedef void *(*memcpy_t)(void *, const void *, size_t);
Rabin Vincent5bce1a52014-12-02 16:50:40 +010055typedef void *(*memset_t)(void *, int, size_t);
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +090056
Ingo Molnar2f211c82015-10-19 10:04:29 +020057struct function {
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090058 const char *name;
59 const char *desc;
Rabin Vincent308197b2014-12-02 16:50:39 +010060 union {
61 memcpy_t memcpy;
Rabin Vincent5bce1a52014-12-02 16:50:40 +010062 memset_t memset;
Rabin Vincent308197b2014-12-02 16:50:39 +010063 } fn;
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090064};
65
Hitoshi Mitake17d7a112012-07-02 22:46:17 +090066static struct perf_event_attr cycle_attr = {
Hitoshi Mitake12eac0b2009-11-20 12:37:17 +090067 .type = PERF_TYPE_HARDWARE,
68 .config = PERF_COUNT_HW_CPU_CYCLES
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090069};
70
Arnaldo Carvalho de Meloc2a218c2016-04-26 13:27:23 -030071static int init_cycles(void)
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090072{
Ingo Molnarb14f2d32015-10-19 10:04:23 +020073 cycles_fd = sys_perf_event_open(&cycle_attr, getpid(), -1, -1, perf_event_open_cloexec_flag());
Hitoshi Mitake12eac0b2009-11-20 12:37:17 +090074
Arnaldo Carvalho de Meloc2a218c2016-04-26 13:27:23 -030075 if (cycles_fd < 0 && errno == ENOSYS) {
76 pr_debug("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
77 return -1;
78 }
79
80 return cycles_fd;
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090081}
82
Ingo Molnarb14f2d32015-10-19 10:04:23 +020083static u64 get_cycles(void)
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090084{
85 int ret;
86 u64 clk;
87
Ingo Molnarb14f2d32015-10-19 10:04:23 +020088 ret = read(cycles_fd, &clk, sizeof(u64));
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090089 BUG_ON(ret != sizeof(u64));
90
91 return clk;
92}
93
94static double timeval2double(struct timeval *ts)
95{
Arnaldo Carvalho de Melof2b91be2016-08-08 14:59:21 -030096 return (double)ts->tv_sec + (double)ts->tv_usec / (double)USEC_PER_SEC;
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090097}
98
Ingo Molnar6db175c2015-10-19 10:04:21 +020099#define print_bps(x) do { \
100 if (x < K) \
Ingo Molnar13b1fdc2015-10-19 10:04:26 +0200101 printf(" %14lf bytes/sec\n", x); \
Ingo Molnar6db175c2015-10-19 10:04:21 +0200102 else if (x < K * K) \
Ingo Molnar13b1fdc2015-10-19 10:04:26 +0200103 printf(" %14lfd KB/sec\n", x / K); \
Ingo Molnar6db175c2015-10-19 10:04:21 +0200104 else if (x < K * K * K) \
Ingo Molnar13b1fdc2015-10-19 10:04:26 +0200105 printf(" %14lf MB/sec\n", x / K / K); \
Ingo Molnar6db175c2015-10-19 10:04:21 +0200106 else \
Ingo Molnar13b1fdc2015-10-19 10:04:26 +0200107 printf(" %14lf GB/sec\n", x / K / K / K); \
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900108 } while (0)
109
Rabin Vincent308197b2014-12-02 16:50:39 +0100110struct bench_mem_info {
Ingo Molnar2f211c82015-10-19 10:04:29 +0200111 const struct function *functions;
Arnaldo Carvalho de Melo47b57572016-10-14 17:52:18 -0300112 u64 (*do_cycles)(const struct function *r, size_t size, void *src, void *dst);
113 double (*do_gettimeofday)(const struct function *r, size_t size, void *src, void *dst);
Rabin Vincent308197b2014-12-02 16:50:39 +0100114 const char *const *usage;
Arnaldo Carvalho de Melo47b57572016-10-14 17:52:18 -0300115 bool alloc_src;
Rabin Vincent308197b2014-12-02 16:50:39 +0100116};
117
Ingo Molnar2f211c82015-10-19 10:04:29 +0200118static 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 +0900119{
Ingo Molnar2f211c82015-10-19 10:04:29 +0200120 const struct function *r = &info->functions[r_idx];
Ingo Molnar6db175c2015-10-19 10:04:21 +0200121 double result_bps = 0.0;
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200122 u64 result_cycles = 0;
Arnaldo Carvalho de Melo47b57572016-10-14 17:52:18 -0300123 void *src = NULL, *dst = zalloc(size);
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900124
Ingo Molnar2f211c82015-10-19 10:04:29 +0200125 printf("# function '%s' (%s)\n", r->name, r->desc);
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900126
Arnaldo Carvalho de Melo47b57572016-10-14 17:52:18 -0300127 if (dst == NULL)
128 goto out_alloc_failed;
129
130 if (info->alloc_src) {
131 src = zalloc(size);
132 if (src == NULL)
133 goto out_alloc_failed;
134 }
135
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900136 if (bench_format == BENCH_FORMAT_DEFAULT)
Ingo Molnar13b1fdc2015-10-19 10:04:26 +0200137 printf("# Copying %s bytes ...\n\n", size_str);
Hitoshi Mitake12eac0b2009-11-20 12:37:17 +0900138
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200139 if (use_cycles) {
Arnaldo Carvalho de Melo47b57572016-10-14 17:52:18 -0300140 result_cycles = info->do_cycles(r, size, src, dst);
Hitoshi Mitake12eac0b2009-11-20 12:37:17 +0900141 } else {
Arnaldo Carvalho de Melo47b57572016-10-14 17:52:18 -0300142 result_bps = info->do_gettimeofday(r, size, src, dst);
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900143 }
144
145 switch (bench_format) {
146 case BENCH_FORMAT_DEFAULT:
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200147 if (use_cycles) {
Ingo Molnar13b1fdc2015-10-19 10:04:26 +0200148 printf(" %14lf cycles/byte\n", (double)result_cycles/size_total);
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900149 } else {
Ingo Molnar6db175c2015-10-19 10:04:21 +0200150 print_bps(result_bps);
151 }
152 break;
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900153
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900154 case BENCH_FORMAT_SIMPLE:
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200155 if (use_cycles) {
Ingo Molnara69b4f72015-10-19 10:04:25 +0200156 printf("%lf\n", (double)result_cycles/size_total);
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900157 } else {
Ingo Molnar6db175c2015-10-19 10:04:21 +0200158 printf("%lf\n", result_bps);
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900159 }
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900160 break;
Ingo Molnar6db175c2015-10-19 10:04:21 +0200161
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900162 default:
Ingo Molnar6db175c2015-10-19 10:04:21 +0200163 BUG_ON(1);
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900164 break;
165 }
Arnaldo Carvalho de Melo47b57572016-10-14 17:52:18 -0300166
167out_free:
168 free(src);
169 free(dst);
170 return;
171out_alloc_failed:
172 printf("# Memory allocation failed - maybe size (%s) is too large?\n", size_str);
173 goto out_free;
Borislav Petkov515e23f2015-02-26 18:51:37 +0100174}
175
Ingo Molnar2946f592015-10-19 10:04:19 +0200176static int bench_mem_common(int argc, const char **argv, struct bench_mem_info *info)
Borislav Petkov515e23f2015-02-26 18:51:37 +0100177{
178 int i;
Ingo Molnara69b4f72015-10-19 10:04:25 +0200179 size_t size;
180 double size_total;
Borislav Petkov515e23f2015-02-26 18:51:37 +0100181
Ingo Molnar13839ec2015-10-19 10:04:17 +0200182 argc = parse_options(argc, argv, options, info->usage, 0);
Borislav Petkov515e23f2015-02-26 18:51:37 +0100183
Arnaldo Carvalho de Meloc2a218c2016-04-26 13:27:23 -0300184 if (use_cycles) {
185 i = init_cycles();
186 if (i < 0) {
187 fprintf(stderr, "Failed to open cycles counter\n");
188 return i;
189 }
190 }
Borislav Petkov515e23f2015-02-26 18:51:37 +0100191
Ingo Molnara69b4f72015-10-19 10:04:25 +0200192 size = (size_t)perf_atoll((char *)size_str);
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200193 size_total = (double)size * nr_loops;
Borislav Petkov515e23f2015-02-26 18:51:37 +0100194
Ingo Molnara69b4f72015-10-19 10:04:25 +0200195 if ((s64)size <= 0) {
196 fprintf(stderr, "Invalid size:%s\n", size_str);
Borislav Petkov515e23f2015-02-26 18:51:37 +0100197 return 1;
198 }
199
Ingo Molnar2f211c82015-10-19 10:04:29 +0200200 if (!strncmp(function_str, "all", 3)) {
201 for (i = 0; info->functions[i].name; i++)
202 __bench_mem_function(info, i, size, size_total);
Borislav Petkovdfecb952015-02-26 19:02:43 +0100203 return 0;
204 }
205
Ingo Molnar2f211c82015-10-19 10:04:29 +0200206 for (i = 0; info->functions[i].name; i++) {
207 if (!strcmp(info->functions[i].name, function_str))
Borislav Petkov515e23f2015-02-26 18:51:37 +0100208 break;
209 }
Ingo Molnar2f211c82015-10-19 10:04:29 +0200210 if (!info->functions[i].name) {
211 if (strcmp(function_str, "help") && strcmp(function_str, "h"))
212 printf("Unknown function: %s\n", function_str);
213 printf("Available functions:\n");
214 for (i = 0; info->functions[i].name; i++) {
Borislav Petkov515e23f2015-02-26 18:51:37 +0100215 printf("\t%s ... %s\n",
Ingo Molnar2f211c82015-10-19 10:04:29 +0200216 info->functions[i].name, info->functions[i].desc);
Borislav Petkov515e23f2015-02-26 18:51:37 +0100217 }
218 return 1;
219 }
220
Ingo Molnar2f211c82015-10-19 10:04:29 +0200221 __bench_mem_function(info, i, size, size_total);
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900222
223 return 0;
224}
Rabin Vincent308197b2014-12-02 16:50:39 +0100225
Arnaldo Carvalho de Melo47b57572016-10-14 17:52:18 -0300226static u64 do_memcpy_cycles(const struct function *r, size_t size, void *src, void *dst)
Rabin Vincent308197b2014-12-02 16:50:39 +0100227{
228 u64 cycle_start = 0ULL, cycle_end = 0ULL;
Rabin Vincent308197b2014-12-02 16:50:39 +0100229 memcpy_t fn = r->fn.memcpy;
230 int i;
231
Arnaldo Carvalho de Melo47b57572016-10-14 17:52:18 -0300232 /* Make sure to always prefault zero pages even if MMAP_THRESH is crossed: */
233 memset(src, 0, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100234
Ingo Molnar6db175c2015-10-19 10:04:21 +0200235 /*
236 * We prefault the freshly allocated memory range here,
237 * to not measure page fault overhead:
238 */
Ingo Molnara69b4f72015-10-19 10:04:25 +0200239 fn(dst, src, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100240
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200241 cycle_start = get_cycles();
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200242 for (i = 0; i < nr_loops; ++i)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200243 fn(dst, src, size);
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200244 cycle_end = get_cycles();
Rabin Vincent308197b2014-12-02 16:50:39 +0100245
Rabin Vincent308197b2014-12-02 16:50:39 +0100246 return cycle_end - cycle_start;
247}
248
Arnaldo Carvalho de Melo47b57572016-10-14 17:52:18 -0300249static double do_memcpy_gettimeofday(const struct function *r, size_t size, void *src, void *dst)
Rabin Vincent308197b2014-12-02 16:50:39 +0100250{
251 struct timeval tv_start, tv_end, tv_diff;
252 memcpy_t fn = r->fn.memcpy;
Rabin Vincent308197b2014-12-02 16:50:39 +0100253 int i;
254
Ingo Molnar6db175c2015-10-19 10:04:21 +0200255 /*
256 * We prefault the freshly allocated memory range here,
257 * to not measure page fault overhead:
258 */
Ingo Molnara69b4f72015-10-19 10:04:25 +0200259 fn(dst, src, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100260
261 BUG_ON(gettimeofday(&tv_start, NULL));
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200262 for (i = 0; i < nr_loops; ++i)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200263 fn(dst, src, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100264 BUG_ON(gettimeofday(&tv_end, NULL));
265
266 timersub(&tv_end, &tv_start, &tv_diff);
267
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200268 return (double)(((double)size * nr_loops) / timeval2double(&tv_diff));
Rabin Vincent308197b2014-12-02 16:50:39 +0100269}
270
Ingo Molnar2f211c82015-10-19 10:04:29 +0200271struct function memcpy_functions[] = {
Ingo Molnar5dd93302015-10-19 10:04:27 +0200272 { .name = "default",
273 .desc = "Default memcpy() provided by glibc",
274 .fn.memcpy = memcpy },
275
276#ifdef HAVE_ARCH_X86_64_SUPPORT
277# define MEMCPY_FN(_fn, _name, _desc) {.name = _name, .desc = _desc, .fn.memcpy = _fn},
278# include "mem-memcpy-x86-64-asm-def.h"
279# undef MEMCPY_FN
280#endif
281
Arnaldo Carvalho de Meloa4c6a3e2015-10-19 18:17:25 -0300282 { .name = NULL, }
Ingo Molnar5dd93302015-10-19 10:04:27 +0200283};
284
285static const char * const bench_mem_memcpy_usage[] = {
286 "perf bench mem memcpy <options>",
287 NULL
288};
289
Arnaldo Carvalho de Melob0ad8ea2017-03-27 11:47:20 -0300290int bench_mem_memcpy(int argc, const char **argv)
Rabin Vincent308197b2014-12-02 16:50:39 +0100291{
292 struct bench_mem_info info = {
Ingo Molnar2f211c82015-10-19 10:04:29 +0200293 .functions = memcpy_functions,
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200294 .do_cycles = do_memcpy_cycles,
Ingo Molnar13839ec2015-10-19 10:04:17 +0200295 .do_gettimeofday = do_memcpy_gettimeofday,
296 .usage = bench_mem_memcpy_usage,
Arnaldo Carvalho de Melo47b57572016-10-14 17:52:18 -0300297 .alloc_src = true,
Rabin Vincent308197b2014-12-02 16:50:39 +0100298 };
299
Ingo Molnar2946f592015-10-19 10:04:19 +0200300 return bench_mem_common(argc, argv, &info);
Rabin Vincent308197b2014-12-02 16:50:39 +0100301}
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100302
Arnaldo Carvalho de Melo47b57572016-10-14 17:52:18 -0300303static u64 do_memset_cycles(const struct function *r, size_t size, void *src __maybe_unused, void *dst)
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100304{
305 u64 cycle_start = 0ULL, cycle_end = 0ULL;
306 memset_t fn = r->fn.memset;
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100307 int i;
308
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
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100320 return cycle_end - cycle_start;
321}
322
Arnaldo Carvalho de Melo47b57572016-10-14 17:52:18 -0300323static double do_memset_gettimeofday(const struct function *r, size_t size, void *src __maybe_unused, void *dst)
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100324{
325 struct timeval tv_start, tv_end, tv_diff;
326 memset_t fn = r->fn.memset;
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100327 int i;
328
Ingo Molnar6db175c2015-10-19 10:04:21 +0200329 /*
330 * We prefault the freshly allocated memory range here,
331 * to not measure page fault overhead:
332 */
Ingo Molnara69b4f72015-10-19 10:04:25 +0200333 fn(dst, -1, size);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100334
335 BUG_ON(gettimeofday(&tv_start, NULL));
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200336 for (i = 0; i < nr_loops; ++i)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200337 fn(dst, i, size);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100338 BUG_ON(gettimeofday(&tv_end, NULL));
339
340 timersub(&tv_end, &tv_start, &tv_diff);
341
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200342 return (double)(((double)size * nr_loops) / timeval2double(&tv_diff));
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100343}
344
345static const char * const bench_mem_memset_usage[] = {
346 "perf bench mem memset <options>",
347 NULL
348};
349
Ingo Molnar2f211c82015-10-19 10:04:29 +0200350static const struct function memset_functions[] = {
Ingo Molnar13839ec2015-10-19 10:04:17 +0200351 { .name = "default",
352 .desc = "Default memset() provided by glibc",
353 .fn.memset = memset },
354
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100355#ifdef HAVE_ARCH_X86_64_SUPPORT
Ingo Molnar13839ec2015-10-19 10:04:17 +0200356# define MEMSET_FN(_fn, _name, _desc) { .name = _name, .desc = _desc, .fn.memset = _fn },
357# include "mem-memset-x86-64-asm-def.h"
358# undef MEMSET_FN
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100359#endif
360
Arnaldo Carvalho de Meloa4c6a3e2015-10-19 18:17:25 -0300361 { .name = NULL, }
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100362};
363
Arnaldo Carvalho de Melob0ad8ea2017-03-27 11:47:20 -0300364int bench_mem_memset(int argc, const char **argv)
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100365{
366 struct bench_mem_info info = {
Ingo Molnar2f211c82015-10-19 10:04:29 +0200367 .functions = memset_functions,
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200368 .do_cycles = do_memset_cycles,
Ingo Molnar13839ec2015-10-19 10:04:17 +0200369 .do_gettimeofday = do_memset_gettimeofday,
370 .usage = bench_mem_memset_usage,
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100371 };
372
Ingo Molnar2946f592015-10-19 10:04:19 +0200373 return bench_mem_common(argc, argv, &info);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100374}