summaryrefslogtreecommitdiff
path: root/modules/benchmark
diff options
context:
space:
mode:
Diffstat (limited to 'modules/benchmark')
-rw-r--r--modules/benchmark/bench_results.c637
-rw-r--r--modules/benchmark/bench_util.c58
-rw-r--r--modules/benchmark/benches.c220
-rw-r--r--modules/benchmark/blowfish.c45
-rw-r--r--modules/benchmark/blowfish2.c83
-rw-r--r--modules/benchmark/cryptohash.c49
-rw-r--r--modules/benchmark/drawing.c4
-rw-r--r--modules/benchmark/fbench.c26
-rw-r--r--modules/benchmark/fft.c41
-rw-r--r--modules/benchmark/fftbench.c6
-rw-r--r--modules/benchmark/fib.c35
-rw-r--r--modules/benchmark/guibench.c6
-rw-r--r--modules/benchmark/nqueens.c41
-rw-r--r--modules/benchmark/raytrace.c28
-rw-r--r--modules/benchmark/sha1.c2
-rw-r--r--modules/benchmark/sysbench.c270
-rw-r--r--modules/benchmark/zlib.c63
17 files changed, 1169 insertions, 445 deletions
diff --git a/modules/benchmark/bench_results.c b/modules/benchmark/bench_results.c
index 27a33a65..18ed0739 100644
--- a/modules/benchmark/bench_results.c
+++ b/modules/benchmark/bench_results.c
@@ -1,12 +1,12 @@
/*
* HardInfo - Displays System Information
- * Copyright (C) 2003-2017 Leandro A. F. Pereira <leandro@hardinfo.org>
+ * Copyright (C) 2020 L. A. F. Pereira <l@tia.mat.br>
* This file:
* Copyright (C) 2017 Burt P. <pburt0@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 2.
+ * the Free Software Foundation, version 2 or later.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,20 +18,39 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-/*/ Used for an unknown value. Having it in only one place cleans up the .po line references */
+#include <stdlib.h>
+#include <locale.h>
+#include <inttypes.h>
+#include <json-glib/json-glib.h>
+#include "nice_name.h"
+
+/* in dmi_memory.c */
+uint64_t memory_devices_get_system_memory_MiB();
+gchar *memory_devices_get_system_memory_types_str();
+
+/*/ Used for an unknown value. Having it in only one place cleans up the .po
+ * line references */
static const char *unk = N_("(Unknown)");
typedef struct {
char *board;
- int memory_kiB;
+ uint64_t memory_kiB; /* from /proc/meminfo -> MemTotal */
char *cpu_name;
char *cpu_desc;
char *cpu_config;
char *ogl_renderer;
+ char *gpu_desc;
int processors;
int cores;
int threads;
+ int nodes;
char *mid;
+ int ptr_bits; /* 32, 64... BENCH_PTR_BITS; 0 for unspecified */
+ int is_su_data; /* 1 = data collected as root */
+ uint64_t memory_phys_MiB; /* from DMI/SPD/DTree/Table/Blocks, etc. */
+ char *ram_types;
+ int machine_data_version;
+ char *machine_type;
} bench_machine;
typedef struct {
@@ -41,7 +60,8 @@ typedef struct {
int legacy; /* an old benchmark.conf result */
} bench_result;
-static char *cpu_config_retranslate(char *str, int force_en, int replacing) {
+static char *cpu_config_retranslate(char *str, int force_en, int replacing)
+{
char *new_str = NULL;
char *mhz = (force_en) ? "MHz" : _("MHz");
char *c = str, *tmp;
@@ -51,19 +71,19 @@ static char *cpu_config_retranslate(char *str, int force_en, int replacing) {
if (str != NULL) {
new_str = strdup("");
if (strchr(str, 'x')) {
- while (c != NULL && sscanf(c, "%dx %f", &t, &f) ) {
- tmp = g_strdup_printf("%s%s%dx %.2f %s",
- new_str, strlen(new_str) ? " + " : "",
- t, f, mhz );
+ while (c != NULL && (sscanf(c, "%dx %f", &t, &f)==2)) {
+ tmp = g_strdup_printf("%s%s%dx %.2f %s", new_str,
+ strlen(new_str) ? " + " : "", t, f, mhz);
free(new_str);
new_str = tmp;
- c = strchr(c+1, '+');
+ c = strchr(c + 1, '+');
+ if (c)
+ c++; /* move past the + */
}
} else {
sscanf(c, "%f", &f);
- tmp = g_strdup_printf("%s%s%dx %.2f %s",
- new_str, strlen(new_str) ? " + " : "",
- 1, f, mhz );
+ tmp = g_strdup_printf("%s%s%dx %.2f %s", new_str,
+ strlen(new_str) ? " + " : "", 1, f, mhz);
free(new_str);
new_str = tmp;
}
@@ -71,19 +91,23 @@ static char *cpu_config_retranslate(char *str, int force_en, int replacing) {
if (replacing)
free(str);
}
+
return new_str;
}
/* "2x 1400.00 MHz + 2x 800.00 MHz" -> 4400.0 */
-static float cpu_config_val(char *str) {
+static float cpu_config_val(char *str)
+{
char *c = str;
int t;
float f, r = 0.0;
if (str != NULL) {
if (strchr(str, 'x')) {
- while (c != NULL && sscanf(c, "%dx %f", &t, &f) ) {
+ while (c != NULL && (sscanf(c, "%dx %f", &t, &f)==2)) {
r += f * t;
- c = strchr(c+1, '+');
+ c = strchr(c + 1, '+');
+ if (c)
+ c++; /* move past the + */
}
} else {
sscanf(c, "%f", &r);
@@ -92,16 +116,20 @@ static float cpu_config_val(char *str) {
return r;
}
-static int cpu_config_cmp(char *str0, char *str1) {
+static int cpu_config_cmp(char *str0, char *str1)
+{
float r0, r1;
r0 = cpu_config_val(str0);
r1 = cpu_config_val(str1);
- if (r0 == r1) return 0;
- if (r0 < r1) return -1;
+ if (r0 == r1)
+ return 0;
+ if (r0 < r1)
+ return -1;
return 1;
}
-static int cpu_config_is_close(char *str0, char *str1) {
+static int cpu_config_is_close(char *str0, char *str1)
+{
float r0, r1, r1n;
r0 = cpu_config_val(str0);
r1 = cpu_config_val(str1);
@@ -111,76 +139,85 @@ static int cpu_config_is_close(char *str0, char *str1) {
return 0;
}
-static gen_machine_id(bench_machine *m) {
+static void gen_machine_id(bench_machine *m)
+{
char *s;
+
if (m) {
if (m->mid != NULL)
free(m->mid);
- /* Don't try and translate unknown. The mid string needs to be made of all
- * untranslated elements.*/
+
+ /* Don't try and translate unknown. The mid string needs to be made of
+ * all untranslated elements.*/
m->mid = g_strdup_printf("%s;%s;%.2f",
- (m->board != NULL) ? m->board : "(Unknown)", m->cpu_name, cpu_config_val(m->cpu_config) );
- s = m->mid;
- while (*s != 0) {
- if (!isalnum(*s)) {
- if (*s != ';'
- && *s != '('
- && *s != '('
- && *s != ')')
+ (m->board != NULL) ? m->board : "(Unknown)",
+ m->cpu_name, cpu_config_val(m->cpu_config));
+ for (s = m->mid; *s; s++) {
+ if (!isalnum(*s) && *s != '(' && *s != ')' && *s != ';')
*s = '_';
- }
- s++;
}
}
}
-bench_machine *bench_machine_new() {
- bench_machine *m = NULL;
- m = malloc(sizeof(bench_machine));
- if (m)
- memset(m, 0, sizeof(bench_machine));
- return m;
+bench_machine *bench_machine_new()
+{
+ return calloc(1, sizeof(bench_machine));
}
-bench_machine *bench_machine_this() {
+bench_machine *bench_machine_this()
+{
bench_machine *m = NULL;
char *tmp;
m = bench_machine_new();
if (m) {
+ m->ptr_bits = BENCH_PTR_BITS;
+ m->is_su_data = (getuid() == 0);
m->board = module_call_method("devices::getMotherboard");
m->cpu_name = module_call_method("devices::getProcessorName");
m->cpu_desc = module_call_method("devices::getProcessorDesc");
- m->cpu_config = module_call_method("devices::getProcessorFrequencyDesc");
+ m->cpu_config =
+ module_call_method("devices::getProcessorFrequencyDesc");
+ m->gpu_desc = module_call_method("devices::getGPUList");
m->ogl_renderer = module_call_method("computer::getOGLRenderer");
- tmp = module_call_method("devices::getMemoryTotal");
- m->memory_kiB = atoi(tmp);
+ tmp = module_call_method("computer::getMemoryTotal");
+ m->memory_kiB = strtoull(tmp, NULL, 10);
+ m->memory_phys_MiB = memory_devices_get_system_memory_MiB();
+ m->ram_types = memory_devices_get_system_memory_types_str();
+ m->machine_type = module_call_method("computer::getMachineType");
free(tmp);
- cpu_procs_cores_threads(&m->processors, &m->cores, &m->threads);
+ cpu_procs_cores_threads_nodes(&m->processors, &m->cores, &m->threads, &m->nodes);
gen_machine_id(m);
}
return m;
}
-void bench_machine_free(bench_machine *s) {
+void bench_machine_free(bench_machine *s)
+{
if (s) {
free(s->board);
free(s->cpu_name);
free(s->cpu_desc);
free(s->cpu_config);
free(s->mid);
+ free(s->ram_types);
+ free(s->machine_type);
+ free(s);
}
}
-void bench_result_free(bench_result *s) {
+void bench_result_free(bench_result *s)
+{
if (s) {
free(s->name);
bench_machine_free(s->machine);
+ g_free(s);
}
}
-bench_result *bench_result_this_machine(const char *bench_name, bench_value r) {
+bench_result *bench_result_this_machine(const char *bench_name, bench_value r)
+{
bench_result *b = NULL;
b = malloc(sizeof(bench_result));
@@ -195,13 +232,14 @@ bench_result *bench_result_this_machine(const char *bench_name, bench_value r) {
}
/* -1 for none */
-static int nx_prefix(const char *str) {
+static int nx_prefix(const char *str)
+{
char *s, *x;
if (str != NULL) {
- s = (char*)str;
+ s = (char *)str;
x = strchr(str, 'x');
- if (x && x-s >= 1) {
- while(s != x) {
+ if (x && x - s >= 1) {
+ while (s != x) {
if (!isdigit(*s))
return -1;
s++;
@@ -214,11 +252,13 @@ static int nx_prefix(const char *str) {
}
/* old results didn't store the actual number of threads used */
-static int guess_threads_old_result(const char *bench_name, int threads_available) {
+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") )
+ if (CHKBNAME("CPU Fibonacci"))
return 1;
- if (CHKBNAME("FPU FFT") ) {
+ if (CHKBNAME("FPU FFT")) {
if (threads_available >= 4)
return 4;
else if (threads_available >= 2)
@@ -226,7 +266,7 @@ static int guess_threads_old_result(const char *bench_name, int threads_availabl
else
return 1;
}
- if (CHKBNAME("CPU N-Queens") ) {
+ if (CHKBNAME("CPU N-Queens")) {
if (threads_available >= 10)
return 10;
else if (threads_available >= 5)
@@ -239,204 +279,327 @@ static int guess_threads_old_result(const char *bench_name, int threads_availabl
return threads_available;
}
-bench_result *bench_result_benchmarkconf(const char *section, const char *key, char **values) {
- bench_result *b = NULL;
- char *s0, *s1, *s2;
- int nx = 0, vl = 0;
- float n, m;
+static gboolean cpu_name_needs_cleanup(const char *cpu_name)
+{
+ return strstr(cpu_name, "Intel") || strstr(cpu_name, "AMD") ||
+ strstr(cpu_name, "VIA") || strstr(cpu_name, "Cyrix");
+}
- vl = g_strv_length(values);
+static void filter_invalid_chars(gchar *str)
+{
+ gchar *p;
- b = malloc(sizeof(bench_result));
- if (b) {
- memset(b, 0, sizeof(bench_result));
- b->machine = bench_machine_new();
- b->name = strdup(section);
-
- if (vl >= 10) { /* the 11th could be empty */
- b->machine->mid = strdup(key);
- /* first try as bench_value, then try as double 'result' only */
- b->bvalue = bench_value_from_str(values[0]);
- if (b->bvalue.result == -1)
- b->bvalue.result = atoi(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]);
- b->machine->cpu_config = strdup(values[5]);
- b->machine->memory_kiB = atoi(values[6]);
- b->machine->processors = atoi(values[7]);
- b->machine->cores = atoi(values[8]);
- b->machine->threads = atoi(values[9]);
- if (vl >= 11)
- b->machine->ogl_renderer = strdup(values[10]);
- b->legacy = 0;
- } else if (vl >= 2) {
- b->bvalue.result = atof(values[0]);
- b->legacy = 1;
-
- /* old old format has prefix before cpu name (ex: 4x Pentium...) */
- nx = nx_prefix(key);
- if (nx > 0) {
- b->machine->cpu_name = strdup(strchr(key, 'x') + 1);
- b->machine->threads = nx;
- } else {
- b->machine->cpu_name = strdup(key);
- b->machine->threads = 1;
- }
+ for (p = str; *p; p++) {
+ if (*p == '\n' || *p == ';' || *p == '|')
+ *p = '_';
+ }
+}
- b->machine->cpu_config = strdup(values[1]);
- /* new old format has cpu_config string with nx prefix */
- nx = nx_prefix(values[1]);
- if (nx > 0) {
- b->machine->threads = nx;
- }
+static gboolean json_get_boolean(JsonObject *obj, const gchar *key)
+{
+ if (!json_object_has_member(obj, key))
+ return FALSE;
+ return json_object_get_boolean_member(obj, key);
+}
- 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.
- * "...@ 2.00GHz" -> 2000.0 */
- s0 = b->machine->cpu_name;
- s2 = strstr(s0, "Hz");
- if (s2 && s2 > s0 + 2) {
- m = 1; /* assume M */
- if (*(s2-1) == 'G')
- m = 1000;
- s1 = s2 - 2;
- while (s1 > s0) {
- if (!( isdigit(*s1) || *s1 == '.' || *s1 == ' '))
- break;
- s1--;
- }
-
- if (s1 > s0) {
- n = atof(s1+1);
- n *= m;
-
- 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);
- b->machine->cpu_config = s1;
- } else {
- free(s1);
- }
- }
- }
+static double json_get_double(JsonObject *obj, const gchar *key)
+{
+ if (!json_object_has_member(obj, key))
+ return 0;
+ return json_object_get_double_member(obj, key);
+}
- /* old results only give threads */
- b->machine->processors = -1;
- b->machine->cores = -1;
- }
+static int json_get_int(JsonObject *obj, const gchar *key)
+{
+ if (!json_object_has_member(obj, key))
+ return 0;
+ return json_object_get_int_member(obj, key);
+}
- b->machine->cpu_config = cpu_config_retranslate(b->machine->cpu_config, 0, 1);
- if (b->machine->board != NULL && strlen(b->machine->board) == 0) {
- free(b->machine->board);
- b->machine->board = NULL;
- }
- if (b->machine->cpu_desc != NULL && strlen(b->machine->cpu_desc) == 0) {
- free(b->machine->cpu_desc);
- b->machine->cpu_desc = NULL;
- }
- gen_machine_id(b->machine);
- }
- return b;
+static const gchar *json_get_string(JsonObject *obj, const gchar *key)
+{
+ if (!json_object_has_member(obj, key))
+ return "";
+ return json_object_get_string_member(obj, key);
+}
+
+static gchar *json_get_string_dup(JsonObject *obj, const gchar *key)
+{
+ return g_strdup(json_get_string(obj, key));
+}
+
+static double parse_frequency(const char *freq)
+{
+ static locale_t locale;
+
+ if (!locale)
+ locale = newlocale(LC_NUMERIC_MASK, "C", NULL);
+
+ return strtod_l(freq, NULL, locale);
+}
+
+static void append_cpu_config(JsonObject *object,
+ const gchar *member_name,
+ JsonNode *member_node,
+ gpointer user_data)
+{
+ GString *output = user_data;
+
+ if (output->len)
+ g_string_append(output, ", ");
+
+ g_string_append_printf(output, "%ldx %.2f %s", (long int)json_node_get_int(member_node),
+ parse_frequency(member_name), _("MHz"));
}
-char *bench_result_benchmarkconf_line(bench_result *b) {
- char *cpu_config = cpu_config_retranslate(b->machine->cpu_config, 1, 0);
- char *bv = bench_value_to_str(b->bvalue);
- char *ret = g_strdup_printf("%s=%s|%d|%s|%s|%s|%s|%d|%d|%d|%d|%s\n",
- b->machine->mid, bv, b->bvalue.threads_used,
- (b->machine->board != NULL) ? b->machine->board : "",
- b->machine->cpu_name,
- (b->machine->cpu_desc != NULL) ? b->machine->cpu_desc : "",
- cpu_config,
- b->machine->memory_kiB,
- b->machine->processors, b->machine->cores, b->machine->threads,
- (b->machine->ogl_renderer != NULL) ? b->machine->ogl_renderer : ""
- );
- free(cpu_config);
- free(bv);
+static gchar *get_cpu_config(JsonObject *machine)
+{
+ JsonObject *cpu_config_map =
+ json_object_get_object_member(machine, "CpuConfigMap");
+
+ if (!cpu_config_map)
+ return json_get_string_dup(machine, "CpuConfig");
+
+ GString *output = g_string_new(NULL);
+ json_object_foreach_member(cpu_config_map, append_cpu_config, output);
+ return g_string_free(output, FALSE);
+}
+
+static gchar *get_cpu_desc(JsonObject *machine)
+{
+ int num_cpus = json_get_int(machine, "NumCpus");
+
+ if (!num_cpus)
+ return json_get_string_dup(machine, "CpuDesc");
+
+ /* FIXME: This is adapted from processor_describe_default() in
+ * devices.c! */
+
+ int num_cores = json_get_int(machine, "NumCores");
+ int num_threads = json_get_int(machine, "NumThreads");
+ int num_nodes = json_get_int(machine, "NumNodes");
+ const char *packs_fmt =
+ ngettext("%d physical processor", "%d physical processors", num_cpus);
+ const char *cores_fmt = ngettext("%d core", "%d cores", num_cores);
+ const char *threads_fmt = ngettext("%d thread", "%d threads", num_threads);
+ char *full_fmt, *ret;
+
+ if (num_nodes > 1) {
+ const char *nodes_fmt =
+ ngettext("%d NUMA node", "%d NUMA nodes", num_nodes);
+
+ full_fmt = g_strdup_printf(
+ _(/*/NP procs; NC cores across NN nodes; NT threads*/
+ "%s; %s across %s; %s"),
+ packs_fmt, cores_fmt, nodes_fmt, threads_fmt);
+ ret = g_strdup_printf(full_fmt, num_cpus, num_cores * num_nodes, num_nodes, num_threads);
+ } else {
+ full_fmt =
+ g_strdup_printf(_(/*/NP procs; NC cores; NT threads*/ "%s; %s; %s"),
+ packs_fmt, cores_fmt, threads_fmt);
+ ret = g_strdup_printf(full_fmt, num_cpus, num_cores, num_threads);
+ }
+
+ free(full_fmt);
return ret;
}
-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") )
- : g_strdup(_(unk) );
-
- char *ret = g_strdup_printf("[%s]\n"
- /* threads */ "%s=%d\n"
- /* legacy */ "%s=%s\n"
- "[%s]\n"
- /* board */ "%s=%s\n"
- /* cpu */ "%s=%s\n"
- /* cpudesc */ "%s=%s\n"
- /* cpucfg */ "%s=%s\n"
- /* threads */ "%s=%d\n"
- /* ogl rend */ "%s=%s\n"
- /* mem */ "%s=%s\n",
- _("Benchmark Result"),
- _("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"),
- _("Board"), (b->machine->board != NULL) ? b->machine->board : _(unk),
- _("CPU Name"), b->machine->cpu_name,
- _("CPU Description"), (b->machine->cpu_desc != NULL) ? b->machine->cpu_desc : _(unk),
- _("CPU Config"), b->machine->cpu_config,
- _("Threads Available"), b->machine->threads,
- _("OpenGL Renderer"), (b->machine->ogl_renderer != NULL) ? b->machine->ogl_renderer : _(unk),
- _("Memory"), memory
- );
+bench_result *bench_result_benchmarkjson(const gchar *bench_name,
+ JsonNode *node)
+{
+ JsonObject *machine;
+ bench_result *b;
+ gchar *p;
+
+ if (json_node_get_node_type(node) != JSON_NODE_OBJECT)
+ return NULL;
+
+ machine = json_node_get_object(node);
+
+ b = g_new0(bench_result, 1);
+ b->name = g_strdup(bench_name);
+ b->legacy = json_get_boolean(machine, "Legacy");
+
+ b->bvalue = (bench_value){
+ .result = json_get_double(machine, "BenchmarkResult"),
+ .elapsed_time = json_get_double(machine, "ElapsedTime"),
+ .threads_used = json_get_int(machine, "UsedThreads"),
+ .revision = json_get_int(machine, "BenchmarkRevision"),
+ };
+
+ snprintf(b->bvalue.extra, sizeof(b->bvalue.extra), "%s",
+ json_get_string(machine, "ExtraInfo"));
+ filter_invalid_chars(b->bvalue.extra);
+
+ snprintf(b->bvalue.user_note, sizeof(b->bvalue.user_note), "%s",
+ json_get_string(machine, "UserNote"));
+ filter_invalid_chars(b->bvalue.user_note);
+
+ int nodes = json_get_int(machine, "NumNodes");
+
+ if (nodes == 0)
+ nodes = 1;
+
+ b->machine = bench_machine_new();
+ *b->machine = (bench_machine){
+ .board = json_get_string_dup(machine, "Board"),
+ .memory_kiB = json_get_int(machine, "MemoryInKiB"),
+ .cpu_name = json_get_string_dup(machine, "CpuName"),
+ .cpu_desc = get_cpu_desc(machine),
+ .cpu_config = get_cpu_config(machine),
+ .ogl_renderer = json_get_string_dup(machine, "OpenGlRenderer"),
+ .gpu_desc = json_get_string_dup(machine, "GpuDesc"),
+ .processors = json_get_int(machine, "NumCpus"),
+ .cores = json_get_int(machine, "NumCores"),
+ .threads = json_get_int(machine, "NumThreads"),
+ .nodes = nodes,
+ .mid = json_get_string_dup(machine, "MachineId"),
+ .ptr_bits = json_get_int(machine, "PointerBits"),
+ .is_su_data = json_get_boolean(machine, "DataFromSuperUser"),
+ .memory_phys_MiB = json_get_int(machine, "PhysicalMemoryInMiB"),
+ .ram_types = json_get_string_dup(machine, "MemoryTypes"),
+ .machine_data_version = json_get_int(machine, "MachineDataVersion"),
+ .machine_type = json_get_string_dup(machine, "MachineType"),
+ };
+
+ return b;
+}
+
+static char *bench_result_more_info_less(bench_result *b)
+{
+ char *memory = NULL;
+ if (b->machine->memory_phys_MiB) {
+ memory =
+ g_strdup_printf("%" PRId64 " %s %s", b->machine->memory_phys_MiB,
+ _("MiB"), b->machine->ram_types);
+ } else {
+ memory =
+ (b->machine->memory_kiB > 0)
+ ? g_strdup_printf("%" PRId64 " %s %s", b->machine->memory_kiB,
+ _("kiB"), problem_marker())
+ : g_strdup(_(unk));
+ }
+ char bench_str[256] = "";
+ if (b->bvalue.revision >= 0)
+ snprintf(bench_str, 127, "%d", b->bvalue.revision);
+ char bits[24] = "";
+ if (b->machine->ptr_bits)
+ snprintf(bits, 23, _("%d-bit"), b->machine->ptr_bits);
+
+ char *ret = g_strdup_printf(
+ "[%s]\n"
+ /* threads */ "%s=%d\n"
+ /* elapsed */ "%s=%0.4f %s\n"
+ "%s=%s\n"
+ "%s=%s\n"
+ "%s=%s\n"
+ /* legacy */ "%s%s=%s\n"
+ "[%s]\n"
+ /* board */ "%s=%s\n"
+ /* machine_type */ "%s=%s\n"
+ /* cpu */ "%s=%s\n"
+ /* cpudesc */ "%s=%s\n"
+ /* cpucfg */ "%s=%s\n"
+ /* threads */ "%s=%d\n"
+ /* gpu desc */ "%s=%s\n"
+ /* ogl rend */ "%s=%s\n"
+ /* mem */ "%s=%s\n"
+ /* bits */ "%s=%s\n",
+ _("Benchmark Result"), _("Threads"), b->bvalue.threads_used,
+ _("Elapsed Time"), b->bvalue.elapsed_time, _("seconds"),
+ *bench_str ? _("Revision") : "#Revision", bench_str,
+ *b->bvalue.extra ? _("Extra Information") : "#Extra", b->bvalue.extra,
+ *b->bvalue.user_note ? _("User Note") : "#User Note",
+ b->bvalue.user_note, b->legacy ? problem_marker() : "",
+ 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"),
+ _("Board"), (b->machine->board != NULL) ? b->machine->board : _(unk),
+ _("Machine Type"), (b->machine->machine_type != NULL) ? b->machine->machine_type : _(unk),
+ _("CPU Name"), b->machine->cpu_name,
+ _("CPU Description"), (b->machine->cpu_desc != NULL) ? b->machine->cpu_desc : _(unk),
+ _("CPU Config"), b->machine->cpu_config,
+ _("Threads Available"), b->machine->threads,
+ _("GPU"), (b->machine->gpu_desc != NULL) ? b->machine->gpu_desc : _(unk),
+ _("OpenGL Renderer"), (b->machine->ogl_renderer != NULL) ? b->machine->ogl_renderer : _(unk),
+ _("Memory"), memory,
+ b->machine->ptr_bits ? _("Pointer Size") : "#AddySize", bits);
free(memory);
return ret;
}
-static char *bench_result_more_info_complete(bench_result *b) {
- return g_strdup_printf("[%s]\n"
- /* bench name */"%s=%s\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"
- /* cpu */ "%s=%s\n"
- /* cpudesc */ "%s=%s\n"
- /* cpucfg */ "%s=%s\n"
- /* threads */ "%s=%d\n"
- /* ogl rend */ "%s=%s\n"
- /* mem */ "%s=%d %s\n"
- "[%s]\n"
- /* mid */ "%s=%s\n"
- /* cfg_val */ "%s=%.2f\n",
- _("Benchmark Result"),
- _("Benchmark"), b->name,
- _("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"),
- _("Board"), (b->machine->board != NULL) ? b->machine->board : _(unk),
- _("CPU Name"), b->machine->cpu_name,
- _("CPU Description"), (b->machine->cpu_desc != NULL) ? b->machine->cpu_desc : _(unk),
- _("CPU Config"), b->machine->cpu_config,
- _("Threads Available"), b->machine->threads,
- _("OpenGL Renderer"), (b->machine->ogl_renderer != NULL) ? b->machine->ogl_renderer : _(unk),
- _("Memory"), b->machine->memory_kiB, _("kiB"),
- _("Handles"),
- _("mid"), b->machine->mid,
- _("cfg_val"), cpu_config_val(b->machine->cpu_config)
- );
+static char *bench_result_more_info_complete(bench_result *b)
+{
+ char bench_str[256] = "";
+ strncpy(bench_str, b->name, 127);
+ if (b->bvalue.revision >= 0)
+ snprintf(bench_str + strlen(bench_str), 127, " (r%d)",
+ b->bvalue.revision);
+ char bits[24] = "";
+ if (b->machine->ptr_bits)
+ snprintf(bits, 23, _("%d-bit"), b->machine->ptr_bits);
+
+ return g_strdup_printf(
+ "[%s]\n"
+ /* bench name */ "%s=%s\n"
+ /* threads */ "%s=%d\n"
+ /* result */ "%s=%0.2f\n"
+ /* elapsed */ "%s=%0.4f %s\n"
+ "%s=%s\n"
+ "%s=%s\n"
+ /* legacy */ "%s%s=%s\n"
+ "[%s]\n"
+ /* board */ "%s=%s\n"
+ /* machine_type */ "%s=%s\n"
+ /* cpu */ "%s=%s\n"
+ /* cpudesc */ "%s=%s\n"
+ /* cpucfg */ "%s=%s\n"
+ /* threads */ "%s=%d\n"
+ /* gpu desc */ "%s=%s\n"
+ /* ogl rend */ "%s=%s\n"
+ /* mem */ "%s=%" PRId64 " %s\n"
+ /* mem phys */ "%s=%" PRId64 " %s %s\n"
+ /* bits */ "%s=%s\n"
+ "%s=%d\n"
+ "%s=%d\n"
+ "[%s]\n"
+ /* mid */ "%s=%s\n"
+ /* cfg_val */ "%s=%.2f\n",
+ _("Benchmark Result"), _("Benchmark"), bench_str, _("Threads"),
+ b->bvalue.threads_used, _("Result"), b->bvalue.result,
+ _("Elapsed Time"), b->bvalue.elapsed_time, _("seconds"),
+ *b->bvalue.extra ? _("Extra Information") : "#Extra", b->bvalue.extra,
+ *b->bvalue.user_note ? _("User Note") : "#User Note",
+ b->bvalue.user_note, b->legacy ? problem_marker() : "",
+ 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"), _("Board"),
+ (b->machine->board != NULL) ? b->machine->board : _(unk),
+ _("Machine Type"), (b->machine->machine_type != NULL) ? b->machine->machine_type : _(unk),
+ _("CPU Name"),
+ b->machine->cpu_name, _("CPU Description"),
+ (b->machine->cpu_desc != NULL) ? b->machine->cpu_desc : _(unk),
+ _("CPU Config"), b->machine->cpu_config, _("Threads Available"),
+ b->machine->threads, _("GPU"),
+ (b->machine->gpu_desc != NULL) ? b->machine->gpu_desc : _(unk),
+ _("OpenGL Renderer"),
+ (b->machine->ogl_renderer != NULL) ? b->machine->ogl_renderer : _(unk),
+ _("Memory"), b->machine->memory_kiB, _("kiB"), _("Physical Memory"),
+ b->machine->memory_phys_MiB, _("MiB"), b->machine->ram_types,
+ b->machine->ptr_bits ? _("Pointer Size") : "#AddySize", bits,
+ ".machine_data_version", b->machine->machine_data_version,
+ ".is_su_data", b->machine->is_su_data, _("Handles"), _("mid"),
+ b->machine->mid, _("cfg_val"), cpu_config_val(b->machine->cpu_config));
}
-char *bench_result_more_info(bench_result *b) {
- //return bench_result_more_info_complete(b);
+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/bench_util.c b/modules/benchmark/bench_util.c
new file mode 100644
index 00000000..d9e5bc55
--- /dev/null
+++ b/modules/benchmark/bench_util.c
@@ -0,0 +1,58 @@
+
+#include "benchmark.h"
+#include "md5.h"
+
+gchar *get_test_data(gsize min_size) {
+ gchar *bdata_path, *data;
+ gsize data_size;
+
+ gchar *exp_data, *p;
+ gsize sz;
+
+ bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL);
+ if (!g_file_get_contents(bdata_path, &data, &data_size, NULL)) {
+ g_free(bdata_path);
+ return NULL;
+ }
+
+ if (data_size < min_size) {
+ DEBUG("expanding %lu bytes of test data to %lu bytes", data_size, min_size);
+ exp_data = g_malloc(min_size + 1);
+ memcpy(exp_data, data, data_size);
+ p = exp_data + data_size;
+ sz = data_size;
+ while (sz < (min_size - data_size) ) {
+ memcpy(p, data, data_size);
+ p += data_size;
+ sz += data_size;
+ }
+ strncpy(p, data, min_size - sz);
+ g_free(data);
+ data = exp_data;
+ }
+ g_free(bdata_path);
+
+ return data;
+}
+
+char *digest_to_str(const char *digest, int len) {
+ int max = len * 2;
+ char *ret = malloc(max+1);
+ char *p = ret;
+ memset(ret, 0, max+1);
+ int i = 0;
+ for(; i < len; i++) {
+ unsigned char byte = digest[i];
+ p += sprintf(p, "%02x", byte);
+ }
+ return ret;
+}
+
+char *md5_digest_str(const char *data, unsigned int len) {
+ struct MD5Context ctx;
+ guchar digest[16];
+ MD5Init(&ctx);
+ MD5Update(&ctx, (guchar *)data, len);
+ MD5Final(digest, &ctx);
+ return digest_to_str(digest, 16);
+}
diff --git a/modules/benchmark/benches.c b/modules/benchmark/benches.c
index e09dedcc..c621d695 100644
--- a/modules/benchmark/benches.c
+++ b/modules/benchmark/benches.c
@@ -1,10 +1,10 @@
/*
- * HardInfo - Displays System Information
- * Copyright (C) 2003-2017 Leandro A. F. Pereira <leandro@hardinfo.org>
+ * HardInfo - System Information and Benchmark
+ * Copyright (C) 2003-2017 L. A. F. Pereira <l@tia.mat.br>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 2.
+ * the Free Software Foundation, version 2 or later.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -26,15 +26,6 @@ gchar *CN() { \
return benchmark_include_results(bench_results[BID], BN); \
}
-BENCH_CALLBACK(callback_gui, "GPU Drawing", BENCHMARK_GUI, 1);
-BENCH_CALLBACK(callback_fft, "FPU FFT", BENCHMARK_FFT, 0);
-BENCH_CALLBACK(callback_nqueens, "CPU N-Queens", BENCHMARK_NQUEENS, 0);
-BENCH_CALLBACK(callback_raytr, "FPU Raytracing", BENCHMARK_RAYTRACE, 0);
-BENCH_CALLBACK(callback_bfsh, "CPU Blowfish", BENCHMARK_BLOWFISH, 0);
-BENCH_CALLBACK(callback_cryptohash, "CPU CryptoHash", BENCHMARK_CRYPTOHASH, 1);
-BENCH_CALLBACK(callback_fib, "CPU Fibonacci", BENCHMARK_FIB, 0);
-BENCH_CALLBACK(callback_zlib, "CPU Zlib", BENCHMARK_ZLIB, 0);
-
#define BENCH_SCAN_SIMPLE(SN, BF, BID) \
void SN(gboolean reload) { \
SCAN_START(); \
@@ -42,14 +33,30 @@ void SN(gboolean reload) { \
SCAN_END(); \
}
-BENCH_SCAN_SIMPLE(scan_fft, benchmark_fft, BENCHMARK_FFT);
-BENCH_SCAN_SIMPLE(scan_nqueens, benchmark_nqueens, BENCHMARK_NQUEENS);
-BENCH_SCAN_SIMPLE(scan_raytr, benchmark_raytrace, BENCHMARK_RAYTRACE);
-BENCH_SCAN_SIMPLE(scan_bfsh, benchmark_fish, BENCHMARK_BLOWFISH);
-BENCH_SCAN_SIMPLE(scan_cryptohash, benchmark_cryptohash, BENCHMARK_CRYPTOHASH);
-BENCH_SCAN_SIMPLE(scan_fib, benchmark_fib, BENCHMARK_FIB);
-BENCH_SCAN_SIMPLE(scan_zlib, benchmark_zlib, BENCHMARK_ZLIB);
+#define BENCH_SIMPLE(BID, BN, BF, R) \
+ BENCH_CALLBACK(callback_##BF, BN, BID, R); \
+ BENCH_SCAN_SIMPLE(scan_##BF, BF, BID);
+// ID, NAME, FUNCTION, R (0 = lower is better, 1 = higher is better)
+BENCH_SIMPLE(BENCHMARK_FIB, "CPU Fibonacci", benchmark_fib, 1);
+BENCH_SIMPLE(BENCHMARK_NQUEENS, "CPU N-Queens", benchmark_nqueens, 1);
+BENCH_SIMPLE(BENCHMARK_FFT, "FPU FFT", benchmark_fft, 1);
+BENCH_SIMPLE(BENCHMARK_RAYTRACE, "FPU Raytracing (Single-thread)", benchmark_raytrace, 1);
+BENCH_SIMPLE(BENCHMARK_BLOWFISH_SINGLE, "CPU Blowfish (Single-thread)", benchmark_bfish_single, 1);
+BENCH_SIMPLE(BENCHMARK_BLOWFISH_THREADS, "CPU Blowfish (Multi-thread)", benchmark_bfish_threads, 1);
+BENCH_SIMPLE(BENCHMARK_BLOWFISH_CORES, "CPU Blowfish (Multi-core)", benchmark_bfish_cores, 1);
+BENCH_SIMPLE(BENCHMARK_ZLIB, "CPU Zlib", benchmark_zlib, 1);
+BENCH_SIMPLE(BENCHMARK_CRYPTOHASH, "CPU CryptoHash", benchmark_cryptohash, 1);
+BENCH_SIMPLE(BENCHMARK_SBCPU_SINGLE, "SysBench CPU (Single-thread)", benchmark_sbcpu_single, 1);
+BENCH_SIMPLE(BENCHMARK_SBCPU_ALL, "SysBench CPU (Multi-thread)", benchmark_sbcpu_all, 1);
+BENCH_SIMPLE(BENCHMARK_SBCPU_QUAD, "SysBench CPU (Four threads)", benchmark_sbcpu_quad, 1);
+BENCH_SIMPLE(BENCHMARK_MEMORY_SINGLE, "SysBench Memory (Single-thread)", benchmark_memory_single, 1);
+BENCH_SIMPLE(BENCHMARK_MEMORY_DUAL, "SysBench Memory (Two threads)", benchmark_memory_dual, 1);
+BENCH_SIMPLE(BENCHMARK_MEMORY_QUAD, "SysBench Memory (Quad threads)", benchmark_memory_quad, 1);
+BENCH_SIMPLE(BENCHMARK_MEMORY_ALL, "SysBench Memory (Multi-thread)", benchmark_memory_all, 1);
+
+#if !GTK_CHECK_VERSION(3,0,0)
+BENCH_CALLBACK(callback_gui, "GPU Drawing", BENCHMARK_GUI, 1);
void scan_gui(gboolean reload)
{
SCAN_START();
@@ -69,37 +76,178 @@ void scan_gui(gboolean reload)
}
SCAN_END();
}
+#endif
static ModuleEntry entries[] = {
- {N_("CPU Blowfish"), "blowfish.png", callback_bfsh, scan_bfsh, MODULE_FLAG_NONE},
- {N_("CPU CryptoHash"), "cryptohash.png", callback_cryptohash, scan_cryptohash, MODULE_FLAG_NONE},
- {N_("CPU Fibonacci"), "nautilus.png", callback_fib, scan_fib, MODULE_FLAG_NONE},
- {N_("CPU N-Queens"), "nqueens.png", callback_nqueens, scan_nqueens, MODULE_FLAG_NONE},
- {N_("CPU Zlib"), "file-roller.png", callback_zlib, scan_zlib, MODULE_FLAG_NONE},
- {N_("FPU FFT"), "fft.png", callback_fft, scan_fft, MODULE_FLAG_NONE},
- {N_("FPU Raytracing"), "raytrace.png", callback_raytr, scan_raytr, MODULE_FLAG_NONE},
-#if !GTK_CHECK_VERSION(3,0,0)
- {N_("GPU Drawing"), "module.png", callback_gui, scan_gui, MODULE_FLAG_NO_REMOTE},
+ [BENCHMARK_BLOWFISH_SINGLE] =
+ {
+ N_("CPU Blowfish (Single-thread)"),
+ "blowfish.png",
+ callback_benchmark_bfish_single,
+ scan_benchmark_bfish_single,
+ MODULE_FLAG_NONE,
+ },
+ [BENCHMARK_BLOWFISH_THREADS] =
+ {
+ N_("CPU Blowfish (Multi-thread)"),
+ "blowfish.png",
+ callback_benchmark_bfish_threads,
+ scan_benchmark_bfish_threads,
+ MODULE_FLAG_NONE,
+ },
+ [BENCHMARK_BLOWFISH_CORES] =
+ {
+ N_("CPU Blowfish (Multi-core)"),
+ "blowfish.png",
+ callback_benchmark_bfish_cores,
+ scan_benchmark_bfish_cores,
+ MODULE_FLAG_NONE,
+ },
+ [BENCHMARK_ZLIB] =
+ {
+ N_("CPU Zlib"),
+ "file-roller.png",
+ callback_benchmark_zlib,
+ scan_benchmark_zlib,
+ MODULE_FLAG_NONE,
+ },
+ [BENCHMARK_CRYPTOHASH] =
+ {
+ N_("CPU CryptoHash"),
+ "cryptohash.png",
+ callback_benchmark_cryptohash,
+ scan_benchmark_cryptohash,
+ MODULE_FLAG_NONE,
+ },
+ [BENCHMARK_FIB] =
+ {
+ N_("CPU Fibonacci"),
+ "nautilus.png",
+ callback_benchmark_fib,
+ scan_benchmark_fib,
+ MODULE_FLAG_NONE,
+ },
+ [BENCHMARK_NQUEENS] =
+ {
+ N_("CPU N-Queens"),
+ "nqueens.png",
+ callback_benchmark_nqueens,
+ scan_benchmark_nqueens,
+ MODULE_FLAG_NONE,
+ },
+ [BENCHMARK_FFT] =
+ {
+ N_("FPU FFT"),
+ "fft.png",
+ callback_benchmark_fft,
+ scan_benchmark_fft,
+ MODULE_FLAG_NONE,
+ },
+ [BENCHMARK_RAYTRACE] =
+ {
+ N_("FPU Raytracing (Single-thread)"),
+ "raytrace.png",
+ callback_benchmark_raytrace,
+ scan_benchmark_raytrace,
+ MODULE_FLAG_NONE,
+ },
+ [BENCHMARK_SBCPU_SINGLE] =
+ {
+ N_("SysBench CPU (Single-thread)"),
+ "processor.png",
+ callback_benchmark_sbcpu_single,
+ scan_benchmark_sbcpu_single,
+ MODULE_FLAG_NONE,
+ },
+ [BENCHMARK_SBCPU_ALL] =
+ {
+ N_("SysBench CPU (Multi-thread)"),
+ "processor.png",
+ callback_benchmark_sbcpu_all,
+ scan_benchmark_sbcpu_all,
+ MODULE_FLAG_NONE,
+ },
+ [BENCHMARK_SBCPU_QUAD] =
+ {
+ N_("SysBench CPU (Four threads)"),
+ "processor.png",
+ callback_benchmark_sbcpu_quad,
+ scan_benchmark_sbcpu_quad,
+ MODULE_FLAG_HIDE,
+ },
+ [BENCHMARK_MEMORY_SINGLE] =
+ {
+ N_("SysBench Memory (Single-thread)"),
+ "memory.png",
+ callback_benchmark_memory_single,
+ scan_benchmark_memory_single,
+ MODULE_FLAG_NONE,
+ },
+ [BENCHMARK_MEMORY_DUAL] =
+ {
+ N_("SysBench Memory (Two threads)"),
+ "memory.png",
+ callback_benchmark_memory_dual,
+ scan_benchmark_memory_dual,
+ MODULE_FLAG_HIDE,
+ },
+ [BENCHMARK_MEMORY_QUAD] =
+ {
+ N_("SysBench Memory (Quad threads)"),
+ "memory.png",
+ callback_benchmark_memory_quad,
+ scan_benchmark_memory_quad,
+ MODULE_FLAG_HIDE,
+ },
+ [BENCHMARK_MEMORY_ALL] =
+ {
+ N_("SysBench Memory (Multi-thread)"),
+ "memory.png",
+ callback_benchmark_memory_all,
+ scan_benchmark_memory_all,
+ MODULE_FLAG_NONE,
+ },
+#if !GTK_CHECK_VERSION(3, 0, 0)
+ [BENCHMARK_GUI] =
+ {
+ N_("GPU Drawing"),
+ "module.png",
+ callback_gui,
+ scan_gui,
+ MODULE_FLAG_NO_REMOTE | MODULE_FLAG_HIDE,
+ },
+#else
+ [BENCHMARK_GUI] = {"#"},
#endif
- {NULL}
-};
+ {NULL}};
const gchar *hi_note_func(gint entry)
{
switch (entry) {
- case BENCHMARK_CRYPTOHASH:
- return _("Results in MiB/second. Higher is better.");
+ case BENCHMARK_SBCPU_SINGLE:
+ case BENCHMARK_SBCPU_QUAD:
+ case BENCHMARK_SBCPU_ALL:
+ return _("Alexey Kopytov's <i><b>sysbench</b></i> is required.\n"
+ "Results in events/second. Higher is better.");
+
+ case BENCHMARK_MEMORY_SINGLE:
+ case BENCHMARK_MEMORY_DUAL:
+ case BENCHMARK_MEMORY_QUAD:
+ case BENCHMARK_MEMORY_ALL:
+ return _("Alexey Kopytov's <i><b>sysbench</b></i> is required.\n"
+ "Results in MiB/second. Higher is better.");
+ case BENCHMARK_CRYPTOHASH:
+ case BENCHMARK_BLOWFISH_SINGLE:
+ case BENCHMARK_BLOWFISH_THREADS:
+ case BENCHMARK_BLOWFISH_CORES:
case BENCHMARK_ZLIB:
case BENCHMARK_GUI:
- return _("Results in HIMarks. Higher is better.");
-
case BENCHMARK_FFT:
case BENCHMARK_RAYTRACE:
- case BENCHMARK_BLOWFISH:
case BENCHMARK_FIB:
case BENCHMARK_NQUEENS:
- return _("Results in seconds. Lower is better.");
+ return _("Results in HIMarks. Higher is better.");
}
return NULL;
diff --git a/modules/benchmark/blowfish.c b/modules/benchmark/blowfish.c
index 2aa11a2a..f8d2e14a 100644
--- a/modules/benchmark/blowfish.c
+++ b/modules/benchmark/blowfish.c
@@ -491,48 +491,3 @@ void Blowfish_Init(BLOWFISH_CTX * ctx, unsigned char *key, int keyLen)
}
}
}
-
-static gpointer
-parallel_blowfish(unsigned int start, unsigned int end, void *data, gint thread_number)
-{
- BLOWFISH_CTX ctx;
- unsigned int i;
- unsigned long L, R;
-
- L = 0xBEBACAFE;
- R = 0xDEADBEEF;
-
- for (i = start; i <= end; i++) {
- Blowfish_Init(&ctx, (unsigned char*)data, 65536);
- Blowfish_Encrypt(&ctx, &L, &R);
- Blowfish_Decrypt(&ctx, &L, &R);
- }
-
- return NULL;
-}
-
-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] = r;
- g_free(bdata_path);
- return;
- }
-
- shell_view_set_enabled(FALSE);
- shell_status_update("Performing Blowfish benchmark...");
-
- 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/blowfish2.c b/modules/benchmark/blowfish2.c
new file mode 100644
index 00000000..7426bef9
--- /dev/null
+++ b/modules/benchmark/blowfish2.c
@@ -0,0 +1,83 @@
+/*
+ * HardInfo - Displays System Information
+ * Copyright (C) 2003-2017 L. A. F. Pereira <l@tia.mat.br>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 2 or later.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "hardinfo.h"
+#include "benchmark.h"
+#include "blowfish.h"
+
+/* if anything changes in this block, increment revision */
+#define BENCH_REVISION 1
+#define CRUNCH_TIME 7
+#define BENCH_DATA_SIZE 65536
+#define BENCH_DATA_MD5 "c25cf5c889f7bead2ff39788eedae37b"
+#define BLOW_KEY "Has my shampoo arrived?"
+#define BLOW_KEY_MD5 "6eac709cca51a228bfa70150c9c5a7c4"
+
+static gpointer bfish_exec(const void *in_data, gint thread_number)
+{
+ unsigned char key[] = BLOW_KEY;
+ unsigned char *data = NULL;
+ unsigned long data_len = BENCH_DATA_SIZE, i = 0;
+ BLOWFISH_CTX ctx;
+
+ data = malloc(BENCH_DATA_SIZE);
+ memcpy(data, in_data, BENCH_DATA_SIZE);
+
+ Blowfish_Init(&ctx, key, strlen(key));
+ for(i = 0; i < data_len; i += 8) {
+ Blowfish_Encrypt(&ctx, (unsigned long*)&data[i], (unsigned long*)&data[i+4]);
+ }
+ for(i = 0; i < data_len; i += 8) {
+ Blowfish_Decrypt(&ctx, (unsigned long*)&data[i], (unsigned long*)&data[i+4]);
+ }
+
+ free(data);
+ return NULL;
+}
+
+void benchmark_bfish_do(int threads, int entry, const char *status)
+{
+ bench_value r = EMPTY_BENCH_VALUE;
+ gchar *test_data = get_test_data(BENCH_DATA_SIZE);
+ if (!test_data) return;
+
+ shell_view_set_enabled(FALSE);
+ shell_status_update(status);
+
+ gchar *k = md5_digest_str(BLOW_KEY, strlen(BLOW_KEY));
+ if (!SEQ(k, BLOW_KEY_MD5))
+ bench_msg("test key has different md5sum: expected %s, actual %s", BLOW_KEY_MD5, k);
+ gchar *d = md5_digest_str(test_data, BENCH_DATA_SIZE);
+ if (!SEQ(d, BENCH_DATA_MD5))
+ bench_msg("test data has different md5sum: expected %s, actual %s", BENCH_DATA_MD5, d);
+
+ r = benchmark_crunch_for(CRUNCH_TIME, threads, bfish_exec, test_data);
+ r.result /= 100;
+ r.revision = BENCH_REVISION;
+ snprintf(r.extra, 255, "%0.1fs, k:%s, d:%s", (double)CRUNCH_TIME, k, d);
+
+ g_free(test_data);
+ g_free(k);
+ g_free(d);
+
+ bench_results[entry] = r;
+}
+
+void benchmark_bfish_threads(void) { benchmark_bfish_do(0, BENCHMARK_BLOWFISH_THREADS, "Performing Blowfish benchmark (multi-thread)..."); }
+void benchmark_bfish_single(void) { benchmark_bfish_do(1, BENCHMARK_BLOWFISH_SINGLE, "Performing Blowfish benchmark (single-thread)..."); }
+void benchmark_bfish_cores(void) { benchmark_bfish_do(-1, BENCHMARK_BLOWFISH_CORES, "Performing Blowfish benchmark (multi-core)..."); }
diff --git a/modules/benchmark/cryptohash.c b/modules/benchmark/cryptohash.c
index 6150f3ef..6daef545 100644
--- a/modules/benchmark/cryptohash.c
+++ b/modules/benchmark/cryptohash.c
@@ -1,10 +1,10 @@
/*
- * HardInfo - Displays System Information
- * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org>
+ * HardInfo - System Information and Benchmark
+ * Copyright (C) 2003-2007 L. A. F. Pereira <l@tia.mat.br>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 2.
+ * the Free Software Foundation, version 2 or later.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,7 +20,14 @@
#include "sha1.h"
#include "benchmark.h"
-void inline md5_step(char *data, glong srclen)
+/* if anything changes in this block, increment revision */
+#define BENCH_REVISION 2
+#define BENCH_DATA_SIZE 65536
+#define CRUNCH_TIME 5
+#define BENCH_DATA_MD5 "c25cf5c889f7bead2ff39788eedae37b"
+#define STEPS 250
+
+inline void md5_step(char *data, glong srclen)
{
struct MD5Context ctx;
guchar checksum[16];
@@ -30,7 +37,7 @@ void inline md5_step(char *data, glong srclen)
MD5Final(checksum, &ctx);
}
-void inline sha1_step(char *data, glong srclen)
+inline void sha1_step(char *data, glong srclen)
{
SHA1_CTX ctx;
guchar checksum[20];
@@ -40,15 +47,15 @@ void inline sha1_step(char *data, glong srclen)
SHA1Final(checksum, &ctx);
}
-static gpointer cryptohash_for(unsigned int start, unsigned int end, void *data, gint thread_number)
+static gpointer cryptohash_for(void *in_data, gint thread_number)
{
unsigned int i;
- for (i = start; i <= end; i++) {
+ for (i = 0;i <= STEPS; i++) {
if (i & 1) {
- md5_step(data, 65536);
+ md5_step(in_data, BENCH_DATA_SIZE);
} else {
- sha1_step(data, 65536);
+ sha1_step(in_data, BENCH_DATA_SIZE);
}
}
@@ -59,22 +66,24 @@ void
benchmark_cryptohash(void)
{
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;
- }
+ gchar *test_data = get_test_data(BENCH_DATA_SIZE);
+ if (!test_data) return;
shell_view_set_enabled(FALSE);
shell_status_update("Running CryptoHash benchmark...");
- r = benchmark_parallel_for(0, 0, 5000, cryptohash_for, tmpsrc);
+ gchar *d = md5_digest_str(test_data, BENCH_DATA_SIZE);
+ if (!SEQ(d, BENCH_DATA_MD5))
+ bench_msg("test data has different md5sum: expected %s, actual %s", BENCH_DATA_MD5, d);
+
+ r = benchmark_crunch_for(CRUNCH_TIME, 0, cryptohash_for, test_data);
+ r.revision = BENCH_REVISION;
+ snprintf(r.extra, 255, "r:%d, d:%s", STEPS, d);
+
+ g_free(test_data);
+ g_free(d);
- g_free(bdata_path);
- g_free(tmpsrc);
+ r.result /= 10;
- 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 d0905954..e92b9d62 100644
--- a/modules/benchmark/drawing.c
+++ b/modules/benchmark/drawing.c
@@ -1,10 +1,10 @@
/*
* HardInfo - Displays System Information
- * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org>
+ * Copyright (C) 2003-2007 L. A. F. Pereira <l@tia.mat.br>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 2.
+ * the Free Software Foundation, version 2 or later.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
diff --git a/modules/benchmark/fbench.c b/modules/benchmark/fbench.c
index b5afc1bc..cf1ff934 100644
--- a/modules/benchmark/fbench.c
+++ b/modules/benchmark/fbench.c
@@ -277,9 +277,7 @@ static int itercount; /* The iteration counter for the main loop
optimise out the loop over the ray
tracing code. */
-#ifndef ITERATIONS
-#define ITERATIONS 1000
-#endif
+#define ITERATIONS 300
static int niter = ITERATIONS; /* Iteration counter */
#if 0
@@ -690,8 +688,6 @@ void fbench()
spectral_line[7] = 4340.477; /* G' */
spectral_line[8] = 3968.494; /* H */
- niter = 3000;
-
/* Load test case into working array */
clear_aperture = 4.0;
@@ -701,15 +697,21 @@ void fbench()
s[i + 1][j + 1] = testcase[i][j];
for (itercount = 0; itercount < niter; itercount++) {
- for (paraxial = 0; paraxial <= 1; paraxial++) {
+ /* Do main trace in D light */
- /* Do main trace in D light */
+ paraxial = FALSE;
- trace_line(4, clear_aperture / 2.0);
- od_sa[paraxial][0] = object_distance;
- od_sa[paraxial][1] = axis_slope_angle;
- }
- paraxial = FALSE;
+ trace_line(4, clear_aperture / 2.0);
+ od_sa[0][0] = object_distance;
+ od_sa[0][1] = axis_slope_angle;
+
+ paraxial = TRUE;
+
+ trace_line(4, clear_aperture / 2.0);
+ od_sa[1][0] = object_distance;
+ od_sa[1][1] = axis_slope_angle;
+
+ paraxial = FALSE;
/* Trace marginal ray in C */
diff --git a/modules/benchmark/fft.c b/modules/benchmark/fft.c
index caa52d3d..503a7aaf 100644
--- a/modules/benchmark/fft.c
+++ b/modules/benchmark/fft.c
@@ -1,10 +1,10 @@
/*
- * HardInfo - Displays System Information
- * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org>
+ * HardInfo - System Information and Benchmark
+ * Copyright (C) 2003-2007 L. A. F. Pereira <l@tia.mat.br>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 2.
+ * the Free Software Foundation, version 2 or later.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,48 +20,51 @@
#include "benchmark.h"
#include "fftbench.h"
-static gpointer fft_for(unsigned int start, unsigned int end, void *data, gint thread_number)
+/* if anything changes in this block, increment revision */
+#define BENCH_REVISION 2
+#define CRUNCH_TIME 5
+
+static gpointer fft_for(void *in_data, gint thread_number)
{
unsigned int i;
- FFTBench **benches = (FFTBench **)data;
+ FFTBench **benches = (FFTBench **)in_data;
FFTBench *fftbench = (FFTBench *)(benches[thread_number]);
- for (i = start; i <= end; i++) {
- fft_bench_run(fftbench);
- }
+ fft_bench_run(benches[thread_number]);
return NULL;
}
-#define FFT_MAXT 4
-
void
benchmark_fft(void)
{
+ int cpu_procs, cpu_cores, cpu_threads, cpu_nodes;
bench_value r = EMPTY_BENCH_VALUE;
int n_cores, i;
gchar *temp;
- FFTBench **benches;
+ FFTBench **benches=NULL;
shell_view_set_enabled(FALSE);
shell_status_update("Running FFT benchmark...");
+ cpu_procs_cores_threads_nodes(&cpu_procs, &cpu_cores, &cpu_threads, &cpu_nodes);
+
/* Pre-allocate all benchmarks */
- benches = g_new0(FFTBench *, FFT_MAXT);
- for (i = 0; i < FFT_MAXT; i++) {
- benches[i] = fft_bench_new();
- }
+ benches = g_new0(FFTBench *, cpu_threads);
+ for (i = 0; i < cpu_threads; i++) {benches[i] = fft_bench_new();}
/* Run the benchmark */
- r = benchmark_parallel_for(FFT_MAXT, 0, FFT_MAXT, fft_for, benches);
+ r = benchmark_crunch_for(CRUNCH_TIME, 0, fft_for, benches);
/* Free up the memory */
- for (i = 0; i < FFT_MAXT; i++) {
- fft_bench_free(benches[i]);
+ for (i = 0; i < cpu_threads; i++) {
+ fft_bench_free(benches[i]);
}
g_free(benches);
- r.result = r.elapsed_time;
+ r.result /= 100;
+
+ r.revision = BENCH_REVISION;
bench_results[BENCHMARK_FFT] = r;
}
diff --git a/modules/benchmark/fftbench.c b/modules/benchmark/fftbench.c
index 89fd5a73..9449cffd 100644
--- a/modules/benchmark/fftbench.c
+++ b/modules/benchmark/fftbench.c
@@ -59,9 +59,9 @@ static double random_double()
return result;
}
-static const int N = 800;
-static const int NM1 = 799; // N - 1
-static const int NP1 = 801; // N + 1
+static const int N = 100;
+static const int NM1 = 99; // N - 1
+static const int NP1 = 101; // N + 1
static void lup_decompose(FFTBench *fftbench)
{
diff --git a/modules/benchmark/fib.c b/modules/benchmark/fib.c
index d75ac367..2bec8bed 100644
--- a/modules/benchmark/fib.c
+++ b/modules/benchmark/fib.c
@@ -1,10 +1,10 @@
/*
- * HardInfo - Displays System Information
- * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org>
+ * HardInfo - System Information and Benchmark
+ * Copyright (C) 2003-2007 L. A. F. Pereira <l@tia.mat.br>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 2.
+ * the Free Software Foundation, version 2 or later.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,6 +18,11 @@
#include "benchmark.h"
+/* if anything changes in this block, increment revision */
+#define BENCH_REVISION 2
+#define ANSWER 25
+#define CRUNCH_TIME 5
+
gulong fib(gulong n)
{
if (n == 0)
@@ -27,6 +32,14 @@ gulong fib(gulong n)
return fib(n - 1) + fib(n - 2);
}
+static gpointer fib_for(void *in_data, gint thread_number)
+{
+ fib(ANSWER);
+
+ return NULL;
+}
+
+
void
benchmark_fib(void)
{
@@ -34,19 +47,15 @@ benchmark_fib(void)
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);
+ shell_status_update("Calculating Fibonacci number...");
- fib(42);
+ r = benchmark_crunch_for(CRUNCH_TIME, 0, fib_for, NULL);
+ //r.threads_used = 1;
- g_timer_stop(timer);
- r.elapsed_time = g_timer_elapsed(timer, NULL);
- g_timer_destroy(timer);
+ r.result /= 100;
- r.threads_used = 1;
- r.result = r.elapsed_time;
+ r.revision = BENCH_REVISION;
+ snprintf(r.extra, 255, "a:%d", ANSWER);
bench_results[BENCHMARK_FIB] = r;
}
diff --git a/modules/benchmark/guibench.c b/modules/benchmark/guibench.c
index b9573278..0faf6b69 100644
--- a/modules/benchmark/guibench.c
+++ b/modules/benchmark/guibench.c
@@ -1,10 +1,10 @@
/*
* HardInfo - Displays System Information
- * Copyright (C) 2003-2009 Leandro A. F. Pereira <leandro@hardinfo.org>
+ * Copyright (C) 2003-2009 L. A. F. Pereira <l@tia.mat.br>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 2.
+ * the Free Software Foundation, version 2 or later.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -108,7 +108,7 @@ static double test_icons(GtkWindow *window)
gc = gdk_gc_new(GDK_DRAWABLE(gdk_window));
timer = g_timer_new();
- pixbufs[0] = icon_cache_get_pixbuf("logo.png");
+ pixbufs[0] = icon_cache_get_pixbuf("hardinfo2.png");
pixbufs[1] = icon_cache_get_pixbuf("syncmanager.png");
pixbufs[2] = icon_cache_get_pixbuf("report-large.png");
diff --git a/modules/benchmark/nqueens.c b/modules/benchmark/nqueens.c
index 78293abb..6aad7638 100644
--- a/modules/benchmark/nqueens.c
+++ b/modules/benchmark/nqueens.c
@@ -9,29 +9,30 @@
#include "hardinfo.h"
#include "benchmark.h"
-#define QUEENS 11
+/* if anything changes in this block, increment revision */
+#define BENCH_REVISION 2
+#define QUEENS 6
+#define CRUNCH_TIME 5
int row[QUEENS];
-bool safe(int x, int y)
-{
+bool safe(int x, int y) {
int i;
for (i = 1; i <= y; i++)
- if (row[y - i] == x || row[y - i] == x - i || row[y - i] == x + i)
- return false;
+ if (row[y - i] == x || row[y - i] == x - i || row[y - i] == x + i)
+ return false;
return true;
}
-int nqueens(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) {
- nqueens(y + 1);
- } else {
- break;
+ if (safe((row[y - 1] = x), y - 1)) {
+ if (y < QUEENS) {
+ nqueens(y + 1);
+ } else {
+ break;
}
}
}
@@ -39,13 +40,9 @@ int nqueens(int y)
return 0;
}
-static gpointer nqueens_for(unsigned int start, unsigned int end, void *data, gint thread_number)
+static gpointer nqueens_for(void *data, gint thread_number)
{
- unsigned int i;
-
- for (i = start; i <= end; i++) {
- nqueens(0);
- }
+ nqueens(0);
return NULL;
}
@@ -58,9 +55,13 @@ benchmark_nqueens(void)
shell_view_set_enabled(FALSE);
shell_status_update("Running N-Queens benchmark...");
- r = benchmark_parallel_for(0, 0, 10, nqueens_for, NULL);
- r.result = r.elapsed_time;
+ r = benchmark_crunch_for(CRUNCH_TIME, 0, nqueens_for, NULL);
+
+ r.revision = BENCH_REVISION;
+ snprintf(r.extra, 255, "q:%d", QUEENS);
+ r.result /= 25;
+
bench_results[BENCHMARK_NQUEENS] = r;
}
diff --git a/modules/benchmark/raytrace.c b/modules/benchmark/raytrace.c
index c7963583..bddc3232 100644
--- a/modules/benchmark/raytrace.c
+++ b/modules/benchmark/raytrace.c
@@ -1,10 +1,10 @@
/*
- * HardInfo - Displays System Information
- * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org>
+ * HardInfo - System Information and Benchmark
+ * Copyright (C) 2003-2007 L. A. F. Pereira <l@tia.mat.br>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 2.
+ * the Free Software Foundation, version 2 or later.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,16 +18,17 @@
#include "benchmark.h"
+/* if anything changes in this block, increment revision */
+#define BENCH_REVISION 2
+#define CRUNCH_TIME 5
+
void fbench(); /* fbench.c */
-static gpointer
-parallel_raytrace(unsigned int start, unsigned int end, gpointer data, gint thread_number)
+static gpointer parallel_raytrace(void *in_data, gint thread_number)
{
unsigned int i;
- for (i = start; i <= end; i++) {
- fbench();
- }
+ fbench();
return NULL;
}
@@ -36,13 +37,20 @@ void
benchmark_raytrace(void)
{
bench_value r = EMPTY_BENCH_VALUE;
+ gchar *test_data = get_test_data(1000);
shell_view_set_enabled(FALSE);
shell_status_update("Performing John Walker's FBENCH...");
- r = benchmark_parallel_for(0, 0, 1000, parallel_raytrace, NULL);
- r.result = r.elapsed_time;
+ r = benchmark_crunch_for(CRUNCH_TIME, 1, parallel_raytrace, test_data);
+
+ r.revision = BENCH_REVISION;
+ snprintf(r.extra, 255, "r:%d", 500);//niter from fbench
+
+ g_free(test_data);
+ r.result /= 10;
+
bench_results[BENCHMARK_RAYTRACE] = r;
}
diff --git a/modules/benchmark/sha1.c b/modules/benchmark/sha1.c
index b94ce254..3b213218 100644
--- a/modules/benchmark/sha1.c
+++ b/modules/benchmark/sha1.c
@@ -47,7 +47,7 @@ A million repetitions of "a"
/* Hash a single 512-bit block. This is the core of the algorithm. */
-void SHA1Transform(guint32 state[5], guchar buffer[64])
+void SHA1Transform(guint32 state[20], guchar buffer[64])
{
guint32 a, b, c, d, e;
typedef union {
diff --git a/modules/benchmark/sysbench.c b/modules/benchmark/sysbench.c
new file mode 100644
index 00000000..5c45831d
--- /dev/null
+++ b/modules/benchmark/sysbench.c
@@ -0,0 +1,270 @@
+/*
+ * HardInfo - Displays System Information
+ * Copyright (C) 2003-2017 L. A. F. Pereira <l@tia.mat.br>
+ * Copyright (C) 2019 Burt P. <pburt0@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 2 or later.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "hardinfo.h"
+#include "benchmark.h"
+#include "cpu_util.h"
+
+#define STATMSG "Performing Alexey Kopytov's sysbench memory benchmark"
+
+/* known to work with:
+ * sysbench 0.4.12 --> r:4012
+ * sysbench 1.0.11 --> r:1000011
+ * sysbench 1.0.15 --> r:1000015
+ */
+
+struct sysbench_ctx {
+ char *test;
+ int threads;
+ int max_time;
+ char *parms_test;
+ bench_value r;
+};
+
+int sysbench_version() {
+ int ret = -1;
+ int v1 = 0, v2 = 0, v3 = 0, mc = 0;
+ gboolean spawned;
+ gchar *out, *err, *p, *next_nl;
+
+ spawned = g_spawn_command_line_sync("sysbench --version",
+ &out, &err, NULL, NULL);
+ if (spawned) {
+ ret = 0;
+ p = out;
+ while(next_nl = strchr(p, '\n')) {
+ *next_nl = 0;
+ /* version */
+ mc = sscanf(p, "sysbench %d.%d.%d", &v1, &v2, &v3);
+ if (mc >= 1) {
+ ret += v1 * 1000000;
+ ret += v2 * 1000;
+ ret += v3;
+ break;
+ }
+ p = next_nl + 1;
+ }
+ g_free(out);
+ g_free(err);
+ }
+ return ret;
+}
+
+static gboolean sysbench_run(struct sysbench_ctx *ctx, int expecting_version) {
+ gboolean spawned;
+ gchar *out, *err, *p, *next_nl;
+
+ int v1 = 0, v2 = 0, v3 = 0, mc = 0;
+ char *pp = NULL;
+
+ if (!ctx) return FALSE;
+ if (!ctx->test) return FALSE;
+ if (!ctx->parms_test) return FALSE;
+ if (!ctx->threads) ctx->threads = 1;
+ ctx->r.threads_used = ctx->threads;
+ if (!ctx->max_time) ctx->max_time = 7;
+
+ gchar *cmd_line = NULL;
+ snprintf(ctx->r.extra, 255, "--time=%d %s", ctx->max_time, ctx->parms_test);
+ util_compress_space(ctx->r.extra);
+
+ if (!expecting_version)
+ expecting_version = sysbench_version();
+ if (expecting_version < 1000000) {
+ /* v0.x.x: sysbench [general-options]... --test=<test-name> [test-options]... command */
+ cmd_line = g_strdup_printf("sysbench --num-threads=%d --max-time=%d --test=%s %s run", ctx->threads, ctx->max_time, ctx->test, ctx->parms_test);
+ } else {
+ /* v1.x.x: sysbench [options]... [testname] [command] */
+ cmd_line = g_strdup_printf("sysbench --threads=%d --time=%d %s %s run", ctx->threads, ctx->max_time, ctx->parms_test, ctx->test);
+ }
+ //bench_msg("\ncmd_line: %s", cmd_line);
+
+ spawned = g_spawn_command_line_sync(cmd_line,
+ &out, &err, NULL, NULL);
+ g_free(cmd_line);
+ if (spawned) {
+ p = out;
+ while(next_nl = strchr(p, '\n')) {
+ *next_nl = 0;
+
+ if (strstr(p, "Usage:")) {
+ /* We're hosed */
+ goto sysbench_failed;
+ }
+
+ /* version */
+ mc = sscanf(p, "sysbench %d.%d.%d", &v1, &v2, &v3);
+ if (mc >= 1) {
+ ctx->r.revision = 0;
+ ctx->r.revision += v1 * 1000000;
+ ctx->r.revision += v2 * 1000;
+ ctx->r.revision += v3;
+ }
+
+ /* total_time */
+ if (pp = strstr(p, "total time:")) {
+ pp = strchr(pp, ':') + 1;
+ ctx->r.elapsed_time = strtof(pp, NULL);
+ }
+
+ /* result */
+ if (SEQ(ctx->test, "memory") ) {
+ // 57894.30 MiB transferred (5787.59 MiB/sec)
+ if (pp = strstr(p, " transferred (")) {
+ pp = strchr(pp, '(') + 1;
+ ctx->r.result = strtof(pp, NULL);
+ }
+ }
+ if (SEQ(ctx->test, "cpu") ) {
+ if (ctx->r.revision < 1000000) {
+ // there is not a nice result line
+ // to grab in version 0.x...
+ // total time: 7.0016s
+ // total number of events: 873
+
+ /* should already have "total time:" */
+ if (pp = strstr(p, " total number of events:")) {
+ pp = strchr(pp, ':') + 1;
+ ctx->r.result = strtof(pp, NULL);
+ ctx->r.result /= ctx->r.elapsed_time;
+ }
+ }
+ if (ctx->r.revision >= 1000000) {
+ // events per second: 1674.97
+ if (pp = strstr(p, " events per second:")) {
+ pp = strchr(pp, ':') + 1;
+ ctx->r.result = strtof(pp, NULL);
+ }
+ }
+ }
+
+ p = next_nl + 1;
+ }
+ g_free(out);
+ g_free(err);
+ } else {
+ bench_msg("\nfailed to spawn sysbench");
+ sleep(5);
+ }
+
+ if (ctx->r.result == -1)
+ goto sysbench_failed;
+
+ return spawned;
+
+sysbench_failed:
+ bench_msg("\nfailed to configure sysbench");
+ g_free(out);
+ g_free(err);
+ return 0;
+}
+
+void benchmark_memory_run(int threads, int result_index) {
+ int cpu_procs, cpu_cores, cpu_threads, cpu_nodes;
+
+ cpu_procs_cores_threads_nodes(&cpu_procs, &cpu_cores, &cpu_threads, &cpu_nodes);
+
+ struct sysbench_ctx ctx = {
+ .test = "memory",
+ .threads = threads>0 ? threads : cpu_threads,
+ .parms_test = "",
+ .r = EMPTY_BENCH_VALUE};
+
+ int sbv = sysbench_version();
+ if (BENCH_PTR_BITS > 32 && sbv >= 1000011) {
+ ctx.parms_test =
+ " --memory-block-size=1K"
+ " --memory-total-size=100G"
+ " --memory-scope=global"
+ " --memory-hugetlb=off"
+ " --memory-oper=write"
+ " --memory-access-mode=seq";
+ } else {
+ /* safer set */
+ ctx.parms_test =
+ " --memory-block-size=1K"
+ " --memory-total-size=3056M"
+ " --memory-scope=global"
+ " --memory-hugetlb=off"
+ " --memory-oper=write"
+ " --memory-access-mode=seq";
+ }
+
+ shell_view_set_enabled(FALSE);
+ char msg[128] = "";
+ snprintf(msg, 128, "%s (threads: %d)", STATMSG, threads);
+ shell_status_update(msg);
+
+ sysbench_run(&ctx, sbv);
+ bench_results[result_index] = ctx.r;
+}
+
+void benchmark_memory_single(void) { benchmark_memory_run(1, BENCHMARK_MEMORY_SINGLE); }
+void benchmark_memory_dual(void) { benchmark_memory_run(2, BENCHMARK_MEMORY_DUAL); }
+void benchmark_memory_quad(void) { benchmark_memory_run(4, BENCHMARK_MEMORY_QUAD); }
+void benchmark_memory_all(void) { benchmark_memory_run(0, BENCHMARK_MEMORY_ALL); }
+
+void benchmark_sbcpu_single(void) {
+ struct sysbench_ctx ctx = {
+ .test = "cpu",
+ .threads = 1,
+ .parms_test =
+ "--cpu-max-prime=10000",
+ .r = EMPTY_BENCH_VALUE};
+
+ shell_view_set_enabled(FALSE);
+ shell_status_update(STATMSG " (single thread)...");
+
+ sysbench_run(&ctx, 0);
+ bench_results[BENCHMARK_SBCPU_SINGLE] = ctx.r;
+}
+
+void benchmark_sbcpu_all(void) {
+ int cpu_procs, cpu_cores, cpu_threads, cpu_nodes;
+
+ cpu_procs_cores_threads_nodes(&cpu_procs, &cpu_cores, &cpu_threads, &cpu_nodes);
+
+ struct sysbench_ctx ctx = {
+ .test = "cpu",
+ .threads = cpu_threads,
+ .parms_test =
+ "--cpu-max-prime=10000",
+ .r = EMPTY_BENCH_VALUE};
+
+ shell_view_set_enabled(FALSE);
+ shell_status_update(STATMSG " (Multi-thread)...");
+
+ sysbench_run(&ctx, 0);
+ bench_results[BENCHMARK_SBCPU_ALL] = ctx.r;
+}
+
+void benchmark_sbcpu_quad(void) {
+ struct sysbench_ctx ctx = {
+ .test = "cpu",
+ .threads = 4,
+ .parms_test =
+ "--cpu-max-prime=10000",
+ .r = EMPTY_BENCH_VALUE};
+
+ shell_view_set_enabled(FALSE);
+ shell_status_update(STATMSG " (Four thread)...");
+
+ sysbench_run(&ctx, 0);
+ bench_results[BENCHMARK_SBCPU_QUAD] = ctx.r;
+}
diff --git a/modules/benchmark/zlib.c b/modules/benchmark/zlib.c
index 2ded59a4..2045969f 100644
--- a/modules/benchmark/zlib.c
+++ b/modules/benchmark/zlib.c
@@ -1,10 +1,10 @@
/*
* HardInfo - Displays System Information
- * Copyright (C) 2017 Leandro A. F. Pereira <leandro@hardinfo.org>
+ * Copyright (C) 2017 L. A. F. Pereira <l@tia.mat.br>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 2.
+ * the Free Software Foundation, version 2 or later.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,23 +22,39 @@
#include "benchmark.h"
-static gpointer zlib_for(unsigned int start, unsigned int end, void *data, gint thread_number)
-{
+/* zip/unzip 256KB blocks for 7 seconds
+ * result is number of full completions / 100 */
+
+/* if anything changes in this block, increment revision */
+#define BENCH_REVISION 3
+#define BENCH_DATA_SIZE 262144
+#define BENCH_DATA_MD5 "3753b649c4fa9ea4576fc8f89a773de2"
+#define CRUNCH_TIME 7
+#define VERIFY_RESULT 1
+
+static unsigned int zlib_errors = 0;
+
+static gpointer zlib_for(void *in_data, gint thread_number) {
char *compressed;
- uLong bound = compressBound(bound);
+ uLong bound = compressBound(BENCH_DATA_SIZE);
unsigned int i;
compressed = malloc(bound);
if (!compressed)
return NULL;
- for (i = start; i <= end; i++) {
- char uncompressed[65536];
- uLong compressedBound = bound;
- uLong destBound = sizeof(uncompressed);
+ char uncompressed[BENCH_DATA_SIZE];
+ uLong compressedBound = bound;
+ uLong destBound = sizeof(uncompressed);
- compress(compressed, &compressedBound, data, 65536);
- uncompress(uncompressed, &destBound, compressed, compressedBound);
+ compress(compressed, &compressedBound, in_data, BENCH_DATA_SIZE);
+ uncompress(uncompressed, &destBound, compressed, compressedBound);
+ if (VERIFY_RESULT) {
+ int cr = memcmp(in_data, uncompressed, BENCH_DATA_SIZE);
+ if (!!cr) {
+ zlib_errors++;
+ bench_msg("zlib error: uncompressed != original");
+ }
}
free(compressed);
@@ -50,24 +66,23 @@ void
benchmark_zlib(void)
{
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);
+ gchar *test_data = get_test_data(BENCH_DATA_SIZE);
+ if (!test_data)
return;
- }
shell_view_set_enabled(FALSE);
shell_status_update("Running Zlib benchmark...");
- r = benchmark_parallel_for(0, 0, 50000, zlib_for, tmpsrc);
+ gchar *d = md5_digest_str(test_data, BENCH_DATA_SIZE);
+ if (!SEQ(d, BENCH_DATA_MD5))
+ bench_msg("test data has different md5sum: expected %s, actual %s", BENCH_DATA_MD5, d);
- g_free(bdata_path);
- g_free(tmpsrc);
-
- //TODO: explain in code comments
- gdouble marks = (50000. * 65536.) / (r.elapsed_time * 840205128.);
- r.result = marks;
+ r = benchmark_crunch_for(CRUNCH_TIME, 0, zlib_for, test_data);
+ r.result /= 100;
+ r.revision = BENCH_REVISION;
+ snprintf(r.extra, 255, "zlib %s (built against: %s), d:%s, e:%d", zlib_version, ZLIB_VERSION, d, zlib_errors);
bench_results[BENCHMARK_ZLIB] = r;
+
+ g_free(test_data);
+ g_free(d);
}