26
26
#include <sys/resource.h>
34
34
BENCHMARK_RAYTRACE,
35
35
BENCHMARK_N_ENTRIES
38
void scan_zlib(gboolean reload);
38
void scan_fft(gboolean reload);
39
39
void scan_raytr(gboolean reload);
40
40
void scan_bfsh(gboolean reload);
41
void scan_md5(gboolean reload);
41
void scan_cryptohash(gboolean reload);
42
42
void scan_fib(gboolean reload);
43
void scan_sha1(gboolean reload);
43
void scan_nqueens(gboolean reload);
45
gchar *callback_zlib();
45
gchar *callback_fft();
46
46
gchar *callback_raytr();
47
47
gchar *callback_bfsh();
48
gchar *callback_md5();
49
48
gchar *callback_fib();
50
gchar *callback_sha1();
49
gchar *callback_cryptohash();
50
gchar *callback_nqueens();
52
52
static ModuleEntry entries[] = {
53
{"CPU ZLib", "compress.png", callback_zlib, scan_zlib},
54
{"CPU Fibonacci", "module.png", callback_fib, scan_fib},
55
{"CPU MD5", "module.png", callback_md5, scan_md5},
56
{"CPU SHA1", "module.png", callback_sha1, scan_sha1},
57
53
{"CPU Blowfish", "blowfish.png", callback_bfsh, scan_bfsh},
54
{"CPU CryptoHash", "cryptohash.png", callback_cryptohash, scan_cryptohash},
55
{"CPU Fibonacci", "nautilus.png", callback_fib, scan_fib},
56
{"CPU N-Queens", "nqueens.png", callback_nqueens, scan_nqueens},
57
{"FPU FFT", "fft.png", callback_fft, scan_fft},
58
58
{"FPU Raytracing", "raytrace.png", callback_raytr, scan_raytr},
62
typedef struct _ParallelBenchTask ParallelBenchTask;
64
struct _ParallelBenchTask {
66
gpointer data, callback;
69
gpointer benchmark_parallel_for_dispatcher(gpointer data)
71
ParallelBenchTask *pbt = (ParallelBenchTask *)data;
72
gpointer (*callback)(unsigned int start, unsigned int end, void *data);
73
gpointer return_value;
75
if ((callback = pbt->callback)) {
76
DEBUG("this is thread %p; items %d -> %d, data %p", g_thread_self(),
77
pbt->start, pbt->end, pbt->data);
78
return_value = callback(pbt->start, pbt->end, pbt->data);
79
DEBUG("this is thread %p; return value is %p", g_thread_self(), return_value);
81
DEBUG("this is thread %p; callback is NULL and it should't be!", g_thread_self());
89
gdouble benchmark_parallel_for(guint start, guint end,
90
gpointer callback, gpointer callback_data) {
92
guint n_cores, iter_per_core, iter;
94
GSList *threads = NULL, *t;
97
timer = g_timer_new();
99
temp = module_call_method("devices::getProcessorCount");
100
n_cores = temp ? atoi(temp) : 1;
104
iter_per_core = (end - start) / n_cores;
106
if (iter_per_core == 0) {
107
DEBUG("not enough items per core; disabling one");
114
DEBUG("processor has %d cores; processing %d elements (%d per core)",
115
n_cores, (end - start), iter_per_core);
117
g_timer_start(timer);
118
for (iter = start; iter < end; iter += iter_per_core) {
119
ParallelBenchTask *pbt = g_new0(ParallelBenchTask, 1);
122
DEBUG("launching thread %d", 1 + (iter / iter_per_core));
124
pbt->start = iter == 0 ? 0 : iter + 1;
125
pbt->end = iter + iter_per_core - 1;
126
pbt->data = callback_data;
127
pbt->callback = callback;
132
thread = g_thread_create((GThreadFunc) benchmark_parallel_for_dispatcher,
134
threads = g_slist_append(threads, thread);
136
DEBUG("thread %d launched as context %p", 1 + (iter / iter_per_core), threads->data);
139
DEBUG("waiting for all threads to finish");
140
for (t = threads; t; t = t->next) {
141
DEBUG("waiting for thread with context %p", t->data);
142
g_thread_join((GThread *)t->data);
146
elapsed_time = g_timer_elapsed(timer, NULL);
148
g_slist_free(threads);
149
g_timer_destroy(timer);
151
DEBUG("finishing; all threads took %f seconds to finish", elapsed_time);
62
156
static gchar *__benchmark_include_results(gdouble result,
63
157
const gchar * benchmark,
64
158
ShellOrderType order_type)
68
gchar *path, *results = g_strdup("");
162
gchar *path, *results = g_strdup(""), *return_value, *processor_frequency;
71
165
conf = g_key_file_new();
74
g_build_filename(g_get_home_dir(), ".hardinfo", "benchmark.conf",
167
path = g_build_filename(g_get_home_dir(), ".hardinfo", "benchmark.conf", NULL);
76
168
if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
77
169
DEBUG("local benchmark.conf not found, trying system-wide");
96
188
g_key_file_free(conf);
98
DEBUG("results = %s", results);
100
return g_strdup_printf("[$ShellParam$]\n"
105
"<i>This Machine</i>=%.3f\n"
106
"%s", order_type, benchmark, result, results);
190
processor_frequency = module_call_method("devices::getProcessorFrequency");
191
return_value = g_strdup_printf("[$ShellParam$]\n"
195
"ColumnTitle$Extra1=CPU Clock\n"
196
"ColumnTitle$Progress=Results\n"
197
"ColumnTitle$TextValue=CPU\n"
198
"ShowColumnHeaders=true\n"
200
"<big><b>This Machine</b></big>=%.3f|%s MHz\n"
201
"%s", order_type, benchmark, result, processor_frequency, results);
202
g_free(processor_frequency);
109
208
static gchar *benchmark_include_results_reverse(gdouble result,
110
209
const gchar * benchmark)