blob: fecd70747a9a4f9d87639b43e3340ee582227494 [file] [log] [blame]
Christopher Ferris82ac1af2013-02-15 12:27:58 -08001/*
2** Copyright 2010 The Android Open Source Project
3**
4** Licensed under the Apache License, Version 2.0 (the "License");
5** you may not use this file except in compliance with the License.
6** You may obtain a copy of the License at
7**
8** http://www.apache.org/licenses/LICENSE-2.0
9**
10** Unless required by applicable law or agreed to in writing, software
11** distributed under the License is distributed on an "AS IS" BASIS,
12** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13** See the License for the specific language governing permissions and
14** limitations under the License.
15*/
16
17/*
Christopher Ferris25ada902013-04-02 13:28:16 -070018 * Micro-benchmarking of sleep/cpu speed/memcpy/memset/memory reads/strcmp.
Christopher Ferris82ac1af2013-02-15 12:27:58 -080019 */
20
21#include <stdio.h>
22#include <stdlib.h>
Elliott Hughes7e2587f2015-01-28 11:18:24 -080023#include <string.h>
Christopher Ferris82ac1af2013-02-15 12:27:58 -080024#include <ctype.h>
25#include <math.h>
26#include <sched.h>
27#include <sys/resource.h>
28#include <time.h>
29#include <unistd.h>
30
31// The default size of data that will be manipulated in each iteration of
32// a memory benchmark. Can be modified with the --data_size option.
33#define DEFAULT_DATA_SIZE 1000000000
34
Christopher Ferris991bcd42013-07-24 15:34:13 -070035// The amount of memory allocated for the cold benchmarks to use.
36#define DEFAULT_COLD_DATA_SIZE 128*1024*1024
37
38// The default size of the stride between each buffer for cold benchmarks.
39#define DEFAULT_COLD_STRIDE_SIZE 4096
40
Christopher Ferris82ac1af2013-02-15 12:27:58 -080041// Number of nanoseconds in a second.
42#define NS_PER_SEC 1000000000
43
44// The maximum number of arguments that a benchmark will accept.
45#define MAX_ARGS 2
46
Christopher Ferris991bcd42013-07-24 15:34:13 -070047// Default memory alignment of malloc.
48#define DEFAULT_MALLOC_MEMORY_ALIGNMENT 8
49
Christopher Ferris82ac1af2013-02-15 12:27:58 -080050// Contains information about benchmark options.
51typedef struct {
52 bool print_average;
53 bool print_each_iter;
54
55 int dst_align;
Christopher Ferris25ada902013-04-02 13:28:16 -070056 int dst_or_mask;
Christopher Ferris82ac1af2013-02-15 12:27:58 -080057 int src_align;
Christopher Ferris25ada902013-04-02 13:28:16 -070058 int src_or_mask;
Christopher Ferris82ac1af2013-02-15 12:27:58 -080059
60 int cpu_to_lock;
61
62 int data_size;
Christopher Ferris7401bc12013-07-10 18:55:57 -070063 int dst_str_size;
Christopher Ferris991bcd42013-07-24 15:34:13 -070064 int cold_data_size;
65 int cold_stride_size;
Christopher Ferris82ac1af2013-02-15 12:27:58 -080066
67 int args[MAX_ARGS];
68 int num_args;
69} command_data_t;
70
Christopher Ferris014cf9d2013-06-26 13:42:18 -070071typedef void *(*void_func_t)();
72typedef void *(*memcpy_func_t)(void *, const void *, size_t);
73typedef void *(*memset_func_t)(void *, int, size_t);
74typedef int (*strcmp_func_t)(const char *, const char *);
Christopher Ferris7401bc12013-07-10 18:55:57 -070075typedef char *(*str_func_t)(char *, const char *);
76typedef size_t (*strlen_func_t)(const char *);
Christopher Ferris014cf9d2013-06-26 13:42:18 -070077
Christopher Ferris82ac1af2013-02-15 12:27:58 -080078// Struct that contains a mapping of benchmark name to benchmark function.
79typedef struct {
80 const char *name;
Christopher Ferris014cf9d2013-06-26 13:42:18 -070081 int (*ptr)(const char *, const command_data_t &, void_func_t func);
82 void_func_t func;
Christopher Ferris82ac1af2013-02-15 12:27:58 -080083} function_t;
84
85// Get the current time in nanoseconds.
86uint64_t nanoTime() {
87 struct timespec t;
88
89 t.tv_sec = t.tv_nsec = 0;
90 clock_gettime(CLOCK_MONOTONIC, &t);
91 return static_cast<uint64_t>(t.tv_sec) * NS_PER_SEC + t.tv_nsec;
92}
93
94// Allocate memory with a specific alignment and return that pointer.
95// This function assumes an alignment value that is a power of 2.
96// If the alignment is 0, then use the pointer returned by malloc.
Christopher Ferris25ada902013-04-02 13:28:16 -070097uint8_t *getAlignedMemory(uint8_t *orig_ptr, int alignment, int or_mask) {
98 uint64_t ptr = reinterpret_cast<uint64_t>(orig_ptr);
Christopher Ferris82ac1af2013-02-15 12:27:58 -080099 if (alignment > 0) {
100 // When setting the alignment, set it to exactly the alignment chosen.
101 // The pointer returned will be guaranteed not to be aligned to anything
102 // more than that.
103 ptr += alignment - (ptr & (alignment - 1));
Christopher Ferris25ada902013-04-02 13:28:16 -0700104 ptr |= alignment | or_mask;
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800105 }
106
107 return reinterpret_cast<uint8_t*>(ptr);
108}
109
Christopher Ferris25ada902013-04-02 13:28:16 -0700110// Allocate memory with a specific alignment and return that pointer.
111// This function assumes an alignment value that is a power of 2.
112// If the alignment is 0, then use the pointer returned by malloc.
113uint8_t *allocateAlignedMemory(size_t size, int alignment, int or_mask) {
114 uint64_t ptr = reinterpret_cast<uint64_t>(malloc(size + 3 * alignment));
115 if (!ptr)
116 return NULL;
117 return getAlignedMemory((uint8_t*)ptr, alignment, or_mask);
118}
119
Christopher Ferris991bcd42013-07-24 15:34:13 -0700120void initString(uint8_t *buf, size_t size) {
121 for (size_t i = 0; i < size - 1; i++) {
122 buf[i] = static_cast<char>(32 + (i % 96));
Christopher Ferris7401bc12013-07-10 18:55:57 -0700123 }
Christopher Ferris991bcd42013-07-24 15:34:13 -0700124 buf[size-1] = '\0';
Christopher Ferris7401bc12013-07-10 18:55:57 -0700125}
126
Christopher Ferris991bcd42013-07-24 15:34:13 -0700127static inline double computeAverage(uint64_t time_ns, size_t size, size_t copies) {
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700128 return ((size/1024.0) * copies) / ((double)time_ns/NS_PER_SEC);
129}
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800130
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700131static inline double computeRunningAvg(double avg, double running_avg, size_t cur_idx) {
132 return (running_avg / (cur_idx + 1)) * cur_idx + (avg / (cur_idx + 1));
133}
134
135static inline double computeRunningSquareAvg(double avg, double square_avg, size_t cur_idx) {
136 return (square_avg / (cur_idx + 1)) * cur_idx + (avg / (cur_idx + 1)) * avg;
137}
138
139static inline double computeStdDev(double square_avg, double running_avg) {
140 return sqrt(square_avg - running_avg * running_avg);
141}
142
Christopher Ferris991bcd42013-07-24 15:34:13 -0700143static inline void printIter(uint64_t time_ns, const char *name, size_t size, size_t copies, double avg) {
Mark Salyzyn8ec652c2014-03-20 12:46:42 -0700144 printf("%s %zux%zu bytes took %.06f seconds (%f MB/s)\n",
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700145 name, copies, size, (double)time_ns/NS_PER_SEC, avg/1024.0);
146}
147
Mark Salyzyn8ec652c2014-03-20 12:46:42 -0700148static inline void printSummary(uint64_t /*time_ns*/, const char *name, size_t size, size_t copies, double running_avg, double std_dev, double min, double max) {
149 printf(" %s %zux%zu bytes average %.2f MB/s std dev %.4f min %.2f MB/s max %.2f MB/s\n",
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700150 name, copies, size, running_avg/1024.0, std_dev/1024.0, min/1024.0,
151 max/1024.0);
152}
153
Christopher Ferris991bcd42013-07-24 15:34:13 -0700154// For the cold benchmarks, a large buffer will be created which
155// contains many "size" buffers. This function will figure out the increment
156// needed between each buffer so that each one is aligned to "alignment".
157int getAlignmentIncrement(size_t size, int alignment) {
158 if (alignment == 0) {
159 alignment = DEFAULT_MALLOC_MEMORY_ALIGNMENT;
160 }
161 alignment *= 2;
162 return size + alignment - (size % alignment);
163}
164
165uint8_t *getColdBuffer(int num_buffers, size_t incr, int alignment, int or_mask) {
166 uint8_t *buffers = reinterpret_cast<uint8_t*>(malloc(num_buffers * incr + 3 * alignment));
167 if (!buffers) {
168 return NULL;
169 }
170 return getAlignedMemory(buffers, alignment, or_mask);
171}
172
173static inline double computeColdAverage(uint64_t time_ns, size_t size, size_t copies, size_t num_buffers) {
174 return ((size/1024.0) * copies * num_buffers) / ((double)time_ns/NS_PER_SEC);
175}
176
177static void inline printColdIter(uint64_t time_ns, const char *name, size_t size, size_t copies, size_t num_buffers, double avg) {
Mark Salyzyn8ec652c2014-03-20 12:46:42 -0700178 printf("%s %zux%zux%zu bytes took %.06f seconds (%f MB/s)\n",
Christopher Ferris991bcd42013-07-24 15:34:13 -0700179 name, copies, num_buffers, size, (double)time_ns/NS_PER_SEC, avg/1024.0);
180}
181
182static void inline printColdSummary(
Mark Salyzyn8ec652c2014-03-20 12:46:42 -0700183 uint64_t /*time_ns*/, const char *name, size_t size, size_t copies, size_t num_buffers,
Christopher Ferris991bcd42013-07-24 15:34:13 -0700184 double running_avg, double square_avg, double min, double max) {
Mark Salyzyn8ec652c2014-03-20 12:46:42 -0700185 printf(" %s %zux%zux%zu bytes average %.2f MB/s std dev %.4f min %.2f MB/s max %.2f MB/s\n",
Christopher Ferris991bcd42013-07-24 15:34:13 -0700186 name, copies, num_buffers, size, running_avg/1024.0,
187 computeStdDev(running_avg, square_avg)/1024.0, min/1024.0, max/1024.0);
188}
189
190#define MAINLOOP(cmd_data, BENCH, COMPUTE_AVG, PRINT_ITER, PRINT_AVG) \
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700191 uint64_t time_ns; \
192 int iters = cmd_data.args[1]; \
193 bool print_average = cmd_data.print_average; \
194 bool print_each_iter = cmd_data.print_each_iter; \
195 double min = 0.0, max = 0.0, running_avg = 0.0, square_avg = 0.0; \
196 double avg; \
197 for (int i = 0; iters == -1 || i < iters; i++) { \
198 time_ns = nanoTime(); \
199 BENCH; \
200 time_ns = nanoTime() - time_ns; \
201 avg = COMPUTE_AVG; \
202 if (print_average) { \
203 running_avg = computeRunningAvg(avg, running_avg, i); \
204 square_avg = computeRunningSquareAvg(avg, square_avg, i); \
205 if (min == 0.0 || avg < min) { \
206 min = avg; \
207 } \
208 if (avg > max) { \
209 max = avg; \
210 } \
211 } \
212 if (print_each_iter) { \
213 PRINT_ITER; \
214 } \
215 } \
216 if (print_average) { \
217 PRINT_AVG; \
218 }
219
Christopher Ferris991bcd42013-07-24 15:34:13 -0700220#define MAINLOOP_DATA(name, cmd_data, size, BENCH) \
221 size_t copies = cmd_data.data_size/size; \
222 size_t j; \
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700223 MAINLOOP(cmd_data, \
224 for (j = 0; j < copies; j++) { \
225 BENCH; \
226 }, \
227 computeAverage(time_ns, size, copies), \
228 printIter(time_ns, name, size, copies, avg), \
229 double std_dev = computeStdDev(square_avg, running_avg); \
230 printSummary(time_ns, name, size, copies, running_avg, \
231 std_dev, min, max));
232
Christopher Ferris991bcd42013-07-24 15:34:13 -0700233#define MAINLOOP_COLD(name, cmd_data, size, num_incrs, BENCH) \
234 size_t num_strides = num_buffers / num_incrs; \
235 if ((num_buffers % num_incrs) != 0) { \
236 num_strides--; \
237 } \
238 size_t copies = 1; \
239 num_buffers = num_incrs * num_strides; \
240 if (num_buffers * size < static_cast<size_t>(cmd_data.data_size)) { \
241 copies = cmd_data.data_size / (num_buffers * size); \
242 } \
243 if (num_strides == 0) { \
244 printf("%s: Chosen options lead to no copies, aborting.\n", name); \
245 return -1; \
246 } \
247 size_t j, k; \
248 MAINLOOP(cmd_data, \
249 for (j = 0; j < copies; j++) { \
250 for (k = 0; k < num_incrs; k++) { \
251 BENCH; \
252 } \
253 }, \
254 computeColdAverage(time_ns, size, copies, num_buffers), \
255 printColdIter(time_ns, name, size, copies, num_buffers, avg), \
256 printColdSummary(time_ns, name, size, copies, num_buffers, \
257 running_avg, square_avg, min, max));
258
259// This version of the macro creates a single buffer of the given size and
260// alignment. The variable "buf" will be a pointer to the buffer and should
261// be used by the BENCH code.
262// INIT - Any specialized code needed to initialize the data. This will only
263// be executed once.
264// BENCH - The actual code to benchmark and is timed.
265#define BENCH_ONE_BUF(name, cmd_data, INIT, BENCH) \
266 size_t size = cmd_data.args[0]; \
267 uint8_t *buf = allocateAlignedMemory(size, cmd_data.dst_align, cmd_data.dst_or_mask); \
268 if (!buf) \
269 return -1; \
270 INIT; \
271 MAINLOOP_DATA(name, cmd_data, size, BENCH);
272
273// This version of the macro creates two buffers of the given sizes and
274// alignments. The variables "buf1" and "buf2" will be pointers to the
275// buffers and should be used by the BENCH code.
276// INIT - Any specialized code needed to initialize the data. This will only
277// be executed once.
278// BENCH - The actual code to benchmark and is timed.
279#define BENCH_TWO_BUFS(name, cmd_data, INIT, BENCH) \
280 size_t size = cmd_data.args[0]; \
281 uint8_t *buf1 = allocateAlignedMemory(size, cmd_data.src_align, cmd_data.src_or_mask); \
282 if (!buf1) \
283 return -1; \
284 size_t total_size = size; \
285 if (cmd_data.dst_str_size > 0) \
286 total_size += cmd_data.dst_str_size; \
287 uint8_t *buf2 = allocateAlignedMemory(total_size, cmd_data.dst_align, cmd_data.dst_or_mask); \
288 if (!buf2) \
289 return -1; \
290 INIT; \
291 MAINLOOP_DATA(name, cmd_data, size, BENCH);
292
293// This version of the macro attempts to benchmark code when the data
294// being manipulated is not in the cache, thus the cache is cold. It does
295// this by creating a single large buffer that is designed to be larger than
296// the largest cache in the system. The variable "buf" will be one slice
297// of the buffer that the BENCH code should use that is of the correct size
298// and alignment. In order to avoid any algorithms that prefetch past the end
299// of their "buf" and into the next sequential buffer, the code strides
300// through the buffer. Specifically, as "buf" values are iterated in BENCH
301// code, the end of "buf" is guaranteed to be at least "stride_size" away
302// from the next "buf".
303// INIT - Any specialized code needed to initialize the data. This will only
304// be executed once.
305// BENCH - The actual code to benchmark and is timed.
306#define COLD_ONE_BUF(name, cmd_data, INIT, BENCH) \
307 size_t size = cmd_data.args[0]; \
308 size_t incr = getAlignmentIncrement(size, cmd_data.dst_align); \
309 size_t num_buffers = cmd_data.cold_data_size / incr; \
310 size_t buffer_size = num_buffers * incr; \
311 uint8_t *buffer = getColdBuffer(num_buffers, incr, cmd_data.dst_align, cmd_data.dst_or_mask); \
312 if (!buffer) \
313 return -1; \
314 size_t num_incrs = cmd_data.cold_stride_size / incr + 1; \
315 size_t stride_incr = incr * num_incrs; \
316 uint8_t *buf; \
317 size_t l; \
318 INIT; \
319 MAINLOOP_COLD(name, cmd_data, size, num_incrs, \
320 buf = buffer + k * incr; \
321 for (l = 0; l < num_strides; l++) { \
322 BENCH; \
323 buf += stride_incr; \
324 });
325
326// This version of the macro attempts to benchmark code when the data
327// being manipulated is not in the cache, thus the cache is cold. It does
328// this by creating two large buffers each of which is designed to be
329// larger than the largest cache in the system. Two variables "buf1" and
330// "buf2" will be the two buffers that BENCH code should use. In order
331// to avoid any algorithms that prefetch past the end of either "buf1"
332// or "buf2" and into the next sequential buffer, the code strides through
333// both buffers. Specifically, as "buf1" and "buf2" values are iterated in
334// BENCH code, the end of "buf1" and "buf2" is guaranteed to be at least
335// "stride_size" away from the next "buf1" and "buf2".
336// INIT - Any specialized code needed to initialize the data. This will only
337// be executed once.
338// BENCH - The actual code to benchmark and is timed.
339#define COLD_TWO_BUFS(name, cmd_data, INIT, BENCH) \
340 size_t size = cmd_data.args[0]; \
341 size_t buf1_incr = getAlignmentIncrement(size, cmd_data.src_align); \
342 size_t total_size = size; \
343 if (cmd_data.dst_str_size > 0) \
344 total_size += cmd_data.dst_str_size; \
345 size_t buf2_incr = getAlignmentIncrement(total_size, cmd_data.dst_align); \
346 size_t max_incr = (buf1_incr > buf2_incr) ? buf1_incr : buf2_incr; \
347 size_t num_buffers = cmd_data.cold_data_size / max_incr; \
348 size_t buffer1_size = num_buffers * buf1_incr; \
349 size_t buffer2_size = num_buffers * buf2_incr; \
350 uint8_t *buffer1 = getColdBuffer(num_buffers, buf1_incr, cmd_data.src_align, cmd_data.src_or_mask); \
351 if (!buffer1) \
352 return -1; \
353 uint8_t *buffer2 = getColdBuffer(num_buffers, buf2_incr, cmd_data.dst_align, cmd_data.dst_or_mask); \
354 if (!buffer2) \
355 return -1; \
356 size_t min_incr = (buf1_incr < buf2_incr) ? buf1_incr : buf2_incr; \
357 size_t num_incrs = cmd_data.cold_stride_size / min_incr + 1; \
358 size_t buf1_stride_incr = buf1_incr * num_incrs; \
359 size_t buf2_stride_incr = buf2_incr * num_incrs; \
360 size_t l; \
361 uint8_t *buf1; \
362 uint8_t *buf2; \
363 INIT; \
364 MAINLOOP_COLD(name, cmd_data, size, num_incrs, \
365 buf1 = buffer1 + k * buf1_incr; \
366 buf2 = buffer2 + k * buf2_incr; \
367 for (l = 0; l < num_strides; l++) { \
368 BENCH; \
369 buf1 += buf1_stride_incr; \
370 buf2 += buf2_stride_incr; \
371 });
372
Mark Salyzyn8ec652c2014-03-20 12:46:42 -0700373int benchmarkSleep(const char* /*name*/, const command_data_t &cmd_data, void_func_t /*func*/) {
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800374 int delay = cmd_data.args[0];
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700375 MAINLOOP(cmd_data, sleep(delay),
376 (double)time_ns/NS_PER_SEC,
377 printf("sleep(%d) took %.06f seconds\n", delay, avg);,
378 printf(" sleep(%d) average %.06f seconds std dev %f min %.06f seconds max %0.6f seconds\n", \
379 delay, running_avg, computeStdDev(square_avg, running_avg), \
380 min, max));
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800381
382 return 0;
383}
384
Mark Salyzyn8ec652c2014-03-20 12:46:42 -0700385int benchmarkCpu(const char* /*name*/, const command_data_t &cmd_data, void_func_t /*func*/) {
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800386 // Use volatile so that the loop is not optimized away by the compiler.
387 volatile int cpu_foo;
388
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700389 MAINLOOP(cmd_data,
390 for (cpu_foo = 0; cpu_foo < 100000000; cpu_foo++),
391 (double)time_ns/NS_PER_SEC,
392 printf("cpu took %.06f seconds\n", avg),
393 printf(" cpu average %.06f seconds std dev %f min %0.6f seconds max %0.6f seconds\n", \
394 running_avg, computeStdDev(square_avg, running_avg), min, max));
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800395
396 return 0;
397}
398
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700399int benchmarkMemset(const char *name, const command_data_t &cmd_data, void_func_t func) {
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700400 memset_func_t memset_func = reinterpret_cast<memset_func_t>(func);
Christopher Ferris991bcd42013-07-24 15:34:13 -0700401 BENCH_ONE_BUF(name, cmd_data, ;, memset_func(buf, i, size));
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800402
Christopher Ferris991bcd42013-07-24 15:34:13 -0700403 return 0;
404}
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800405
Christopher Ferris991bcd42013-07-24 15:34:13 -0700406int benchmarkMemsetCold(const char *name, const command_data_t &cmd_data, void_func_t func) {
407 memset_func_t memset_func = reinterpret_cast<memset_func_t>(func);
408 COLD_ONE_BUF(name, cmd_data, ;, memset_func(buf, l, size));
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800409
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800410 return 0;
411}
412
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700413int benchmarkMemcpy(const char *name, const command_data_t &cmd_data, void_func_t func) {
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700414 memcpy_func_t memcpy_func = reinterpret_cast<memcpy_func_t>(func);
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800415
Christopher Ferris991bcd42013-07-24 15:34:13 -0700416 BENCH_TWO_BUFS(name, cmd_data,
417 memset(buf1, 0xff, size); \
418 memset(buf2, 0, size),
419 memcpy_func(buf2, buf1, size));
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800420
Christopher Ferris991bcd42013-07-24 15:34:13 -0700421 return 0;
422}
Christopher Ferris25ada902013-04-02 13:28:16 -0700423
Christopher Ferris991bcd42013-07-24 15:34:13 -0700424int benchmarkMemcpyCold(const char *name, const command_data_t &cmd_data, void_func_t func) {
425 memcpy_func_t memcpy_func = reinterpret_cast<memcpy_func_t>(func);
426
427 COLD_TWO_BUFS(name, cmd_data,
428 memset(buffer1, 0xff, buffer1_size); \
429 memset(buffer2, 0x0, buffer2_size),
430 memcpy_func(buf2, buf1, size));
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800431
Christopher Ferris25ada902013-04-02 13:28:16 -0700432 return 0;
433}
434
Mark Salyzyn8ec652c2014-03-20 12:46:42 -0700435int benchmarkMemread(const char *name, const command_data_t &cmd_data, void_func_t /*func*/) {
Christopher Ferris25ada902013-04-02 13:28:16 -0700436 int size = cmd_data.args[0];
Christopher Ferris25ada902013-04-02 13:28:16 -0700437
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700438 uint32_t *src = reinterpret_cast<uint32_t*>(malloc(size));
439 if (!src)
Christopher Ferris25ada902013-04-02 13:28:16 -0700440 return -1;
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700441 memset(src, 0xff, size);
Christopher Ferris25ada902013-04-02 13:28:16 -0700442
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700443 // Use volatile so the compiler does not optimize away the reads.
444 volatile int foo;
445 size_t k;
446 MAINLOOP_DATA(name, cmd_data, size,
Christopher Ferris991bcd42013-07-24 15:34:13 -0700447 for (k = 0; k < size/sizeof(uint32_t); k++) foo = src[k]);
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700448
449 return 0;
450}
451
452int benchmarkStrcmp(const char *name, const command_data_t &cmd_data, void_func_t func) {
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700453 strcmp_func_t strcmp_func = reinterpret_cast<strcmp_func_t>(func);
454
Christopher Ferris991bcd42013-07-24 15:34:13 -0700455 int retval;
456 BENCH_TWO_BUFS(name, cmd_data,
457 initString(buf1, size); \
458 initString(buf2, size),
459 retval = strcmp_func(reinterpret_cast<char*>(buf1), reinterpret_cast<char*>(buf2)); \
460 if (retval != 0) printf("%s failed, return value %d\n", name, retval));
461
462 return 0;
463}
464
465int benchmarkStrcmpCold(const char *name, const command_data_t &cmd_data, void_func_t func) {
466 strcmp_func_t strcmp_func = reinterpret_cast<strcmp_func_t>(func);
Christopher Ferris25ada902013-04-02 13:28:16 -0700467
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700468 int retval;
Christopher Ferris991bcd42013-07-24 15:34:13 -0700469 COLD_TWO_BUFS(name, cmd_data,
470 memset(buffer1, 'a', buffer1_size); \
471 memset(buffer2, 'a', buffer2_size); \
472 for (size_t i =0; i < num_buffers; i++) { \
473 buffer1[size-1+buf1_incr*i] = '\0'; \
474 buffer2[size-1+buf2_incr*i] = '\0'; \
475 },
476 retval = strcmp_func(reinterpret_cast<char*>(buf1), reinterpret_cast<char*>(buf2)); \
477 if (retval != 0) printf("%s failed, return value %d\n", name, retval));
Christopher Ferris7401bc12013-07-10 18:55:57 -0700478
479 return 0;
480}
481
482int benchmarkStrlen(const char *name, const command_data_t &cmd_data, void_func_t func) {
Christopher Ferris7401bc12013-07-10 18:55:57 -0700483 size_t real_size;
Christopher Ferris991bcd42013-07-24 15:34:13 -0700484 strlen_func_t strlen_func = reinterpret_cast<strlen_func_t>(func);
485 BENCH_ONE_BUF(name, cmd_data,
486 initString(buf, size),
487 real_size = strlen_func(reinterpret_cast<char*>(buf)); \
Christopher Ferris7401bc12013-07-10 18:55:57 -0700488 if (real_size + 1 != size) { \
Mark Salyzyn8ec652c2014-03-20 12:46:42 -0700489 printf("%s failed, expected %zu, got %zu\n", name, size, real_size); \
Christopher Ferris7401bc12013-07-10 18:55:57 -0700490 return -1; \
Christopher Ferris991bcd42013-07-24 15:34:13 -0700491 });
Christopher Ferris7401bc12013-07-10 18:55:57 -0700492
493 return 0;
494}
495
Christopher Ferris991bcd42013-07-24 15:34:13 -0700496int benchmarkStrlenCold(const char *name, const command_data_t &cmd_data, void_func_t func) {
497 strlen_func_t strlen_func = reinterpret_cast<strlen_func_t>(func);
498 size_t real_size;
499 COLD_ONE_BUF(name, cmd_data,
500 memset(buffer, 'a', buffer_size); \
501 for (size_t i = 0; i < num_buffers; i++) { \
502 buffer[size-1+incr*i] = '\0'; \
503 },
504 real_size = strlen_func(reinterpret_cast<char*>(buf)); \
505 if (real_size + 1 != size) { \
Mark Salyzyn8ec652c2014-03-20 12:46:42 -0700506 printf("%s failed, expected %zu, got %zu\n", name, size, real_size); \
Christopher Ferris991bcd42013-07-24 15:34:13 -0700507 return -1; \
508 });
509 return 0;
510}
511
Christopher Ferris7401bc12013-07-10 18:55:57 -0700512int benchmarkStrcat(const char *name, const command_data_t &cmd_data, void_func_t func) {
Christopher Ferris7401bc12013-07-10 18:55:57 -0700513 str_func_t str_func = reinterpret_cast<str_func_t>(func);
514
515 int dst_str_size = cmd_data.dst_str_size;
516 if (dst_str_size <= 0) {
517 printf("%s requires --dst_str_size to be set to a non-zero value.\n",
518 name);
519 return -1;
520 }
Christopher Ferris991bcd42013-07-24 15:34:13 -0700521 BENCH_TWO_BUFS(name, cmd_data,
522 initString(buf1, size); \
523 initString(buf2, dst_str_size),
524 str_func(reinterpret_cast<char*>(buf2), reinterpret_cast<char*>(buf1)); buf2[dst_str_size-1] = '\0');
Christopher Ferris25ada902013-04-02 13:28:16 -0700525
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800526 return 0;
527}
528
Christopher Ferris991bcd42013-07-24 15:34:13 -0700529int benchmarkStrcatCold(const char *name, const command_data_t &cmd_data, void_func_t func) {
Christopher Ferris7401bc12013-07-10 18:55:57 -0700530 str_func_t str_func = reinterpret_cast<str_func_t>(func);
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800531
Christopher Ferris991bcd42013-07-24 15:34:13 -0700532 int dst_str_size = cmd_data.dst_str_size;
533 if (dst_str_size <= 0) {
534 printf("%s requires --dst_str_size to be set to a non-zero value.\n",
535 name);
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800536 return -1;
Christopher Ferris991bcd42013-07-24 15:34:13 -0700537 }
538 COLD_TWO_BUFS(name, cmd_data,
539 memset(buffer1, 'a', buffer1_size); \
540 memset(buffer2, 'b', buffer2_size); \
541 for (size_t i = 0; i < num_buffers; i++) { \
542 buffer1[size-1+buf1_incr*i] = '\0'; \
543 buffer2[dst_str_size-1+buf2_incr*i] = '\0'; \
544 },
545 str_func(reinterpret_cast<char*>(buf2), reinterpret_cast<char*>(buf1)); buf2[dst_str_size-1] = '\0');
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800546
Christopher Ferris991bcd42013-07-24 15:34:13 -0700547 return 0;
548}
549
550
551int benchmarkStrcpy(const char *name, const command_data_t &cmd_data, void_func_t func) {
552 str_func_t str_func = reinterpret_cast<str_func_t>(func);
553
554 BENCH_TWO_BUFS(name, cmd_data,
555 initString(buf1, size); \
556 memset(buf2, 0, size),
557 str_func(reinterpret_cast<char*>(buf2), reinterpret_cast<char*>(buf1)));
558
559 return 0;
560}
561
562int benchmarkStrcpyCold(const char *name, const command_data_t &cmd_data, void_func_t func) {
563 str_func_t str_func = reinterpret_cast<str_func_t>(func);
564
565 COLD_TWO_BUFS(name, cmd_data,
566 memset(buffer1, 'a', buffer1_size); \
567 for (size_t i = 0; i < num_buffers; i++) { \
568 buffer1[size-1+buf1_incr*i] = '\0'; \
569 } \
570 memset(buffer2, 0, buffer2_size),
571 str_func(reinterpret_cast<char*>(buf2), reinterpret_cast<char*>(buf1)));
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800572
573 return 0;
574}
575
576// Create the mapping structure.
577function_t function_table[] = {
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700578 { "cpu", benchmarkCpu, NULL },
Christopher Ferris991bcd42013-07-24 15:34:13 -0700579 { "memcpy", benchmarkMemcpy, reinterpret_cast<void_func_t>(memcpy) },
580 { "memcpy_cold", benchmarkMemcpyCold, reinterpret_cast<void_func_t>(memcpy) },
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700581 { "memread", benchmarkMemread, NULL },
582 { "memset", benchmarkMemset, reinterpret_cast<void_func_t>(memset) },
Christopher Ferris991bcd42013-07-24 15:34:13 -0700583 { "memset_cold", benchmarkMemsetCold, reinterpret_cast<void_func_t>(memset) },
584 { "sleep", benchmarkSleep, NULL },
Christopher Ferris7401bc12013-07-10 18:55:57 -0700585 { "strcat", benchmarkStrcat, reinterpret_cast<void_func_t>(strcat) },
Christopher Ferris991bcd42013-07-24 15:34:13 -0700586 { "strcat_cold", benchmarkStrcatCold, reinterpret_cast<void_func_t>(strcat) },
587 { "strcmp", benchmarkStrcmp, reinterpret_cast<void_func_t>(strcmp) },
588 { "strcmp_cold", benchmarkStrcmpCold, reinterpret_cast<void_func_t>(strcmp) },
589 { "strcpy", benchmarkStrcpy, reinterpret_cast<void_func_t>(strcpy) },
590 { "strcpy_cold", benchmarkStrcpyCold, reinterpret_cast<void_func_t>(strcpy) },
591 { "strlen", benchmarkStrlen, reinterpret_cast<void_func_t>(strlen) },
592 { "strlen_cold", benchmarkStrlenCold, reinterpret_cast<void_func_t>(strlen) },
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800593};
594
595void usage() {
596 printf("Usage:\n");
597 printf(" micro_bench [--data_size DATA_BYTES] [--print_average]\n");
598 printf(" [--no_print_each_iter] [--lock_to_cpu CORE]\n");
Christopher Ferris7401bc12013-07-10 18:55:57 -0700599 printf(" [--src_align ALIGN] [--src_or_mask OR_MASK]\n");
600 printf(" [--dst_align ALIGN] [--dst_or_mask OR_MASK]\n");
Christopher Ferris991bcd42013-07-24 15:34:13 -0700601 printf(" [--dst_str_size SIZE] [--cold_data_size DATA_BYTES]\n");
602 printf(" [--cold_stride_size SIZE]\n");
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800603 printf(" --data_size DATA_BYTES\n");
604 printf(" For the data benchmarks (memcpy/memset/memread) the approximate\n");
605 printf(" size of data, in bytes, that will be manipulated in each iteration.\n");
606 printf(" --print_average\n");
607 printf(" Print the average and standard deviation of all iterations.\n");
608 printf(" --no_print_each_iter\n");
609 printf(" Do not print any values in each iteration.\n");
610 printf(" --lock_to_cpu CORE\n");
611 printf(" Lock to the specified CORE. The default is to use the last core found.\n");
Christopher Ferris7401bc12013-07-10 18:55:57 -0700612 printf(" --dst_align ALIGN\n");
613 printf(" If the command supports it, align the destination pointer to ALIGN.\n");
614 printf(" The default is to use the value returned by malloc.\n");
615 printf(" --dst_or_mask OR_MASK\n");
616 printf(" If the command supports it, or in the OR_MASK on to the destination pointer.\n");
617 printf(" The OR_MASK must be smaller than the dst_align value.\n");
618 printf(" The default value is 0.\n");
619
620 printf(" --src_align ALIGN\n");
621 printf(" If the command supports it, align the source pointer to ALIGN. The default is to use the\n");
622 printf(" value returned by malloc.\n");
623 printf(" --src_or_mask OR_MASK\n");
624 printf(" If the command supports it, or in the OR_MASK on to the source pointer.\n");
625 printf(" The OR_MASK must be smaller than the src_align value.\n");
626 printf(" The default value is 0.\n");
627 printf(" --dst_str_size SIZE\n");
628 printf(" If the command supports it, create a destination string of this length.\n");
629 printf(" The default is to not update the destination string.\n");
Christopher Ferris991bcd42013-07-24 15:34:13 -0700630 printf(" --cold_data_size DATA_SIZE\n");
631 printf(" For _cold benchmarks, use this as the total amount of memory to use.\n");
632 printf(" The default is 128MB, and the number should be larger than the cache on the chip.\n");
633 printf(" This value is specified in bytes.\n");
634 printf(" --cold_stride_size SIZE\n");
635 printf(" For _cold benchmarks, use this as the minimum stride between iterations.\n");
636 printf(" The default is 4096 bytes and the number should be larger than the amount of data\n");
637 printf(" pulled in to the cache by each run of the benchmark.\n");
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800638 printf(" ITERS\n");
639 printf(" The number of iterations to execute each benchmark. If not\n");
640 printf(" passed in then run forever.\n");
Christopher Ferris991bcd42013-07-24 15:34:13 -0700641 printf(" micro_bench cpu UNUSED [ITERS]\n");
642 printf(" micro_bench [--dst_align ALIGN] [--dst_or_mask OR_MASK] memcpy NUM_BYTES [ITERS]\n");
643 printf(" micro_bench memread NUM_BYTES [ITERS]\n");
644 printf(" micro_bench [--dst_align ALIGN] [--dst_or_mask OR_MASK] memset NUM_BYTES [ITERS]\n");
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800645 printf(" micro_bench sleep TIME_TO_SLEEP [ITERS]\n");
646 printf(" TIME_TO_SLEEP\n");
647 printf(" The time in seconds to sleep.\n");
Christopher Ferris7401bc12013-07-10 18:55:57 -0700648 printf(" micro_bench [--src_align ALIGN] [--src_or_mask OR_MASK] [--dst_align ALIGN] [--dst_or_mask] [--dst_str_size SIZE] strcat NUM_BYTES [ITERS]\n");
649 printf(" micro_bench [--src_align ALIGN] [--src_or_mask OR_MASK] [--dst_align ALIGN] [--dst_or_mask OR_MASK] strcmp NUM_BYTES [ITERS]\n");
650 printf(" micro_bench [--src_align ALIGN] [--src_or_mask OR_MASK] [--dst_align ALIGN] [--dst_or_mask] strcpy NUM_BYTES [ITERS]\n");
651 printf(" micro_bench [--dst_align ALIGN] [--dst_or_mask OR_MASK] strlen NUM_BYTES [ITERS]\n");
Christopher Ferris991bcd42013-07-24 15:34:13 -0700652 printf("\n");
653 printf(" In addition, memcpy/memcpy/memset/strcat/strcpy/strlen have _cold versions\n");
654 printf(" that will execute the function on a buffer not in the cache.\n");
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800655}
656
657function_t *processOptions(int argc, char **argv, command_data_t *cmd_data) {
658 function_t *command = NULL;
659
660 // Initialize the command_flags.
661 cmd_data->print_average = false;
662 cmd_data->print_each_iter = true;
663 cmd_data->dst_align = 0;
664 cmd_data->src_align = 0;
Christopher Ferris25ada902013-04-02 13:28:16 -0700665 cmd_data->src_or_mask = 0;
666 cmd_data->dst_or_mask = 0;
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800667 cmd_data->num_args = 0;
668 cmd_data->cpu_to_lock = -1;
669 cmd_data->data_size = DEFAULT_DATA_SIZE;
Christopher Ferris7401bc12013-07-10 18:55:57 -0700670 cmd_data->dst_str_size = -1;
Christopher Ferris991bcd42013-07-24 15:34:13 -0700671 cmd_data->cold_data_size = DEFAULT_COLD_DATA_SIZE;
672 cmd_data->cold_stride_size = DEFAULT_COLD_STRIDE_SIZE;
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800673 for (int i = 0; i < MAX_ARGS; i++) {
674 cmd_data->args[i] = -1;
675 }
676
677 for (int i = 1; i < argc; i++) {
678 if (argv[i][0] == '-') {
679 int *save_value = NULL;
680 if (strcmp(argv[i], "--print_average") == 0) {
Christopher Ferris991bcd42013-07-24 15:34:13 -0700681 cmd_data->print_average = true;
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800682 } else if (strcmp(argv[i], "--no_print_each_iter") == 0) {
Christopher Ferris991bcd42013-07-24 15:34:13 -0700683 cmd_data->print_each_iter = false;
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800684 } else if (strcmp(argv[i], "--dst_align") == 0) {
Christopher Ferris991bcd42013-07-24 15:34:13 -0700685 save_value = &cmd_data->dst_align;
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800686 } else if (strcmp(argv[i], "--src_align") == 0) {
Christopher Ferris991bcd42013-07-24 15:34:13 -0700687 save_value = &cmd_data->src_align;
Christopher Ferris25ada902013-04-02 13:28:16 -0700688 } else if (strcmp(argv[i], "--dst_or_mask") == 0) {
Christopher Ferris991bcd42013-07-24 15:34:13 -0700689 save_value = &cmd_data->dst_or_mask;
Christopher Ferris25ada902013-04-02 13:28:16 -0700690 } else if (strcmp(argv[i], "--src_or_mask") == 0) {
Christopher Ferris991bcd42013-07-24 15:34:13 -0700691 save_value = &cmd_data->src_or_mask;
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800692 } else if (strcmp(argv[i], "--lock_to_cpu") == 0) {
Christopher Ferris991bcd42013-07-24 15:34:13 -0700693 save_value = &cmd_data->cpu_to_lock;
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800694 } else if (strcmp(argv[i], "--data_size") == 0) {
Christopher Ferris991bcd42013-07-24 15:34:13 -0700695 save_value = &cmd_data->data_size;
Christopher Ferris7401bc12013-07-10 18:55:57 -0700696 } else if (strcmp(argv[i], "--dst_str_size") == 0) {
Christopher Ferris991bcd42013-07-24 15:34:13 -0700697 save_value = &cmd_data->dst_str_size;
698 } else if (strcmp(argv[i], "--cold_data_size") == 0) {
699 save_value = &cmd_data->cold_data_size;
700 } else if (strcmp(argv[i], "--cold_stride_size") == 0) {
701 save_value = &cmd_data->cold_stride_size;
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800702 } else {
703 printf("Unknown option %s\n", argv[i]);
704 return NULL;
705 }
706 if (save_value) {
707 // Checking both characters without a strlen() call should be
708 // safe since as long as the argument exists, one character will
709 // be present (\0). And if the first character is '-', then
710 // there will always be a second character (\0 again).
711 if (i == argc - 1 || (argv[i + 1][0] == '-' && !isdigit(argv[i + 1][1]))) {
712 printf("The option %s requires one argument.\n",
713 argv[i]);
714 return NULL;
715 }
Christopher Ferris25ada902013-04-02 13:28:16 -0700716 *save_value = (int)strtol(argv[++i], NULL, 0);
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800717 }
718 } else if (!command) {
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700719 for (size_t j = 0; j < sizeof(function_table)/sizeof(function_t); j++) {
720 if (strcmp(argv[i], function_table[j].name) == 0) {
721 command = &function_table[j];
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800722 break;
723 }
724 }
725 if (!command) {
726 printf("Uknown command %s\n", argv[i]);
727 return NULL;
728 }
729 } else if (cmd_data->num_args > MAX_ARGS) {
730 printf("More than %d number arguments passed in.\n", MAX_ARGS);
731 return NULL;
732 } else {
733 cmd_data->args[cmd_data->num_args++] = atoi(argv[i]);
734 }
735 }
736
737 // Check the arguments passed in make sense.
738 if (cmd_data->num_args != 1 && cmd_data->num_args != 2) {
739 printf("Not enough arguments passed in.\n");
740 return NULL;
741 } else if (cmd_data->dst_align < 0) {
742 printf("The --dst_align option must be greater than or equal to 0.\n");
743 return NULL;
744 } else if (cmd_data->src_align < 0) {
745 printf("The --src_align option must be greater than or equal to 0.\n");
746 return NULL;
747 } else if (cmd_data->data_size <= 0) {
748 printf("The --data_size option must be a positive number.\n");
749 return NULL;
750 } else if ((cmd_data->dst_align & (cmd_data->dst_align - 1))) {
751 printf("The --dst_align option must be a power of 2.\n");
752 return NULL;
753 } else if ((cmd_data->src_align & (cmd_data->src_align - 1))) {
754 printf("The --src_align option must be a power of 2.\n");
755 return NULL;
Christopher Ferris25ada902013-04-02 13:28:16 -0700756 } else if (!cmd_data->src_align && cmd_data->src_or_mask) {
757 printf("The --src_or_mask option requires that --src_align be set.\n");
758 return NULL;
759 } else if (!cmd_data->dst_align && cmd_data->dst_or_mask) {
760 printf("The --dst_or_mask option requires that --dst_align be set.\n");
761 return NULL;
762 } else if (cmd_data->src_or_mask > cmd_data->src_align) {
763 printf("The value of --src_or_mask cannot be larger that --src_align.\n");
764 return NULL;
765 } else if (cmd_data->dst_or_mask > cmd_data->dst_align) {
766 printf("The value of --src_or_mask cannot be larger that --src_align.\n");
767 return NULL;
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800768 }
769
770 return command;
771}
772
773bool raisePriorityAndLock(int cpu_to_lock) {
774 cpu_set_t cpuset;
775
776 if (setpriority(PRIO_PROCESS, 0, -20)) {
777 perror("Unable to raise priority of process.\n");
778 return false;
779 }
780
781 CPU_ZERO(&cpuset);
782 if (sched_getaffinity(0, sizeof(cpuset), &cpuset) != 0) {
783 perror("sched_getaffinity failed");
784 return false;
785 }
786
787 if (cpu_to_lock < 0) {
788 // Lock to the last active core we find.
789 for (int i = 0; i < CPU_SETSIZE; i++) {
790 if (CPU_ISSET(i, &cpuset)) {
791 cpu_to_lock = i;
792 }
793 }
794 } else if (!CPU_ISSET(cpu_to_lock, &cpuset)) {
795 printf("Cpu %d does not exist.\n", cpu_to_lock);
796 return false;
797 }
798
799 if (cpu_to_lock < 0) {
800 printf("Cannot find any valid cpu to lock.\n");
801 return false;
802 }
803
804 CPU_ZERO(&cpuset);
805 CPU_SET(cpu_to_lock, &cpuset);
806 if (sched_setaffinity(0, sizeof(cpuset), &cpuset) != 0) {
807 perror("sched_setaffinity failed");
808 return false;
809 }
810
811 return true;
812}
813
814int main(int argc, char **argv) {
815 command_data_t cmd_data;
816
817 function_t *command = processOptions(argc, argv, &cmd_data);
818 if (!command) {
819 usage();
820 return -1;
821 }
822
823 if (!raisePriorityAndLock(cmd_data.cpu_to_lock)) {
824 return -1;
825 }
826
827 printf("%s\n", command->name);
Christopher Ferris014cf9d2013-06-26 13:42:18 -0700828 return (*command->ptr)(command->name, cmd_data, command->func);
Christopher Ferris82ac1af2013-02-15 12:27:58 -0800829}