blob: 2b54d0f2672a39eaee68c5b5a48de2c01ba2956f [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
Arnaldo Carvalho de Meloc2a218c2016-04-26 13:27:23 -03009#include "debug.h"
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090010#include "../perf.h"
11#include "../util/util.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"
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090015#include "bench.h"
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +090016#include "mem-memcpy-arch.h"
Rabin Vincent5bce1a52014-12-02 16:50:40 +010017#include "mem-memset-arch.h"
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090018
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include <sys/time.h>
23#include <errno.h>
24
25#define K 1024
26
Ingo Molnara69b4f72015-10-19 10:04:25 +020027static const char *size_str = "1MB";
Ingo Molnar2f211c82015-10-19 10:04:29 +020028static const char *function_str = "all";
Ingo Molnarb0d22e52015-10-19 10:04:28 +020029static int nr_loops = 1;
Ingo Molnarb14f2d32015-10-19 10:04:23 +020030static bool use_cycles;
31static int cycles_fd;
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090032
33static const struct option options[] = {
Ingo Molnarb0d22e52015-10-19 10:04:28 +020034 OPT_STRING('s', "size", &size_str, "1MB",
Ingo Molnara69b4f72015-10-19 10:04:25 +020035 "Specify the size of the memory buffers. "
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020036 "Available units: B, KB, MB, GB and TB (case insensitive)"),
37
Ingo Molnar2f211c82015-10-19 10:04:29 +020038 OPT_STRING('f', "function", &function_str, "all",
39 "Specify the function to run, \"all\" runs all available functions, \"help\" lists them"),
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020040
Ingo Molnarb0d22e52015-10-19 10:04:28 +020041 OPT_INTEGER('l', "nr_loops", &nr_loops,
42 "Specify the number of loops to run. (default: 1)"),
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020043
Ingo Molnarb14f2d32015-10-19 10:04:23 +020044 OPT_BOOLEAN('c', "cycles", &use_cycles,
45 "Use a cycles event instead of gettimeofday() to measure performance"),
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020046
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090047 OPT_END()
48};
49
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +090050typedef void *(*memcpy_t)(void *, const void *, size_t);
Rabin Vincent5bce1a52014-12-02 16:50:40 +010051typedef void *(*memset_t)(void *, int, size_t);
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +090052
Ingo Molnar2f211c82015-10-19 10:04:29 +020053struct function {
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090054 const char *name;
55 const char *desc;
Rabin Vincent308197b2014-12-02 16:50:39 +010056 union {
57 memcpy_t memcpy;
Rabin Vincent5bce1a52014-12-02 16:50:40 +010058 memset_t memset;
Rabin Vincent308197b2014-12-02 16:50:39 +010059 } fn;
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090060};
61
Hitoshi Mitake17d7a112012-07-02 22:46:17 +090062static struct perf_event_attr cycle_attr = {
Hitoshi Mitake12eac0b2009-11-20 12:37:17 +090063 .type = PERF_TYPE_HARDWARE,
64 .config = PERF_COUNT_HW_CPU_CYCLES
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090065};
66
Arnaldo Carvalho de Meloc2a218c2016-04-26 13:27:23 -030067static int init_cycles(void)
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090068{
Ingo Molnarb14f2d32015-10-19 10:04:23 +020069 cycles_fd = sys_perf_event_open(&cycle_attr, getpid(), -1, -1, perf_event_open_cloexec_flag());
Hitoshi Mitake12eac0b2009-11-20 12:37:17 +090070
Arnaldo Carvalho de Meloc2a218c2016-04-26 13:27:23 -030071 if (cycles_fd < 0 && errno == ENOSYS) {
72 pr_debug("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
73 return -1;
74 }
75
76 return cycles_fd;
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090077}
78
Ingo Molnarb14f2d32015-10-19 10:04:23 +020079static u64 get_cycles(void)
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090080{
81 int ret;
82 u64 clk;
83
Ingo Molnarb14f2d32015-10-19 10:04:23 +020084 ret = read(cycles_fd, &clk, sizeof(u64));
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090085 BUG_ON(ret != sizeof(u64));
86
87 return clk;
88}
89
90static double timeval2double(struct timeval *ts)
91{
Ingo Molnar13839ec2015-10-19 10:04:17 +020092 return (double)ts->tv_sec + (double)ts->tv_usec / (double)1000000;
Hitoshi Mitake827f3b42009-11-18 00:20:09 +090093}
94
Ingo Molnar6db175c2015-10-19 10:04:21 +020095#define print_bps(x) do { \
96 if (x < K) \
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020097 printf(" %14lf bytes/sec\n", x); \
Ingo Molnar6db175c2015-10-19 10:04:21 +020098 else if (x < K * K) \
Ingo Molnar13b1fdc2015-10-19 10:04:26 +020099 printf(" %14lfd KB/sec\n", x / K); \
Ingo Molnar6db175c2015-10-19 10:04:21 +0200100 else if (x < K * K * K) \
Ingo Molnar13b1fdc2015-10-19 10:04:26 +0200101 printf(" %14lf MB/sec\n", x / K / K); \
Ingo Molnar6db175c2015-10-19 10:04:21 +0200102 else \
Ingo Molnar13b1fdc2015-10-19 10:04:26 +0200103 printf(" %14lf GB/sec\n", x / K / K / K); \
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900104 } while (0)
105
Rabin Vincent308197b2014-12-02 16:50:39 +0100106struct bench_mem_info {
Ingo Molnar2f211c82015-10-19 10:04:29 +0200107 const struct function *functions;
108 u64 (*do_cycles)(const struct function *r, size_t size);
109 double (*do_gettimeofday)(const struct function *r, size_t size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100110 const char *const *usage;
111};
112
Ingo Molnar2f211c82015-10-19 10:04:29 +0200113static 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 +0900114{
Ingo Molnar2f211c82015-10-19 10:04:29 +0200115 const struct function *r = &info->functions[r_idx];
Ingo Molnar6db175c2015-10-19 10:04:21 +0200116 double result_bps = 0.0;
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200117 u64 result_cycles = 0;
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900118
Ingo Molnar2f211c82015-10-19 10:04:29 +0200119 printf("# function '%s' (%s)\n", r->name, r->desc);
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900120
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900121 if (bench_format == BENCH_FORMAT_DEFAULT)
Ingo Molnar13b1fdc2015-10-19 10:04:26 +0200122 printf("# Copying %s bytes ...\n\n", size_str);
Hitoshi Mitake12eac0b2009-11-20 12:37:17 +0900123
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200124 if (use_cycles) {
Ingo Molnara69b4f72015-10-19 10:04:25 +0200125 result_cycles = info->do_cycles(r, size);
Hitoshi Mitake12eac0b2009-11-20 12:37:17 +0900126 } else {
Ingo Molnara69b4f72015-10-19 10:04:25 +0200127 result_bps = info->do_gettimeofday(r, size);
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900128 }
129
130 switch (bench_format) {
131 case BENCH_FORMAT_DEFAULT:
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200132 if (use_cycles) {
Ingo Molnar13b1fdc2015-10-19 10:04:26 +0200133 printf(" %14lf cycles/byte\n", (double)result_cycles/size_total);
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900134 } else {
Ingo Molnar6db175c2015-10-19 10:04:21 +0200135 print_bps(result_bps);
136 }
137 break;
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900138
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900139 case BENCH_FORMAT_SIMPLE:
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200140 if (use_cycles) {
Ingo Molnara69b4f72015-10-19 10:04:25 +0200141 printf("%lf\n", (double)result_cycles/size_total);
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900142 } else {
Ingo Molnar6db175c2015-10-19 10:04:21 +0200143 printf("%lf\n", result_bps);
Hitoshi Mitake49ce8fc2010-11-25 16:04:52 +0900144 }
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900145 break;
Ingo Molnar6db175c2015-10-19 10:04:21 +0200146
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900147 default:
Ingo Molnar6db175c2015-10-19 10:04:21 +0200148 BUG_ON(1);
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900149 break;
150 }
Borislav Petkov515e23f2015-02-26 18:51:37 +0100151}
152
Ingo Molnar2946f592015-10-19 10:04:19 +0200153static int bench_mem_common(int argc, const char **argv, struct bench_mem_info *info)
Borislav Petkov515e23f2015-02-26 18:51:37 +0100154{
155 int i;
Ingo Molnara69b4f72015-10-19 10:04:25 +0200156 size_t size;
157 double size_total;
Borislav Petkov515e23f2015-02-26 18:51:37 +0100158
Ingo Molnar13839ec2015-10-19 10:04:17 +0200159 argc = parse_options(argc, argv, options, info->usage, 0);
Borislav Petkov515e23f2015-02-26 18:51:37 +0100160
Arnaldo Carvalho de Meloc2a218c2016-04-26 13:27:23 -0300161 if (use_cycles) {
162 i = init_cycles();
163 if (i < 0) {
164 fprintf(stderr, "Failed to open cycles counter\n");
165 return i;
166 }
167 }
Borislav Petkov515e23f2015-02-26 18:51:37 +0100168
Ingo Molnara69b4f72015-10-19 10:04:25 +0200169 size = (size_t)perf_atoll((char *)size_str);
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200170 size_total = (double)size * nr_loops;
Borislav Petkov515e23f2015-02-26 18:51:37 +0100171
Ingo Molnara69b4f72015-10-19 10:04:25 +0200172 if ((s64)size <= 0) {
173 fprintf(stderr, "Invalid size:%s\n", size_str);
Borislav Petkov515e23f2015-02-26 18:51:37 +0100174 return 1;
175 }
176
Ingo Molnar2f211c82015-10-19 10:04:29 +0200177 if (!strncmp(function_str, "all", 3)) {
178 for (i = 0; info->functions[i].name; i++)
179 __bench_mem_function(info, i, size, size_total);
Borislav Petkovdfecb952015-02-26 19:02:43 +0100180 return 0;
181 }
182
Ingo Molnar2f211c82015-10-19 10:04:29 +0200183 for (i = 0; info->functions[i].name; i++) {
184 if (!strcmp(info->functions[i].name, function_str))
Borislav Petkov515e23f2015-02-26 18:51:37 +0100185 break;
186 }
Ingo Molnar2f211c82015-10-19 10:04:29 +0200187 if (!info->functions[i].name) {
188 if (strcmp(function_str, "help") && strcmp(function_str, "h"))
189 printf("Unknown function: %s\n", function_str);
190 printf("Available functions:\n");
191 for (i = 0; info->functions[i].name; i++) {
Borislav Petkov515e23f2015-02-26 18:51:37 +0100192 printf("\t%s ... %s\n",
Ingo Molnar2f211c82015-10-19 10:04:29 +0200193 info->functions[i].name, info->functions[i].desc);
Borislav Petkov515e23f2015-02-26 18:51:37 +0100194 }
195 return 1;
196 }
197
Ingo Molnar2f211c82015-10-19 10:04:29 +0200198 __bench_mem_function(info, i, size, size_total);
Hitoshi Mitake827f3b42009-11-18 00:20:09 +0900199
200 return 0;
201}
Rabin Vincent308197b2014-12-02 16:50:39 +0100202
Ingo Molnara69b4f72015-10-19 10:04:25 +0200203static void memcpy_alloc_mem(void **dst, void **src, size_t size)
Rabin Vincent308197b2014-12-02 16:50:39 +0100204{
Ingo Molnara69b4f72015-10-19 10:04:25 +0200205 *dst = zalloc(size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100206 if (!*dst)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200207 die("memory allocation failed - maybe size is too large?\n");
Rabin Vincent308197b2014-12-02 16:50:39 +0100208
Ingo Molnara69b4f72015-10-19 10:04:25 +0200209 *src = zalloc(size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100210 if (!*src)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200211 die("memory allocation failed - maybe size is too large?\n");
Ingo Molnar13839ec2015-10-19 10:04:17 +0200212
213 /* Make sure to always prefault zero pages even if MMAP_THRESH is crossed: */
Ingo Molnara69b4f72015-10-19 10:04:25 +0200214 memset(*src, 0, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100215}
216
Ingo Molnar2f211c82015-10-19 10:04:29 +0200217static u64 do_memcpy_cycles(const struct function *r, size_t size)
Rabin Vincent308197b2014-12-02 16:50:39 +0100218{
219 u64 cycle_start = 0ULL, cycle_end = 0ULL;
220 void *src = NULL, *dst = NULL;
221 memcpy_t fn = r->fn.memcpy;
222 int i;
223
Ingo Molnara69b4f72015-10-19 10:04:25 +0200224 memcpy_alloc_mem(&dst, &src, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100225
Ingo Molnar6db175c2015-10-19 10:04:21 +0200226 /*
227 * We prefault the freshly allocated memory range here,
228 * to not measure page fault overhead:
229 */
Ingo Molnara69b4f72015-10-19 10:04:25 +0200230 fn(dst, src, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100231
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200232 cycle_start = get_cycles();
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200233 for (i = 0; i < nr_loops; ++i)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200234 fn(dst, src, size);
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200235 cycle_end = get_cycles();
Rabin Vincent308197b2014-12-02 16:50:39 +0100236
237 free(src);
238 free(dst);
239 return cycle_end - cycle_start;
240}
241
Ingo Molnar2f211c82015-10-19 10:04:29 +0200242static double do_memcpy_gettimeofday(const struct function *r, size_t size)
Rabin Vincent308197b2014-12-02 16:50:39 +0100243{
244 struct timeval tv_start, tv_end, tv_diff;
245 memcpy_t fn = r->fn.memcpy;
246 void *src = NULL, *dst = NULL;
247 int i;
248
Ingo Molnara69b4f72015-10-19 10:04:25 +0200249 memcpy_alloc_mem(&dst, &src, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100250
Ingo Molnar6db175c2015-10-19 10:04:21 +0200251 /*
252 * We prefault the freshly allocated memory range here,
253 * to not measure page fault overhead:
254 */
Ingo Molnara69b4f72015-10-19 10:04:25 +0200255 fn(dst, src, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100256
257 BUG_ON(gettimeofday(&tv_start, NULL));
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200258 for (i = 0; i < nr_loops; ++i)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200259 fn(dst, src, size);
Rabin Vincent308197b2014-12-02 16:50:39 +0100260 BUG_ON(gettimeofday(&tv_end, NULL));
261
262 timersub(&tv_end, &tv_start, &tv_diff);
263
264 free(src);
265 free(dst);
Ingo Molnar6db175c2015-10-19 10:04:21 +0200266
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200267 return (double)(((double)size * nr_loops) / timeval2double(&tv_diff));
Rabin Vincent308197b2014-12-02 16:50:39 +0100268}
269
Ingo Molnar2f211c82015-10-19 10:04:29 +0200270struct function memcpy_functions[] = {
Ingo Molnar5dd93302015-10-19 10:04:27 +0200271 { .name = "default",
272 .desc = "Default memcpy() provided by glibc",
273 .fn.memcpy = memcpy },
274
275#ifdef HAVE_ARCH_X86_64_SUPPORT
276# define MEMCPY_FN(_fn, _name, _desc) {.name = _name, .desc = _desc, .fn.memcpy = _fn},
277# include "mem-memcpy-x86-64-asm-def.h"
278# undef MEMCPY_FN
279#endif
280
Arnaldo Carvalho de Meloa4c6a3e2015-10-19 18:17:25 -0300281 { .name = NULL, }
Ingo Molnar5dd93302015-10-19 10:04:27 +0200282};
283
284static const char * const bench_mem_memcpy_usage[] = {
285 "perf bench mem memcpy <options>",
286 NULL
287};
288
Ingo Molnar2946f592015-10-19 10:04:19 +0200289int bench_mem_memcpy(int argc, const char **argv, const char *prefix __maybe_unused)
Rabin Vincent308197b2014-12-02 16:50:39 +0100290{
291 struct bench_mem_info info = {
Ingo Molnar2f211c82015-10-19 10:04:29 +0200292 .functions = memcpy_functions,
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200293 .do_cycles = do_memcpy_cycles,
Ingo Molnar13839ec2015-10-19 10:04:17 +0200294 .do_gettimeofday = do_memcpy_gettimeofday,
295 .usage = bench_mem_memcpy_usage,
Rabin Vincent308197b2014-12-02 16:50:39 +0100296 };
297
Ingo Molnar2946f592015-10-19 10:04:19 +0200298 return bench_mem_common(argc, argv, &info);
Rabin Vincent308197b2014-12-02 16:50:39 +0100299}
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100300
Ingo Molnara69b4f72015-10-19 10:04:25 +0200301static void memset_alloc_mem(void **dst, size_t size)
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100302{
Ingo Molnara69b4f72015-10-19 10:04:25 +0200303 *dst = zalloc(size);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100304 if (!*dst)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200305 die("memory allocation failed - maybe size is too large?\n");
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100306}
307
Ingo Molnar2f211c82015-10-19 10:04:29 +0200308static u64 do_memset_cycles(const struct function *r, size_t size)
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100309{
310 u64 cycle_start = 0ULL, cycle_end = 0ULL;
311 memset_t fn = r->fn.memset;
312 void *dst = NULL;
313 int i;
314
Ingo Molnara69b4f72015-10-19 10:04:25 +0200315 memset_alloc_mem(&dst, size);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100316
Ingo Molnar6db175c2015-10-19 10:04:21 +0200317 /*
318 * We prefault the freshly allocated memory range here,
319 * to not measure page fault overhead:
320 */
Ingo Molnara69b4f72015-10-19 10:04:25 +0200321 fn(dst, -1, size);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100322
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200323 cycle_start = get_cycles();
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200324 for (i = 0; i < nr_loops; ++i)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200325 fn(dst, i, size);
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200326 cycle_end = get_cycles();
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100327
328 free(dst);
329 return cycle_end - cycle_start;
330}
331
Ingo Molnar2f211c82015-10-19 10:04:29 +0200332static double do_memset_gettimeofday(const struct function *r, size_t size)
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100333{
334 struct timeval tv_start, tv_end, tv_diff;
335 memset_t fn = r->fn.memset;
336 void *dst = NULL;
337 int i;
338
Ingo Molnara69b4f72015-10-19 10:04:25 +0200339 memset_alloc_mem(&dst, size);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100340
Ingo Molnar6db175c2015-10-19 10:04:21 +0200341 /*
342 * We prefault the freshly allocated memory range here,
343 * to not measure page fault overhead:
344 */
Ingo Molnara69b4f72015-10-19 10:04:25 +0200345 fn(dst, -1, size);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100346
347 BUG_ON(gettimeofday(&tv_start, NULL));
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200348 for (i = 0; i < nr_loops; ++i)
Ingo Molnara69b4f72015-10-19 10:04:25 +0200349 fn(dst, i, size);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100350 BUG_ON(gettimeofday(&tv_end, NULL));
351
352 timersub(&tv_end, &tv_start, &tv_diff);
353
354 free(dst);
Ingo Molnarb0d22e52015-10-19 10:04:28 +0200355 return (double)(((double)size * nr_loops) / timeval2double(&tv_diff));
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100356}
357
358static const char * const bench_mem_memset_usage[] = {
359 "perf bench mem memset <options>",
360 NULL
361};
362
Ingo Molnar2f211c82015-10-19 10:04:29 +0200363static const struct function memset_functions[] = {
Ingo Molnar13839ec2015-10-19 10:04:17 +0200364 { .name = "default",
365 .desc = "Default memset() provided by glibc",
366 .fn.memset = memset },
367
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100368#ifdef HAVE_ARCH_X86_64_SUPPORT
Ingo Molnar13839ec2015-10-19 10:04:17 +0200369# define MEMSET_FN(_fn, _name, _desc) { .name = _name, .desc = _desc, .fn.memset = _fn },
370# include "mem-memset-x86-64-asm-def.h"
371# undef MEMSET_FN
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100372#endif
373
Arnaldo Carvalho de Meloa4c6a3e2015-10-19 18:17:25 -0300374 { .name = NULL, }
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100375};
376
Ingo Molnar13839ec2015-10-19 10:04:17 +0200377int bench_mem_memset(int argc, const char **argv, const char *prefix __maybe_unused)
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100378{
379 struct bench_mem_info info = {
Ingo Molnar2f211c82015-10-19 10:04:29 +0200380 .functions = memset_functions,
Ingo Molnarb14f2d32015-10-19 10:04:23 +0200381 .do_cycles = do_memset_cycles,
Ingo Molnar13839ec2015-10-19 10:04:17 +0200382 .do_gettimeofday = do_memset_gettimeofday,
383 .usage = bench_mem_memset_usage,
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100384 };
385
Ingo Molnar2946f592015-10-19 10:04:19 +0200386 return bench_mem_common(argc, argv, &info);
Rabin Vincent5bce1a52014-12-02 16:50:40 +0100387}