2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2007-05-08 01:55:28 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2007-05-08 01:55:28 +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.
|
2007-05-08 01:55:28 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2007-05-08 01:55:28 +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.
|
|
|
|
//
|
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/>.
|
2007-05-08 01:55:28 +00:00
|
|
|
|
|
|
|
// BOINC client simulator.
|
|
|
|
//
|
|
|
|
// usage:
|
|
|
|
// sim [--duration x] [--delta x] [--dirs dir ...]
|
|
|
|
// duration = simulation duration (default 86400)
|
|
|
|
// delta = simulation time step (default 10)
|
|
|
|
//
|
|
|
|
// If no dirs are specified:
|
|
|
|
// reads input files
|
|
|
|
// sim_projects.xml, sim_host.xml, sim_prefs.xml, cc_config.xml
|
|
|
|
// and does simulation, generating output files
|
|
|
|
// sim_log.txt, sim_out.html
|
|
|
|
//
|
|
|
|
// If dirs are specified, chdir into each directory in sequence,
|
|
|
|
// do the above for each one, and write summary info to stdout
|
|
|
|
|
2009-08-22 17:00:19 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define finite _finite
|
|
|
|
#endif
|
|
|
|
|
2009-07-06 16:33:02 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2007-05-08 01:55:28 +00:00
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "str_util.h"
|
2010-09-24 20:02:42 +00:00
|
|
|
#include "util.h"
|
2009-06-16 20:54:44 +00:00
|
|
|
#include "str_replace.h"
|
2007-05-08 01:55:28 +00:00
|
|
|
#include "log_flags.h"
|
|
|
|
#include "filesys.h"
|
|
|
|
#include "client_msgs.h"
|
2010-09-24 20:02:42 +00:00
|
|
|
#include "client_state.h"
|
2007-05-08 01:55:28 +00:00
|
|
|
#include "sim.h"
|
|
|
|
|
|
|
|
//////////////// FUNCTIONS MODIFIED OR STUBBED OUT /////////////
|
|
|
|
|
|
|
|
void HOST_INFO::generate_host_cpid() {}
|
|
|
|
|
2008-01-11 23:52:49 +00:00
|
|
|
//int get_connected_state() {return 1;}
|
2007-05-08 01:55:28 +00:00
|
|
|
|
2011-06-25 17:58:37 +00:00
|
|
|
void show_message(PROJ_AM *p, char* msg, int priority, bool, const char*) {
|
2007-05-08 01:55:28 +00:00
|
|
|
const char* x;
|
|
|
|
char message[1024];
|
|
|
|
|
|
|
|
if (priority == MSG_INTERNAL_ERROR) {
|
|
|
|
strcpy(message, "[error] ");
|
|
|
|
strlcpy(message+8, msg, sizeof(message)-8);
|
|
|
|
} else {
|
|
|
|
strlcpy(message, msg, sizeof(message));
|
|
|
|
}
|
|
|
|
while (strlen(message)&&message[strlen(message)-1] == '\n') {
|
|
|
|
message[strlen(message)-1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p) {
|
|
|
|
x = p->get_project_name();
|
|
|
|
} else {
|
|
|
|
x = "---";
|
|
|
|
}
|
|
|
|
|
2010-10-15 20:16:00 +00:00
|
|
|
fprintf(logfile, "%.0f [%s] %s\n", gstate.now, x, message);
|
2007-05-08 01:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
APP_CLIENT_SHM::APP_CLIENT_SHM() {}
|
|
|
|
GRAPHICS_MSG::GRAPHICS_MSG() {}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////// FUNCTIONS WE NEED TO IMPLEMENT /////////////
|
|
|
|
|
|
|
|
int ACTIVE_TASK::suspend() {
|
|
|
|
if (task_state() != PROCESS_EXECUTING) {
|
|
|
|
msg_printf(0, MSG_INFO, "Internal error: expected process to be executing");
|
|
|
|
}
|
|
|
|
set_task_state(PROCESS_SUSPENDED, "suspend");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ACTIVE_TASK::request_exit() {
|
|
|
|
set_task_state(PROCESS_UNINITIALIZED, "request_exit");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ACTIVE_TASK::resume_or_start(bool first_time) {
|
|
|
|
if (log_flags.task) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
2010-11-23 19:39:47 +00:00
|
|
|
"[task] %s task %s: FLOPS left %.2fG",
|
|
|
|
first_time?"Starting":"Resuming", result->name, flops_left/1e9
|
2007-05-08 01:55:28 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
set_task_state(PROCESS_EXECUTING, "start");
|
|
|
|
char buf[256];
|
2010-11-23 19:39:47 +00:00
|
|
|
sprintf(buf, "Starting %s: %.2fG<br>", result->name, flops_left/1e9);
|
2010-10-08 23:18:12 +00:00
|
|
|
html_msg += buf;
|
2007-05-08 01:55:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ACTIVE_TASK::init(RESULT* rp) {
|
|
|
|
result = rp;
|
|
|
|
wup = rp->wup;
|
|
|
|
app_version = rp->avp;
|
2009-02-26 22:04:53 +00:00
|
|
|
max_elapsed_time = rp->wup->rsc_fpops_bound/result->avp->flops;
|
2007-05-08 01:55:28 +00:00
|
|
|
max_disk_usage = rp->wup->rsc_disk_bound;
|
|
|
|
max_mem_usage = rp->wup->rsc_memory_bound;
|
2010-11-23 19:39:47 +00:00
|
|
|
flops_left = rp->wup->rsc_fpops_est;
|
2007-05-08 01:55:28 +00:00
|
|
|
_task_state = PROCESS_UNINITIALIZED;
|
|
|
|
scheduler_state = CPU_SCHED_UNINITIALIZED;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////// OTHER
|
|
|
|
|
|
|
|
double NORMAL_DIST::sample() {
|
2010-10-19 15:48:33 +00:00
|
|
|
if (!std_dev) return mean;
|
2010-12-09 00:32:50 +00:00
|
|
|
return (mean + std_dev * rand_normal());
|
2007-05-08 01:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline double exponential(double mean) {
|
|
|
|
return -mean*log(1-drand());
|
|
|
|
}
|
|
|
|
|
2010-12-18 17:09:57 +00:00
|
|
|
bool RANDOM_PROCESS::sample(double diff) {
|
2007-05-08 01:55:28 +00:00
|
|
|
if (frac==1) return true;
|
|
|
|
time_left -= diff;
|
|
|
|
if (time_left < 0) {
|
|
|
|
if (value) {
|
|
|
|
time_left += exponential(off_lambda);
|
|
|
|
value = false;
|
|
|
|
} else {
|
|
|
|
time_left += exponential(lambda);
|
|
|
|
value = true;
|
|
|
|
}
|
|
|
|
}
|
2010-12-23 23:39:30 +00:00
|
|
|
#if 0
|
2010-01-21 00:14:56 +00:00
|
|
|
msg_printf(0, MSG_INFO,
|
2010-12-18 17:09:57 +00:00
|
|
|
"value: %d lambda: %f time_left %f",
|
|
|
|
value, lambda, time_left
|
2010-01-21 00:14:56 +00:00
|
|
|
);
|
2010-12-23 23:39:30 +00:00
|
|
|
#endif
|
2007-05-08 01:55:28 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
RANDOM_PROCESS::RANDOM_PROCESS() {
|
|
|
|
frac = 1;
|
2010-12-18 17:09:57 +00:00
|
|
|
last_time = 0;
|
2007-05-08 01:55:28 +00:00
|
|
|
}
|
|
|
|
|
2010-12-18 17:09:57 +00:00
|
|
|
void RANDOM_PROCESS::init(double f, double l) {
|
|
|
|
frac = f;
|
|
|
|
lambda = l;
|
|
|
|
last_time = 0;
|
2007-05-08 01:55:28 +00:00
|
|
|
value = true;
|
|
|
|
time_left = exponential(lambda);
|
|
|
|
off_lambda = lambda/frac - lambda;
|
|
|
|
}
|
|
|
|
|
2010-09-24 20:02:42 +00:00
|
|
|
int UNIFORM_DIST::parse(XML_PARSER& xp, const char* end_tag) {
|
2007-05-08 01:55:28 +00:00
|
|
|
char tag[256];
|
|
|
|
bool is_tag;
|
2010-12-18 17:09:57 +00:00
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
2007-05-08 01:55:28 +00:00
|
|
|
if (!is_tag) return ERR_XML_PARSE;
|
|
|
|
if (xp.parse_double(tag, "lo", lo)) continue;
|
|
|
|
else if (xp.parse_double(tag, "hi", hi)) continue;
|
|
|
|
else if (!strcmp(tag, end_tag)) return 0;
|
|
|
|
else {
|
|
|
|
printf("unrecognized: %s\n", tag);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2010-12-18 17:09:57 +00:00
|
|
|
int NORMAL_DIST::parse(XML_PARSER& xp, const char* end_tag) {
|
2007-05-08 01:55:28 +00:00
|
|
|
char tag[256];
|
|
|
|
bool is_tag;
|
|
|
|
while(!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) return ERR_XML_PARSE;
|
2010-12-18 17:09:57 +00:00
|
|
|
if (xp.parse_double(tag, "mean", mean)) continue;
|
|
|
|
else if (xp.parse_double(tag, "std_dev", std_dev)) continue;
|
2007-05-08 01:55:28 +00:00
|
|
|
else if (!strcmp(tag, end_tag)) return 0;
|
|
|
|
else {
|
|
|
|
printf("unrecognized: %s\n", tag);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|