2007-04-06 19:47:37 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2006 University of California
|
|
|
|
//
|
|
|
|
// This 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 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This software 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 Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
// BOINC client simulator.
|
|
|
|
//
|
2007-02-22 16:33:37 +00:00
|
|
|
// usage:
|
2007-04-06 19:47:37 +00:00
|
|
|
// 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
|
2007-02-22 16:33:37 +00:00
|
|
|
|
2007-02-24 00:11:30 +00:00
|
|
|
#include "error_numbers.h"
|
2007-02-21 16:26:51 +00:00
|
|
|
#include "str_util.h"
|
2007-05-08 01:55:28 +00:00
|
|
|
#include "util.h"
|
2007-02-24 20:10:06 +00:00
|
|
|
#include "log_flags.h"
|
2007-02-24 00:11:30 +00:00
|
|
|
#include "filesys.h"
|
|
|
|
#include "network.h"
|
2007-03-23 18:48:06 +00:00
|
|
|
#include "client_msgs.h"
|
2007-05-08 01:55:28 +00:00
|
|
|
#include "../sched/edf_sim.h"
|
2007-02-15 21:11:05 +00:00
|
|
|
#include "sim.h"
|
|
|
|
|
2007-05-08 01:55:28 +00:00
|
|
|
#define SCHED_RETRY_DELAY_MIN 60 // 1 minute
|
|
|
|
#define SCHED_RETRY_DELAY_MAX (60*60*4) // 4 hours
|
|
|
|
|
2007-02-15 21:11:05 +00:00
|
|
|
CLIENT_STATE gstate;
|
2007-02-21 22:27:35 +00:00
|
|
|
NET_STATUS net_status;
|
|
|
|
bool user_active;
|
2007-04-06 19:47:37 +00:00
|
|
|
double duration = 86400, delta = 60;
|
|
|
|
FILE* logfile;
|
2007-04-09 02:17:26 +00:00
|
|
|
bool running;
|
2007-05-04 23:05:17 +00:00
|
|
|
double running_time = 0;
|
2007-05-08 01:55:28 +00:00
|
|
|
bool server_uses_workload = false;
|
2007-05-09 15:23:10 +00:00
|
|
|
bool dcf_dont_use;
|
|
|
|
bool dcf_stats;
|
2007-05-15 20:29:26 +00:00
|
|
|
bool dual_dcf;
|
|
|
|
bool cpu_sched_rr_only;
|
2007-07-11 20:13:53 +00:00
|
|
|
bool work_fetch_old;
|
2007-07-12 18:38:53 +00:00
|
|
|
int line_limit = 1000000;
|
2007-04-06 19:47:37 +00:00
|
|
|
|
|
|
|
SIM_RESULTS sim_results;
|
2007-02-21 22:27:35 +00:00
|
|
|
|
2007-05-09 15:23:10 +00:00
|
|
|
void SIM_PROJECT::update_dcf_stats(RESULT* rp) {
|
|
|
|
double raw_ratio = rp->final_cpu_time/rp->estimated_cpu_time_uncorrected();
|
2007-05-18 22:02:51 +00:00
|
|
|
// see http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Algorithm_III
|
2007-05-09 15:23:10 +00:00
|
|
|
++completed_task_count;
|
|
|
|
double delta = raw_ratio - completions_ratio_mean;
|
|
|
|
completions_ratio_mean += delta / completed_task_count;
|
|
|
|
completions_ratio_s += delta * ( raw_ratio - completions_ratio_mean);
|
|
|
|
if (completed_task_count > 1) {
|
2007-05-22 02:58:01 +00:00
|
|
|
completions_ratio_stdev = sqrt(completions_ratio_s / (completed_task_count - 1));
|
2007-05-09 15:23:10 +00:00
|
|
|
double required_stdev = (raw_ratio - completions_ratio_mean) / completions_ratio_stdev;
|
|
|
|
if (required_stdev > completions_required_stdevs) {
|
|
|
|
completions_required_stdevs = std::min(required_stdev, 7.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
duration_correction_factor = completions_ratio_mean +
|
|
|
|
completions_required_stdevs * completions_ratio_stdev;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-08 01:55:28 +00:00
|
|
|
// generate a job; pick a random app,
|
|
|
|
// and pick a FLOP count from its distribution
|
2007-02-21 22:27:35 +00:00
|
|
|
//
|
2007-05-08 01:55:28 +00:00
|
|
|
void CLIENT_STATE::make_job(SIM_PROJECT* p, WORKUNIT* wup, RESULT* rp) {
|
|
|
|
SIM_APP* ap1, *ap=0;
|
|
|
|
double net_fpops = host_info.p_fpops;
|
|
|
|
double x = drand();
|
|
|
|
|
|
|
|
for (unsigned int i=0; i<apps.size();i++) {
|
|
|
|
ap1 = (SIM_APP*)apps[i];
|
|
|
|
if (ap1->project != p) continue;
|
|
|
|
x -= ap1->weight;
|
|
|
|
if (x <= 0) {
|
|
|
|
ap = ap1;
|
|
|
|
break;
|
|
|
|
}
|
2007-02-21 22:27:35 +00:00
|
|
|
}
|
2007-05-08 01:55:28 +00:00
|
|
|
if (!ap) {
|
|
|
|
printf("ERROR-NO APP\n");
|
|
|
|
exit(1);
|
2007-02-21 22:27:35 +00:00
|
|
|
}
|
2007-05-08 01:55:28 +00:00
|
|
|
rp->clear();
|
|
|
|
rp->project = p;
|
|
|
|
rp->wup = wup;
|
|
|
|
sprintf(rp->name, "%s_%d", p->project_name, p->result_index++);
|
|
|
|
wup->project = p;
|
|
|
|
wup->rsc_fpops_est = ap->fpops_est;
|
|
|
|
double ops = ap->fpops.sample();
|
|
|
|
if (ops < 0) ops = 0;
|
|
|
|
rp->final_cpu_time = ops/net_fpops;
|
|
|
|
rp->report_deadline = now + ap->latency_bound;
|
2007-02-21 22:27:35 +00:00
|
|
|
}
|
|
|
|
|
2007-05-08 01:55:28 +00:00
|
|
|
// process ready-to-report results
|
|
|
|
//
|
|
|
|
void CLIENT_STATE::handle_completed_results() {
|
2007-04-04 16:15:18 +00:00
|
|
|
char buf[256];
|
2007-04-03 20:30:44 +00:00
|
|
|
vector<RESULT*>::iterator result_iter;
|
2007-05-08 01:55:28 +00:00
|
|
|
|
2007-04-03 20:30:44 +00:00
|
|
|
result_iter = results.begin();
|
|
|
|
while (result_iter != results.end()) {
|
|
|
|
RESULT* rp = *result_iter;
|
|
|
|
if (rp->ready_to_report) {
|
2007-04-06 16:20:19 +00:00
|
|
|
sprintf(buf, "result %s reported; %s<br>",
|
|
|
|
rp->name,
|
|
|
|
(gstate.now > rp->report_deadline)?
|
|
|
|
"<font color=#cc0000>MISSED DEADLINE</font>":
|
|
|
|
"<font color=#00cc00>MADE DEADLINE</font>"
|
|
|
|
);
|
2007-04-10 20:13:15 +00:00
|
|
|
SIM_PROJECT* spp = (SIM_PROJECT*)rp->project;
|
2007-04-06 16:20:19 +00:00
|
|
|
if (gstate.now > rp->report_deadline) {
|
2007-04-06 19:47:37 +00:00
|
|
|
sim_results.cpu_wasted += rp->final_cpu_time;
|
2007-04-10 20:13:15 +00:00
|
|
|
sim_results.nresults_missed_deadline++;
|
|
|
|
spp->project_results.nresults_missed_deadline++;
|
|
|
|
spp->project_results.cpu_wasted += rp->final_cpu_time;
|
2007-04-06 16:20:19 +00:00
|
|
|
} else {
|
2007-04-06 19:47:37 +00:00
|
|
|
sim_results.cpu_used += rp->final_cpu_time;
|
2007-04-10 20:13:15 +00:00
|
|
|
sim_results.nresults_met_deadline++;
|
|
|
|
spp->project_results.nresults_met_deadline++;
|
|
|
|
spp->project_results.cpu_used += rp->final_cpu_time;
|
2007-04-06 16:20:19 +00:00
|
|
|
}
|
|
|
|
gstate.html_msg += buf;
|
2007-04-03 20:30:44 +00:00
|
|
|
delete rp;
|
|
|
|
result_iter = results.erase(result_iter);
|
|
|
|
} else {
|
|
|
|
result_iter++;
|
|
|
|
}
|
|
|
|
}
|
2007-05-08 01:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// convert results in progress to IP_RESULTs,
|
|
|
|
// and get an initial schedule for them
|
|
|
|
//
|
|
|
|
void CLIENT_STATE::get_workload(vector<IP_RESULT>& ip_results) {
|
|
|
|
for (unsigned int i=0; i<results.size(); i++) {
|
|
|
|
RESULT* rp = results[i];
|
2007-05-15 20:29:26 +00:00
|
|
|
double x = rp->estimated_cpu_time_remaining(false);
|
2007-05-08 01:55:28 +00:00
|
|
|
if (x == 0) continue;
|
|
|
|
IP_RESULT ipr(rp->name, rp->report_deadline, x);
|
|
|
|
ip_results.push_back(ipr);
|
|
|
|
}
|
|
|
|
init_ip_results(work_buf_min(), ncpus, ip_results);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CLIENT_STATE::simulate_rpc(PROJECT* _p) {
|
|
|
|
char buf[256];
|
|
|
|
SIM_PROJECT* p = (SIM_PROJECT*) _p;
|
|
|
|
static double last_time=0;
|
|
|
|
vector<IP_RESULT> ip_results;
|
2007-05-08 23:12:40 +00:00
|
|
|
int infeasible_count = 0;
|
2007-05-08 01:55:28 +00:00
|
|
|
|
|
|
|
double diff = now - last_time;
|
|
|
|
if (diff && diff < host_info.connection_interval) {
|
|
|
|
msg_printf(NULL, MSG_INFO, "simulate_rpc: too soon %f < %f", diff, host_info.connection_interval);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
last_time = now;
|
|
|
|
|
|
|
|
sprintf(buf, "RPC to %s; asking for %f<br>", p->project_name, p->work_request);
|
|
|
|
html_msg += buf;
|
|
|
|
|
|
|
|
handle_completed_results();
|
|
|
|
|
|
|
|
if (server_uses_workload) {
|
|
|
|
get_workload(ip_results);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool sent_something = false;
|
|
|
|
double work_left = p->work_request;
|
|
|
|
while (work_left > 0) {
|
|
|
|
RESULT* rp = new RESULT;
|
|
|
|
WORKUNIT* wup = new WORKUNIT;
|
|
|
|
make_job(p, wup, rp);
|
2007-04-03 20:30:44 +00:00
|
|
|
|
2007-05-08 01:55:28 +00:00
|
|
|
if (server_uses_workload) {
|
|
|
|
IP_RESULT c(rp->name, rp->report_deadline, rp->final_cpu_time);
|
|
|
|
if (check_candidate(c, ncpus, ip_results)) {
|
|
|
|
ip_results.push_back(c);
|
|
|
|
} else {
|
|
|
|
delete rp;
|
|
|
|
delete wup;
|
2007-05-08 23:12:40 +00:00
|
|
|
if (++infeasible_count > p->max_infeasible_count) {
|
|
|
|
p->min_rpc_time = now + 1;
|
|
|
|
break;
|
|
|
|
}
|
2007-04-05 23:15:20 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-08 01:55:28 +00:00
|
|
|
|
|
|
|
sent_something = true;
|
2007-03-29 16:40:43 +00:00
|
|
|
rp->set_state(RESULT_FILES_DOWNLOADED, "simulate_rpc");
|
|
|
|
results.push_back(rp);
|
2007-04-05 23:15:20 +00:00
|
|
|
sprintf(buf, "got job %s: CPU time %.2f, deadline %s<br>",
|
|
|
|
rp->name, rp->final_cpu_time, time_to_string(rp->report_deadline)
|
|
|
|
);
|
2007-04-04 16:15:18 +00:00
|
|
|
html_msg += buf;
|
2007-05-08 01:55:28 +00:00
|
|
|
work_left -= p->duration_correction_factor*wup->rsc_fpops_est/host_info.p_fpops;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p->work_request > 0 && !sent_something) {
|
|
|
|
p->backoff();
|
|
|
|
} else {
|
|
|
|
p->nrpc_failures = 0;
|
2007-03-29 16:40:43 +00:00
|
|
|
}
|
2007-04-02 18:04:54 +00:00
|
|
|
p->work_request = 0;
|
2007-03-04 02:30:48 +00:00
|
|
|
request_schedule_cpus("simulate_rpc");
|
2007-04-05 23:15:20 +00:00
|
|
|
request_work_fetch("simulate_rpc");
|
|
|
|
return true;
|
2007-02-24 20:10:06 +00:00
|
|
|
}
|
|
|
|
|
2007-05-08 01:55:28 +00:00
|
|
|
void SIM_PROJECT::backoff() {
|
|
|
|
nrpc_failures++;
|
|
|
|
double backoff = calculate_exponential_backoff(
|
|
|
|
nrpc_failures, SCHED_RETRY_DELAY_MIN, SCHED_RETRY_DELAY_MAX
|
|
|
|
);
|
|
|
|
min_rpc_time = gstate.now + backoff;
|
|
|
|
}
|
|
|
|
|
2007-02-23 17:29:19 +00:00
|
|
|
bool CLIENT_STATE::scheduler_rpc_poll() {
|
|
|
|
PROJECT *p;
|
|
|
|
|
2007-05-08 01:55:28 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "RPC poll start");
|
2007-02-23 17:29:19 +00:00
|
|
|
p = next_project_sched_rpc_pending();
|
|
|
|
if (p) {
|
2007-04-05 23:15:20 +00:00
|
|
|
return simulate_rpc(p);
|
2007-02-23 17:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p = find_project_with_overdue_results();
|
|
|
|
if (p) {
|
2007-04-05 23:15:20 +00:00
|
|
|
return simulate_rpc(p);
|
2007-02-23 17:29:19 +00:00
|
|
|
}
|
|
|
|
p = next_project_need_work();
|
|
|
|
if (p) {
|
2007-04-05 23:15:20 +00:00
|
|
|
return simulate_rpc(p);
|
2007-02-23 17:29:19 +00:00
|
|
|
}
|
2007-05-08 01:55:28 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "RPC poll: nothing to do");
|
2007-02-23 17:29:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ACTIVE_TASK_SET::poll() {
|
2007-03-23 18:48:06 +00:00
|
|
|
unsigned int i;
|
2007-04-04 15:40:07 +00:00
|
|
|
char buf[256];
|
2007-03-23 18:48:06 +00:00
|
|
|
bool action = false;
|
|
|
|
static double last_time = 0;
|
|
|
|
double diff = gstate.now - last_time;
|
|
|
|
if (diff < 1.0) return false;
|
|
|
|
last_time = gstate.now;
|
2007-04-10 20:13:15 +00:00
|
|
|
SIM_PROJECT* p;
|
2007-03-23 18:48:06 +00:00
|
|
|
|
2007-04-09 02:17:26 +00:00
|
|
|
if (!running) return false;
|
|
|
|
|
2007-04-10 20:13:15 +00:00
|
|
|
for (i=0; i<gstate.projects.size(); i++) {
|
|
|
|
p = (SIM_PROJECT*) gstate.projects[i];
|
|
|
|
p->idle = true;
|
2007-05-08 01:55:28 +00:00
|
|
|
sprintf(buf, "%s STD: %f min RPC<br>",
|
|
|
|
p->project_name, p->short_term_debt,
|
|
|
|
time_to_string(p->min_rpc_time)
|
|
|
|
);
|
2007-05-03 21:22:24 +00:00
|
|
|
gstate.html_msg += buf;
|
2007-04-10 20:13:15 +00:00
|
|
|
}
|
|
|
|
|
2007-04-06 16:20:19 +00:00
|
|
|
int n=0;
|
2007-03-23 18:48:06 +00:00
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
ACTIVE_TASK* atp = active_tasks[i];
|
|
|
|
switch (atp->task_state()) {
|
|
|
|
case PROCESS_EXECUTING:
|
|
|
|
atp->cpu_time_left -= diff;
|
2007-05-03 21:22:24 +00:00
|
|
|
atp->current_cpu_time += diff;
|
2007-04-10 20:13:15 +00:00
|
|
|
RESULT* rp = atp->result;
|
2007-04-10 21:56:11 +00:00
|
|
|
|
|
|
|
double cpu_time_used = rp->final_cpu_time - atp->cpu_time_left;
|
|
|
|
atp->fraction_done = cpu_time_used/rp->final_cpu_time;
|
|
|
|
atp->checkpoint_wall_time = gstate.now;
|
|
|
|
|
2007-03-23 18:48:06 +00:00
|
|
|
if (atp->cpu_time_left <= 0) {
|
|
|
|
atp->set_task_state(PROCESS_EXITED, "poll");
|
2007-04-05 23:15:20 +00:00
|
|
|
rp->exit_status = 0;
|
2007-04-06 16:20:19 +00:00
|
|
|
rp->ready_to_report = true;
|
2007-04-03 19:06:26 +00:00
|
|
|
gstate.request_schedule_cpus("ATP poll");
|
|
|
|
gstate.request_work_fetch("ATP poll");
|
2007-04-06 16:20:19 +00:00
|
|
|
sprintf(buf, "result %s finished<br>", rp->name);
|
2007-04-04 15:40:07 +00:00
|
|
|
gstate.html_msg += buf;
|
2007-05-03 21:22:24 +00:00
|
|
|
action = true;
|
2007-03-23 18:48:06 +00:00
|
|
|
}
|
2007-04-10 20:13:15 +00:00
|
|
|
((SIM_PROJECT*)rp->project)->idle = false;
|
2007-04-06 16:20:19 +00:00
|
|
|
n++;
|
2007-03-23 18:48:06 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-06 16:20:19 +00:00
|
|
|
if (n < gstate.ncpus) {
|
2007-04-06 19:47:37 +00:00
|
|
|
sim_results.cpu_idle += diff*(gstate.ncpus-n);
|
2007-04-06 16:20:19 +00:00
|
|
|
}
|
|
|
|
if (n > gstate.ncpus) {
|
|
|
|
sprintf(buf, "TOO MANY JOBS RUNNING");
|
|
|
|
gstate.html_msg += buf;
|
|
|
|
}
|
2007-04-09 02:17:26 +00:00
|
|
|
|
2007-04-10 20:13:15 +00:00
|
|
|
for (i=0; i<gstate.projects.size(); i++) {
|
|
|
|
p = (SIM_PROJECT*) gstate.projects[i];
|
|
|
|
if (p->idle) {
|
2007-05-04 23:05:17 +00:00
|
|
|
p->idle_time += diff;
|
|
|
|
p->idle_time_sumsq += diff*(p->idle_time*p->idle_time);
|
2007-04-10 20:13:15 +00:00
|
|
|
} else {
|
2007-05-04 23:05:17 +00:00
|
|
|
p->idle_time = 0;
|
2007-04-10 20:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-04 23:05:17 +00:00
|
|
|
running_time += diff;
|
2007-04-10 20:13:15 +00:00
|
|
|
|
2007-03-23 18:48:06 +00:00
|
|
|
return action;
|
2007-02-23 17:29:19 +00:00
|
|
|
}
|
|
|
|
|
2007-02-24 00:11:30 +00:00
|
|
|
int SIM_APP::parse(XML_PARSER& xp) {
|
|
|
|
char tag[256];
|
|
|
|
bool is_tag;
|
|
|
|
int retval;
|
|
|
|
|
2007-04-05 23:15:20 +00:00
|
|
|
weight = 1;
|
2007-02-24 00:11:30 +00:00
|
|
|
while(!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) return ERR_XML_PARSE;
|
|
|
|
if (!strcmp(tag, "/app")) {
|
|
|
|
return 0;
|
2007-03-29 16:40:43 +00:00
|
|
|
}
|
|
|
|
else if (xp.parse_double(tag, "latency_bound", latency_bound)) continue;
|
|
|
|
else if (xp.parse_double(tag, "fpops_est", fpops_est)) continue;
|
2007-04-05 23:15:20 +00:00
|
|
|
else if (xp.parse_double(tag, "weight", weight)) continue;
|
2007-02-24 00:11:30 +00:00
|
|
|
else if (!strcmp(tag, "fpops")) {
|
|
|
|
retval = fpops.parse(xp, "/fpops");
|
|
|
|
if (retval) return retval;
|
|
|
|
} else if (!strcmp(tag, "checkpoint_period")) {
|
|
|
|
retval = checkpoint_period.parse(xp, "/checkpoint_period");
|
|
|
|
if (retval) return retval;
|
|
|
|
} else if (xp.parse_double(tag, "working_set", working_set)) continue;
|
2007-04-04 19:34:01 +00:00
|
|
|
else {
|
|
|
|
printf("unrecognized: %s\n", tag);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2007-02-24 00:11:30 +00:00
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
2007-02-23 17:29:19 +00:00
|
|
|
}
|
|
|
|
|
2007-04-10 20:13:15 +00:00
|
|
|
// return the fraction of CPU time that was spent in violation of shares
|
|
|
|
// i.e., if a project got X and it should have got Y,
|
|
|
|
// add up |X-Y| over all projects, and divide by total CPU
|
|
|
|
//
|
|
|
|
double CLIENT_STATE::share_violation() {
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
double tot = 0, trs=0;
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
SIM_PROJECT* p = (SIM_PROJECT*) projects[i];
|
|
|
|
tot += p->project_results.cpu_used + p->project_results.cpu_wasted;
|
|
|
|
trs += p->resource_share;
|
|
|
|
}
|
|
|
|
double sum = 0;
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
SIM_PROJECT* p = (SIM_PROJECT*) projects[i];
|
|
|
|
double t = p->project_results.cpu_used + p->project_results.cpu_wasted;
|
|
|
|
double rs = p->resource_share/trs;
|
|
|
|
double rt = tot*rs;
|
|
|
|
sum += fabs(t - rt);
|
|
|
|
}
|
|
|
|
return sum/tot;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-07-12 19:52:58 +00:00
|
|
|
// "monotony" is defined as follows:
|
2007-05-04 23:05:17 +00:00
|
|
|
// for each project P, maintain R(P), the time since P last ran,
|
|
|
|
// let S(P) be the RMS of R(P).
|
2007-07-12 19:52:58 +00:00
|
|
|
// Let X = mean(S(P))/(sched_interval*nprojects)
|
|
|
|
// (the *nprojects reflects the fact that in the limit of nprojects,
|
|
|
|
// each one waits for a time to run proportional to nprojects)
|
|
|
|
// X varies from zero (no monotony) to infinity.
|
|
|
|
// X is one in the case of round-robin on 1 CPU.
|
|
|
|
// Let monotony = 1-1/(x+1)
|
2007-04-10 20:13:15 +00:00
|
|
|
//
|
2007-07-12 19:52:58 +00:00
|
|
|
double CLIENT_STATE::monotony() {
|
2007-04-10 20:13:15 +00:00
|
|
|
double sum = 0;
|
2007-06-20 16:27:27 +00:00
|
|
|
double schedint = global_prefs.cpu_scheduling_period();
|
2007-04-10 20:13:15 +00:00
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
SIM_PROJECT* p = (SIM_PROJECT*) projects[i];
|
2007-05-04 23:05:17 +00:00
|
|
|
double avg_ss = p->idle_time_sumsq/running_time;
|
|
|
|
double s = sqrt(avg_ss);
|
|
|
|
sum += s;
|
2007-04-10 20:13:15 +00:00
|
|
|
}
|
2007-07-12 19:52:58 +00:00
|
|
|
int n = (int)projects.size();
|
|
|
|
double x = sum/(n*schedint*n);
|
|
|
|
double m = 1-(1/(x+1));
|
|
|
|
//printf("sum: %f; x: %f m: %f\n", sum, x, m);
|
|
|
|
return m;
|
2007-04-10 20:13:15 +00:00
|
|
|
}
|
|
|
|
|
2007-05-04 23:05:17 +00:00
|
|
|
// the CPU totals are there; compute the other fields
|
|
|
|
//
|
2007-04-10 21:56:11 +00:00
|
|
|
void SIM_RESULTS::compute() {
|
2007-04-10 20:13:15 +00:00
|
|
|
double total = cpu_used + cpu_wasted + cpu_idle;
|
2007-04-10 21:56:11 +00:00
|
|
|
cpu_wasted_frac = cpu_wasted/total;
|
|
|
|
cpu_idle_frac = cpu_idle/total;
|
|
|
|
share_violation = gstate.share_violation();
|
2007-07-12 19:52:58 +00:00
|
|
|
monotony = gstate.monotony();
|
2007-04-10 20:13:15 +00:00
|
|
|
}
|
|
|
|
|
2007-04-10 21:56:11 +00:00
|
|
|
// top-level results (for aggregating multiple simulations)
|
2007-04-10 20:13:15 +00:00
|
|
|
//
|
2007-04-10 21:56:11 +00:00
|
|
|
void SIM_RESULTS::print(FILE* f, const char* title) {
|
|
|
|
if (title) {
|
2007-05-04 23:05:17 +00:00
|
|
|
fprintf(f, "%s: ", title);
|
2007-04-10 21:56:11 +00:00
|
|
|
}
|
2007-07-12 19:52:58 +00:00
|
|
|
fprintf(f, "wasted_frac %f idle_frac %f share_violation %f monotony %f\n",
|
|
|
|
cpu_wasted_frac, cpu_idle_frac, share_violation, monotony
|
2007-04-10 20:13:15 +00:00
|
|
|
);
|
|
|
|
}
|
2007-04-10 21:56:11 +00:00
|
|
|
|
2007-04-10 20:13:15 +00:00
|
|
|
void SIM_RESULTS::parse(FILE* f) {
|
2007-07-12 19:52:58 +00:00
|
|
|
fscanf(f, "wasted_frac %lf idle_frac %lf share_violation %lf monotony %lf",
|
|
|
|
&cpu_wasted_frac, &cpu_idle_frac, &share_violation, &monotony
|
2007-04-10 20:13:15 +00:00
|
|
|
);
|
|
|
|
}
|
2007-05-04 23:05:17 +00:00
|
|
|
|
2007-04-10 20:13:15 +00:00
|
|
|
void SIM_RESULTS::add(SIM_RESULTS& r) {
|
2007-05-04 23:05:17 +00:00
|
|
|
cpu_wasted_frac += r.cpu_wasted_frac;
|
|
|
|
cpu_idle_frac += r.cpu_idle_frac;
|
|
|
|
share_violation += r.share_violation;
|
2007-07-12 19:52:58 +00:00
|
|
|
monotony += r.monotony;
|
2007-04-10 20:13:15 +00:00
|
|
|
}
|
|
|
|
|
2007-05-04 23:05:17 +00:00
|
|
|
void SIM_RESULTS::divide(int n) {
|
|
|
|
cpu_wasted_frac /= n;
|
|
|
|
cpu_idle_frac /= n;
|
|
|
|
share_violation /= n;
|
2007-07-12 19:52:58 +00:00
|
|
|
monotony /= n;
|
2007-05-04 23:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SIM_RESULTS::clear() {
|
|
|
|
memset(this, 0, sizeof(*this));
|
2007-04-10 20:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SIM_PROJECT::print_results(FILE* f, SIM_RESULTS& sr) {
|
|
|
|
double t = project_results.cpu_used + project_results.cpu_wasted;
|
|
|
|
double gt = sr.cpu_used + sr.cpu_wasted;
|
|
|
|
fprintf(f, "%s: share %.2f total CPU %2f (%.2f%%)\n"
|
|
|
|
" used %.2f wasted %.2f\n"
|
|
|
|
" met %d missed %d\n",
|
|
|
|
project_name, resource_share,
|
|
|
|
t, (t/gt)*100,
|
|
|
|
project_results.cpu_used,
|
|
|
|
project_results.cpu_wasted,
|
|
|
|
project_results.nresults_met_deadline,
|
|
|
|
project_results.nresults_missed_deadline
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-04-04 19:34:01 +00:00
|
|
|
char* colors[] = {
|
|
|
|
"#ffffdd",
|
|
|
|
"#ffddff",
|
|
|
|
"#ddffff",
|
|
|
|
"#ddffdd",
|
|
|
|
"#ddddff",
|
|
|
|
"#ffdddd",
|
|
|
|
};
|
|
|
|
|
2007-07-12 18:38:53 +00:00
|
|
|
static int outfile_num=0;
|
|
|
|
|
|
|
|
void CLIENT_STATE::html_start(bool show_prev) {
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
sprintf(buf, "sim_out_%d.html", outfile_num++);
|
|
|
|
html_out = fopen(buf, "w");
|
2007-05-08 01:55:28 +00:00
|
|
|
setbuf(html_out, 0);
|
2007-07-12 18:38:53 +00:00
|
|
|
fprintf(html_out, "<h2>Simulator output</h2>\n");
|
|
|
|
if (show_prev) {
|
|
|
|
fprintf(html_out,
|
|
|
|
"<a href=sim_out_%d.html>Previous file</a><p>\n",
|
|
|
|
outfile_num-2
|
|
|
|
);
|
|
|
|
}
|
|
|
|
fprintf(html_out,
|
2007-04-06 19:47:37 +00:00
|
|
|
"<a href=sim_log.txt>message log</a><p>"
|
2007-07-18 23:26:49 +00:00
|
|
|
"<table border=1><tr><th>Time</th>\n"
|
2007-04-04 21:12:00 +00:00
|
|
|
);
|
2007-07-18 23:26:49 +00:00
|
|
|
for (int i=0; i<ncpus; i++) {
|
|
|
|
fprintf(html_out,
|
|
|
|
"<th>CPU %d<br><font size=-2>Job name and estimated time left<br>color denotes project<br>* means EDF mode</font></th>", i
|
|
|
|
);
|
|
|
|
}
|
|
|
|
fprintf(html_out, "<th>Notes</th></tr>\n");
|
2007-04-04 15:40:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLIENT_STATE::html_rec() {
|
2007-07-12 18:38:53 +00:00
|
|
|
static int line_num=0;
|
|
|
|
|
2007-04-04 16:15:18 +00:00
|
|
|
fprintf(html_out, "<tr><td>%s</td>", time_to_string(now));
|
2007-04-09 02:17:26 +00:00
|
|
|
|
|
|
|
if (!running) {
|
|
|
|
for (int j=0; j<ncpus; j++) {
|
2007-05-03 21:22:24 +00:00
|
|
|
fprintf(html_out, "<td bgcolor=#aaaaaa>OFF</td>");
|
2007-04-09 02:17:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int n=0;
|
|
|
|
for (unsigned int i=0; i<active_tasks.active_tasks.size(); i++) {
|
|
|
|
ACTIVE_TASK* atp = active_tasks.active_tasks[i];
|
|
|
|
if (atp->task_state() == PROCESS_EXECUTING) {
|
|
|
|
SIM_PROJECT* p = (SIM_PROJECT*)atp->result->project;
|
2007-05-03 21:22:24 +00:00
|
|
|
fprintf(html_out, "<td bgcolor=%s>%s%s: %.2f</td>",
|
|
|
|
colors[p->index],
|
|
|
|
atp->result->rr_sim_misses_deadline?"*":"",
|
|
|
|
atp->result->name, atp->cpu_time_left
|
|
|
|
);
|
2007-04-09 02:17:26 +00:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (n<ncpus) {
|
2007-05-03 21:22:24 +00:00
|
|
|
fprintf(html_out, "<td>IDLE</td>");
|
2007-04-04 21:12:00 +00:00
|
|
|
n++;
|
2007-04-04 15:40:07 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-04 19:34:01 +00:00
|
|
|
fprintf(html_out, "<td><font size=-2>%s</font></td></tr>\n", html_msg.c_str());
|
2007-04-04 15:40:07 +00:00
|
|
|
html_msg = "";
|
2007-07-12 18:38:53 +00:00
|
|
|
|
|
|
|
if (++line_num == line_limit) {
|
|
|
|
line_num = 0;
|
|
|
|
html_end(true);
|
|
|
|
html_start(true);
|
|
|
|
}
|
2007-04-04 15:40:07 +00:00
|
|
|
}
|
|
|
|
|
2007-07-12 18:38:53 +00:00
|
|
|
void CLIENT_STATE::html_end(bool show_next) {
|
|
|
|
fprintf(html_out, "</table>");
|
|
|
|
if (show_next) {
|
|
|
|
fprintf(html_out,
|
|
|
|
"<p><a href=sim_out_%d.html>Next file</a>\n",
|
|
|
|
outfile_num
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
fprintf(html_out, "<pre>\n");
|
|
|
|
sim_results.compute();
|
|
|
|
sim_results.print(html_out);
|
|
|
|
print_project_results(html_out);
|
|
|
|
fprintf(html_out, "</pre>\n");
|
|
|
|
}
|
|
|
|
if (show_next) {
|
|
|
|
fprintf(html_out, "<p><a href=sim_out_last.html>Last file</a>\n");
|
|
|
|
} else {
|
|
|
|
char buf[256];
|
|
|
|
sprintf(buf, "sim_out_%d.html", outfile_num-1);
|
2007-07-14 20:04:47 +00:00
|
|
|
#ifndef _WIN32
|
2007-07-12 18:38:53 +00:00
|
|
|
symlink(buf, "sim_out_last.html");
|
2007-07-14 20:04:47 +00:00
|
|
|
#endif
|
2007-07-12 18:38:53 +00:00
|
|
|
}
|
2007-04-04 16:15:18 +00:00
|
|
|
fclose(html_out);
|
2007-04-04 15:40:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-06 19:47:37 +00:00
|
|
|
void CLIENT_STATE::simulate() {
|
2007-02-23 17:29:19 +00:00
|
|
|
bool action;
|
|
|
|
now = 0;
|
2007-07-12 18:38:53 +00:00
|
|
|
html_start(false);
|
2007-02-23 17:29:19 +00:00
|
|
|
while (1) {
|
2007-04-09 02:17:26 +00:00
|
|
|
running = host_info.available.sample(now);
|
2007-02-23 17:29:19 +00:00
|
|
|
while (1) {
|
|
|
|
action = active_tasks.poll();
|
2007-04-09 02:17:26 +00:00
|
|
|
if (running) {
|
|
|
|
action |= handle_finished_apps();
|
|
|
|
action |= possibly_schedule_cpus();
|
|
|
|
action |= enforce_schedule();
|
|
|
|
action |= compute_work_requests();
|
|
|
|
action |= scheduler_rpc_poll();
|
|
|
|
}
|
2007-02-23 17:29:19 +00:00
|
|
|
if (!action) break;
|
|
|
|
}
|
2007-04-03 19:06:26 +00:00
|
|
|
now += delta;
|
2007-04-04 15:40:07 +00:00
|
|
|
html_rec();
|
2007-02-23 17:29:19 +00:00
|
|
|
if (now > duration) break;
|
|
|
|
}
|
2007-07-12 18:38:53 +00:00
|
|
|
html_end(false);
|
2007-02-23 17:29:19 +00:00
|
|
|
}
|
2007-02-15 21:11:05 +00:00
|
|
|
|
2007-04-04 19:34:01 +00:00
|
|
|
void parse_error(char* file, int retval) {
|
|
|
|
printf("can't parse %s: %d\n", file, retval);
|
2007-04-03 17:16:39 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2007-04-03 19:06:26 +00:00
|
|
|
void help(char* prog) {
|
2007-05-08 23:12:40 +00:00
|
|
|
fprintf(stderr, "usage: %s\n"
|
|
|
|
"[--duration X]\n"
|
|
|
|
"[--delta X]\n"
|
|
|
|
"[--server_uses_workload]\n"
|
|
|
|
"[--dirs ...]\n",
|
|
|
|
prog
|
|
|
|
);
|
2007-04-03 19:06:26 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
char* next_arg(int argc, char** argv, int& i) {
|
|
|
|
if (i >= argc) {
|
|
|
|
fprintf(stderr, "Missing command-line argument\n");
|
|
|
|
help(argv[0]);
|
|
|
|
}
|
|
|
|
return argv[i++];
|
|
|
|
}
|
|
|
|
|
2007-04-06 19:47:37 +00:00
|
|
|
#define PROJECTS_FILE "sim_projects.xml"
|
|
|
|
#define HOST_FILE "sim_host.xml"
|
|
|
|
#define PREFS_FILE "sim_prefs.xml"
|
|
|
|
#define SUMMARY_FILE "sim_summary.txt"
|
|
|
|
#define LOG_FILE "sim_log.txt"
|
|
|
|
|
2007-02-15 21:11:05 +00:00
|
|
|
int main(int argc, char** argv) {
|
2007-04-03 19:06:26 +00:00
|
|
|
int i, retval;
|
2007-04-06 19:47:37 +00:00
|
|
|
vector<std::string> dirs;
|
2007-04-03 19:06:26 +00:00
|
|
|
|
2007-04-06 19:47:37 +00:00
|
|
|
logfile = fopen("sim_log.txt", "w");
|
2007-04-04 16:15:18 +00:00
|
|
|
|
2007-05-04 23:05:17 +00:00
|
|
|
sim_results.clear();
|
2007-04-04 21:12:00 +00:00
|
|
|
for (i=1; i<argc;) {
|
|
|
|
char* opt = argv[i++];
|
|
|
|
if (!strcmp(opt, "--duration")) {
|
|
|
|
duration = atof(next_arg(argc, argv, i));
|
|
|
|
} else if (!strcmp(opt, "--delta")) {
|
|
|
|
delta = atof(next_arg(argc, argv, i));
|
2007-04-06 19:47:37 +00:00
|
|
|
} else if (!strcmp(opt, "--dirs")) {
|
|
|
|
while (i<argc) {
|
|
|
|
dirs.push_back(argv[i++]);
|
|
|
|
}
|
2007-05-08 01:55:28 +00:00
|
|
|
} else if (!strcmp(opt, "--server_uses_workload")) {
|
|
|
|
server_uses_workload = true;
|
2007-05-09 15:23:10 +00:00
|
|
|
} else if (!strcmp(opt, "--dcf_dont_use")) {
|
|
|
|
dcf_dont_use = true;
|
|
|
|
} else if (!strcmp(opt, "--dcf_stats")) {
|
|
|
|
dcf_stats = true;
|
2007-05-15 20:29:26 +00:00
|
|
|
} else if (!strcmp(opt, "--dual_dcf")) {
|
|
|
|
dual_dcf = true;
|
|
|
|
dcf_stats = true;
|
|
|
|
} else if (!strcmp(opt, "--cpu_sched_rr_only")) {
|
|
|
|
cpu_sched_rr_only = true;
|
2007-07-11 20:13:53 +00:00
|
|
|
} else if (!strcmp(opt, "--work_fetch_old")) {
|
|
|
|
work_fetch_old = true;
|
2007-07-12 18:38:53 +00:00
|
|
|
} else if (!strcmp(opt, "--line_limit")) {
|
|
|
|
line_limit = atoi(next_arg(argc, argv, i));
|
2007-04-03 19:06:26 +00:00
|
|
|
} else {
|
|
|
|
help(argv[0]);
|
|
|
|
}
|
|
|
|
}
|
2007-02-22 16:33:37 +00:00
|
|
|
|
2007-04-04 21:12:00 +00:00
|
|
|
if (duration <= 0) {
|
|
|
|
printf("non-pos duration\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (delta <= 0) {
|
|
|
|
printf("non-pos delta\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2007-04-06 19:47:37 +00:00
|
|
|
if (dirs.size()) {
|
|
|
|
// If we need to do several simulations,
|
|
|
|
// use system() to do each one in a separate process,
|
|
|
|
// because there are lots of static variables and we need to ensure
|
|
|
|
// that they start off with the right initial values
|
|
|
|
//
|
|
|
|
unsigned int i;
|
|
|
|
SIM_RESULTS total_results;
|
2007-05-04 23:05:17 +00:00
|
|
|
total_results.clear();
|
2007-04-06 19:47:37 +00:00
|
|
|
for (i=0; i<dirs.size(); i++) {
|
|
|
|
std::string dir = dirs[i];
|
|
|
|
retval = chdir(dir.c_str());
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "can't chdir into %s: ", dir.c_str());
|
|
|
|
perror("chdir");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
char buf[256];
|
|
|
|
sprintf(
|
|
|
|
buf, "../sim --duration %f --delta %f > %s",
|
|
|
|
duration, delta, SUMMARY_FILE
|
|
|
|
);
|
2007-05-04 23:05:17 +00:00
|
|
|
retval = system(buf);
|
|
|
|
if (retval) {
|
|
|
|
printf("simulation in %s failed\n", dir.c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
2007-04-06 19:47:37 +00:00
|
|
|
FILE* f = fopen(SUMMARY_FILE, "r");
|
|
|
|
sim_results.parse(f);
|
|
|
|
fclose(f);
|
2007-04-10 21:56:11 +00:00
|
|
|
sim_results.print(stdout, dir.c_str());
|
2007-04-06 19:47:37 +00:00
|
|
|
total_results.add(sim_results);
|
|
|
|
chdir("..");
|
|
|
|
}
|
2007-05-14 19:18:45 +00:00
|
|
|
total_results.divide((int)(dirs.size()));
|
2007-04-10 21:56:11 +00:00
|
|
|
total_results.print(stdout, "Total");
|
2007-04-06 19:47:37 +00:00
|
|
|
} else {
|
|
|
|
read_config_file();
|
|
|
|
int retval;
|
|
|
|
bool flag;
|
|
|
|
|
|
|
|
retval = gstate.parse_projects(PROJECTS_FILE);
|
|
|
|
if (retval) parse_error(PROJECTS_FILE, retval);
|
|
|
|
retval = gstate.parse_host(HOST_FILE);
|
|
|
|
if (retval) parse_error(HOST_FILE, retval);
|
|
|
|
retval = gstate.global_prefs.parse_file(PREFS_FILE, "", flag);
|
|
|
|
if (retval) parse_error(PREFS_FILE, retval);
|
|
|
|
|
|
|
|
gstate.set_ncpus();
|
|
|
|
gstate.request_work_fetch("init");
|
|
|
|
gstate.simulate();
|
2007-04-10 21:56:11 +00:00
|
|
|
|
|
|
|
sim_results.compute();
|
|
|
|
|
|
|
|
// print machine-readable first
|
2007-04-06 19:47:37 +00:00
|
|
|
sim_results.print(stdout);
|
2007-04-10 21:56:11 +00:00
|
|
|
|
|
|
|
// then other
|
|
|
|
gstate.print_project_results(stdout);
|
2007-04-06 19:47:37 +00:00
|
|
|
}
|
2007-02-15 21:11:05 +00:00
|
|
|
}
|