2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2003-10-18 19:35:58 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2003-10-18 19:35:58 +00:00
|
|
|
|
2004-05-21 22:40:54 +00:00
|
|
|
// Manage a (perhaps multi-processor) benchmark.
|
|
|
|
// Because of hyperthreaded CPUs we can't just benchmark 1 CPU;
|
2007-06-12 17:28:08 +00:00
|
|
|
// we must run parallel benchmarks
|
|
|
|
// and ensure that they run more or less concurrently.
|
2004-05-21 22:40:54 +00:00
|
|
|
// Here's our scheme:
|
|
|
|
// - the main program forks N benchmarks threads or processes
|
|
|
|
// - after FP_START seconds it creates a file "do_fp"
|
|
|
|
// - after FP_END seconds it deletes do_fp
|
|
|
|
// - after INT_START seconds it creates do_int
|
|
|
|
// - after INT_END seconds it deletes do_int and starts waiting for processes
|
|
|
|
// Each thread/process checks for the relevant file before
|
|
|
|
// starting or stopping each benchmark
|
2003-10-18 19:35:58 +00:00
|
|
|
|
|
|
|
#include "cpp.h"
|
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2007-03-20 19:55:53 +00:00
|
|
|
#else
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2008-07-09 11:08:53 +00:00
|
|
|
#include <string>
|
2003-10-18 19:35:58 +00:00
|
|
|
#if HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
2007-04-13 04:06:42 +00:00
|
|
|
#if HAVE_SYS_RESOURCE_H
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#endif
|
2003-10-18 19:35:58 +00:00
|
|
|
#if HAVE_SYS_WAIT_H
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
2009-02-26 00:23:23 +00:00
|
|
|
#include <signal.h>
|
2003-10-18 19:35:58 +00:00
|
|
|
#if HAVE_SYS_SIGNAL_H
|
|
|
|
#endif
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <ctime>
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2003-10-18 19:35:58 +00:00
|
|
|
|
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "file_names.h"
|
|
|
|
#include "filesys.h"
|
2004-04-07 06:51:42 +00:00
|
|
|
#include "util.h"
|
2003-10-19 19:03:49 +00:00
|
|
|
#include "cpu_benchmark.h"
|
2013-08-28 04:08:02 +00:00
|
|
|
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "client_msgs.h"
|
2006-06-22 19:40:30 +00:00
|
|
|
#include "log_flags.h"
|
2003-10-18 19:35:58 +00:00
|
|
|
#include "client_state.h"
|
|
|
|
|
2003-11-02 22:51:49 +00:00
|
|
|
// defaults in case benchmarks fail or time out.
|
|
|
|
// better to err on the low side so hosts don't get too much work
|
|
|
|
|
2006-11-05 00:15:10 +00:00
|
|
|
#define DEFAULT_FPOPS 1e9
|
|
|
|
#define DEFAULT_IOPS 1e9
|
|
|
|
#define DEFAULT_MEMBW 1e9
|
2003-11-02 22:51:49 +00:00
|
|
|
#define DEFAULT_CACHE 1e6
|
|
|
|
|
2004-05-22 01:36:36 +00:00
|
|
|
#define FP_START 2
|
2007-06-03 20:13:38 +00:00
|
|
|
#define FP_END 12
|
|
|
|
#define INT_START 17
|
|
|
|
#define INT_END 27
|
|
|
|
#define OVERALL_END 30
|
2004-05-21 22:40:54 +00:00
|
|
|
|
2008-05-25 04:06:45 +00:00
|
|
|
#define MIN_CPU_TIME 2
|
2008-05-05 00:51:20 +00:00
|
|
|
// if the CPU time accumulated during one of the 10-sec segments
|
|
|
|
// is less than this, ignored the benchmark
|
|
|
|
|
2004-05-22 01:36:36 +00:00
|
|
|
#define BM_FP_INIT 0
|
2004-05-21 22:40:54 +00:00
|
|
|
#define BM_FP 1
|
2004-05-22 01:36:36 +00:00
|
|
|
#define BM_INT_INIT 2
|
2004-05-21 22:40:54 +00:00
|
|
|
#define BM_INT 3
|
2004-05-22 01:36:36 +00:00
|
|
|
#define BM_SLEEP 4
|
|
|
|
#define BM_DONE 5
|
2004-05-21 22:40:54 +00:00
|
|
|
static int bm_state;
|
|
|
|
|
2010-09-15 23:38:59 +00:00
|
|
|
static bool did_benchmarks = false;
|
|
|
|
// true if we successfully did benchmarks.
|
|
|
|
// don't do them again during this run of client
|
|
|
|
|
2004-06-01 22:12:41 +00:00
|
|
|
#define BENCHMARK_PERIOD (SECONDS_PER_DAY*5)
|
2003-10-18 19:35:58 +00:00
|
|
|
// rerun CPU benchmarks this often (hardware may have been upgraded)
|
|
|
|
|
2004-03-21 00:10:15 +00:00
|
|
|
// represents a benchmark thread/process, in progress or completed
|
2003-10-18 19:35:58 +00:00
|
|
|
//
|
2004-03-21 00:10:15 +00:00
|
|
|
struct BENCHMARK_DESC {
|
|
|
|
int ordinal;
|
|
|
|
HOST_INFO host_info;
|
|
|
|
bool done;
|
|
|
|
bool error;
|
2008-05-05 00:51:20 +00:00
|
|
|
char error_str[256];
|
2007-02-10 04:13:08 +00:00
|
|
|
double int_loops;
|
|
|
|
double int_time;
|
2003-10-18 19:35:58 +00:00
|
|
|
#ifdef _WIN32
|
2004-03-21 00:10:15 +00:00
|
|
|
HANDLE handle;
|
|
|
|
DWORD pid;
|
|
|
|
#else
|
|
|
|
char filename[256];
|
|
|
|
PROCESS_ID pid;
|
2003-10-18 19:35:58 +00:00
|
|
|
#endif
|
2004-03-21 00:10:15 +00:00
|
|
|
};
|
2003-10-18 19:35:58 +00:00
|
|
|
|
2004-03-21 02:19:37 +00:00
|
|
|
static BENCHMARK_DESC* benchmark_descs=0;
|
2004-03-21 00:10:15 +00:00
|
|
|
static double cpu_benchmarks_start;
|
2007-05-22 02:58:01 +00:00
|
|
|
static int bm_ncpus;
|
|
|
|
// user might change ncpus during benchmarks.
|
|
|
|
// store starting value here.
|
2004-03-21 00:10:15 +00:00
|
|
|
|
2005-02-16 23:17:43 +00:00
|
|
|
const char *file_names[2] = {"do_fp", "do_int"};
|
2004-05-21 22:40:54 +00:00
|
|
|
|
|
|
|
static void remove_benchmark_file(int which) {
|
|
|
|
boinc_delete_file(file_names[which]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_benchmark_file(int which) {
|
|
|
|
FILE* f = boinc_fopen(file_names[which], "w");
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void benchmark_wait_to_start(int which) {
|
|
|
|
while (1) {
|
|
|
|
if (boinc_file_exists(file_names[which])) {
|
|
|
|
break;
|
|
|
|
}
|
2009-05-07 13:54:51 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
// UNIX: check if client has died.
|
|
|
|
// Not needed on windows, where we run as thread in client process
|
|
|
|
//
|
|
|
|
if (getppid() == 1) {
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
#endif
|
2004-05-21 22:40:54 +00:00
|
|
|
boinc_sleep(0.1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool benchmark_time_to_stop(int which) {
|
2009-05-07 13:54:51 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
if (getppid() == 1) {
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
#endif
|
2009-05-08 02:01:25 +00:00
|
|
|
if (boinc_file_exists(file_names[which])) {
|
|
|
|
return false;
|
|
|
|
}
|
2004-05-21 22:40:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-03-21 02:19:37 +00:00
|
|
|
// benchmark a single CPU
|
2003-10-18 19:35:58 +00:00
|
|
|
//
|
2004-03-21 00:10:15 +00:00
|
|
|
int cpu_benchmarks(BENCHMARK_DESC* bdp) {
|
2003-10-18 19:35:58 +00:00
|
|
|
HOST_INFO host_info;
|
2008-05-05 00:51:20 +00:00
|
|
|
int retval;
|
|
|
|
double vax_mips, int_loops=0, int_time=0, fp_time;
|
2003-10-18 19:35:58 +00:00
|
|
|
|
2008-05-06 00:38:18 +00:00
|
|
|
bdp->error_str[0] = '\0';
|
2004-03-31 19:43:15 +00:00
|
|
|
host_info.clear_host_info();
|
2013-08-28 07:17:51 +00:00
|
|
|
|
2013-10-22 18:26:51 +00:00
|
|
|
#if defined(ANDROID) && defined(__arm__)
|
2013-08-28 07:17:51 +00:00
|
|
|
// check for FP accelerator: VFP, Neon, or none;
|
|
|
|
// run the appropriate version of Whetstone
|
|
|
|
// (separated using namespaces)
|
|
|
|
//
|
|
|
|
if (strstr(gstate.host_info.p_features, " neon ")) {
|
|
|
|
// have ARM neon FP capabilities
|
|
|
|
retval = android_neon::whetstone(host_info.p_fpops, fp_time, MIN_CPU_TIME);
|
|
|
|
} else if (strstr(gstate.host_info.p_features, " vfp ")) {
|
|
|
|
// have ARM vfp FP capabilities
|
|
|
|
retval = android_vfp::whetstone(host_info.p_fpops, fp_time, MIN_CPU_TIME);
|
|
|
|
} else { // just run normal test
|
|
|
|
retval = whetstone(host_info.p_fpops, fp_time, MIN_CPU_TIME);
|
2013-08-28 04:08:02 +00:00
|
|
|
}
|
|
|
|
#else
|
2008-05-05 00:51:20 +00:00
|
|
|
retval = whetstone(host_info.p_fpops, fp_time, MIN_CPU_TIME);
|
2013-08-28 04:08:02 +00:00
|
|
|
#endif
|
2008-05-05 00:51:20 +00:00
|
|
|
if (retval) {
|
|
|
|
bdp->error = true;
|
|
|
|
sprintf(bdp->error_str, "FP benchmark ran only %f sec; ignoring", fp_time);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-06-03 20:13:38 +00:00
|
|
|
#ifdef _WIN32
|
2011-01-06 23:09:13 +00:00
|
|
|
// Windows: do integer benchmark only on CPU zero.
|
|
|
|
// There's a mysterious bug/problem that gives wildly
|
|
|
|
// differing benchmarks on multi-CPU and multi-core machines,
|
|
|
|
// if you use all the CPUs at once.
|
|
|
|
//
|
|
|
|
if (bdp->ordinal == 0) {
|
2007-06-03 20:13:38 +00:00
|
|
|
#endif
|
2008-05-05 00:51:20 +00:00
|
|
|
retval = dhrystone(vax_mips, int_loops, int_time, MIN_CPU_TIME);
|
|
|
|
if (retval) {
|
|
|
|
bdp->error = true;
|
|
|
|
sprintf(bdp->error_str, "Integer benchmark ran only %f sec; ignoring", int_time);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-02-10 04:13:08 +00:00
|
|
|
host_info.p_iops = vax_mips*1e6;
|
2004-05-19 19:49:46 +00:00
|
|
|
host_info.p_membw = 1e9;
|
2004-03-21 00:10:15 +00:00
|
|
|
#ifdef _WIN32
|
2011-01-06 23:09:13 +00:00
|
|
|
}
|
2004-03-21 00:10:15 +00:00
|
|
|
bdp->host_info = host_info;
|
2007-02-10 04:13:08 +00:00
|
|
|
bdp->int_loops = int_loops;
|
|
|
|
bdp->int_time = int_time;
|
2004-03-21 00:10:15 +00:00
|
|
|
#else
|
|
|
|
FILE* finfo;
|
|
|
|
finfo = boinc_fopen(bdp->filename, "w");
|
|
|
|
if (!finfo) return ERR_FOPEN;
|
2003-10-18 19:35:58 +00:00
|
|
|
host_info.write_cpu_benchmarks(finfo);
|
|
|
|
fclose(finfo);
|
2004-03-21 00:10:15 +00:00
|
|
|
#endif
|
2003-10-18 19:35:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-03-21 00:10:15 +00:00
|
|
|
#ifdef _WIN32
|
2004-03-21 00:32:03 +00:00
|
|
|
DWORD WINAPI win_cpu_benchmarks(LPVOID p) {
|
2004-03-21 00:10:15 +00:00
|
|
|
return cpu_benchmarks((BENCHMARK_DESC*)p);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void CLIENT_STATE::start_cpu_benchmarks() {
|
2005-11-10 06:03:39 +00:00
|
|
|
int i;
|
2004-03-21 00:10:15 +00:00
|
|
|
|
2007-01-17 20:28:17 +00:00
|
|
|
if (benchmarks_running) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"Can't start benchmarks - they're already running"
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-02 18:21:30 +00:00
|
|
|
if (config.skip_cpu_benchmarks) {
|
2007-02-06 20:43:54 +00:00
|
|
|
if (log_flags.benchmark_debug) {
|
2006-06-22 19:40:30 +00:00
|
|
|
msg_printf(0, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[benchmark] start_cpu_benchmarks(): Skipping CPU benchmarks"
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
|
|
|
}
|
2011-01-06 23:09:13 +00:00
|
|
|
cpu_benchmarks_set_defaults();
|
2004-03-21 00:10:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-02-06 20:43:54 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "Running CPU benchmarks");
|
2003-10-18 19:35:58 +00:00
|
|
|
|
2005-07-24 18:23:56 +00:00
|
|
|
cpu_benchmarks_pending = false;
|
|
|
|
|
2004-05-22 01:36:36 +00:00
|
|
|
bm_state = BM_FP_INIT;
|
2004-05-21 22:40:54 +00:00
|
|
|
remove_benchmark_file(BM_TYPE_FP);
|
|
|
|
remove_benchmark_file(BM_TYPE_INT);
|
2005-03-10 00:43:22 +00:00
|
|
|
cpu_benchmarks_start = dtime();
|
2004-05-21 22:40:54 +00:00
|
|
|
|
2006-07-06 04:32:37 +00:00
|
|
|
if (benchmark_descs) {
|
|
|
|
free(benchmark_descs);
|
2004-03-21 02:19:37 +00:00
|
|
|
}
|
2007-05-22 02:58:01 +00:00
|
|
|
bm_ncpus = ncpus;
|
|
|
|
benchmark_descs = (BENCHMARK_DESC*)calloc(bm_ncpus, sizeof(BENCHMARK_DESC));
|
2004-03-21 00:10:15 +00:00
|
|
|
benchmarks_running = true;
|
|
|
|
|
2007-05-22 02:58:01 +00:00
|
|
|
for (i=0; i<bm_ncpus; i++) {
|
2004-03-21 00:10:15 +00:00
|
|
|
benchmark_descs[i].ordinal = i;
|
|
|
|
benchmark_descs[i].done = false;
|
|
|
|
benchmark_descs[i].error = false;
|
2003-10-18 19:35:58 +00:00
|
|
|
#ifdef _WIN32
|
2004-03-21 00:10:15 +00:00
|
|
|
benchmark_descs[i].handle = CreateThread(
|
|
|
|
NULL, 0, win_cpu_benchmarks, benchmark_descs+i, 0,
|
|
|
|
&benchmark_descs[i].pid
|
|
|
|
);
|
2007-02-22 20:11:26 +00:00
|
|
|
SetThreadAffinityMask(benchmark_descs[i].handle, 1<<i);
|
2006-10-17 07:24:03 +00:00
|
|
|
SetThreadPriority(benchmark_descs[i].handle, THREAD_PRIORITY_IDLE);
|
2004-03-21 00:10:15 +00:00
|
|
|
#else
|
|
|
|
sprintf(benchmark_descs[i].filename, "%s_%d.xml", CPU_BENCHMARKS_FILE_NAME, i);
|
|
|
|
PROCESS_ID pid = fork();
|
|
|
|
if (pid == 0) {
|
2011-09-27 19:45:27 +00:00
|
|
|
#if HAVE_SETPRIORITY
|
2007-03-20 19:55:53 +00:00
|
|
|
if (setpriority(PRIO_PROCESS, 0, PROCESS_IDLE_PRIORITY)) {
|
|
|
|
perror("setpriority");
|
|
|
|
}
|
|
|
|
#endif
|
2005-11-10 06:03:39 +00:00
|
|
|
int retval = cpu_benchmarks(benchmark_descs+i);
|
2005-10-05 20:39:00 +00:00
|
|
|
fflush(NULL);
|
|
|
|
_exit(retval);
|
2004-03-21 00:10:15 +00:00
|
|
|
} else {
|
|
|
|
benchmark_descs[i].pid = pid;
|
2003-10-18 19:35:58 +00:00
|
|
|
}
|
2004-03-21 00:10:15 +00:00
|
|
|
#endif
|
2004-03-21 00:32:03 +00:00
|
|
|
}
|
2004-03-21 00:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if CPU benchmarks should be run:
|
2004-08-10 20:27:51 +00:00
|
|
|
// flag is set or it's been 5 days since we last ran
|
2004-03-21 00:10:15 +00:00
|
|
|
//
|
|
|
|
bool CLIENT_STATE::should_run_cpu_benchmarks() {
|
2010-09-15 23:38:59 +00:00
|
|
|
if (did_benchmarks) return false;
|
2004-03-21 00:10:15 +00:00
|
|
|
// Note: if skip_cpu_benchmarks we still should "run" cpu benchmarks
|
|
|
|
// (we'll just use default values in cpu_benchmarks())
|
2004-11-24 22:00:10 +00:00
|
|
|
//
|
2005-12-24 06:32:07 +00:00
|
|
|
if (tasks_suspended) return false;
|
2007-02-21 16:37:27 +00:00
|
|
|
|
|
|
|
// if user has changed p_calculated into the future
|
|
|
|
// (as part of cheating, presumably) always run benchmarks
|
|
|
|
//
|
|
|
|
double diff = now - host_info.p_calculated;
|
|
|
|
if (diff < 0) return true;
|
|
|
|
|
2007-05-14 19:18:45 +00:00
|
|
|
// if no projects attached yet, don't run
|
|
|
|
//
|
|
|
|
if (projects.size()==0 && !run_cpu_benchmarks) return false;
|
|
|
|
|
2007-02-21 16:37:27 +00:00
|
|
|
return ((run_cpu_benchmarks || diff > BENCHMARK_PERIOD));
|
2004-03-21 00:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// abort a running benchmark thread/process
|
|
|
|
//
|
|
|
|
void abort_benchmark(BENCHMARK_DESC& desc) {
|
|
|
|
if (desc.done) return;
|
|
|
|
#ifdef _WIN32
|
|
|
|
TerminateThread(desc.handle, 0);
|
|
|
|
CloseHandle(desc.handle);
|
2003-10-18 19:35:58 +00:00
|
|
|
#else
|
2004-03-21 00:10:15 +00:00
|
|
|
kill(desc.pid, SIGKILL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// check a running benchmark thread/process.
|
|
|
|
//
|
|
|
|
void check_benchmark(BENCHMARK_DESC& desc) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
DWORD exit_code = 0;
|
|
|
|
GetExitCodeThread(desc.handle, &exit_code);
|
|
|
|
if (exit_code != STILL_ACTIVE) {
|
|
|
|
CloseHandle(desc.handle);
|
|
|
|
desc.done = true;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
int retval;
|
|
|
|
int exit_code = 0;
|
|
|
|
retval = waitpid(desc.pid, &exit_code, WNOHANG);
|
|
|
|
if (retval) {
|
|
|
|
desc.done = true;
|
|
|
|
FILE* f = fopen(desc.filename, "r");
|
|
|
|
if (!f) {
|
|
|
|
desc.error = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
retval = desc.host_info.parse_cpu_benchmarks(f);
|
|
|
|
fclose(f);
|
|
|
|
boinc_delete_file(desc.filename);
|
|
|
|
if (retval) {
|
|
|
|
desc.error = true;
|
2003-10-18 19:35:58 +00:00
|
|
|
}
|
2004-03-21 00:10:15 +00:00
|
|
|
}
|
2003-10-18 19:35:58 +00:00
|
|
|
#endif
|
2004-03-21 00:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLIENT_STATE::abort_cpu_benchmarks() {
|
|
|
|
int i;
|
|
|
|
if (!benchmarks_running) return;
|
2007-05-22 02:58:01 +00:00
|
|
|
for (i=0; i<bm_ncpus; i++) {
|
2004-03-21 00:10:15 +00:00
|
|
|
abort_benchmark(benchmark_descs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CLIENT_STATE::cpu_benchmarks_poll() {
|
|
|
|
int i;
|
2007-02-06 20:43:54 +00:00
|
|
|
static double last_time = 0;
|
2004-03-21 00:10:15 +00:00
|
|
|
if (!benchmarks_running) return false;
|
|
|
|
|
2013-03-15 03:43:29 +00:00
|
|
|
if (!clock_change && now < last_time + BENCHMARK_POLL_PERIOD) return false;
|
2007-02-06 20:43:54 +00:00
|
|
|
last_time = now;
|
|
|
|
|
2004-08-10 20:27:51 +00:00
|
|
|
active_tasks.send_heartbeats();
|
2004-07-21 02:47:07 +00:00
|
|
|
|
2005-05-25 21:28:36 +00:00
|
|
|
// if active tasks don't quit after 10 sec, give up on benchmark
|
|
|
|
//
|
2013-03-21 03:37:26 +00:00
|
|
|
if (gstate.clock_change || (now >= (cpu_benchmarks_start + 10.0) && active_tasks.is_task_executing())) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(NULL, MSG_INTERNAL_ERROR,
|
2005-06-15 04:53:08 +00:00
|
|
|
"Failed to stop applications; aborting CPU benchmarks"
|
2005-05-10 03:42:01 +00:00
|
|
|
);
|
|
|
|
host_info.p_calculated = now;
|
|
|
|
abort_cpu_benchmarks();
|
|
|
|
benchmarks_running = false;
|
|
|
|
set_client_state_dirty("CPU benchmarks");
|
2005-07-24 18:23:56 +00:00
|
|
|
cpu_benchmarks_pending = true;
|
2005-05-10 03:42:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-05-21 22:40:54 +00:00
|
|
|
// do transitions through benchmark states
|
|
|
|
//
|
|
|
|
switch (bm_state) {
|
2004-05-22 01:36:36 +00:00
|
|
|
case BM_FP_INIT:
|
2004-05-21 22:40:54 +00:00
|
|
|
if (now - cpu_benchmarks_start > FP_START) {
|
2007-02-06 20:43:54 +00:00
|
|
|
if (log_flags.benchmark_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[benchmark] Starting floating-point benchmark"
|
2007-02-06 20:43:54 +00:00
|
|
|
);
|
|
|
|
}
|
2004-05-21 22:40:54 +00:00
|
|
|
make_benchmark_file(BM_TYPE_FP);
|
|
|
|
bm_state = BM_FP;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
case BM_FP:
|
|
|
|
if (now - cpu_benchmarks_start > FP_END) {
|
2007-02-06 20:43:54 +00:00
|
|
|
if (log_flags.benchmark_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[benchmark] Ended floating-point benchmark"
|
2007-02-06 20:43:54 +00:00
|
|
|
);
|
|
|
|
}
|
2004-05-21 22:40:54 +00:00
|
|
|
remove_benchmark_file(BM_TYPE_FP);
|
2004-05-22 01:36:36 +00:00
|
|
|
bm_state = BM_INT_INIT;
|
2004-05-21 22:40:54 +00:00
|
|
|
}
|
|
|
|
return false;
|
2004-05-22 01:36:36 +00:00
|
|
|
case BM_INT_INIT:
|
2004-05-21 22:40:54 +00:00
|
|
|
if (now - cpu_benchmarks_start > INT_START) {
|
2007-02-06 20:43:54 +00:00
|
|
|
if (log_flags.benchmark_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[benchmark] Starting integer benchmark"
|
2007-02-06 20:43:54 +00:00
|
|
|
);
|
|
|
|
}
|
2004-05-21 22:40:54 +00:00
|
|
|
make_benchmark_file(BM_TYPE_INT);
|
|
|
|
bm_state = BM_INT;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
case BM_INT:
|
|
|
|
if (now - cpu_benchmarks_start > INT_END) {
|
2007-02-06 20:43:54 +00:00
|
|
|
if (log_flags.benchmark_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[benchmark] Ended integer benchmark"
|
2007-02-06 20:43:54 +00:00
|
|
|
);
|
|
|
|
}
|
2004-05-21 22:40:54 +00:00
|
|
|
remove_benchmark_file(BM_TYPE_INT);
|
2004-05-22 01:36:36 +00:00
|
|
|
bm_state = BM_SLEEP;
|
2004-05-21 22:40:54 +00:00
|
|
|
}
|
|
|
|
return false;
|
2004-05-22 01:36:36 +00:00
|
|
|
case BM_SLEEP:
|
2007-02-06 20:43:54 +00:00
|
|
|
if (now - cpu_benchmarks_start > OVERALL_END) {
|
|
|
|
if (log_flags.benchmark_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[benchmark] Ended benchmark"
|
2007-02-06 20:43:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
bm_state = BM_DONE;
|
|
|
|
}
|
2004-05-22 01:36:36 +00:00
|
|
|
return false;
|
2004-05-21 22:40:54 +00:00
|
|
|
}
|
|
|
|
|
2004-03-21 00:10:15 +00:00
|
|
|
// check for timeout
|
|
|
|
//
|
2004-05-21 22:40:54 +00:00
|
|
|
if (now > cpu_benchmarks_start + MAX_CPU_BENCHMARKS_SECONDS) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(NULL, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"CPU benchmarks timed out, using default values"
|
|
|
|
);
|
2004-03-21 00:10:15 +00:00
|
|
|
abort_cpu_benchmarks();
|
2011-01-06 23:09:13 +00:00
|
|
|
cpu_benchmarks_set_defaults();
|
2004-03-21 00:10:15 +00:00
|
|
|
benchmarks_running = false;
|
|
|
|
set_client_state_dirty("CPU benchmarks");
|
|
|
|
}
|
2006-11-09 17:01:08 +00:00
|
|
|
|
2004-03-21 00:10:15 +00:00
|
|
|
int ndone = 0;
|
|
|
|
bool had_error = false;
|
2007-05-22 02:58:01 +00:00
|
|
|
for (i=0; i<bm_ncpus; i++) {
|
2004-03-21 00:10:15 +00:00
|
|
|
if (!benchmark_descs[i].done) {
|
|
|
|
check_benchmark(benchmark_descs[i]);
|
|
|
|
}
|
|
|
|
if (benchmark_descs[i].done) {
|
2007-02-06 20:43:54 +00:00
|
|
|
if (log_flags.benchmark_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[benchmark] CPU %d has finished", i
|
2007-02-06 20:43:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
ndone++;
|
2008-05-05 00:51:20 +00:00
|
|
|
if (benchmark_descs[i].error) {
|
2013-04-25 08:39:03 +00:00
|
|
|
msg_printf(0, MSG_INFO, "%s", benchmark_descs[i].error_str);
|
2008-05-05 00:51:20 +00:00
|
|
|
had_error = true;
|
|
|
|
}
|
2004-03-21 00:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-06 20:43:54 +00:00
|
|
|
if (log_flags.benchmark_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[benchmark] %d out of %d CPUs done", ndone, bm_ncpus
|
2007-02-06 20:43:54 +00:00
|
|
|
);
|
|
|
|
}
|
2007-05-22 02:58:01 +00:00
|
|
|
if (ndone == bm_ncpus) {
|
2006-01-17 07:30:28 +00:00
|
|
|
double old_p_fpops = host_info.p_fpops;
|
2004-03-21 00:10:15 +00:00
|
|
|
if (had_error) {
|
2011-01-06 23:09:13 +00:00
|
|
|
cpu_benchmarks_set_defaults();
|
2004-03-21 00:10:15 +00:00
|
|
|
} else {
|
2006-11-09 17:01:08 +00:00
|
|
|
double p_fpops = 0;
|
|
|
|
double p_iops = 0;
|
|
|
|
double p_membw = 0;
|
2007-05-22 02:58:01 +00:00
|
|
|
for (i=0; i<bm_ncpus; i++) {
|
2007-02-06 20:43:54 +00:00
|
|
|
if (log_flags.benchmark_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[benchmark] CPU %d: fp %f int %f intloops %f inttime %f",
|
2007-02-06 20:43:54 +00:00
|
|
|
i, benchmark_descs[i].host_info.p_fpops,
|
2007-02-10 04:13:08 +00:00
|
|
|
benchmark_descs[i].host_info.p_iops,
|
|
|
|
benchmark_descs[i].int_loops,
|
|
|
|
benchmark_descs[i].int_time
|
2007-02-06 20:43:54 +00:00
|
|
|
);
|
|
|
|
}
|
2006-11-09 17:01:08 +00:00
|
|
|
p_fpops += benchmark_descs[i].host_info.p_fpops;
|
2007-06-03 20:13:38 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
p_iops += benchmark_descs[0].host_info.p_iops;
|
|
|
|
#else
|
2006-11-09 17:01:08 +00:00
|
|
|
p_iops += benchmark_descs[i].host_info.p_iops;
|
2007-06-03 20:13:38 +00:00
|
|
|
#endif
|
2006-11-09 17:01:08 +00:00
|
|
|
p_membw += benchmark_descs[i].host_info.p_membw;
|
|
|
|
}
|
2007-05-22 02:58:01 +00:00
|
|
|
p_fpops /= bm_ncpus;
|
|
|
|
p_iops /= bm_ncpus;
|
|
|
|
p_membw /= bm_ncpus;
|
2006-11-09 17:01:08 +00:00
|
|
|
if (p_fpops > 0) {
|
|
|
|
host_info.p_fpops = p_fpops;
|
|
|
|
} else {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(NULL, MSG_INTERNAL_ERROR, "Benchmark: FP unexpectedly zero; ignoring");
|
2004-03-21 00:10:15 +00:00
|
|
|
}
|
2006-11-09 17:01:08 +00:00
|
|
|
if (p_iops > 0) {
|
|
|
|
host_info.p_iops = p_iops;
|
|
|
|
} else {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(NULL, MSG_INTERNAL_ERROR, "Benchmark: int unexpectedly zero; ignoring");
|
2006-11-09 17:01:08 +00:00
|
|
|
}
|
|
|
|
host_info.p_membw = p_membw;
|
2008-05-05 00:51:20 +00:00
|
|
|
print_benchmark_results();
|
2010-09-15 23:38:59 +00:00
|
|
|
did_benchmarks = true;
|
2003-10-18 19:35:58 +00:00
|
|
|
}
|
2004-03-21 02:19:37 +00:00
|
|
|
|
2006-01-17 07:30:28 +00:00
|
|
|
// scale duration correction factor according to change in benchmarks.
|
|
|
|
//
|
2006-08-24 22:12:04 +00:00
|
|
|
if (host_info.p_calculated && old_p_fpops) {
|
2006-01-17 07:30:28 +00:00
|
|
|
scale_duration_correction_factors(host_info.p_fpops/old_p_fpops);
|
|
|
|
}
|
2004-05-21 22:40:54 +00:00
|
|
|
host_info.p_calculated = now;
|
2004-03-21 00:10:15 +00:00
|
|
|
benchmarks_running = false;
|
|
|
|
set_client_state_dirty("CPU benchmarks");
|
2003-10-18 19:35:58 +00:00
|
|
|
}
|
2004-03-21 00:10:15 +00:00
|
|
|
return false;
|
2003-10-18 19:35:58 +00:00
|
|
|
}
|
|
|
|
|
2006-11-09 17:01:08 +00:00
|
|
|
void CLIENT_STATE::print_benchmark_results() {
|
|
|
|
msg_printf(NULL, MSG_INFO, "Benchmark results:");
|
2007-05-22 02:58:01 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, " Number of CPUs: %d", bm_ncpus);
|
2006-11-09 17:01:08 +00:00
|
|
|
msg_printf(
|
|
|
|
NULL, MSG_INFO, " %.0f floating point MIPS (Whetstone) per CPU",
|
|
|
|
host_info.p_fpops/1e6
|
|
|
|
);
|
|
|
|
msg_printf(
|
|
|
|
NULL, MSG_INFO, " %.0f integer MIPS (Dhrystone) per CPU",
|
|
|
|
host_info.p_iops/1e6
|
|
|
|
);
|
|
|
|
#if 0
|
|
|
|
msg_printf(
|
|
|
|
NULL, MSG_INFO, "Benchmark results: %.0f million bytes/sec memory bandwidth%s",
|
2009-03-20 01:46:29 +00:00
|
|
|
host_info.p_membw/1e6, (host_info.p_membw_err?" [ERROR]":"")
|
2006-11-09 17:01:08 +00:00
|
|
|
);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-08-24 20:33:46 +00:00
|
|
|
bool CLIENT_STATE::cpu_benchmarks_done() {
|
2011-01-06 23:09:13 +00:00
|
|
|
return (host_info.p_calculated != 0);
|
2006-08-24 20:33:46 +00:00
|
|
|
}
|
|
|
|
|
2006-11-09 17:01:08 +00:00
|
|
|
// If a benchmark is nonzero, keep it. Otherwise use default value
|
|
|
|
//
|
2006-08-24 20:33:46 +00:00
|
|
|
void CLIENT_STATE::cpu_benchmarks_set_defaults() {
|
2006-11-09 17:01:08 +00:00
|
|
|
if (!host_info.p_fpops) host_info.p_fpops = DEFAULT_FPOPS;
|
|
|
|
if (!host_info.p_iops) host_info.p_iops = DEFAULT_IOPS;
|
|
|
|
if (!host_info.p_membw) host_info.p_membw = DEFAULT_MEMBW;
|
|
|
|
if (!host_info.m_cache) host_info.m_cache = DEFAULT_CACHE;
|
2006-08-24 20:33:46 +00:00
|
|
|
}
|