summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2017-12-17 08:56:46 -0600
committerLeandro A. F. Pereira <leandro@hardinfo.org>2018-02-27 07:41:51 -0800
commitc8785521f39c3a86454ade890018ca021272c621 (patch)
tree4df2fa40ca918cb26460d07939136bef6a63ef13 /modules
parent8fb9ed49987ca006495891f04e5250496d6e00f4 (diff)
Benchmark results: store threads used
Benchmark results store actual number of threads used by benchmark when it was run. Previously, results assumed all available threads were used. Examples: * CPU Fib only uses one * FPU FFT uses 4, 2, or 1 * N-Queens uses 10, 5, 2, or 1 Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'modules')
-rw-r--r--modules/benchmark.c127
-rw-r--r--modules/benchmark/bench_results.c74
-rw-r--r--modules/benchmark/blowfish.c45
-rw-r--r--modules/benchmark/cryptohash.c33
-rw-r--r--modules/benchmark/drawing.c8
-rw-r--r--modules/benchmark/fft.c36
-rw-r--r--modules/benchmark/fib.c20
-rw-r--r--modules/benchmark/nqueens.c23
-rw-r--r--modules/benchmark/raytrace.c19
-rw-r--r--modules/benchmark/zlib.c26
10 files changed, 235 insertions, 176 deletions
diff --git a/modules/benchmark.c b/modules/benchmark.c
index 857904a8..80575cfa 100644
--- a/modules/benchmark.c
+++ b/modules/benchmark.c
@@ -66,6 +66,25 @@ static ModuleEntry entries[] = {
static gboolean sending_benchmark_results = FALSE;
+char *bench_value_to_str(bench_value r) {
+ return g_strdup_printf("%lf; %lf; %d", r.result, r.elapsed_time, r.threads_used);
+}
+
+bench_value bench_value_from_str(const char* str) {
+ bench_value ret = EMPTY_BENCH_VALUE;
+ double r, e;
+ int t, c;
+ if (str) {
+ c = sscanf(str, "%lf; %lf; %d", &r, &e, &t);
+ if (c >= 3) {
+ ret.result = r;
+ ret.elapsed_time = e;
+ ret.threads_used = t;
+ }
+ }
+ return ret;
+}
+
typedef struct _ParallelBenchTask ParallelBenchTask;
struct _ParallelBenchTask {
@@ -94,44 +113,51 @@ static gpointer benchmark_parallel_for_dispatcher(gpointer data)
return return_value;
}
-gdouble benchmark_parallel_for(guint start, guint end,
+bench_value benchmark_parallel_for(gint n_threads, guint start, guint end,
gpointer callback, gpointer callback_data) {
gchar *temp;
- guint n_cores, iter_per_core, iter, thread_number = 0;
- gdouble elapsed_time;
+ int cpu_procs, cpu_cores, cpu_threads;
+ guint iter_per_thread, iter, thread_number = 0;
GSList *threads = NULL, *t;
GTimer *timer;
+ bench_value ret = EMPTY_BENCH_VALUE;
+
timer = g_timer_new();
- temp = module_call_method("devices::getProcessorCount");
- n_cores = temp ? atoi(temp) : 1;
- g_free(temp);
+ cpu_procs_cores_threads(&cpu_procs, &cpu_cores, &cpu_threads);
+
+ if (n_threads > 0)
+ ret.threads_used = n_threads;
+ else if (n_threads < 0)
+ ret.threads_used = cpu_cores;
+ else
+ ret.threads_used = cpu_threads;
- while (n_cores > 0) {
- iter_per_core = (end - start) / n_cores;
+ while (ret.threads_used > 0) {
+ iter_per_thread = (end - start) / ret.threads_used;
- if (iter_per_core == 0) {
- DEBUG("not enough items per core; disabling one");
- n_cores--;
+ if (iter_per_thread == 0) {
+ DEBUG("not enough items per thread; disabling one thread");
+ ret.threads_used--;
} else {
break;
}
}
- DEBUG("processor has %d cores; processing %d elements (%d per core)",
- n_cores, (end - start), iter_per_core);
+ DEBUG("Using %d threads across %d logical processors; processing %d elements (%d per thread)",
+ ret.threads_used, cpu_threads, (end - start), iter_per_thread);
g_timer_start(timer);
- for (iter = start; iter < end; iter += iter_per_core) {
+ for (iter = start; iter < end; iter += iter_per_thread) {
ParallelBenchTask *pbt = g_new0(ParallelBenchTask, 1);
GThread *thread;
- DEBUG("launching thread %d", 1 + (iter / iter_per_core));
+ DEBUG("launching thread %d", 1 + (iter / iter_per_thread));
pbt->thread_number = thread_number++;
pbt->start = iter == 0 ? 0 : iter;
- pbt->end = iter + iter_per_core - 1;
+ pbt->end = iter + iter_per_thread - 1;
pbt->data = callback_data;
pbt->callback = callback;
@@ -152,14 +178,14 @@ gdouble benchmark_parallel_for(guint start, guint end,
}
g_timer_stop(timer);
- elapsed_time = g_timer_elapsed(timer, NULL);
+ ret.elapsed_time = g_timer_elapsed(timer, NULL);
g_slist_free(threads);
g_timer_destroy(timer);
- DEBUG("finishing; all threads took %f seconds to finish", elapsed_time);
+ DEBUG("finishing; all threads took %f seconds to finish", ret.elapsed_time);
- return elapsed_time;
+ return ret;
}
static gchar *clean_cpuname(gchar *cpuname)
@@ -212,7 +238,7 @@ static void br_mi_add(char **results_list, bench_result *b, gboolean select) {
*results_list = h_strdup_cprintf("$%s%s$%s=%.2f|%s\n", *results_list,
select ? "*" : "", rkey, ckey,
- b->result, b->machine->cpu_config);
+ b->bvalue.result, b->machine->cpu_config);
moreinfo_add_with_prefix("BENCH", rkey, bench_result_more_info(b) );
@@ -220,7 +246,7 @@ static void br_mi_add(char **results_list, bench_result *b, gboolean select) {
g_free(rkey);
}
-static gchar *__benchmark_include_results(gdouble result,
+static gchar *__benchmark_include_results(bench_value r,
const gchar * benchmark,
ShellOrderType order_type)
{
@@ -232,12 +258,8 @@ static gchar *__benchmark_include_results(gdouble result,
moreinfo_del_with_prefix("BENCH");
- if (result > 0.0) {
- temp = module_call_method("devices::getProcessorCount");
- n_threads = temp ? atoi(temp) : 1;
- g_free(temp); temp = NULL;
-
- b = bench_result_this_machine(benchmark, result, n_threads);
+ if (r.result > 0.0) {
+ b = bench_result_this_machine(benchmark, r);
br_mi_add(&results, b, 1);
temp = bench_result_benchmarkconf_line(b);
@@ -292,23 +314,21 @@ static gchar *__benchmark_include_results(gdouble result,
return return_value;
}
-
-
-static gchar *benchmark_include_results_reverse(gdouble result,
+static gchar *benchmark_include_results_reverse(bench_value result,
const gchar * benchmark)
{
return __benchmark_include_results(result, benchmark,
SHELL_ORDER_DESCENDING);
}
-static gchar *benchmark_include_results(gdouble result,
+static gchar *benchmark_include_results(bench_value result,
const gchar * benchmark)
{
return __benchmark_include_results(result, benchmark,
SHELL_ORDER_ASCENDING);
}
-gdouble bench_results[BENCHMARK_N_ENTRIES];
+bench_value bench_results[BENCHMARK_N_ENTRIES];
gchar *callback_gui()
{
@@ -361,7 +381,7 @@ gchar *callback_zlib()
typedef struct _BenchmarkDialog BenchmarkDialog;
struct _BenchmarkDialog {
GtkWidget *dialog;
- double result;
+ bench_value r;
};
static gboolean do_benchmark_handler(GIOChannel *source,
@@ -371,25 +391,19 @@ static gboolean do_benchmark_handler(GIOChannel *source,
BenchmarkDialog *bench_dialog = (BenchmarkDialog*)data;
GIOStatus status;
gchar *result;
- gchar *buffer;
- float float_result;
+ bench_value r = EMPTY_BENCH_VALUE;
status = g_io_channel_read_line(source, &result, NULL, NULL, NULL);
if (status != G_IO_STATUS_NORMAL) {
DEBUG("error while reading benchmark result");
-
- bench_dialog->result = -1.0f;
+ r.result = -1.0f;
+ bench_dialog->r = r;
gtk_widget_destroy(bench_dialog->dialog);
return FALSE;
}
- float_result = strtof(result, &buffer);
- if (buffer == result) {
- DEBUG("error while converting floating point value");
- bench_dialog->result = -1.0f;
- } else {
- bench_dialog->result = float_result;
- }
+ r = bench_value_from_str(result);
+ bench_dialog->r = r;
gtk_widget_destroy(bench_dialog->dialog);
g_free(result);
@@ -412,6 +426,9 @@ static void do_benchmark(void (*benchmark_function)(void), int entry)
GSpawnFlags spawn_flags = G_SPAWN_STDERR_TO_DEV_NULL;
gchar *bench_status;
+ bench_value r = EMPTY_BENCH_VALUE;
+ bench_results[entry] = r;
+
bench_status = g_strdup_printf(_("Benchmarking: <b>%s</b>."), entries[entry].name);
shell_view_set_enabled(FALSE);
@@ -427,7 +444,7 @@ static void do_benchmark(void (*benchmark_function)(void), int entry)
GtkWidget *content_area;
GtkWidget *hbox;
GtkWidget *label;
-
+
bench_dialog = gtk_dialog_new_with_buttons("",
NULL,
GTK_DIALOG_MODAL,
@@ -442,14 +459,13 @@ static void do_benchmark(void (*benchmark_function)(void), int entry)
gtk_box_pack_end(GTK_BOX(hbox), label, TRUE, TRUE, 5);
gtk_container_add(GTK_CONTAINER (content_area), hbox);
gtk_widget_show_all(bench_dialog);
-#else
+#else
bench_dialog = gtk_message_dialog_new(GTK_WINDOW(shell_get_main_shell()->window),
GTK_DIALOG_MODAL,
GTK_MESSAGE_INFO,
GTK_BUTTONS_NONE,
_("Benchmarking. Please do not move your mouse " \
"or press any keys."));
- g_object_set_data(G_OBJECT(bench_dialog), "result", "0.0");
gtk_dialog_add_buttons(GTK_DIALOG(bench_dialog),
_("Cancel"), GTK_RESPONSE_ACCEPT, NULL);
gtk_message_dialog_set_image(GTK_MESSAGE_DIALOG(bench_dialog), bench_image);
@@ -461,7 +477,7 @@ static void do_benchmark(void (*benchmark_function)(void), int entry)
benchmark_dialog = g_new0(BenchmarkDialog, 1);
benchmark_dialog->dialog = bench_dialog;
- benchmark_dialog->result = -1.0f;
+ benchmark_dialog->r = r;
if (!g_path_is_absolute(params.argv0)) {
spawn_flags |= G_SPAWN_SEARCH_PATH;
@@ -495,7 +511,7 @@ static void do_benchmark(void (*benchmark_function)(void), int entry)
kill(bench_pid, SIGINT);
}
- bench_results[entry] = benchmark_dialog->result;
+ bench_results[entry] = benchmark_dialog->r;
g_io_channel_unref(channel);
shell_view_set_enabled(TRUE);
@@ -522,6 +538,8 @@ void scan_gui(gboolean reload)
{
SCAN_START();
+ bench_value er = EMPTY_BENCH_VALUE;
+
if (params.run_benchmark) {
int argc = 0;
@@ -531,7 +549,7 @@ void scan_gui(gboolean reload)
if (params.gui_running || params.run_benchmark) {
do_benchmark(benchmark_gui, BENCHMARK_GUI);
} else {
- bench_results[BENCHMARK_GUI] = 0.0f;
+ bench_results[BENCHMARK_GUI] = er;
}
SCAN_END();
}
@@ -658,7 +676,7 @@ static gchar *get_benchmark_results()
if (!scan_callback)
continue;
- if (bench_results[i] < 0.0) {
+ if (bench_results[i].result < 0.0) {
/* benchmark was cancelled */
scan_callback(TRUE);
} else {
@@ -694,7 +712,7 @@ static gchar *run_benchmark(gchar *name)
if ((scan_callback = entries[i].scan_callback)) {
scan_callback(FALSE);
- return g_strdup_printf("%f", bench_results[i]);
+ return bench_value_to_str(bench_results[i]);
}
}
}
@@ -706,7 +724,7 @@ ShellModuleMethod *hi_exported_methods(void)
{
static ShellModuleMethod m[] = {
{"runBenchmark", run_benchmark},
- {NULL}
+ {NULL}
};
return m;
@@ -730,9 +748,10 @@ void hi_module_init(void)
sync_manager_add_entry(&se[0]);
sync_manager_add_entry(&se[1]);
+ bench_value er = EMPTY_BENCH_VALUE;
int i;
for (i = 0; i < G_N_ELEMENTS(entries) - 1; i++) {
- bench_results[i] = -1.0f;
+ bench_results[i] = er;
}
}
diff --git a/modules/benchmark/bench_results.c b/modules/benchmark/bench_results.c
index 6c03250b..6c3f1c75 100644
--- a/modules/benchmark/bench_results.c
+++ b/modules/benchmark/bench_results.c
@@ -36,8 +36,7 @@ typedef struct {
typedef struct {
char *name;
- float result;
- int threads;
+ bench_value bvalue;
bench_machine *machine;
int legacy; /* an old benchmark.conf result */
} bench_result;
@@ -159,12 +158,6 @@ bench_machine *bench_machine_this() {
free(tmp);
cpu_procs_cores_threads(&m->processors, &m->cores, &m->threads);
- /*
- tmp = module_call_method("devices::getProcessorCount");
- m->threads = atoi(tmp);
- free(tmp);
- */
-
gen_machine_id(m);
}
return m;
@@ -187,7 +180,7 @@ void bench_result_free(bench_result *s) {
}
}
-bench_result *bench_result_this_machine(const char *bench_name, float result, int threads) {
+bench_result *bench_result_this_machine(const char *bench_name, bench_value r) {
bench_result *b = NULL;
b = malloc(sizeof(bench_result));
@@ -195,8 +188,7 @@ bench_result *bench_result_this_machine(const char *bench_name, float result, in
memset(b, 0, sizeof(bench_result));
b->machine = bench_machine_this();
b->name = strdup(bench_name);
- b->result = result;
- b->threads = threads;
+ b->bvalue = r;
b->legacy = 0;
}
return b;
@@ -221,6 +213,32 @@ static int nx_prefix(const char *str) {
return -1;
}
+/* old results didn't store the actual number of threads used */
+static int guess_threads_old_result(const char *bench_name, int threads_available) {
+#define CHKBNAME(BN) (strcmp(bench_name, BN) == 0)
+ if (CHKBNAME("CPU Fibonacci") )
+ return 1;
+ if (CHKBNAME("FPU FFT") ) {
+ if (threads_available >= 4)
+ return 4;
+ else if (threads_available >= 2)
+ return 2;
+ else
+ return 1;
+ }
+ if (CHKBNAME("CPU N-Queens") ) {
+ if (threads_available >= 10)
+ return 10;
+ else if (threads_available >= 5)
+ return 5;
+ else if (threads_available >= 2)
+ return 2;
+ else
+ return 1;
+ }
+ return threads_available;
+}
+
bench_result *bench_result_benchmarkconf(const char *section, const char *key, char **values) {
bench_result *b = NULL;
char *s0, *s1, *s2;
@@ -237,8 +255,8 @@ bench_result *bench_result_benchmarkconf(const char *section, const char *key, c
if (vl >= 10) { /* the 11th could be empty */
b->machine->mid = strdup(key);
- b->result = atof(values[0]);
- b->threads = atoi(values[1]);
+ b->bvalue.result = atof(values[0]);
+ b->bvalue.threads_used = atoi(values[1]);
b->machine->board = strdup(values[2]);
b->machine->cpu_name = strdup(values[3]);
b->machine->cpu_desc = strdup(values[4]);
@@ -251,7 +269,7 @@ bench_result *bench_result_benchmarkconf(const char *section, const char *key, c
b->machine->ogl_renderer = strdup(values[10]);
b->legacy = 0;
} else if (vl >= 2) {
- b->result = atof(values[0]);
+ b->bvalue.result = atof(values[0]);
b->legacy = 1;
/* old old format has prefix before cpu name (ex: 4x Pentium...) */
@@ -259,11 +277,9 @@ bench_result *bench_result_benchmarkconf(const char *section, const char *key, c
if (nx > 0) {
b->machine->cpu_name = strdup(strchr(key, 'x') + 1);
b->machine->threads = nx;
- b->threads = nx;
} else {
b->machine->cpu_name = strdup(key);
b->machine->threads = 1;
- b->threads = 1;
}
b->machine->cpu_config = strdup(values[1]);
@@ -271,9 +287,10 @@ bench_result *bench_result_benchmarkconf(const char *section, const char *key, c
nx = nx_prefix(values[1]);
if (nx > 0) {
b->machine->threads = nx;
- b->threads = nx;
}
+ b->bvalue.threads_used = guess_threads_old_result(section, b->machine->threads);
+
/* If the clock rate in the id string is more than the
* config string, use that. Older hardinfo used current cpu freq
* instead of max freq.
@@ -295,7 +312,7 @@ bench_result *bench_result_benchmarkconf(const char *section, const char *key, c
n = atof(s1+1);
n *= m;
- s1 = g_strdup_printf("%dx %.2f %s", b->threads, n, _("MHz"));
+ s1 = g_strdup_printf("%dx %.2f %s", b->bvalue.threads_used, n, _("MHz"));
if ( cpu_config_cmp(b->machine->cpu_config, s1) == -1
&& !cpu_config_is_close(b->machine->cpu_config, s1) ) {
free(b->machine->cpu_config);
@@ -328,7 +345,7 @@ bench_result *bench_result_benchmarkconf(const char *section, const char *key, c
char *bench_result_benchmarkconf_line(bench_result *b) {
char *cpu_config = cpu_config_retranslate(b->machine->cpu_config, 1, 0);
char *ret = g_strdup_printf("%s=%.2f|%d|%s|%s|%s|%s|%d|%d|%d|%d|%s\n",
- b->machine->mid, b->result, b->threads,
+ b->machine->mid, b->bvalue.result, b->bvalue.threads_used,
(b->machine->board != NULL) ? b->machine->board : "",
b->machine->cpu_name,
(b->machine->cpu_desc != NULL) ? b->machine->cpu_desc : "",
@@ -341,7 +358,7 @@ char *bench_result_benchmarkconf_line(bench_result *b) {
return ret;
}
-char *bench_result_more_info(bench_result *b) {
+static char *bench_result_more_info_less(bench_result *b) {
char *memory =
(b->machine->memory_kiB > 0)
? g_strdup_printf("%d %s", b->machine->memory_kiB, _("kiB") )
@@ -359,7 +376,7 @@ char *bench_result_more_info(bench_result *b) {
/* ogl rend */ "%s=%s\n"
/* mem */ "%s=%s\n",
_("Benchmark Result"),
- _("Threads"), b->threads,
+ _("Threads"), b->bvalue.threads_used,
b->legacy ? _("Note") : "#Note",
b->legacy ? _("This result is from an old version of HardInfo. Results might not be comparable to current version. Some details are missing.") : "",
_("Machine"),
@@ -375,11 +392,12 @@ char *bench_result_more_info(bench_result *b) {
return ret;
}
-char *bench_result_more_info_complete(bench_result *b) {
+static char *bench_result_more_info_complete(bench_result *b) {
return g_strdup_printf("[%s]\n"
/* bench name */"%s=%s\n"
- /* result */ "%s=%0.2f\n"
/* threads */ "%s=%d\n"
+ /* result */ "%s=%0.2f\n"
+ /* elapsed */ "%s=%0.2f\n"
/* legacy */ "%s=%s\n"
"[%s]\n"
/* board */ "%s=%s\n"
@@ -394,8 +412,9 @@ char *bench_result_more_info_complete(bench_result *b) {
/* cfg_val */ "%s=%.2f\n",
_("Benchmark Result"),
_("Benchmark"), b->name,
- _("Result"), b->result,
- _("Threads"), b->threads,
+ _("Threads"), b->bvalue.threads_used,
+ _("Result"), b->bvalue.result,
+ _("Elapsed Time"), b->bvalue.elapsed_time,
b->legacy ? _("Note") : "#Note",
b->legacy ? _("This result is from an old version of HardInfo. Results might not be comparable to current version. Some details are missing.") : "",
_("Machine"),
@@ -411,3 +430,8 @@ char *bench_result_more_info_complete(bench_result *b) {
_("cfg_val"), cpu_config_val(b->machine->cpu_config)
);
}
+
+char *bench_result_more_info(bench_result *b) {
+ //return bench_result_more_info_complete(b);
+ return bench_result_more_info_less(b);
+}
diff --git a/modules/benchmark/blowfish.c b/modules/benchmark/blowfish.c
index feadc430..2aa11a2a 100644
--- a/modules/benchmark/blowfish.c
+++ b/modules/benchmark/blowfish.c
@@ -15,8 +15,8 @@ You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-
+
+
COMMENTS ON USING THIS CODE:
@@ -31,7 +31,7 @@ Normal usage is as follows:
[4] Decryption is the same as encryption except that the plaintext and
ciphertext are reversed.
-Warning #1: The code does not check key lengths. (Caveat encryptor.)
+Warning #1: The code does not check key lengths. (Caveat encryptor.)
Warning #2: Beware that Blowfish keys repeat such that "ab" = "abab".
Warning #3: It is normally a good idea to zeroize the BLOWFISH_CTX before
freeing it.
@@ -41,33 +41,33 @@ Warning #4: Endianness conversions are the responsibility of the caller.
Warning #5: Make sure to use a reasonable mode of operation for your
application. (If you don't know what CBC mode is, see Warning #7.)
Warning #6: This code is susceptible to timing attacks.
-Warning #7: Security engineering is risky and non-intuitive. Have someone
+Warning #7: Security engineering is risky and non-intuitive. Have someone
check your work. If you don't know what you are doing, get help.
This is code is fast enough for most applications, but is not optimized for
speed.
-If you require this code under a license other than LGPL, please ask. (I
-can be located using your favorite search engine.) Unfortunately, I do not
-have time to provide unpaid support for everyone who uses this code.
+If you require this code under a license other than LGPL, please ask. (I
+can be located using your favorite search engine.) Unfortunately, I do not
+have time to provide unpaid support for everyone who uses this code.
-- Paul Kocher
-*/
-
+*/
+
#include "hardinfo.h"
#include "benchmark.h"
#include "blowfish.h"
-
+
#define N 16
static const unsigned long ORIG_P[16 + 2] =
{ 0x243F6A88L, 0x85A308D3L, 0x13198A2EL, 0x03707344L, 0xA4093822L,
0x299F31D0L, 0x082EFA98L, 0xEC4E6C89L, 0x452821E6L, 0x38D01377L,
0xBE5466CFL, 0x34E90C6CL, 0xC0AC29B7L,
- 0xC97C50DDL, 0x3F84D5B5L, 0xB5470917L, 0x9216D5D9L, 0x8979FB1BL
+ 0xC97C50DDL, 0x3F84D5B5L, 0xB5470917L, 0x9216D5D9L, 0x8979FB1BL
};
-static const unsigned long ORIG_S[4][256] = {
+static const unsigned long ORIG_S[4][256] = {
{0xD1310BA6L, 0x98DFB5ACL, 0x2FFD72DBL, 0xD01ADFB7L, 0xB8E1AFEDL,
0x6A267E96L, 0xBA7C9045L, 0xF12C7F99L, 0x24A19947L, 0xB3916CF7L,
0x0801F2E2L, 0x858EFC16L, 0x636920D8L, 0x71574E69L, 0xA458FEA3L,
@@ -383,7 +383,7 @@ static const unsigned long ORIG_S[4][256] = {
0x85CBFE4EL, 0x8AE88DD8L, 0x7AAAF9B0L, 0x4CF9AA7EL, 0x1948C25CL,
0x02FB8A8CL, 0x01C36AE4L, 0xD6EBE1F9L, 0x90D4F869L, 0xA65CDEA0L,
0x3F09252DL, 0xC208E69FL, 0xB74E6132L, 0xCE77E25BL, 0x578FDFE3L,
- 0x3AC372E6L}
+ 0x3AC372E6L}
};
static unsigned long F(BLOWFISH_CTX * ctx, unsigned long x)
@@ -440,14 +440,14 @@ void Blowfish_Decrypt(BLOWFISH_CTX * ctx, unsigned long *xl,
for (i = N + 1; i > 1; --i) {
Xl = Xl ^ ctx->P[i];
Xr = F(ctx, Xl) ^ Xr;
-
- /* Exchange Xl and Xr */
+
+ /* Exchange Xl and Xr */
temp = Xl;
Xl = Xr;
Xr = temp;
}
-
- /* Exchange Xl and Xr */
+
+ /* Exchange Xl and Xr */
temp = Xl;
Xl = Xr;
Xr = temp;
@@ -502,7 +502,7 @@ parallel_blowfish(unsigned int start, unsigned int end, void *data, gint thread_
L = 0xBEBACAFE;
R = 0xDEADBEEF;
- for (i = start; i <= end; i++) {
+ for (i = start; i <= end; i++) {
Blowfish_Init(&ctx, (unsigned char*)data, 65536);
Blowfish_Encrypt(&ctx, &L, &R);
Blowfish_Decrypt(&ctx, &L, &R);
@@ -514,12 +514,14 @@ parallel_blowfish(unsigned int start, unsigned int end, void *data, gint thread_
void
benchmark_fish(void)
{
+ bench_value r = EMPTY_BENCH_VALUE;
+
gchar *tmpsrc;
gchar *bdata_path;
bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL);
if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) {
- bench_results[BENCHMARK_BLOWFISH] = -1.0f;
+ bench_results[BENCHMARK_BLOWFISH] = r;
g_free(bdata_path);
return;
}
@@ -527,7 +529,10 @@ benchmark_fish(void)
shell_view_set_enabled(FALSE);
shell_status_update("Performing Blowfish benchmark...");
- bench_results[BENCHMARK_BLOWFISH] = benchmark_parallel_for(0, 50000, parallel_blowfish, tmpsrc);
+ r = benchmark_parallel_for(0, 0, 50000, parallel_blowfish, tmpsrc);
+ r.result = r.elapsed_time;
+
+ bench_results[BENCHMARK_BLOWFISH] = r;
g_free(bdata_path);
g_free(tmpsrc);
}
diff --git a/modules/benchmark/cryptohash.c b/modules/benchmark/cryptohash.c
index d97e85c7..6150f3ef 100644
--- a/modules/benchmark/cryptohash.c
+++ b/modules/benchmark/cryptohash.c
@@ -20,21 +20,21 @@
#include "sha1.h"
#include "benchmark.h"
-static void inline md5_step(char *data, glong srclen)
+void inline md5_step(char *data, glong srclen)
{
struct MD5Context ctx;
guchar checksum[16];
-
+
MD5Init(&ctx);
MD5Update(&ctx, (guchar *)data, srclen);
MD5Final(checksum, &ctx);
}
-static void inline sha1_step(char *data, glong srclen)
+void inline sha1_step(char *data, glong srclen)
{
SHA1_CTX ctx;
guchar checksum[20];
-
+
SHA1Init(&ctx);
SHA1Update(&ctx, (guchar*)data, srclen);
SHA1Final(checksum, &ctx);
@@ -43,37 +43,38 @@ static void inline sha1_step(char *data, glong srclen)
static gpointer cryptohash_for(unsigned int start, unsigned int end, void *data, gint thread_number)
{
unsigned int i;
-
- for (i = start; i <= end; i++) {
+
+ for (i = start; i <= end; i++) {
if (i & 1) {
md5_step(data, 65536);
} else {
sha1_step(data, 65536);
}
}
-
+
return NULL;
}
void
benchmark_cryptohash(void)
{
- gdouble elapsed = 0;
+ bench_value r = EMPTY_BENCH_VALUE;
gchar *tmpsrc, *bdata_path;
-
+
bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL);
if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) {
g_free(bdata_path);
return;
- }
-
+ }
+
shell_view_set_enabled(FALSE);
shell_status_update("Running CryptoHash benchmark...");
-
- elapsed = benchmark_parallel_for(0, 5000, cryptohash_for, tmpsrc);
-
+
+ r = benchmark_parallel_for(0, 0, 5000, cryptohash_for, tmpsrc);
+
g_free(bdata_path);
g_free(tmpsrc);
-
- bench_results[BENCHMARK_CRYPTOHASH] = 312.0 / elapsed;
+
+ r.result = 312.0 / r.elapsed_time; //TODO: explain in code comments
+ bench_results[BENCHMARK_CRYPTOHASH] = r;
}
diff --git a/modules/benchmark/drawing.c b/modules/benchmark/drawing.c
index 67a2c264..d0905954 100644
--- a/modules/benchmark/drawing.c
+++ b/modules/benchmark/drawing.c
@@ -22,8 +22,12 @@
void
benchmark_gui(void)
{
+ bench_value r = EMPTY_BENCH_VALUE;
+
shell_view_set_enabled(FALSE);
shell_status_update("Running drawing benchmark...");
-
- bench_results[BENCHMARK_GUI] = guibench();
+
+ r.result = guibench(); //TODO: explain in code comments
+
+ bench_results[BENCHMARK_GUI] = r;
}
diff --git a/modules/benchmark/fft.c b/modules/benchmark/fft.c
index 7c5889c8..caa52d3d 100644
--- a/modules/benchmark/fft.c
+++ b/modules/benchmark/fft.c
@@ -25,43 +25,43 @@ static gpointer fft_for(unsigned int start, unsigned int end, void *data, gint t
unsigned int i;
FFTBench **benches = (FFTBench **)data;
FFTBench *fftbench = (FFTBench *)(benches[thread_number]);
-
- for (i = start; i <= end; i++) {
+
+ for (i = start; i <= end; i++) {
fft_bench_run(fftbench);
}
-
+
return NULL;
}
+#define FFT_MAXT 4
+
void
benchmark_fft(void)
{
- gdouble elapsed = 0;
+ bench_value r = EMPTY_BENCH_VALUE;
+
int n_cores, i;
gchar *temp;
FFTBench **benches;
-
+
shell_view_set_enabled(FALSE);
shell_status_update("Running FFT benchmark...");
-
+
/* Pre-allocate all benchmarks */
- temp = module_call_method("devices::getProcessorCount");
- n_cores = temp ? atoi(temp) : 1;
- g_free(temp);
-
- benches = g_new0(FFTBench *, n_cores);
- for (i = 0; i < n_cores; i++) {
+ benches = g_new0(FFTBench *, FFT_MAXT);
+ for (i = 0; i < FFT_MAXT; i++) {
benches[i] = fft_bench_new();
}
-
+
/* Run the benchmark */
- elapsed = benchmark_parallel_for(0, 4, fft_for, benches);
-
+ r = benchmark_parallel_for(FFT_MAXT, 0, FFT_MAXT, fft_for, benches);
+
/* Free up the memory */
- for (i = 0; i < n_cores; i++) {
+ for (i = 0; i < FFT_MAXT; i++) {
fft_bench_free(benches[i]);
}
g_free(benches);
-
- bench_results[BENCHMARK_FFT] = elapsed;
+
+ r.result = r.elapsed_time;
+ bench_results[BENCHMARK_FFT] = r;
}
diff --git a/modules/benchmark/fib.c b/modules/benchmark/fib.c
index 0f88be59..d75ac367 100644
--- a/modules/benchmark/fib.c
+++ b/modules/benchmark/fib.c
@@ -18,8 +18,7 @@
#include "benchmark.h"
-static gulong
-fib(gulong n)
+gulong fib(gulong n)
{
if (n == 0)
return 0;
@@ -32,19 +31,22 @@ void
benchmark_fib(void)
{
GTimer *timer = g_timer_new();
- gdouble elapsed;
-
+ bench_value r = EMPTY_BENCH_VALUE;
+
shell_view_set_enabled(FALSE);
shell_status_update("Calculating the 42nd Fibonacci number...");
-
+
g_timer_reset(timer);
g_timer_start(timer);
fib(42);
-
+
g_timer_stop(timer);
- elapsed = g_timer_elapsed(timer, NULL);
+ r.elapsed_time = g_timer_elapsed(timer, NULL);
g_timer_destroy(timer);
-
- bench_results[BENCHMARK_FIB] = elapsed;
+
+ r.threads_used = 1;
+ r.result = r.elapsed_time;
+
+ bench_results[BENCHMARK_FIB] = r;
}
diff --git a/modules/benchmark/nqueens.c b/modules/benchmark/nqueens.c
index a32ed8c1..78293abb 100644
--- a/modules/benchmark/nqueens.c
+++ b/modules/benchmark/nqueens.c
@@ -25,7 +25,7 @@ bool safe(int x, int y)
int nqueens(int y)
{
int x;
-
+
for (x = 0; x < QUEENS; x++) {
if (safe((row[y - 1] = x), y - 1)) {
if (y < QUEENS) {
@@ -35,32 +35,33 @@ int nqueens(int y)
}
}
}
-
+
return 0;
}
static gpointer nqueens_for(unsigned int start, unsigned int end, void *data, gint thread_number)
{
unsigned int i;
-
- for (i = start; i <= end; i++) {
+
+ for (i = start; i <= end; i++) {
nqueens(0);
}
-
+
return NULL;
}
void
benchmark_nqueens(void)
{
- gdouble elapsed = 0;
-
+ bench_value r = EMPTY_BENCH_VALUE;
+
shell_view_set_enabled(FALSE);
shell_status_update("Running N-Queens benchmark...");
-
- elapsed = benchmark_parallel_for(0, 10, nqueens_for, NULL);
-
- bench_results[BENCHMARK_NQUEENS] = elapsed;
+
+ r = benchmark_parallel_for(0, 0, 10, nqueens_for, NULL);
+ r.result = r.elapsed_time;
+
+ bench_results[BENCHMARK_NQUEENS] = r;
}
diff --git a/modules/benchmark/raytrace.c b/modules/benchmark/raytrace.c
index 2ee36a93..c7963583 100644
--- a/modules/benchmark/raytrace.c
+++ b/modules/benchmark/raytrace.c
@@ -24,24 +24,25 @@ static gpointer
parallel_raytrace(unsigned int start, unsigned int end, gpointer data, gint thread_number)
{
unsigned int i;
-
- for (i = start; i <= end; i++) {
+
+ for (i = start; i <= end; i++) {
fbench();
}
-
+
return NULL;
}
void
benchmark_raytrace(void)
{
- gdouble elapsed = 0;
-
+ bench_value r = EMPTY_BENCH_VALUE;
+
shell_view_set_enabled(FALSE);
shell_status_update("Performing John Walker's FBENCH...");
-
- elapsed = benchmark_parallel_for(0, 1000, parallel_raytrace, NULL);
-
- bench_results[BENCHMARK_RAYTRACE] = elapsed;
+
+ r = benchmark_parallel_for(0, 0, 1000, parallel_raytrace, NULL);
+ r.result = r.elapsed_time;
+
+ bench_results[BENCHMARK_RAYTRACE] = r;
}
diff --git a/modules/benchmark/zlib.c b/modules/benchmark/zlib.c
index eeec9d0e..2ded59a4 100644
--- a/modules/benchmark/zlib.c
+++ b/modules/benchmark/zlib.c
@@ -31,8 +31,8 @@ static gpointer zlib_for(unsigned int start, unsigned int end, void *data, gint
compressed = malloc(bound);
if (!compressed)
return NULL;
-
- for (i = start; i <= end; i++) {
+
+ for (i = start; i <= end; i++) {
char uncompressed[65536];
uLong compressedBound = bound;
uLong destBound = sizeof(uncompressed);
@@ -42,30 +42,32 @@ static gpointer zlib_for(unsigned int start, unsigned int end, void *data, gint
}
free(compressed);
-
+
return NULL;
}
void
benchmark_zlib(void)
{
- gdouble elapsed = 0;
+ bench_value r = EMPTY_BENCH_VALUE;
gchar *tmpsrc, *bdata_path;
-
+
bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL);
if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) {
g_free(bdata_path);
return;
- }
-
+ }
+
shell_view_set_enabled(FALSE);
shell_status_update("Running Zlib benchmark...");
-
- elapsed = benchmark_parallel_for(0, 50000, zlib_for, tmpsrc);
-
+
+ r = benchmark_parallel_for(0, 0, 50000, zlib_for, tmpsrc);
+
g_free(bdata_path);
g_free(tmpsrc);
- gdouble marks = (50000. * 65536.) / (elapsed * 840205128.);
- bench_results[BENCHMARK_ZLIB] = marks;
+ //TODO: explain in code comments
+ gdouble marks = (50000. * 65536.) / (r.elapsed_time * 840205128.);
+ r.result = marks;
+ bench_results[BENCHMARK_ZLIB] = r;
}