2006-02-08 21:05:51 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 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
|
|
|
|
|
2006-04-25 18:28:44 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
|
|
|
#endif
|
|
|
|
|
2006-02-08 21:05:51 +00:00
|
|
|
#include "client_msgs.h"
|
|
|
|
#include "client_state.h"
|
2006-06-15 23:15:27 +00:00
|
|
|
#include "util.h"
|
|
|
|
#include "log_flags.h"
|
2006-02-08 21:05:51 +00:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
#define MAX_DEBT (86400)
|
|
|
|
// maximum project debt
|
|
|
|
|
|
|
|
#define CPU_PESSIMISM_FACTOR 0.9
|
|
|
|
// assume actual CPU utilization will be this multiple
|
|
|
|
// of what we've actually measured recently
|
|
|
|
|
2006-06-19 22:20:24 +00:00
|
|
|
static bool more_preemptable(ACTIVE_TASK* t0, ACTIVE_TASK* t1) {
|
|
|
|
// returning true means t1 is more preemptable than t0,
|
2006-06-16 18:52:25 +00:00
|
|
|
// the "largest" result is at the front of a heap,
|
|
|
|
// and we want the best replacement at the front,
|
|
|
|
//
|
2006-06-19 22:20:24 +00:00
|
|
|
if (t0->result->project->deadlines_missed && !t1->result->project->deadlines_missed) return false;
|
|
|
|
if (!t0->result->project->deadlines_missed && t1->result->project->deadlines_missed) return true;
|
|
|
|
if (t0->result->project->deadlines_missed && t1->result->project->deadlines_missed) {
|
|
|
|
if (t0->result->report_deadline > t1->result->report_deadline) return true;
|
2006-06-16 18:52:25 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
2006-06-19 22:20:24 +00:00
|
|
|
double t0_episode_time = gstate.now - t0->episode_start_wall_time;
|
|
|
|
double t1_episode_time = gstate.now - t1->episode_start_wall_time;
|
|
|
|
if (t0_episode_time < t1_episode_time) return false;
|
|
|
|
if (t0_episode_time > t1_episode_time) return true;
|
|
|
|
if (t0->result->report_deadline > t1->result->report_deadline) return true;
|
2006-06-16 18:52:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-08 21:05:51 +00:00
|
|
|
// Choose a "best" runnable result for each project
|
|
|
|
//
|
|
|
|
// Values are returned in project->next_runnable_result
|
|
|
|
// (skip projects for which this is already non-NULL)
|
|
|
|
//
|
|
|
|
// Don't choose results with already_selected == true;
|
|
|
|
// mark chosen results as already_selected.
|
|
|
|
//
|
|
|
|
// The preference order:
|
|
|
|
// 1. results with active tasks that are running
|
|
|
|
// 2. results with active tasks that are preempted (but have a process)
|
|
|
|
// 3. results with active tasks that have no process
|
|
|
|
// 4. results with no active task
|
|
|
|
//
|
|
|
|
void CLIENT_STATE::assign_results_to_projects() {
|
|
|
|
unsigned int i;
|
|
|
|
RESULT* rp;
|
|
|
|
PROJECT* project;
|
|
|
|
|
|
|
|
// scan results with an ACTIVE_TASK
|
|
|
|
//
|
2006-06-15 23:15:27 +00:00
|
|
|
for (i=0; i<active_tasks.active_tasks.size(); i++) {
|
2006-02-08 21:05:51 +00:00
|
|
|
ACTIVE_TASK *atp = active_tasks.active_tasks[i];
|
|
|
|
rp = atp->result;
|
|
|
|
if (rp->already_selected) continue;
|
|
|
|
if (!rp->runnable()) continue;
|
|
|
|
project = rp->project;
|
|
|
|
if (!project->next_runnable_result) {
|
|
|
|
project->next_runnable_result = rp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// see if this task is "better" than the one currently
|
|
|
|
// selected for this project
|
|
|
|
//
|
|
|
|
ACTIVE_TASK *next_atp = lookup_active_task_by_result(
|
|
|
|
project->next_runnable_result
|
|
|
|
);
|
|
|
|
|
|
|
|
if ((next_atp->task_state == PROCESS_UNINITIALIZED && atp->process_exists())
|
|
|
|
|| (next_atp->scheduler_state == CPU_SCHED_PREEMPTED
|
|
|
|
&& atp->scheduler_state == CPU_SCHED_SCHEDULED)
|
|
|
|
) {
|
|
|
|
project->next_runnable_result = atp->result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now consider results that don't have an active task
|
|
|
|
//
|
|
|
|
for (i=0; i<results.size(); i++) {
|
|
|
|
rp = results[i];
|
|
|
|
if (rp->already_selected) continue;
|
|
|
|
if (lookup_active_task_by_result(rp)) continue;
|
|
|
|
if (!rp->runnable()) continue;
|
|
|
|
|
|
|
|
project = rp->project;
|
|
|
|
if (project->next_runnable_result) continue;
|
|
|
|
|
2006-06-16 18:52:25 +00:00
|
|
|
// don't start results if project has > 2 uploads in progress.
|
|
|
|
// This avoids creating an unbounded number of completed
|
|
|
|
// results for a project that can download and compute
|
|
|
|
// faster than it can upload.
|
2006-02-08 21:05:51 +00:00
|
|
|
//
|
|
|
|
if (project->nactive_uploads > 2) continue;
|
|
|
|
|
|
|
|
project->next_runnable_result = rp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// mark selected results, so CPU scheduler won't try to consider
|
|
|
|
// a result more than once
|
|
|
|
//
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
project = projects[i];
|
|
|
|
if (project->next_runnable_result) {
|
|
|
|
project->next_runnable_result->already_selected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-21 17:34:55 +00:00
|
|
|
// Among projects with a "next runnable result",
|
|
|
|
// find the project P with the greatest anticipated debt,
|
|
|
|
// and return its next runnable result
|
2006-02-08 21:05:51 +00:00
|
|
|
//
|
2006-06-21 17:34:55 +00:00
|
|
|
RESULT* CLIENT_STATE::largest_debt_project_best_result() {
|
2006-02-08 21:05:51 +00:00
|
|
|
PROJECT *best_project = NULL;
|
|
|
|
double best_debt = -MAX_DEBT;
|
|
|
|
bool first = true;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
PROJECT* p = projects[i];
|
|
|
|
if (!p->next_runnable_result) continue;
|
|
|
|
if (p->non_cpu_intensive) continue;
|
|
|
|
if (first || p->anticipated_debt > best_debt) {
|
|
|
|
first = false;
|
|
|
|
best_project = p;
|
|
|
|
best_debt = p->anticipated_debt;
|
|
|
|
}
|
|
|
|
}
|
2006-06-17 16:26:29 +00:00
|
|
|
if (!best_project) return NULL;
|
2006-02-08 21:05:51 +00:00
|
|
|
|
2006-06-21 22:08:20 +00:00
|
|
|
if (log_flags.cpu_sched_debug) {
|
2006-06-15 23:15:27 +00:00
|
|
|
msg_printf(best_project, MSG_INFO,
|
|
|
|
"highest debt: %f %s",
|
|
|
|
best_project->anticipated_debt,
|
|
|
|
best_project->next_runnable_result->name
|
|
|
|
);
|
|
|
|
}
|
2006-06-17 16:26:29 +00:00
|
|
|
RESULT* rp = best_project->next_runnable_result;
|
2006-02-08 21:05:51 +00:00
|
|
|
best_project->next_runnable_result = 0;
|
2006-06-17 16:26:29 +00:00
|
|
|
return rp;
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
|
|
|
|
2006-06-21 17:34:55 +00:00
|
|
|
// Return earliest-deadline result from a project with deadlines_missed>0
|
2006-02-08 21:05:51 +00:00
|
|
|
//
|
2006-06-21 17:34:55 +00:00
|
|
|
RESULT* CLIENT_STATE::earliest_deadline_result() {
|
2006-02-08 21:05:51 +00:00
|
|
|
RESULT *best_result = NULL;
|
|
|
|
unsigned int i;
|
|
|
|
|
2006-06-19 22:20:24 +00:00
|
|
|
for (i=0; i<results.size(); i++) {
|
|
|
|
RESULT* rp = results[i];
|
2006-02-08 21:05:51 +00:00
|
|
|
if (!rp->runnable()) continue;
|
|
|
|
if (rp->project->non_cpu_intensive) continue;
|
|
|
|
if (rp->already_selected) continue;
|
2006-06-19 22:20:24 +00:00
|
|
|
if (!rp->project->deadlines_missed) continue;
|
2006-06-15 23:15:27 +00:00
|
|
|
if (!best_result || rp->report_deadline < best_result->report_deadline) {
|
2006-02-08 21:05:51 +00:00
|
|
|
best_result = rp;
|
|
|
|
}
|
|
|
|
}
|
2006-06-17 16:26:29 +00:00
|
|
|
if (!best_result) return NULL;
|
2006-02-08 21:05:51 +00:00
|
|
|
|
2006-06-21 22:08:20 +00:00
|
|
|
if (log_flags.cpu_sched_debug) {
|
2006-06-15 23:15:27 +00:00
|
|
|
msg_printf(best_result->project, MSG_INFO,
|
|
|
|
"earliest deadline: %f %s",
|
|
|
|
best_result->report_deadline, best_result->name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2006-06-17 16:26:29 +00:00
|
|
|
return best_result;
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// adjust project debts (short, long-term)
|
|
|
|
//
|
|
|
|
void CLIENT_STATE::adjust_debts() {
|
|
|
|
unsigned int i;
|
|
|
|
double total_long_term_debt = 0;
|
|
|
|
double total_short_term_debt = 0;
|
|
|
|
double prrs, rrs;
|
|
|
|
int nprojects=0, nrprojects=0;
|
|
|
|
PROJECT *p;
|
|
|
|
double share_frac;
|
|
|
|
double wall_cpu_time = gstate.now - cpu_sched_last_time;
|
|
|
|
|
|
|
|
// Total up total and per-project "wall CPU" since last CPU reschedule.
|
|
|
|
// "Wall CPU" is the wall time during which a task was
|
|
|
|
// runnable (at the OS level).
|
|
|
|
//
|
|
|
|
// We use wall CPU for debt calculation
|
|
|
|
// (instead of reported actual CPU) for two reasons:
|
|
|
|
// 1) the process might have paged a lot, so the actual CPU
|
|
|
|
// may be a lot less than wall CPU
|
|
|
|
// 2) BOINC relies on apps to report their CPU time.
|
|
|
|
// Sometimes there are bugs and apps report zero CPU.
|
|
|
|
// It's safer not to trust them.
|
|
|
|
//
|
|
|
|
for (i=0; i<active_tasks.active_tasks.size(); i++) {
|
|
|
|
ACTIVE_TASK* atp = active_tasks.active_tasks[i];
|
|
|
|
if (atp->scheduler_state != CPU_SCHED_SCHEDULED) continue;
|
2006-06-26 17:09:23 +00:00
|
|
|
if (atp->wup->project->non_cpu_intensive) continue;
|
2006-02-08 21:05:51 +00:00
|
|
|
|
|
|
|
atp->result->project->wall_cpu_time_this_period += wall_cpu_time;
|
|
|
|
total_wall_cpu_time_this_period += wall_cpu_time;
|
|
|
|
total_cpu_time_this_period += atp->current_cpu_time - atp->cpu_time_at_last_sched;
|
|
|
|
}
|
|
|
|
|
|
|
|
time_stats.update_cpu_efficiency(
|
|
|
|
total_wall_cpu_time_this_period, total_cpu_time_this_period
|
|
|
|
);
|
|
|
|
|
|
|
|
rrs = runnable_resource_share();
|
|
|
|
prrs = potentially_runnable_resource_share();
|
|
|
|
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
2006-06-15 23:15:27 +00:00
|
|
|
|
2006-02-08 21:05:51 +00:00
|
|
|
// potentially_runnable() can be false right after a result completes,
|
|
|
|
// but we still need to update its LTD.
|
|
|
|
// In this case its wall_cpu_time_this_period will be nonzero.
|
|
|
|
//
|
2006-06-15 23:15:27 +00:00
|
|
|
if (!(p->potentially_runnable()) && p->wall_cpu_time_this_period) {
|
2006-02-08 21:05:51 +00:00
|
|
|
prrs += p->resource_share;
|
2006-06-15 23:15:27 +00:00
|
|
|
}
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
|
|
|
if (p->non_cpu_intensive) continue;
|
|
|
|
nprojects++;
|
|
|
|
|
|
|
|
// adjust long-term debts
|
|
|
|
//
|
|
|
|
if (p->potentially_runnable() || p->wall_cpu_time_this_period) {
|
|
|
|
share_frac = p->resource_share/prrs;
|
|
|
|
p->long_term_debt += share_frac*total_wall_cpu_time_this_period
|
|
|
|
- p->wall_cpu_time_this_period;
|
|
|
|
}
|
|
|
|
total_long_term_debt += p->long_term_debt;
|
|
|
|
|
|
|
|
// adjust short term debts
|
|
|
|
//
|
|
|
|
if (p->runnable()) {
|
|
|
|
nrprojects++;
|
|
|
|
share_frac = p->resource_share/rrs;
|
|
|
|
p->short_term_debt += share_frac*total_wall_cpu_time_this_period
|
2006-06-15 23:15:27 +00:00
|
|
|
- p->wall_cpu_time_this_period;
|
2006-02-08 21:05:51 +00:00
|
|
|
total_short_term_debt += p->short_term_debt;
|
|
|
|
} else {
|
|
|
|
p->short_term_debt = 0;
|
|
|
|
p->anticipated_debt = 0;
|
|
|
|
}
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.debt_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"adjust_debts(): project %s: short-term debt %f",
|
|
|
|
p->project_name, p->short_term_debt
|
|
|
|
);
|
|
|
|
}
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nprojects==0) return;
|
|
|
|
|
|
|
|
// long-term debt:
|
|
|
|
// normalize so mean is zero,
|
|
|
|
// short-term debt:
|
|
|
|
// normalize so mean is zero, and limit abs value at MAX_DEBT
|
|
|
|
//
|
|
|
|
double avg_long_term_debt = total_long_term_debt / nprojects;
|
|
|
|
double avg_short_term_debt = 0;
|
|
|
|
if (nrprojects) {
|
|
|
|
avg_short_term_debt = total_short_term_debt / nrprojects;
|
|
|
|
}
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
|
|
|
if (p->non_cpu_intensive) continue;
|
|
|
|
if (p->runnable()) {
|
|
|
|
p->short_term_debt -= avg_short_term_debt;
|
|
|
|
if (p->short_term_debt > MAX_DEBT) {
|
|
|
|
p->short_term_debt = MAX_DEBT;
|
|
|
|
}
|
|
|
|
if (p->short_term_debt < -MAX_DEBT) {
|
|
|
|
p->short_term_debt = -MAX_DEBT;
|
|
|
|
}
|
|
|
|
//msg_printf(p, MSG_INFO, "debt %f", p->short_term_debt);
|
|
|
|
}
|
|
|
|
|
|
|
|
p->long_term_debt -= avg_long_term_debt;
|
|
|
|
}
|
2006-06-15 23:15:27 +00:00
|
|
|
|
|
|
|
// reset work accounting
|
|
|
|
//
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
|
|
|
p->wall_cpu_time_this_period = 0.0;
|
|
|
|
}
|
2006-06-17 16:26:29 +00:00
|
|
|
for (i = 0; i < active_tasks.active_tasks.size(); ++i) {
|
|
|
|
ACTIVE_TASK* atp = active_tasks.active_tasks[i];
|
|
|
|
atp->cpu_time_at_last_sched = atp->current_cpu_time;
|
|
|
|
}
|
2006-06-15 23:15:27 +00:00
|
|
|
total_wall_cpu_time_this_period = 0.0;
|
|
|
|
total_cpu_time_this_period = 0.0;
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-16 18:52:25 +00:00
|
|
|
// Decide whether to run the CPU scheduler.
|
|
|
|
// This is called periodically.
|
2006-06-17 16:26:29 +00:00
|
|
|
// Scheduled tasks are placed in order of urgency for scheduling in the ordered_scheduled_results vector
|
2006-02-08 21:05:51 +00:00
|
|
|
//
|
2006-06-16 18:52:25 +00:00
|
|
|
bool CLIENT_STATE::possibly_schedule_cpus() {
|
2006-02-08 21:05:51 +00:00
|
|
|
double elapsed_time;
|
2006-06-19 16:21:35 +00:00
|
|
|
static double last_reschedule=0;
|
2006-06-15 23:15:27 +00:00
|
|
|
|
2006-02-08 21:05:51 +00:00
|
|
|
if (projects.size() == 0) return false;
|
|
|
|
if (results.size() == 0) return false;
|
|
|
|
|
|
|
|
// Reschedule every cpu_sched_period seconds,
|
|
|
|
// or if must_schedule_cpus is set
|
|
|
|
// (meaning a new result is available, or a CPU has been freed).
|
|
|
|
//
|
2006-06-19 16:21:35 +00:00
|
|
|
elapsed_time = gstate.now - last_reschedule;
|
2006-06-15 23:15:27 +00:00
|
|
|
if (elapsed_time >= gstate.global_prefs.cpu_scheduling_period_minutes * 60) {
|
2006-06-19 16:21:35 +00:00
|
|
|
request_schedule_cpus("Scheduling period elapsed.");
|
2006-06-15 23:15:27 +00:00
|
|
|
}
|
2006-02-08 21:05:51 +00:00
|
|
|
|
2006-06-15 23:15:27 +00:00
|
|
|
if (!must_schedule_cpus) return false;
|
2006-06-19 16:21:35 +00:00
|
|
|
last_reschedule = now;
|
2006-06-15 23:15:27 +00:00
|
|
|
must_schedule_cpus = false;
|
2006-06-16 18:52:25 +00:00
|
|
|
schedule_cpus();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-06-21 17:34:55 +00:00
|
|
|
void CLIENT_STATE::print_deadline_misses() {
|
|
|
|
unsigned int i;
|
|
|
|
RESULT* rp;
|
|
|
|
PROJECT* p;
|
|
|
|
for (i=0; i<results.size(); i++){
|
|
|
|
rp = results[i];
|
|
|
|
if (rp->rr_sim_misses_deadline && !rp->last_rr_sim_missed_deadline) {
|
|
|
|
msg_printf(rp->project, MSG_INFO,
|
2006-06-23 20:05:12 +00:00
|
|
|
"Result %s projected to miss deadline.", rp->name
|
2006-06-21 17:34:55 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (!rp->rr_sim_misses_deadline && rp->last_rr_sim_missed_deadline) {
|
|
|
|
msg_printf(rp->project, MSG_INFO,
|
2006-06-23 20:05:12 +00:00
|
|
|
"Result %s projected to meet deadline.", rp->name
|
2006-06-21 17:34:55 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
|
|
|
if (p->rr_sim_deadlines_missed) {
|
|
|
|
msg_printf(p, MSG_INFO,
|
2006-06-23 20:05:12 +00:00
|
|
|
"Project has %d projected deadline misses",
|
2006-06-21 17:34:55 +00:00
|
|
|
p->rr_sim_deadlines_missed
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-16 18:52:25 +00:00
|
|
|
// CPU scheduler - decide which results to run.
|
2006-06-21 17:34:55 +00:00
|
|
|
// output: sets ordered_scheduled_result.
|
2006-06-16 18:52:25 +00:00
|
|
|
//
|
|
|
|
void CLIENT_STATE::schedule_cpus() {
|
|
|
|
RESULT* rp;
|
|
|
|
PROJECT* p;
|
|
|
|
double expected_pay_off;
|
|
|
|
unsigned int i;
|
2006-06-21 17:34:55 +00:00
|
|
|
double rrs = runnable_resource_share();
|
2006-06-15 23:15:27 +00:00
|
|
|
|
2006-06-21 17:34:55 +00:00
|
|
|
// do round-robin simulation to find what results miss deadline,
|
2006-06-15 23:15:27 +00:00
|
|
|
//
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.cpu_sched_debug) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"rr_simulation: calling from cpu_scheduler"
|
|
|
|
);
|
|
|
|
}
|
2006-06-16 18:52:25 +00:00
|
|
|
rr_simulation(avg_proc_rate()/ncpus, runnable_resource_share());
|
2006-06-21 22:08:20 +00:00
|
|
|
if (log_flags.cpu_sched_debug) {
|
2006-06-21 17:34:55 +00:00
|
|
|
print_deadline_misses();
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 23:15:27 +00:00
|
|
|
// set temporary variables
|
2006-02-08 21:05:51 +00:00
|
|
|
//
|
2006-06-15 23:15:27 +00:00
|
|
|
for (i=0; i<results.size(); i++) {
|
2006-06-16 18:52:25 +00:00
|
|
|
rp = results[i];
|
|
|
|
rp->already_selected = false;
|
2006-06-15 23:15:27 +00:00
|
|
|
}
|
2006-02-08 21:05:51 +00:00
|
|
|
for (i=0; i<projects.size(); i++) {
|
2006-06-16 18:52:25 +00:00
|
|
|
p = projects[i];
|
|
|
|
p->next_runnable_result = NULL;
|
|
|
|
p->nactive_uploads = 0;
|
|
|
|
p->anticipated_debt = p->short_term_debt;
|
2006-06-19 22:20:24 +00:00
|
|
|
p->deadlines_missed = p->rr_sim_deadlines_missed;
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
|
|
|
for (i=0; i<file_xfers->file_xfers.size(); i++) {
|
|
|
|
FILE_XFER* fxp = file_xfers->file_xfers[i];
|
|
|
|
if (fxp->is_upload) {
|
|
|
|
fxp->fip->project->nactive_uploads++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-21 17:34:55 +00:00
|
|
|
// adjust long and short term debts
|
2006-06-15 23:15:27 +00:00
|
|
|
// based on the work done during the last period
|
|
|
|
//
|
2006-02-08 21:05:51 +00:00
|
|
|
adjust_debts();
|
|
|
|
|
2006-06-15 23:15:27 +00:00
|
|
|
cpu_sched_last_time = gstate.now;
|
|
|
|
expected_pay_off = gstate.global_prefs.cpu_scheduling_period_minutes * 60;
|
|
|
|
ordered_scheduled_results.clear();
|
2006-06-17 16:26:29 +00:00
|
|
|
|
2006-06-21 17:34:55 +00:00
|
|
|
// First choose results from projects with P.deadlines_missed>0
|
|
|
|
//
|
2006-06-15 23:15:27 +00:00
|
|
|
while ((int)ordered_scheduled_results.size() < ncpus) {
|
2006-06-21 17:34:55 +00:00
|
|
|
rp = earliest_deadline_result();
|
2006-06-17 16:26:29 +00:00
|
|
|
if (!rp) break;
|
|
|
|
|
2006-06-21 17:34:55 +00:00
|
|
|
// If such an R exists, decrement P.deadlines_missed
|
2006-06-19 16:21:35 +00:00
|
|
|
//
|
2006-06-21 17:34:55 +00:00
|
|
|
rp->already_selected = true;
|
|
|
|
rp->project->anticipated_debt -= (1 - rp->project->resource_share / rrs) * expected_pay_off;
|
2006-06-19 22:20:24 +00:00
|
|
|
rp->project->deadlines_missed--;
|
2006-06-17 16:26:29 +00:00
|
|
|
ordered_scheduled_results.push_back(rp);
|
2006-06-19 16:21:35 +00:00
|
|
|
}
|
2006-06-15 23:15:27 +00:00
|
|
|
|
2006-06-21 17:34:55 +00:00
|
|
|
// Next, choose results from projects with large debt
|
2006-06-19 22:20:24 +00:00
|
|
|
//
|
2006-06-15 23:15:27 +00:00
|
|
|
while ((int)ordered_scheduled_results.size() < ncpus) {
|
|
|
|
assign_results_to_projects();
|
2006-06-21 17:34:55 +00:00
|
|
|
rp = largest_debt_project_best_result();
|
2006-06-17 16:26:29 +00:00
|
|
|
if (!rp) break;
|
2006-06-21 17:34:55 +00:00
|
|
|
rp->project->anticipated_debt -= (1 - rp->project->resource_share / rrs) * expected_pay_off;
|
2006-06-17 16:26:29 +00:00
|
|
|
ordered_scheduled_results.push_back(rp);
|
2006-06-19 16:21:35 +00:00
|
|
|
}
|
2006-06-15 23:15:27 +00:00
|
|
|
|
2006-06-23 20:05:12 +00:00
|
|
|
request_enforce_schedule("schedule_cpus");
|
2006-06-15 23:15:27 +00:00
|
|
|
set_client_state_dirty("schedule_cpus");
|
|
|
|
}
|
|
|
|
|
2006-06-21 17:34:55 +00:00
|
|
|
// make a list of preemptable tasks, ordered by their preemptability.
|
2006-06-19 22:20:24 +00:00
|
|
|
//
|
|
|
|
void CLIENT_STATE::make_running_task_heap(
|
2006-06-21 17:34:55 +00:00
|
|
|
vector<ACTIVE_TASK*> &running_tasks
|
2006-06-19 22:20:24 +00:00
|
|
|
) {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks.active_tasks[i];
|
|
|
|
if (atp->result->project->non_cpu_intensive) continue;
|
2006-06-21 17:34:55 +00:00
|
|
|
if (atp->next_scheduler_state == CPU_SCHED_PREEMPTED) continue;
|
|
|
|
if (atp->scheduler_state != CPU_SCHED_SCHEDULED) continue;
|
|
|
|
running_tasks.push_back(atp);
|
2006-06-19 22:20:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::make_heap(
|
2006-06-21 17:34:55 +00:00
|
|
|
running_tasks.begin(),
|
|
|
|
running_tasks.end(),
|
2006-06-19 22:20:24 +00:00
|
|
|
more_preemptable
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enforce the CPU schedule.
|
2006-06-21 17:34:55 +00:00
|
|
|
// Inputs:
|
|
|
|
// ordered_scheduled_results
|
|
|
|
// List of tasks that should (ideally) run, set by schedule_cpus().
|
|
|
|
// Most important tasks (e.g. early deadline) are first
|
|
|
|
// Method:
|
|
|
|
// Make a list "running_tasks" of currently running tasks
|
|
|
|
// Most preemptable tasks are first in list.
|
|
|
|
// Details:
|
|
|
|
// Initially, each task's scheduler_state is PREEMPTED or SCHEDULED
|
|
|
|
// depending on whether or not it is running.
|
|
|
|
// This function sets each task's next_scheduler_state,
|
|
|
|
// and at the end it starts/resumes and preempts tasks
|
|
|
|
// based on scheduler_state and next_scheduler_state.
|
2006-06-17 16:26:29 +00:00
|
|
|
//
|
2006-06-15 23:15:27 +00:00
|
|
|
bool CLIENT_STATE::enforce_schedule() {
|
2006-06-16 18:52:25 +00:00
|
|
|
unsigned int i;
|
2006-06-19 22:20:24 +00:00
|
|
|
ACTIVE_TASK* atp;
|
2006-06-21 17:34:55 +00:00
|
|
|
vector<ACTIVE_TASK*> running_tasks;
|
2006-06-15 23:15:27 +00:00
|
|
|
|
2006-06-17 16:26:29 +00:00
|
|
|
// Don't do this once per second.
|
2006-06-19 22:20:24 +00:00
|
|
|
//
|
|
|
|
if (!must_enforce_cpu_schedule) return false;
|
2006-06-15 23:15:27 +00:00
|
|
|
must_enforce_cpu_schedule = false;
|
2006-06-16 18:52:25 +00:00
|
|
|
bool action = false;
|
2006-06-15 23:15:27 +00:00
|
|
|
|
2006-06-23 22:25:08 +00:00
|
|
|
if (log_flags.cpu_sched) {
|
2006-06-15 23:15:27 +00:00
|
|
|
msg_printf(0, MSG_INFO, "Enforcing schedule");
|
|
|
|
}
|
|
|
|
|
|
|
|
// set temporary variables
|
2006-06-16 18:52:25 +00:00
|
|
|
//
|
2006-06-15 23:15:27 +00:00
|
|
|
for (i=0; i<projects.size(); i++){
|
2006-06-19 22:20:24 +00:00
|
|
|
projects[i]->deadlines_missed = projects[i]->rr_sim_deadlines_missed;
|
2006-06-15 23:15:27 +00:00
|
|
|
}
|
|
|
|
for (i=0; i< active_tasks.active_tasks.size(); i++) {
|
2006-06-19 22:20:24 +00:00
|
|
|
atp = active_tasks.active_tasks[i];
|
2006-06-21 17:34:55 +00:00
|
|
|
if (atp->result->runnable()) {
|
|
|
|
atp->next_scheduler_state = atp->scheduler_state;
|
|
|
|
} else {
|
|
|
|
atp->next_scheduler_state = CPU_SCHED_PREEMPTED;
|
|
|
|
}
|
2006-06-15 23:15:27 +00:00
|
|
|
}
|
|
|
|
|
2006-06-21 17:34:55 +00:00
|
|
|
// make list of preemptable tasks
|
|
|
|
//
|
|
|
|
make_running_task_heap(running_tasks);
|
2006-06-19 22:20:24 +00:00
|
|
|
|
|
|
|
// if there are more running tasks than ncpus,
|
|
|
|
// then mark the extras for preemption
|
|
|
|
//
|
2006-06-21 17:34:55 +00:00
|
|
|
while (running_tasks.size() > (unsigned int)ncpus) {
|
|
|
|
running_tasks[0]->next_scheduler_state = CPU_SCHED_PREEMPTED;
|
2006-06-15 23:15:27 +00:00
|
|
|
std::pop_heap(
|
2006-06-21 17:34:55 +00:00
|
|
|
running_tasks.begin(),
|
|
|
|
running_tasks.end(),
|
2006-06-19 22:20:24 +00:00
|
|
|
more_preemptable
|
2006-06-15 23:15:27 +00:00
|
|
|
);
|
2006-06-21 17:34:55 +00:00
|
|
|
running_tasks.pop_back();
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
|
|
|
|
2006-06-21 17:34:55 +00:00
|
|
|
// count of how many tasks have next_scheduler_state = SCHEDULED
|
|
|
|
//
|
|
|
|
int nrunning = running_tasks.size();
|
|
|
|
|
2006-06-19 22:20:24 +00:00
|
|
|
// Loop through the scheduled results
|
|
|
|
// to see if they should preempt something
|
|
|
|
//
|
2006-06-15 23:15:27 +00:00
|
|
|
for (i=0; i<ordered_scheduled_results.size(); i++) {
|
2006-06-19 22:20:24 +00:00
|
|
|
RESULT* rp = ordered_scheduled_results[i];
|
|
|
|
|
|
|
|
// See if the result is already running.
|
|
|
|
//
|
|
|
|
atp = NULL;
|
2006-06-21 17:34:55 +00:00
|
|
|
for (vector<ACTIVE_TASK*>::iterator it = running_tasks.begin(); it != running_tasks.end(); it++) {
|
2006-06-15 23:15:27 +00:00
|
|
|
ACTIVE_TASK *atp1 = *it;
|
|
|
|
if (atp1 && atp1->result == rp) {
|
2006-06-19 22:20:24 +00:00
|
|
|
// The task is already running; remove it from the heap
|
|
|
|
//
|
2006-06-15 23:15:27 +00:00
|
|
|
atp = atp1;
|
2006-06-21 17:34:55 +00:00
|
|
|
running_tasks.erase(it);
|
2006-06-16 18:52:25 +00:00
|
|
|
std::make_heap(
|
2006-06-21 17:34:55 +00:00
|
|
|
running_tasks.begin(),
|
|
|
|
running_tasks.end(),
|
2006-06-19 22:20:24 +00:00
|
|
|
more_preemptable
|
2006-06-16 18:52:25 +00:00
|
|
|
);
|
2006-06-15 23:15:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-06-19 22:20:24 +00:00
|
|
|
if (atp) continue; // the scheduled result is already running.
|
|
|
|
|
|
|
|
// The scheduled result is not already running.
|
|
|
|
// Preempt something if needed and possible.
|
|
|
|
//
|
|
|
|
bool run_task = false;
|
2006-06-21 17:34:55 +00:00
|
|
|
bool need_to_preempt = (nrunning==ncpus) && running_tasks.size();
|
|
|
|
// the 2nd half of the above is redundant
|
|
|
|
if (need_to_preempt) {
|
|
|
|
atp = running_tasks[0];
|
2006-06-19 22:20:24 +00:00
|
|
|
bool running_beyond_sched_period =
|
|
|
|
gstate.now - atp->episode_start_wall_time
|
|
|
|
> gstate.global_prefs.cpu_scheduling_period_minutes;
|
|
|
|
bool checkpointed_recently =
|
|
|
|
atp->checkpoint_wall_time > atp->episode_start_wall_time;
|
|
|
|
if (rp->project->deadlines_missed
|
|
|
|
|| (running_beyond_sched_period && checkpointed_recently)
|
|
|
|
) {
|
|
|
|
// only deadlines_missed results from a project
|
|
|
|
// will qualify for immediate enforcement.
|
|
|
|
//
|
|
|
|
if (rp->project->deadlines_missed) {
|
|
|
|
rp->project->deadlines_missed--;
|
|
|
|
}
|
|
|
|
atp->next_scheduler_state = CPU_SCHED_PREEMPTED;
|
2006-06-21 17:34:55 +00:00
|
|
|
nrunning--;
|
2006-06-19 22:20:24 +00:00
|
|
|
std::pop_heap(
|
2006-06-21 17:34:55 +00:00
|
|
|
running_tasks.begin(),
|
|
|
|
running_tasks.end(),
|
2006-06-19 22:20:24 +00:00
|
|
|
more_preemptable
|
|
|
|
);
|
2006-06-21 17:34:55 +00:00
|
|
|
running_tasks.pop_back();
|
2006-06-19 22:20:24 +00:00
|
|
|
run_task = true;
|
2006-06-15 23:15:27 +00:00
|
|
|
}
|
2006-06-19 22:20:24 +00:00
|
|
|
} else {
|
|
|
|
run_task = true;
|
|
|
|
}
|
|
|
|
if (run_task) {
|
2006-06-15 23:15:27 +00:00
|
|
|
schedule_result(rp);
|
2006-06-21 17:34:55 +00:00
|
|
|
nrunning++;
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// schedule new non CPU intensive tasks
|
|
|
|
//
|
|
|
|
for (i=0; i<results.size(); i++) {
|
|
|
|
RESULT* rp = results[i];
|
|
|
|
if (rp->project->non_cpu_intensive && rp->runnable()) {
|
|
|
|
schedule_result(rp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-15 23:15:27 +00:00
|
|
|
double vm_limit = (global_prefs.vm_max_used_pct/100.0)*host_info.m_swap;
|
2006-02-08 21:05:51 +00:00
|
|
|
|
2006-06-19 22:20:24 +00:00
|
|
|
// preempt and start tasks as needed
|
|
|
|
//
|
2006-02-08 21:05:51 +00:00
|
|
|
for (i=0; i<active_tasks.active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks.active_tasks[i];
|
|
|
|
if (atp->scheduler_state == CPU_SCHED_SCHEDULED
|
|
|
|
&& atp->next_scheduler_state == CPU_SCHED_PREEMPTED
|
|
|
|
) {
|
2006-06-16 18:52:25 +00:00
|
|
|
action = true;
|
2006-02-08 21:05:51 +00:00
|
|
|
bool preempt_by_quit = !global_prefs.leave_apps_in_memory;
|
|
|
|
preempt_by_quit |= active_tasks.vm_limit_exceeded(vm_limit);
|
|
|
|
|
|
|
|
atp->preempt(preempt_by_quit);
|
|
|
|
} else if (atp->scheduler_state != CPU_SCHED_SCHEDULED
|
|
|
|
&& atp->next_scheduler_state == CPU_SCHED_SCHEDULED
|
|
|
|
) {
|
2006-06-16 18:52:25 +00:00
|
|
|
action = true;
|
2006-06-15 23:15:27 +00:00
|
|
|
int retval = atp->resume_or_start();
|
2006-02-08 21:05:51 +00:00
|
|
|
if (retval) {
|
|
|
|
report_result_error(
|
|
|
|
*(atp->result), "Couldn't start or resume: %d", retval
|
|
|
|
);
|
|
|
|
request_schedule_cpus("start failed");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
atp->scheduler_state = CPU_SCHED_SCHEDULED;
|
2006-06-15 23:15:27 +00:00
|
|
|
atp->episode_start_wall_time = now;
|
2006-02-08 21:05:51 +00:00
|
|
|
app_started = gstate.now;
|
|
|
|
}
|
|
|
|
}
|
2006-06-17 16:26:29 +00:00
|
|
|
if (action) {
|
|
|
|
set_client_state_dirty("enforce_cpu_schedule");
|
|
|
|
}
|
2006-06-16 18:52:25 +00:00
|
|
|
return action;
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
|
|
|
|
2006-02-11 03:00:37 +00:00
|
|
|
// return true if we don't have enough runnable tasks to keep all CPUs busy
|
|
|
|
//
|
|
|
|
bool CLIENT_STATE::no_work_for_a_cpu() {
|
|
|
|
unsigned int i;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (i=0; i< results.size(); i++){
|
|
|
|
RESULT* rp = results[i];
|
2006-06-20 20:29:10 +00:00
|
|
|
if (!rp->nearly_runnable()) continue;
|
2006-02-11 03:00:37 +00:00
|
|
|
if (rp->project->non_cpu_intensive) continue;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
return ncpus > count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the project's rrsim_proc_rate:
|
|
|
|
// the fraction of each CPU that it will get in round-robin mode.
|
|
|
|
// Precondition: the project's "active" array is populated
|
2006-02-08 21:05:51 +00:00
|
|
|
//
|
|
|
|
void PROJECT::set_rrsim_proc_rate(double per_cpu_proc_rate, double rrs) {
|
|
|
|
int nactive = (int)active.size();
|
|
|
|
if (nactive == 0) return;
|
|
|
|
double x;
|
2006-02-11 03:00:37 +00:00
|
|
|
|
2006-02-08 21:05:51 +00:00
|
|
|
if (rrs) {
|
|
|
|
x = resource_share/rrs;
|
|
|
|
} else {
|
2006-02-11 03:00:37 +00:00
|
|
|
x = 1; // pathological case; maybe should be 1/# runnable projects
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if this project has fewer active results than CPUs,
|
|
|
|
// scale up its share to reflect this
|
|
|
|
//
|
|
|
|
if (nactive < gstate.ncpus) {
|
|
|
|
x *= ((double)gstate.ncpus)/nactive;
|
|
|
|
}
|
|
|
|
|
2006-02-11 03:00:37 +00:00
|
|
|
// But its rate on a given CPU can't exceed 1
|
2006-02-08 21:05:51 +00:00
|
|
|
//
|
|
|
|
if (x>1) {
|
|
|
|
x = 1;
|
|
|
|
}
|
|
|
|
rrsim_proc_rate = x*per_cpu_proc_rate*CPU_PESSIMISM_FACTOR;
|
|
|
|
}
|
|
|
|
|
2006-06-16 18:52:25 +00:00
|
|
|
// Do a simulation of weighted round-robin scheduling.
|
|
|
|
//
|
|
|
|
// Inputs:
|
|
|
|
// per_cpu_proc_rate:
|
|
|
|
// the expected number of CPU seconds per wall second on each CPU
|
|
|
|
// rrs:
|
|
|
|
// the total resource share of runnable projects
|
|
|
|
//
|
|
|
|
// Outputs (changes to global state):
|
|
|
|
// For each project p:
|
|
|
|
// p->rr_sim_deadlines_missed
|
|
|
|
// p->cpu_shortfall
|
|
|
|
// For each result r:
|
|
|
|
// r->rr_sim_misses_deadline
|
|
|
|
// r->last_rr_sim_missed_deadline
|
|
|
|
// gstate.cpu_shortfall
|
|
|
|
//
|
|
|
|
// Returns true if some result misses its deadline
|
2006-02-08 21:05:51 +00:00
|
|
|
//
|
2006-06-16 18:52:25 +00:00
|
|
|
bool CLIENT_STATE::rr_simulation(double per_cpu_proc_rate, double rrs) {
|
2006-06-15 23:15:27 +00:00
|
|
|
double saved_rrs = rrs;
|
2006-02-08 21:05:51 +00:00
|
|
|
PROJECT* p, *pbest;
|
|
|
|
RESULT* rp, *rpbest;
|
|
|
|
vector<RESULT*> active;
|
|
|
|
unsigned int i;
|
|
|
|
double x;
|
|
|
|
vector<RESULT*>::iterator it;
|
2006-06-15 23:15:27 +00:00
|
|
|
bool rval = false;
|
2006-02-08 21:05:51 +00:00
|
|
|
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.rr_simulation) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"rr_simulation: start"
|
|
|
|
);
|
|
|
|
}
|
2006-06-21 23:16:46 +00:00
|
|
|
|
2006-06-16 18:52:25 +00:00
|
|
|
// Initialize the "active" and "pending" lists for each project.
|
2006-02-08 21:05:51 +00:00
|
|
|
// These keep track of that project's results
|
|
|
|
//
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
|
|
|
p->active.clear();
|
|
|
|
p->pending.clear();
|
2006-06-16 18:52:25 +00:00
|
|
|
p->rr_sim_deadlines_missed = 0;
|
|
|
|
p->cpu_shortfall = 0;
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<results.size(); i++) {
|
|
|
|
rp = results[i];
|
2006-06-20 20:29:10 +00:00
|
|
|
if (!rp->nearly_runnable()) continue;
|
2006-02-08 21:05:51 +00:00
|
|
|
if (rp->project->non_cpu_intensive) continue;
|
|
|
|
rp->rrsim_cpu_left = rp->estimated_cpu_time_remaining();
|
|
|
|
p = rp->project;
|
|
|
|
if (p->active.size() < (unsigned int)ncpus) {
|
|
|
|
active.push_back(rp);
|
|
|
|
p->active.push_back(rp);
|
|
|
|
} else {
|
|
|
|
p->pending.push_back(rp);
|
|
|
|
}
|
2006-06-16 18:52:25 +00:00
|
|
|
rp->last_rr_sim_missed_deadline = rp->rr_sim_misses_deadline;
|
|
|
|
rp->rr_sim_misses_deadline = false;
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
|
|
|
p->set_rrsim_proc_rate(per_cpu_proc_rate, rrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simulation loop. Keep going until work done
|
|
|
|
//
|
|
|
|
double sim_now = now;
|
|
|
|
while (active.size()) {
|
|
|
|
|
|
|
|
// compute finish times and see which result finishes first
|
|
|
|
//
|
|
|
|
rpbest = NULL;
|
|
|
|
for (i=0; i<active.size(); i++) {
|
|
|
|
rp = active[i];
|
|
|
|
p = rp->project;
|
|
|
|
rp->rrsim_finish_delay = rp->rrsim_cpu_left/p->rrsim_proc_rate;
|
|
|
|
if (!rpbest || rp->rrsim_finish_delay < rpbest->rrsim_finish_delay) {
|
|
|
|
rpbest = rp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-16 18:52:25 +00:00
|
|
|
pbest = rpbest->project;
|
|
|
|
|
2006-02-08 21:05:51 +00:00
|
|
|
// "rpbest" is first result to finish. Does it miss its deadline?
|
|
|
|
//
|
2006-04-05 05:50:34 +00:00
|
|
|
double diff = sim_now + rpbest->rrsim_finish_delay - rpbest->computation_deadline();
|
2006-02-08 21:05:51 +00:00
|
|
|
if (diff > 0) {
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.rr_simulation) {
|
|
|
|
msg_printf(0, MSG_INFO,
|
|
|
|
"rr_simulation: result %s misses deadline by %f\n",
|
|
|
|
rpbest->name, diff
|
|
|
|
);
|
|
|
|
}
|
2006-06-16 18:52:25 +00:00
|
|
|
rpbest->rr_sim_misses_deadline = true;
|
|
|
|
pbest->rr_sim_deadlines_missed++;
|
2006-06-15 23:15:27 +00:00
|
|
|
rval = true;
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
|
|
|
|
2006-06-16 18:52:25 +00:00
|
|
|
int last_active_size = active.size();
|
|
|
|
int last_proj_active_size = pbest->active.size();
|
|
|
|
|
2006-02-08 21:05:51 +00:00
|
|
|
// remove *rpbest from active set,
|
|
|
|
// and adjust CPU time left for other results
|
|
|
|
//
|
|
|
|
it = active.begin();
|
|
|
|
while (it != active.end()) {
|
|
|
|
rp = *it;
|
|
|
|
if (rp == rpbest) {
|
|
|
|
it = active.erase(it);
|
|
|
|
} else {
|
|
|
|
x = rp->project->rrsim_proc_rate*rpbest->rrsim_finish_delay;
|
|
|
|
rp->rrsim_cpu_left -= x;
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove *rpbest from its project's active set
|
|
|
|
//
|
|
|
|
it = pbest->active.begin();
|
|
|
|
while (it != pbest->active.end()) {
|
|
|
|
rp = *it;
|
|
|
|
if (rp == rpbest) {
|
|
|
|
it = pbest->active.erase(it);
|
|
|
|
} else {
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If project has more results, add one to active set.
|
|
|
|
//
|
|
|
|
if (pbest->pending.size()) {
|
|
|
|
rp = pbest->pending[0];
|
|
|
|
pbest->pending.erase(pbest->pending.begin());
|
|
|
|
active.push_back(rp);
|
|
|
|
pbest->active.push_back(rp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If all work done for a project, subtract that project's share
|
|
|
|
// and recompute processing rates
|
|
|
|
//
|
|
|
|
if (pbest->active.size() == 0) {
|
|
|
|
rrs -= pbest->resource_share;
|
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
|
|
|
p->set_rrsim_proc_rate(per_cpu_proc_rate, rrs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-16 18:52:25 +00:00
|
|
|
// increment CPU shortfalls if necessary
|
|
|
|
//
|
|
|
|
double buf_end = now + global_prefs.work_buf_min_days * SECONDS_PER_DAY;
|
|
|
|
if (sim_now < buf_end) {
|
|
|
|
double end_time = sim_now + rpbest->rrsim_finish_delay;
|
|
|
|
if (end_time > buf_end) end_time = buf_end;
|
|
|
|
double dtime = (end_time - sim_now);
|
|
|
|
int idle_cpus = ncpus - last_active_size;
|
|
|
|
cpu_shortfall += dtime*idle_cpus;
|
|
|
|
|
2006-06-20 20:29:10 +00:00
|
|
|
double proj_cpu_share = ncpus*pbest->resource_share/saved_rrs;
|
2006-06-16 18:52:25 +00:00
|
|
|
if (last_proj_active_size < proj_cpu_share) {
|
2006-06-20 20:29:10 +00:00
|
|
|
pbest->cpu_shortfall += dtime*(proj_cpu_share - last_proj_active_size);
|
2006-06-15 23:15:27 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-08 21:05:51 +00:00
|
|
|
|
2006-06-16 18:52:25 +00:00
|
|
|
sim_now += rpbest->rrsim_finish_delay;
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.rr_simulation) {
|
2006-06-21 23:16:46 +00:00
|
|
|
for (i=0; i<projects.size(); i++) {
|
|
|
|
p = projects[i];
|
2006-06-23 03:28:35 +00:00
|
|
|
if (p->cpu_shortfall) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"rr_simulation: shortfall for %s is %f\n",
|
|
|
|
p->project_name, p->cpu_shortfall
|
|
|
|
);
|
|
|
|
}
|
2006-06-21 23:16:46 +00:00
|
|
|
}
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"rr_simulation: end; returning %s; cpu_shortfall %f\n",
|
|
|
|
rval?"true":"false",
|
|
|
|
cpu_shortfall
|
|
|
|
);
|
2006-06-16 18:52:25 +00:00
|
|
|
}
|
2006-06-15 23:15:27 +00:00
|
|
|
return rval;
|
2006-02-08 21:05:51 +00:00
|
|
|
}
|
|
|
|
|
2006-06-16 18:52:25 +00:00
|
|
|
const char *BOINC_RCSID_e830ee1 = "$Id$";
|