result;
if (!uses_coproc(rp, cp)) continue;
if (atp->task_state() != PROCESS_EXECUTING) continue;
if (!using_instance(rp, j)) continue;
SIM_PROJECT* p = (SIM_PROJECT*)rp->project;
fprintf(gstate.html_out, "%s%s: %.2f | ",
colors[p->index],
atp->result->rr_sim_misses_deadline?"*":"",
atp->result->name, atp->cpu_time_left
);
}
}
}
void gpu_on() {
gpu_on_aux(&gstate.host_info.coprocs.cuda);
gpu_on_aux(&gstate.host_info.coprocs.ati);
}
void CLIENT_STATE::html_start(bool show_prev) {
char buf[256];
sprintf(buf, "sim_out_%d.html", outfile_num++);
html_out = fopen(buf, "w");
if (!html_out) {
fprintf(stderr, "can't open %s for writing\n", buf);
exit(1);
}
setbuf(html_out, 0);
fprintf(html_out, "Simulator output
\n");
if (show_prev) {
fprintf(html_out,
"Previous file\n",
outfile_num-2
);
}
fprintf(html_out,
"message log
"
"
Time | \n"
);
for (int i=0; iCPU %d
Job name and estimated time left
color denotes project
* means EDF mode", i
);
}
gpu_header();
fprintf(html_out, "Notes |
\n");
}
void CLIENT_STATE::html_rec() {
static int line_num=0;
fprintf(html_out, "%s | ", time_to_string(now));
if (!running) {
for (int j=0; jOFF");
}
gpu_off();
} else {
int n=0;
for (unsigned int i=0; itask_state() == PROCESS_EXECUTING) {
SIM_PROJECT* p = (SIM_PROJECT*)atp->result->project;
fprintf(html_out, "%s%s: %.2f | ",
colors[p->index],
atp->result->rr_sim_misses_deadline?"*":"",
atp->result->name, atp->cpu_time_left
);
n++;
}
}
while (nIDLE");
n++;
}
}
fprintf(html_out,
"%s |
\n", html_msg.c_str()
);
html_msg = "";
if (++line_num == line_limit) {
line_num = 0;
html_end(true);
html_start(true);
}
}
void CLIENT_STATE::html_end(bool show_next) {
fprintf(html_out, "
");
if (show_next) {
fprintf(html_out,
"Next file\n",
outfile_num
);
} else {
fprintf(html_out, "
\n");
sim_results.compute();
sim_results.print(html_out);
print_project_results(html_out);
fprintf(html_out, "
\n");
}
if (show_next) {
fprintf(html_out, "Last file\n");
} else {
char buf[256];
sprintf(buf, "sim_out_%d.html", outfile_num-1);
#ifndef _WIN32
symlink(buf, "sim_out_last.html");
#endif
}
fclose(html_out);
}
void CLIENT_STATE::simulate() {
bool action;
double start = START_TIME;
now = start;
html_start(false);
msg_printf(0, MSG_INFO,
"starting simultion. delta %f duration %f", delta, duration
);
while (1) {
running = host_info.available.sample(now);
while (1) {
msg_printf(0, MSG_INFO, "polling");
action = active_tasks.poll();
if (running) {
action |= handle_finished_apps();
action |= possibly_schedule_cpus();
action |= enforce_schedule();
action |= scheduler_rpc_poll();
}
msg_printf(0, MSG_INFO, action?"did action":"did no action");
if (!action) break;
}
now += delta;
msg_printf(0, MSG_INFO, "took time step");
for (unsigned int i=0; itask_state() == PROCESS_EXECUTING) {
atp->elapsed_time += delta;
}
}
html_rec();
if (now > start + duration) break;
}
html_end(false);
}
void parse_error(char* file, int retval) {
printf("can't parse %s: %d\n", file, retval);
exit(1);
}
void help(char* prog) {
fprintf(stderr, "usage: %s\n"
"[--duration X]\n"
"[--delta X]\n"
"[--server_uses_workload]\n"
"[--dcf_dont_user]\n"
"[--dcf_stats]\n"
"[--dual_dcf]\n"
"[--cpu_sched_rr_only]\n"
"[--work_fetch_old]\n"
"[--dirs ...]\n",
prog
);
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++];
}
#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"
int main(int argc, char** argv) {
int i, retval;
vector dirs;
logfile = fopen("sim_log.txt", "w");
if (!logfile) {
fprintf(stderr, "Can't open sim_log.txt\n");
exit(1);
}
sim_results.clear();
for (i=1; i %s",
SIM_EXEC, duration, delta, SUMMARY_FILE
);
retval = system(buf);
if (retval) {
printf("simulation in %s failed\n", dir.c_str());
exit(1);
}
FILE* f = fopen(SUMMARY_FILE, "r");
sim_results.parse(f);
fclose(f);
sim_results.print(stdout, dir.c_str());
total_results.add(sim_results);
chdir("..");
}
total_results.divide((int)(dirs.size()));
total_results.print(stdout, "Total");
} else {
msg_printf(0, MSG_INFO, "SIMULATION START");
read_config_file(true);
config.show();
int retval;
bool flag;
retval = gstate.parse_host(HOST_FILE);
if (retval) parse_error(HOST_FILE, retval);
retval = gstate.parse_projects(PROJECTS_FILE);
if (retval) parse_error(PROJECTS_FILE, retval);
retval = gstate.global_prefs.parse_file(PREFS_FILE, "", flag);
if (retval) parse_error(PREFS_FILE, retval);
gstate.set_ncpus();
work_fetch.init();
gstate.request_work_fetch("init");
gstate.simulate();
sim_results.compute();
// print machine-readable first
sim_results.print(stdout);
// then other
gstate.print_project_results(stdout);
}
}