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
|
2003-07-02 02:02:18 +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.
|
2003-07-02 02:02:18 +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.
|
2002-04-30 22:22:54 +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/>.
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
// Abstraction of a set of executing applications,
|
|
|
|
// connected to I/O files in various ways.
|
|
|
|
// Shouldn't depend on CLIENT_STATE.
|
|
|
|
|
2003-10-16 19:03:49 +00:00
|
|
|
#include "cpp.h"
|
2002-06-06 18:42:01 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2005-11-21 18:34:44 +00:00
|
|
|
#else
|
|
|
|
#include "config.h"
|
2002-07-05 19:20:00 +00:00
|
|
|
#endif
|
2004-03-04 11:41:43 +00:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <unistd.h>
|
2002-07-05 19:20:00 +00:00
|
|
|
#if HAVE_SYS_WAIT_H
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <sys/wait.h>
|
2002-07-05 19:20:00 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_TIME_H
|
2002-05-22 15:52:26 +00:00
|
|
|
#include <sys/time.h>
|
2002-07-05 19:20:00 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_RESOURCE_H
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <sys/resource.h>
|
2002-06-06 18:42:01 +00:00
|
|
|
#endif
|
2002-07-05 19:20:00 +00:00
|
|
|
#if HAVE_SYS_TYPES_H
|
2002-06-06 18:42:01 +00:00
|
|
|
#include <sys/types.h>
|
2002-07-05 19:20:00 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_FCNTL_H
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <fcntl.h>
|
2002-07-05 19:20:00 +00:00
|
|
|
#endif
|
2002-07-15 23:21:20 +00:00
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cctype>
|
|
|
|
#include <ctime>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cmath>
|
|
|
|
#include <cstdlib>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "client_state.h"
|
2007-04-03 19:35:33 +00:00
|
|
|
|
2003-10-16 19:03:49 +00:00
|
|
|
#include "error_numbers.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "filesys.h"
|
|
|
|
#include "file_names.h"
|
|
|
|
#include "parse.h"
|
2003-03-17 19:24:38 +00:00
|
|
|
#include "shmem.h"
|
2007-02-21 16:26:51 +00:00
|
|
|
#include "str_util.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "client_msgs.h"
|
2006-08-28 18:22:07 +00:00
|
|
|
#include "procinfo.h"
|
2007-10-09 00:34:38 +00:00
|
|
|
#include "sandbox.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "app.h"
|
2002-07-31 19:05:15 +00:00
|
|
|
|
2004-06-30 18:17:21 +00:00
|
|
|
using std::max;
|
2004-07-02 03:20:17 +00:00
|
|
|
using std::min;
|
2004-06-30 18:17:21 +00:00
|
|
|
|
2009-11-13 17:49:18 +00:00
|
|
|
bool exclusive_app_running;
|
|
|
|
bool exclusive_gpu_app_running;
|
2009-12-10 23:26:35 +00:00
|
|
|
bool gpu_suspended;
|
2010-01-19 00:03:38 +00:00
|
|
|
double non_boinc_cpu_usage;
|
2009-11-13 17:49:18 +00:00
|
|
|
|
2008-05-09 16:27:20 +00:00
|
|
|
#define ABORT_TIMEOUT 60
|
|
|
|
// if we send app <abort> request, wait this long before killing it.
|
|
|
|
// This gives it time to download symbol files (which can be several MB)
|
|
|
|
// and write stack trace to stderr
|
|
|
|
#define QUIT_TIMEOUT 10
|
|
|
|
// Same, for <quit>. Shorter because no stack trace is generated
|
|
|
|
|
2007-04-03 19:35:33 +00:00
|
|
|
ACTIVE_TASK::~ACTIVE_TASK() {
|
|
|
|
}
|
|
|
|
|
2009-01-23 00:06:55 +00:00
|
|
|
// preempt this task;
|
|
|
|
// called from the CLIENT_STATE::enforce_schedule()
|
|
|
|
// and ACTIVE_TASK_SET::suspend_all()
|
|
|
|
//
|
|
|
|
int ACTIVE_TASK::preempt(int preempt_type) {
|
|
|
|
int retval;
|
|
|
|
bool remove=false;
|
|
|
|
|
|
|
|
switch (preempt_type) {
|
|
|
|
case REMOVE_NEVER:
|
|
|
|
remove = false;
|
|
|
|
break;
|
|
|
|
case REMOVE_MAYBE_USER:
|
2009-06-26 20:54:44 +00:00
|
|
|
case REMOVE_MAYBE_SCHED:
|
|
|
|
// GPU jobs: always remove from mem, since it's tying up GPU RAM
|
|
|
|
//
|
|
|
|
if (result->uses_coprocs()) {
|
2009-01-23 00:06:55 +00:00
|
|
|
remove = true;
|
|
|
|
break;
|
|
|
|
}
|
2009-06-26 20:54:44 +00:00
|
|
|
// if it's never checkpointed, leave in mem
|
|
|
|
//
|
2009-01-23 00:06:55 +00:00
|
|
|
if (checkpoint_elapsed_time == 0) {
|
|
|
|
remove = false;
|
|
|
|
break;
|
|
|
|
}
|
2009-06-26 20:54:44 +00:00
|
|
|
// otherwise obey user prefs
|
|
|
|
//
|
2009-01-23 00:06:55 +00:00
|
|
|
remove = !gstate.global_prefs.leave_apps_in_memory;
|
|
|
|
break;
|
|
|
|
case REMOVE_ALWAYS:
|
|
|
|
remove = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (remove) {
|
|
|
|
if (log_flags.cpu_sched) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"[cpu_sched] Preempting %s (removed from memory)",
|
|
|
|
result->name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
set_task_state(PROCESS_QUIT_PENDING, "preempt");
|
|
|
|
retval = request_exit();
|
|
|
|
} else {
|
|
|
|
if (log_flags.cpu_sched) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"[cpu_sched] Preempting %s (left in memory)",
|
|
|
|
result->name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
retval = suspend();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-03 19:35:33 +00:00
|
|
|
#ifndef SIM
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
ACTIVE_TASK::ACTIVE_TASK() {
|
|
|
|
result = NULL;
|
|
|
|
wup = NULL;
|
|
|
|
app_version = NULL;
|
2002-07-15 23:21:20 +00:00
|
|
|
pid = 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
slot = 0;
|
2007-01-24 21:20:57 +00:00
|
|
|
_task_state = PROCESS_UNINITIALIZED;
|
2004-06-30 01:10:22 +00:00
|
|
|
scheduler_state = CPU_SCHED_UNINITIALIZED;
|
2002-04-30 22:22:54 +00:00
|
|
|
signal = 0;
|
2003-03-19 01:15:46 +00:00
|
|
|
strcpy(slot_dir, "");
|
2004-07-18 04:41:27 +00:00
|
|
|
graphics_mode_acked = MODE_UNSUPPORTED;
|
2006-02-21 12:22:23 +00:00
|
|
|
graphics_mode_ack_timeout = 0;
|
2004-04-03 01:26:40 +00:00
|
|
|
fraction_done = 0;
|
2006-08-22 20:58:57 +00:00
|
|
|
run_interval_start_wall_time = gstate.now;
|
2004-08-11 11:30:25 +00:00
|
|
|
checkpoint_cpu_time = 0;
|
2006-06-15 23:15:27 +00:00
|
|
|
checkpoint_wall_time = 0;
|
2004-08-11 11:30:25 +00:00
|
|
|
current_cpu_time = 0;
|
2010-03-05 21:13:53 +00:00
|
|
|
once_ran_edf = false;
|
2008-12-02 17:48:29 +00:00
|
|
|
elapsed_time = 0;
|
|
|
|
checkpoint_elapsed_time = 0;
|
2004-08-11 11:30:25 +00:00
|
|
|
have_trickle_down = false;
|
2005-04-28 23:19:58 +00:00
|
|
|
send_upload_file_status = false;
|
2006-11-01 23:36:13 +00:00
|
|
|
too_large = false;
|
2007-06-25 11:46:15 +00:00
|
|
|
needs_shmem = false;
|
2005-08-17 22:08:35 +00:00
|
|
|
want_network = 0;
|
2008-05-05 00:51:20 +00:00
|
|
|
premature_exit_count = 0;
|
|
|
|
quit_time = 0;
|
2006-11-01 23:36:13 +00:00
|
|
|
memset(&procinfo, 0, sizeof(procinfo));
|
2004-08-11 11:30:25 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
pid_handle = 0;
|
|
|
|
shm_handle = 0;
|
|
|
|
#endif
|
2007-07-20 23:42:20 +00:00
|
|
|
premature_exit_count = 0;
|
2003-10-30 23:23:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-24 21:20:57 +00:00
|
|
|
static const char* task_state_name(int val) {
|
|
|
|
switch (val) {
|
|
|
|
case PROCESS_UNINITIALIZED: return "UNINITIALIZED";
|
|
|
|
case PROCESS_EXECUTING: return "EXECUTING";
|
|
|
|
case PROCESS_SUSPENDED: return "SUSPENDED";
|
|
|
|
case PROCESS_ABORT_PENDING: return "ABORT_PENDING";
|
|
|
|
case PROCESS_EXITED: return "EXITED";
|
|
|
|
case PROCESS_WAS_SIGNALED: return "WAS_SIGNALED";
|
|
|
|
case PROCESS_EXIT_UNKNOWN: return "EXIT_UNKNOWN";
|
|
|
|
case PROCESS_ABORTED: return "ABORTED";
|
|
|
|
case PROCESS_COULDNT_START: return "COULDNT_START";
|
2007-02-08 21:06:03 +00:00
|
|
|
case PROCESS_QUIT_PENDING: return "QUIT_PENDING";
|
2007-01-24 21:20:57 +00:00
|
|
|
}
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
void ACTIVE_TASK::set_task_state(int val, const char* where) {
|
|
|
|
_task_state = val;
|
|
|
|
if (log_flags.task_debug) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"[task_debug] task_state=%s for %s from %s",
|
|
|
|
task_state_name(val), result->name, where
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-16 20:59:53 +00:00
|
|
|
// called when a process has exited or we've killed it
|
2005-02-25 21:31:46 +00:00
|
|
|
//
|
2008-08-16 20:59:53 +00:00
|
|
|
void ACTIVE_TASK::cleanup_task() {
|
|
|
|
#ifdef _WIN32
|
2004-09-02 22:34:35 +00:00
|
|
|
if (pid_handle) {
|
|
|
|
CloseHandle(pid_handle);
|
|
|
|
pid_handle = NULL;
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
// detach from shared mem.
|
|
|
|
// This will destroy shmem seg since we're the last attachment
|
2003-05-22 20:47:56 +00:00
|
|
|
//
|
2004-08-11 11:30:25 +00:00
|
|
|
if (app_client_shm.shm) {
|
|
|
|
detach_shmem(shm_handle, app_client_shm.shm);
|
|
|
|
app_client_shm.shm = NULL;
|
2003-05-22 20:47:56 +00:00
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
#else
|
2005-02-25 21:31:46 +00:00
|
|
|
int retval;
|
2007-09-26 10:16:04 +00:00
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
if (app_client_shm.shm) {
|
2007-09-26 10:16:04 +00:00
|
|
|
#ifndef __EMX__
|
|
|
|
if (app_version->api_major_version() >= 6) {
|
|
|
|
retval = detach_shmem_mmap(app_client_shm.shm, sizeof(SHARED_MEM));
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
retval = detach_shmem(app_client_shm.shm);
|
|
|
|
if (retval) {
|
2009-02-23 04:54:04 +00:00
|
|
|
msg_printf(wup->project, MSG_INTERNAL_ERROR,
|
2007-09-26 10:16:04 +00:00
|
|
|
"Couldn't detach shared memory: %s", boincerror(retval)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
retval = destroy_shmem(shmem_seg_name);
|
|
|
|
if (retval) {
|
2009-02-23 04:54:04 +00:00
|
|
|
msg_printf(wup->project, MSG_INTERNAL_ERROR,
|
2007-09-26 10:16:04 +00:00
|
|
|
"Couldn't destroy shared memory: %s", boincerror(retval)
|
|
|
|
);
|
|
|
|
}
|
2005-02-25 21:31:46 +00:00
|
|
|
}
|
2007-10-05 10:38:01 +00:00
|
|
|
app_client_shm.shm = NULL;
|
|
|
|
gstate.retry_shmem_time = 0;
|
2003-03-11 22:18:01 +00:00
|
|
|
}
|
2008-03-29 21:53:45 +00:00
|
|
|
#endif
|
2009-03-26 17:39:25 +00:00
|
|
|
|
|
|
|
// clear backoff for app's resource;
|
|
|
|
// this addresses the situation where the project has a
|
|
|
|
// "max # jobs in progress" limit, and we're backed off because of that
|
|
|
|
//
|
|
|
|
if (app_version->ncudas) {
|
|
|
|
result->project->cuda_pwf.clear_backoff();
|
2009-08-17 16:50:40 +00:00
|
|
|
} else if (app_version->natis) {
|
|
|
|
result->project->ati_pwf.clear_backoff();
|
2009-03-26 17:39:25 +00:00
|
|
|
} else {
|
|
|
|
result->project->cpu_pwf.clear_backoff();
|
|
|
|
}
|
|
|
|
|
2007-06-25 11:46:15 +00:00
|
|
|
if (gstate.exit_after_finish) {
|
|
|
|
exit(0);
|
|
|
|
}
|
2003-03-11 22:18:01 +00:00
|
|
|
}
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
int ACTIVE_TASK::init(RESULT* rp) {
|
|
|
|
result = rp;
|
|
|
|
wup = rp->wup;
|
2007-05-03 17:14:30 +00:00
|
|
|
app_version = rp->avp;
|
2009-02-26 17:51:38 +00:00
|
|
|
max_elapsed_time = rp->wup->rsc_fpops_bound/rp->avp->flops;
|
2004-08-11 11:30:25 +00:00
|
|
|
max_disk_usage = rp->wup->rsc_disk_bound;
|
|
|
|
max_mem_usage = rp->wup->rsc_memory_bound;
|
2007-03-13 19:33:27 +00:00
|
|
|
get_slot_dir(slot, slot_dir, sizeof(slot_dir));
|
2007-06-14 23:08:43 +00:00
|
|
|
relative_to_absolute(slot_dir, slot_path);
|
2003-10-19 02:54:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
#if 0
|
|
|
|
// Deallocate memory to prevent unneeded reporting of memory leaks
|
2003-08-12 20:28:55 +00:00
|
|
|
//
|
2004-08-11 11:30:25 +00:00
|
|
|
void ACTIVE_TASK_SET::free_mem() {
|
|
|
|
vector<ACTIVE_TASK*>::iterator at_iter;
|
|
|
|
ACTIVE_TASK *at;
|
2003-08-12 20:28:55 +00:00
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
at_iter = active_tasks.begin();
|
|
|
|
while (at_iter != active_tasks.end()) {
|
|
|
|
at = active_tasks[0];
|
|
|
|
at_iter = active_tasks.erase(at_iter);
|
|
|
|
delete at;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 19:06:47 +00:00
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2008-09-29 16:47:10 +00:00
|
|
|
bool app_running(vector<PROCINFO>& piv, const char* p) {
|
|
|
|
for (unsigned int i=0; i<piv.size(); i++) {
|
|
|
|
PROCINFO& pi = piv[i];
|
2009-11-13 21:57:25 +00:00
|
|
|
//msg_printf(0, MSG_INFO, "running: [%s]", pi.command);
|
2008-09-29 16:47:10 +00:00
|
|
|
if (!strcmp(pi.command, p)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-09-05 19:00:59 +00:00
|
|
|
void ACTIVE_TASK_SET::get_memory_usage() {
|
|
|
|
static double last_mem_time=0;
|
2006-11-01 23:36:13 +00:00
|
|
|
unsigned int i;
|
2006-11-01 22:40:30 +00:00
|
|
|
int retval;
|
2010-01-19 00:03:38 +00:00
|
|
|
static bool first = true;
|
|
|
|
static double last_cpu_time;
|
2006-09-05 19:00:59 +00:00
|
|
|
|
2006-11-01 23:36:13 +00:00
|
|
|
double diff = gstate.now - last_mem_time;
|
2006-09-08 19:27:42 +00:00
|
|
|
if (diff < 10) return;
|
2006-09-05 19:00:59 +00:00
|
|
|
|
|
|
|
last_mem_time = gstate.now;
|
|
|
|
vector<PROCINFO> piv;
|
2006-11-01 22:40:30 +00:00
|
|
|
retval = procinfo_setup(piv);
|
|
|
|
if (retval) {
|
|
|
|
if (log_flags.mem_usage_debug) {
|
2009-02-23 04:54:04 +00:00
|
|
|
msg_printf(NULL, MSG_INTERNAL_ERROR,
|
2006-11-01 22:40:30 +00:00
|
|
|
"[mem_usage_debug] procinfo_setup() returned %d", retval
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2006-09-05 19:00:59 +00:00
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
ACTIVE_TASK* atp = active_tasks[i];
|
2007-01-15 22:53:41 +00:00
|
|
|
if (atp->scheduler_state == CPU_SCHED_SCHEDULED) {
|
2006-11-01 23:36:13 +00:00
|
|
|
PROCINFO& pi = atp->procinfo;
|
|
|
|
unsigned long last_page_fault_count = pi.page_fault_count;
|
2006-09-05 19:00:59 +00:00
|
|
|
memset(&pi, 0, sizeof(pi));
|
|
|
|
pi.id = atp->pid;
|
|
|
|
procinfo_app(pi, piv);
|
2006-10-03 15:43:38 +00:00
|
|
|
pi.working_set_size_smoothed = .5*pi.working_set_size_smoothed + pi.working_set_size;
|
|
|
|
|
2006-11-01 23:36:13 +00:00
|
|
|
int pf = pi.page_fault_count - last_page_fault_count;
|
|
|
|
pi.page_fault_rate = pf/diff;
|
2006-09-05 19:00:59 +00:00
|
|
|
if (log_flags.mem_usage_debug) {
|
2006-10-03 17:14:56 +00:00
|
|
|
msg_printf(atp->result->project, MSG_INFO,
|
|
|
|
"[mem_usage_debug] %s: RAM %.2fMB, page %.2fMB, %.2f page faults/sec, user CPU %.3f, kernel CPU %.3f",
|
2006-09-05 19:00:59 +00:00
|
|
|
atp->result->name,
|
2006-10-03 17:14:56 +00:00
|
|
|
pi.working_set_size/MEGA, pi.swap_size/MEGA,
|
2006-11-01 23:36:13 +00:00
|
|
|
pi.page_fault_rate,
|
2006-09-05 19:00:59 +00:00
|
|
|
pi.user_time, pi.kernel_time
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-29 16:47:10 +00:00
|
|
|
exclusive_app_running = false;
|
2009-11-13 21:57:25 +00:00
|
|
|
bool old_egar = exclusive_gpu_app_running;
|
2009-11-13 17:49:18 +00:00
|
|
|
exclusive_gpu_app_running = false;
|
2008-09-29 16:47:10 +00:00
|
|
|
for (i=0; i<config.exclusive_apps.size(); i++) {
|
|
|
|
if (app_running(piv, config.exclusive_apps[i].c_str())) {
|
|
|
|
exclusive_app_running = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-11-13 17:49:18 +00:00
|
|
|
for (i=0; i<config.exclusive_gpu_apps.size(); i++) {
|
|
|
|
if (app_running(piv, config.exclusive_gpu_apps[i].c_str())) {
|
|
|
|
exclusive_gpu_app_running = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-11-13 21:57:25 +00:00
|
|
|
if (old_egar != exclusive_gpu_app_running) {
|
|
|
|
gstate.request_schedule_cpus("Exclusive GPU app status changed");
|
|
|
|
}
|
2008-09-29 16:47:10 +00:00
|
|
|
|
2010-01-19 00:03:38 +00:00
|
|
|
// get info on non-BOINC processes.
|
|
|
|
// mem usage info is not useful because most OSs don't
|
|
|
|
// move idle processes out of RAM, so physical memory is always full.
|
|
|
|
// Also (at least on Win) page faults are used for various things,
|
|
|
|
// not all of them generate disk I/O,
|
|
|
|
// so they're not useful for detecting paging/thrashing.
|
2006-09-05 19:00:59 +00:00
|
|
|
//
|
2010-01-19 00:03:38 +00:00
|
|
|
PROCINFO pi;
|
2006-09-05 19:00:59 +00:00
|
|
|
procinfo_other(pi, piv);
|
2010-01-28 04:43:31 +00:00
|
|
|
if (log_flags.mem_usage_debug) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
2010-02-18 23:53:14 +00:00
|
|
|
"[mem_usage_debug] All others: RAM %.2fMB, page %.2fMB, user %.3f, kernel %.3f",
|
2010-01-28 04:43:31 +00:00
|
|
|
pi.working_set_size/MEGA, pi.swap_size/MEGA,
|
|
|
|
pi.user_time, pi.kernel_time
|
|
|
|
);
|
|
|
|
}
|
2010-01-19 00:03:38 +00:00
|
|
|
double new_cpu_time = pi.user_time + pi.kernel_time;
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
non_boinc_cpu_usage = (new_cpu_time - last_cpu_time)/(diff*gstate.host_info.p_ncpus);
|
|
|
|
// processes might have exited in the last 10 sec,
|
|
|
|
// causing this to be negative.
|
|
|
|
if (non_boinc_cpu_usage < 0) non_boinc_cpu_usage = 0;
|
2010-01-28 04:43:31 +00:00
|
|
|
if (log_flags.mem_usage_debug) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
2010-02-18 23:53:14 +00:00
|
|
|
"[mem_usage_debug] non-BOINC CPU usage: %.2f%%", non_boinc_cpu_usage*100
|
2010-01-28 04:43:31 +00:00
|
|
|
);
|
|
|
|
}
|
2010-01-19 00:03:38 +00:00
|
|
|
}
|
|
|
|
last_cpu_time = new_cpu_time;
|
2006-09-05 19:00:59 +00:00
|
|
|
}
|
|
|
|
|
2006-02-03 20:48:48 +00:00
|
|
|
// Do periodic checks on running apps:
|
2004-08-11 11:30:25 +00:00
|
|
|
// - get latest CPU time and % done info
|
|
|
|
// - check if any has exited, and clean up
|
|
|
|
// - see if any has exceeded its CPU or disk space limits, and abort it
|
2004-08-10 20:27:51 +00:00
|
|
|
//
|
2005-06-07 19:22:50 +00:00
|
|
|
bool ACTIVE_TASK_SET::poll() {
|
2004-08-11 11:30:25 +00:00
|
|
|
bool action;
|
2006-11-01 23:36:13 +00:00
|
|
|
unsigned int i;
|
2004-10-14 22:01:05 +00:00
|
|
|
static double last_time = 0;
|
2009-02-26 03:24:39 +00:00
|
|
|
if (gstate.now - last_time < TASK_POLL_PERIOD) return false;
|
2005-06-07 19:22:50 +00:00
|
|
|
last_time = gstate.now;
|
2004-08-10 20:27:51 +00:00
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
action = check_app_exited();
|
|
|
|
send_heartbeats();
|
|
|
|
send_trickle_downs();
|
|
|
|
graphics_poll();
|
2004-09-13 05:27:28 +00:00
|
|
|
process_control_poll();
|
2006-09-05 19:00:59 +00:00
|
|
|
get_memory_usage();
|
2004-08-11 11:30:25 +00:00
|
|
|
action |= check_rsc_limits_exceeded();
|
2009-04-15 06:22:53 +00:00
|
|
|
get_msgs();
|
2006-08-28 18:22:07 +00:00
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
2006-02-03 20:48:48 +00:00
|
|
|
ACTIVE_TASK* atp = active_tasks[i];
|
2007-01-24 21:20:57 +00:00
|
|
|
if (atp->task_state() == PROCESS_ABORT_PENDING) {
|
2008-05-09 16:27:20 +00:00
|
|
|
if (gstate.now > atp->abort_time + ABORT_TIMEOUT) {
|
2006-12-07 17:30:48 +00:00
|
|
|
atp->kill_task(false);
|
2006-02-03 20:48:48 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-05 00:51:20 +00:00
|
|
|
if (atp->task_state() == PROCESS_QUIT_PENDING) {
|
2008-05-09 16:27:20 +00:00
|
|
|
if (gstate.now > atp->quit_time + QUIT_TIMEOUT) {
|
2008-05-05 00:51:20 +00:00
|
|
|
atp->kill_task(true);
|
|
|
|
}
|
|
|
|
}
|
2002-07-01 18:16:31 +00:00
|
|
|
}
|
2006-02-03 20:48:48 +00:00
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
if (action) {
|
|
|
|
gstate.set_client_state_dirty("ACTIVE_TASK_SET::poll");
|
2003-03-11 22:18:01 +00:00
|
|
|
}
|
2006-08-28 18:22:07 +00:00
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
return action;
|
2002-12-06 07:33:45 +00:00
|
|
|
}
|
2002-06-06 18:42:01 +00:00
|
|
|
|
2004-01-04 06:48:40 +00:00
|
|
|
// There's a new trickle file.
|
|
|
|
// Move it from slot dir to project dir
|
|
|
|
//
|
|
|
|
int ACTIVE_TASK::move_trickle_file() {
|
2007-03-13 19:33:27 +00:00
|
|
|
char project_dir[256], new_path[1024], old_path[1024];
|
2004-01-04 06:48:40 +00:00
|
|
|
int retval;
|
|
|
|
|
2007-03-13 19:33:27 +00:00
|
|
|
get_project_dir(result->project, project_dir, sizeof(project_dir));
|
2006-03-03 21:34:03 +00:00
|
|
|
sprintf(old_path, "%s/trickle_up.xml", slot_dir);
|
2004-01-04 06:48:40 +00:00
|
|
|
sprintf(new_path,
|
2006-03-03 21:34:03 +00:00
|
|
|
"%s/trickle_up_%s_%d.xml",
|
|
|
|
project_dir, result->name, (int)time(0)
|
2004-01-04 06:48:40 +00:00
|
|
|
);
|
|
|
|
retval = boinc_rename(old_path, new_path);
|
|
|
|
|
|
|
|
// if can't move it, remove
|
|
|
|
//
|
|
|
|
if (retval) {
|
2008-01-15 19:12:43 +00:00
|
|
|
delete_project_owned_file(old_path, true);
|
2004-01-04 06:48:40 +00:00
|
|
|
return ERR_RENAME;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-12-06 07:33:45 +00:00
|
|
|
// size of output files and files in slot dir
|
|
|
|
//
|
|
|
|
int ACTIVE_TASK::current_disk_usage(double& size) {
|
|
|
|
double x;
|
|
|
|
unsigned int i;
|
|
|
|
int retval;
|
|
|
|
FILE_INFO* fip;
|
2007-03-13 19:33:27 +00:00
|
|
|
char path[1024];
|
2002-12-06 07:33:45 +00:00
|
|
|
|
|
|
|
retval = dir_size(slot_dir, size);
|
|
|
|
if (retval) return retval;
|
|
|
|
for (i=0; i<result->output_files.size(); i++) {
|
|
|
|
fip = result->output_files[i].file_info;
|
2007-03-13 19:33:27 +00:00
|
|
|
get_pathname(fip, path, sizeof(path));
|
2002-12-06 07:33:45 +00:00
|
|
|
retval = file_size(path, x);
|
|
|
|
if (!retval) size += x;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-03-15 23:01:51 +00:00
|
|
|
bool ACTIVE_TASK_SET::is_slot_in_use(int slot) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
if (active_tasks[i]->slot == slot) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ACTIVE_TASK_SET::is_slot_dir_in_use(char* dir) {
|
|
|
|
char path[1024];
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
get_slot_dir(active_tasks[i]->slot, path, sizeof(path));
|
|
|
|
if (!strcmp(path, dir)) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get a free slot,
|
|
|
|
// and make a slot dir if needed
|
2002-08-26 22:14:06 +00:00
|
|
|
//
|
2009-05-28 19:26:27 +00:00
|
|
|
void ACTIVE_TASK::get_free_slot(RESULT* rp) {
|
2007-03-15 23:01:51 +00:00
|
|
|
int j, retval;
|
|
|
|
char path[1024];
|
2002-08-26 22:14:06 +00:00
|
|
|
|
2004-06-30 01:10:22 +00:00
|
|
|
for (j=0; ; j++) {
|
2009-05-28 19:26:27 +00:00
|
|
|
if (gstate.active_tasks.is_slot_in_use(j)) continue;
|
2007-03-15 23:01:51 +00:00
|
|
|
|
|
|
|
// make sure we can make an empty directory for this slot
|
|
|
|
//
|
|
|
|
get_slot_dir(j, path, sizeof(path));
|
|
|
|
if (boinc_file_exists(path)) {
|
|
|
|
if (is_dir(path)) {
|
2009-05-28 19:26:27 +00:00
|
|
|
retval = client_clean_out_dir(path, "get_free_slot()");
|
|
|
|
if (!retval) break;
|
2003-02-24 21:25:16 +00:00
|
|
|
}
|
2007-03-15 23:01:51 +00:00
|
|
|
} else {
|
|
|
|
retval = make_slot_dir(j);
|
2009-05-28 19:26:27 +00:00
|
|
|
if (!retval) break;
|
2002-08-26 22:14:06 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-28 19:26:27 +00:00
|
|
|
slot = j;
|
|
|
|
if (log_flags.slot_debug) {
|
|
|
|
msg_printf(rp->project, MSG_INFO, "[slot] assigning slot %d to %s", j, rp->name);
|
|
|
|
}
|
2002-08-26 22:14:06 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 05:14:39 +00:00
|
|
|
bool ACTIVE_TASK_SET::slot_taken(int slot) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
if (active_tasks[i]->slot == slot) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-10-21 20:54:24 +00:00
|
|
|
// <active_task_state> is here for the benefit of 3rd-party software
|
|
|
|
// that reads the client state file
|
|
|
|
//
|
2004-06-12 04:45:36 +00:00
|
|
|
int ACTIVE_TASK::write(MIOFILE& fout) {
|
|
|
|
fout.printf(
|
2002-04-30 22:22:54 +00:00
|
|
|
"<active_task>\n"
|
2002-06-21 06:52:47 +00:00
|
|
|
" <project_master_url>%s</project_master_url>\n"
|
2002-04-30 22:22:54 +00:00
|
|
|
" <result_name>%s</result_name>\n"
|
2007-10-21 20:54:24 +00:00
|
|
|
" <active_task_state>%d</active_task_state>\n"
|
2002-04-30 22:22:54 +00:00
|
|
|
" <app_version_num>%d</app_version_num>\n"
|
|
|
|
" <slot>%d</slot>\n"
|
2007-06-14 23:08:43 +00:00
|
|
|
" <checkpoint_cpu_time>%f</checkpoint_cpu_time>\n"
|
2008-12-02 17:48:29 +00:00
|
|
|
" <checkpoint_elapsed_time>%f</checkpoint_elapsed_time>\n"
|
2007-06-14 23:08:43 +00:00
|
|
|
" <fraction_done>%f</fraction_done>\n"
|
|
|
|
" <current_cpu_time>%f</current_cpu_time>\n"
|
2010-03-05 21:13:53 +00:00
|
|
|
" <once_ran_edf>%d</once_ran_edf>\n"
|
2007-06-14 23:08:43 +00:00
|
|
|
" <swap_size>%f</swap_size>\n"
|
|
|
|
" <working_set_size>%f</working_set_size>\n"
|
|
|
|
" <working_set_size_smoothed>%f</working_set_size_smoothed>\n"
|
|
|
|
" <page_fault_rate>%f</page_fault_rate>\n",
|
|
|
|
result->project->master_url,
|
|
|
|
result->name,
|
2007-10-21 20:54:24 +00:00
|
|
|
task_state(),
|
2007-06-14 23:08:43 +00:00
|
|
|
app_version->version_num,
|
|
|
|
slot,
|
|
|
|
checkpoint_cpu_time,
|
2008-12-02 17:48:29 +00:00
|
|
|
checkpoint_elapsed_time,
|
2007-06-14 23:08:43 +00:00
|
|
|
fraction_done,
|
|
|
|
current_cpu_time,
|
2010-03-05 21:13:53 +00:00
|
|
|
once_ran_edf?1:0,
|
2007-06-14 23:08:43 +00:00
|
|
|
procinfo.swap_size,
|
|
|
|
procinfo.working_set_size,
|
|
|
|
procinfo.working_set_size_smoothed,
|
|
|
|
procinfo.page_fault_rate
|
|
|
|
);
|
|
|
|
fout.printf("</active_task>\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ACTIVE_TASK::write_gui(MIOFILE& fout) {
|
|
|
|
fout.printf(
|
|
|
|
"<active_task>\n"
|
|
|
|
" <active_task_state>%d</active_task_state>\n"
|
|
|
|
" <app_version_num>%d</app_version_num>\n"
|
2007-09-13 06:53:40 +00:00
|
|
|
" <slot>%d</slot>\n"
|
2009-12-21 17:25:43 +00:00
|
|
|
" <pid>%d</pid>\n"
|
2004-06-30 01:10:22 +00:00
|
|
|
" <scheduler_state>%d</scheduler_state>\n"
|
2002-08-05 00:29:34 +00:00
|
|
|
" <checkpoint_cpu_time>%f</checkpoint_cpu_time>\n"
|
2004-01-22 19:30:42 +00:00
|
|
|
" <fraction_done>%f</fraction_done>\n"
|
|
|
|
" <current_cpu_time>%f</current_cpu_time>\n"
|
2008-12-02 17:48:29 +00:00
|
|
|
" <elapsed_time>%f</elapsed_time>\n"
|
2006-09-08 19:27:42 +00:00
|
|
|
" <swap_size>%f</swap_size>\n"
|
|
|
|
" <working_set_size>%f</working_set_size>\n"
|
2006-10-03 17:24:25 +00:00
|
|
|
" <working_set_size_smoothed>%f</working_set_size_smoothed>\n"
|
2006-11-01 23:36:13 +00:00
|
|
|
" <page_fault_rate>%f</page_fault_rate>\n"
|
2007-06-25 11:46:15 +00:00
|
|
|
"%s"
|
2006-10-03 22:50:13 +00:00
|
|
|
"%s",
|
2007-01-24 21:20:57 +00:00
|
|
|
task_state(),
|
2002-04-30 22:22:54 +00:00
|
|
|
app_version->version_num,
|
2007-09-13 06:53:40 +00:00
|
|
|
slot,
|
2009-12-21 17:25:43 +00:00
|
|
|
pid,
|
2004-06-30 01:10:22 +00:00
|
|
|
scheduler_state,
|
2004-01-22 19:30:42 +00:00
|
|
|
checkpoint_cpu_time,
|
|
|
|
fraction_done,
|
2004-10-21 00:23:19 +00:00
|
|
|
current_cpu_time,
|
2008-12-02 17:48:29 +00:00
|
|
|
elapsed_time,
|
2006-09-08 19:27:42 +00:00
|
|
|
procinfo.swap_size,
|
|
|
|
procinfo.working_set_size,
|
2006-10-03 17:24:25 +00:00
|
|
|
procinfo.working_set_size_smoothed,
|
2006-11-01 23:36:13 +00:00
|
|
|
procinfo.page_fault_rate,
|
2007-06-25 11:46:15 +00:00
|
|
|
too_large?" <too_large/>\n":"",
|
|
|
|
needs_shmem?" <needs_shmem/>\n":""
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
2007-06-14 23:08:43 +00:00
|
|
|
if (strlen(app_version->graphics_exec_path)) {
|
|
|
|
fout.printf(
|
|
|
|
" <graphics_exec_path>%s</graphics_exec_path>\n"
|
|
|
|
" <slot_path>%s</slot_path>\n",
|
|
|
|
app_version->graphics_exec_path,
|
|
|
|
slot_path
|
|
|
|
);
|
|
|
|
}
|
2006-03-16 20:29:44 +00:00
|
|
|
if (supports_graphics() && !gstate.disable_graphics) {
|
2005-04-21 23:53:39 +00:00
|
|
|
fout.printf(
|
|
|
|
" <supports_graphics/>\n"
|
|
|
|
" <graphics_mode_acked>%d</graphics_mode_acked>\n",
|
|
|
|
graphics_mode_acked
|
|
|
|
);
|
|
|
|
}
|
|
|
|
fout.printf("</active_task>\n");
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
int ACTIVE_TASK::parse(MIOFILE& fin) {
|
2002-06-21 06:52:47 +00:00
|
|
|
char buf[256], result_name[256], project_master_url[256];
|
2007-10-22 23:56:10 +00:00
|
|
|
int n, dummy;
|
2005-08-12 00:10:54 +00:00
|
|
|
unsigned int i;
|
2009-02-25 15:34:51 +00:00
|
|
|
PROJECT* project=0;
|
2009-01-22 19:51:04 +00:00
|
|
|
double x;
|
2002-08-05 00:29:34 +00:00
|
|
|
|
2003-03-19 01:15:46 +00:00
|
|
|
strcpy(result_name, "");
|
|
|
|
strcpy(project_master_url, "");
|
2004-07-08 17:59:46 +00:00
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
while (fin.fgets(buf, 256)) {
|
2002-04-30 22:22:54 +00:00
|
|
|
if (match_tag(buf, "</active_task>")) {
|
2004-06-12 04:45:36 +00:00
|
|
|
project = gstate.lookup_project(project_master_url);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!project) {
|
2003-07-03 05:01:29 +00:00
|
|
|
msg_printf(
|
2007-01-25 23:39:06 +00:00
|
|
|
NULL, MSG_INTERNAL_ERROR,
|
2009-04-01 23:22:17 +00:00
|
|
|
"State file error: project %s not found for task\n",
|
2002-06-21 06:52:47 +00:00
|
|
|
project_master_url
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
2003-10-21 04:06:55 +00:00
|
|
|
return ERR_NULL;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-06-12 04:45:36 +00:00
|
|
|
result = gstate.lookup_result(project, result_name);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!result) {
|
2003-07-03 05:01:29 +00:00
|
|
|
msg_printf(
|
2007-01-25 23:39:06 +00:00
|
|
|
project, MSG_INTERNAL_ERROR,
|
2009-04-01 23:22:17 +00:00
|
|
|
"State file error: result %s not found for task\n",
|
2006-01-17 22:48:09 +00:00
|
|
|
result_name
|
2003-07-03 05:01:29 +00:00
|
|
|
);
|
2003-10-21 04:06:55 +00:00
|
|
|
return ERR_NULL;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-11-06 00:00:00 +00:00
|
|
|
|
|
|
|
// various sanity checks
|
|
|
|
//
|
|
|
|
if (result->got_server_ack
|
|
|
|
|| result->ready_to_report
|
2007-01-24 21:20:57 +00:00
|
|
|
|| result->state() != RESULT_FILES_DOWNLOADED
|
2003-11-06 00:00:00 +00:00
|
|
|
) {
|
|
|
|
return ERR_BAD_RESULT_STATE;
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
wup = result->wup;
|
2004-06-12 04:45:36 +00:00
|
|
|
app_version = gstate.lookup_app_version(
|
2008-03-27 18:25:29 +00:00
|
|
|
result->app, result->platform, result->version_num,
|
|
|
|
result->plan_class
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
|
|
|
if (!app_version) {
|
2003-07-03 05:01:29 +00:00
|
|
|
msg_printf(
|
2007-01-25 23:39:06 +00:00
|
|
|
project, MSG_INTERNAL_ERROR,
|
2007-05-03 17:14:30 +00:00
|
|
|
"State file error: app %s platform %s version %d not found\n",
|
|
|
|
result->app->name, result->platform, result->version_num
|
2003-07-03 05:01:29 +00:00
|
|
|
);
|
2003-11-06 00:00:00 +00:00
|
|
|
return ERR_NULL;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2005-08-12 00:10:54 +00:00
|
|
|
|
|
|
|
// make sure no two active tasks are in same slot
|
|
|
|
//
|
|
|
|
for (i=0; i<gstate.active_tasks.active_tasks.size(); i++) {
|
|
|
|
ACTIVE_TASK* atp = gstate.active_tasks.active_tasks[i];
|
|
|
|
if (atp->slot == slot) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(project, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"State file error: two tasks in slot %d\n", slot
|
2005-08-12 00:10:54 +00:00
|
|
|
);
|
|
|
|
return ERR_BAD_RESULT_STATE;
|
|
|
|
}
|
|
|
|
}
|
2008-12-04 03:51:14 +00:00
|
|
|
|
|
|
|
// for 6.2/6.4 transition
|
|
|
|
//
|
|
|
|
if (checkpoint_elapsed_time == 0) {
|
|
|
|
elapsed_time = checkpoint_cpu_time;
|
|
|
|
checkpoint_elapsed_time = elapsed_time;
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2002-09-22 23:27:14 +00:00
|
|
|
else if (parse_str(buf, "<result_name>", result_name, sizeof(result_name))) continue;
|
|
|
|
else if (parse_str(buf, "<project_master_url>", project_master_url, sizeof(project_master_url))) continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
else if (parse_int(buf, "<slot>", slot)) continue;
|
2007-10-22 23:56:10 +00:00
|
|
|
else if (parse_int(buf, "<active_task_state>", dummy)) continue;
|
2008-12-04 03:51:14 +00:00
|
|
|
else if (parse_double(buf, "<checkpoint_cpu_time>", checkpoint_cpu_time)) {
|
|
|
|
current_cpu_time = checkpoint_cpu_time;
|
|
|
|
continue;
|
|
|
|
}
|
2010-03-05 21:13:53 +00:00
|
|
|
else if (parse_bool(buf, "once_ran_edf", once_ran_edf)) continue;
|
2004-01-22 19:30:42 +00:00
|
|
|
else if (parse_double(buf, "<fraction_done>", fraction_done)) continue;
|
2008-12-04 03:51:14 +00:00
|
|
|
else if (parse_double(buf, "<checkpoint_elapsed_time>", checkpoint_elapsed_time)) {
|
|
|
|
elapsed_time = checkpoint_elapsed_time;
|
|
|
|
continue;
|
|
|
|
}
|
2007-05-10 16:07:45 +00:00
|
|
|
else if (parse_int(buf, "<app_version_num>", n)) continue;
|
2006-09-08 19:27:42 +00:00
|
|
|
else if (parse_double(buf, "<swap_size>", procinfo.swap_size)) continue;
|
|
|
|
else if (parse_double(buf, "<working_set_size>", procinfo.working_set_size)) continue;
|
2006-10-03 17:24:25 +00:00
|
|
|
else if (parse_double(buf, "<working_set_size_smoothed>", procinfo.working_set_size_smoothed)) continue;
|
2006-09-08 19:27:42 +00:00
|
|
|
else if (parse_double(buf, "<page_fault_rate>", procinfo.page_fault_rate)) continue;
|
2009-01-22 19:51:04 +00:00
|
|
|
else if (parse_double(buf, "<current_cpu_time>", x)) continue;
|
2006-06-22 19:40:30 +00:00
|
|
|
else {
|
|
|
|
if (log_flags.unparsed_xml) {
|
2009-02-23 04:54:04 +00:00
|
|
|
msg_printf(project, MSG_INFO,
|
2006-09-07 20:39:25 +00:00
|
|
|
"[unparsed_xml] ACTIVE_TASK::parse(): unrecognized %s\n", buf
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2003-10-21 04:06:55 +00:00
|
|
|
return ERR_XML_PARSE;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
int ACTIVE_TASK_SET::write(MIOFILE& fout) {
|
2002-04-30 22:22:54 +00:00
|
|
|
unsigned int i;
|
2003-03-08 23:48:05 +00:00
|
|
|
int retval;
|
2002-08-05 00:29:34 +00:00
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<active_task_set>\n");
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
2003-03-08 23:48:05 +00:00
|
|
|
retval = active_tasks[i]->write(fout);
|
|
|
|
if (retval) return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("</active_task_set>\n");
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
int ACTIVE_TASK_SET::parse(MIOFILE& fin) {
|
2002-04-30 22:22:54 +00:00
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
char buf[256];
|
|
|
|
int retval;
|
2002-08-05 00:29:34 +00:00
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
while (fin.fgets(buf, 256)) {
|
2002-04-30 22:22:54 +00:00
|
|
|
if (match_tag(buf, "</active_task_set>")) return 0;
|
|
|
|
else if (match_tag(buf, "<active_task>")) {
|
|
|
|
atp = new ACTIVE_TASK;
|
2004-06-12 04:45:36 +00:00
|
|
|
retval = atp->parse(fin);
|
2006-06-15 05:14:39 +00:00
|
|
|
if (!retval) {
|
|
|
|
if (slot_taken(atp->slot)) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(atp->result->project, MSG_INTERNAL_ERROR,
|
2006-06-15 05:14:39 +00:00
|
|
|
"slot %d in use; discarding result %s",
|
|
|
|
atp->slot, atp->result->name
|
|
|
|
);
|
|
|
|
retval = ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
if (!retval) active_tasks.push_back(atp);
|
|
|
|
else delete atp;
|
2006-06-22 19:40:30 +00:00
|
|
|
} else {
|
|
|
|
if (log_flags.unparsed_xml) {
|
2009-02-23 04:54:04 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
2006-09-07 20:39:25 +00:00
|
|
|
"[unparsed_xml] ACTIVE_TASK_SET::parse(): unrecognized %s\n", buf
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2005-10-10 03:21:52 +00:00
|
|
|
return ERR_XML_PARSE;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-09-13 05:27:28 +00:00
|
|
|
|
2006-12-09 00:10:53 +00:00
|
|
|
void MSG_QUEUE::init(char* n) {
|
|
|
|
strcpy(name, n);
|
|
|
|
last_block = 0;
|
|
|
|
msgs.clear();
|
|
|
|
}
|
|
|
|
|
2005-02-16 23:17:43 +00:00
|
|
|
void MSG_QUEUE::msg_queue_send(const char* msg, MSG_CHANNEL& channel) {
|
2006-11-21 00:45:22 +00:00
|
|
|
if ((msgs.size()==0) && channel.send_msg(msg)) {
|
|
|
|
if (log_flags.app_msg_send) {
|
|
|
|
msg_printf(NULL, MSG_INFO, "[app_msg_send] sent %s to %s", msg, name);
|
|
|
|
}
|
2006-12-09 00:10:53 +00:00
|
|
|
last_block = 0;
|
|
|
|
return;
|
2004-09-13 05:27:28 +00:00
|
|
|
}
|
2006-11-21 00:45:22 +00:00
|
|
|
if (log_flags.app_msg_send) {
|
|
|
|
msg_printf(NULL, MSG_INFO, "[app_msg_send] deferred %s to %s", msg, name);
|
|
|
|
}
|
2004-09-13 05:27:28 +00:00
|
|
|
msgs.push_back(std::string(msg));
|
2006-12-09 00:10:53 +00:00
|
|
|
if (!last_block) last_block = gstate.now;
|
2004-09-13 05:27:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MSG_QUEUE::msg_queue_poll(MSG_CHANNEL& channel) {
|
|
|
|
if (msgs.size() > 0) {
|
2006-11-21 00:45:22 +00:00
|
|
|
if (log_flags.app_msg_send) {
|
2006-12-09 00:10:53 +00:00
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"[app_msg_send] poll: %d msgs queued for %s:",
|
|
|
|
(int)msgs.size(), name
|
|
|
|
);
|
2006-11-21 00:45:22 +00:00
|
|
|
}
|
2005-02-16 23:17:43 +00:00
|
|
|
if (channel.send_msg(msgs[0].c_str())) {
|
2006-11-21 00:45:22 +00:00
|
|
|
if (log_flags.app_msg_send) {
|
2006-12-09 00:10:53 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "[app_msg_send] poll: delayed sent %s", (msgs[0].c_str()));
|
2006-11-21 00:45:22 +00:00
|
|
|
}
|
2004-09-13 05:27:28 +00:00
|
|
|
msgs.erase(msgs.begin());
|
2006-12-09 00:10:53 +00:00
|
|
|
last_block = 0;
|
|
|
|
}
|
|
|
|
for (unsigned int i=0; i<msgs.size(); i++) {
|
2006-11-21 00:45:22 +00:00
|
|
|
if (log_flags.app_msg_send) {
|
2006-12-09 00:10:53 +00:00
|
|
|
msg_printf(NULL, MSG_INFO, "[app_msg_send] poll: deferred: %s", (msgs[0].c_str()));
|
2006-11-21 00:45:22 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-13 05:27:28 +00:00
|
|
|
}
|
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2006-12-09 00:10:53 +00:00
|
|
|
// if the last message in the buffer is "msg", remove it and return 1
|
2006-11-21 00:45:22 +00:00
|
|
|
//
|
|
|
|
int MSG_QUEUE::msg_queue_purge(const char* msg) {
|
2009-12-16 19:55:09 +00:00
|
|
|
int count = (int)msgs.size();
|
2006-12-09 00:10:53 +00:00
|
|
|
if (!count) return 0;
|
2006-11-21 00:45:22 +00:00
|
|
|
vector<string>::iterator iter = msgs.begin();
|
2006-12-09 00:10:53 +00:00
|
|
|
for (int i=0; i<count-1; i++) {
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
if (log_flags.app_msg_send) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"[app_msg_send] purge: wanted %s last msg is %s in %s",
|
|
|
|
msg, iter->c_str(), name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (!strcmp(msg, iter->c_str())) {
|
|
|
|
if (log_flags.app_msg_send) {
|
|
|
|
msg_printf(NULL, MSG_INFO, "[app_msg_send] purged %s from %s", msg, name);
|
2006-11-21 00:45:22 +00:00
|
|
|
}
|
2006-12-09 00:10:53 +00:00
|
|
|
iter = msgs.erase(iter);
|
|
|
|
return 1;
|
2006-11-21 00:45:22 +00:00
|
|
|
}
|
2006-12-09 00:10:53 +00:00
|
|
|
return 0;
|
2006-11-21 00:45:22 +00:00
|
|
|
}
|
|
|
|
|
2006-12-09 00:10:53 +00:00
|
|
|
bool MSG_QUEUE::timeout(double diff) {
|
|
|
|
if (!last_block) return false;
|
|
|
|
if (gstate.now - last_block > diff) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2006-11-21 00:45:22 +00:00
|
|
|
|
2005-06-07 19:22:50 +00:00
|
|
|
void ACTIVE_TASK_SET::report_overdue() {
|
2005-04-20 06:16:54 +00:00
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2005-06-07 19:22:50 +00:00
|
|
|
double diff = (gstate.now - atp->result->report_deadline)/86400;
|
2005-04-20 06:16:54 +00:00
|
|
|
if (diff > 0) {
|
2009-12-23 23:25:45 +00:00
|
|
|
msg_printf(atp->result->project, MSG_INFO,
|
2009-12-02 04:48:17 +00:00
|
|
|
"Task %s is %.2f days overdue; you may not get credit for it. Consider aborting it.", atp->result->name, diff
|
2005-04-20 06:16:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-28 23:19:58 +00:00
|
|
|
// scan the slot directory, looking for files with names
|
|
|
|
// of the form boinc_ufr_X.
|
|
|
|
// Then mark file X as being present (and uploadable)
|
|
|
|
//
|
|
|
|
int ACTIVE_TASK::handle_upload_files() {
|
|
|
|
std::string filename;
|
2007-03-13 19:33:27 +00:00
|
|
|
char buf[256], path[1024];
|
2005-05-02 20:32:36 +00:00
|
|
|
int retval;
|
2005-04-28 23:19:58 +00:00
|
|
|
|
|
|
|
DirScanner dirscan(slot_dir);
|
|
|
|
while (dirscan.scan(filename)) {
|
|
|
|
strcpy(buf, filename.c_str());
|
|
|
|
if (strstr(buf, UPLOAD_FILE_REQ_PREFIX) == buf) {
|
|
|
|
char* p = buf+strlen(UPLOAD_FILE_REQ_PREFIX);
|
|
|
|
FILE_INFO* fip = result->lookup_file_logical(p);
|
|
|
|
if (fip) {
|
2007-03-13 19:33:27 +00:00
|
|
|
get_pathname(fip, path, sizeof(path));
|
2005-06-08 19:02:27 +00:00
|
|
|
retval = md5_file(path, fip->md5_cksum, fip->nbytes);
|
2005-05-02 20:32:36 +00:00
|
|
|
if (retval) {
|
|
|
|
fip->status = retval;
|
|
|
|
} else {
|
|
|
|
fip->status = FILE_PRESENT;
|
|
|
|
}
|
2005-04-28 23:19:58 +00:00
|
|
|
} else {
|
2009-02-23 04:54:04 +00:00
|
|
|
msg_printf(wup->project, MSG_INTERNAL_ERROR,
|
|
|
|
"Can't find uploadable file %s", p
|
|
|
|
);
|
2005-04-28 23:19:58 +00:00
|
|
|
}
|
|
|
|
sprintf(path, "%s/%s", slot_dir, buf);
|
2008-01-15 19:12:43 +00:00
|
|
|
delete_project_owned_file(path, true); // delete the link file
|
2005-04-28 23:19:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ACTIVE_TASK_SET::handle_upload_files() {
|
|
|
|
for (unsigned int i=0; i<active_tasks.size(); i++) {
|
|
|
|
ACTIVE_TASK* atp = active_tasks[i];
|
|
|
|
atp->handle_upload_files();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-17 22:08:35 +00:00
|
|
|
bool ACTIVE_TASK_SET::want_network() {
|
|
|
|
for (unsigned int i=0; i<active_tasks.size(); i++) {
|
|
|
|
ACTIVE_TASK* atp = active_tasks[i];
|
|
|
|
if (atp->want_network) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ACTIVE_TASK_SET::network_available() {
|
|
|
|
for (unsigned int i=0; i<active_tasks.size(); i++) {
|
|
|
|
ACTIVE_TASK* atp = active_tasks[i];
|
|
|
|
if (atp->want_network) {
|
|
|
|
atp->send_network_available();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-28 23:19:58 +00:00
|
|
|
void ACTIVE_TASK::upload_notify_app(const FILE_INFO* fip, const FILE_REF* frp) {
|
|
|
|
char path[256];
|
|
|
|
sprintf(path, "%s/%s%s", slot_dir, UPLOAD_FILE_STATUS_PREFIX, frp->open_name);
|
|
|
|
FILE* f = boinc_fopen(path, "w");
|
|
|
|
if (!f) return;
|
|
|
|
fprintf(f, "<status>%d</status>\n", fip->status);
|
|
|
|
fclose(f);
|
|
|
|
send_upload_file_status = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// a file upload has finished.
|
|
|
|
// If any running apps are waiting for it, notify them
|
|
|
|
//
|
|
|
|
void ACTIVE_TASK_SET::upload_notify_app(FILE_INFO* fip) {
|
|
|
|
for (unsigned int i=0; i<active_tasks.size(); i++) {
|
|
|
|
ACTIVE_TASK* atp = active_tasks[i];
|
|
|
|
RESULT* rp = atp->result;
|
|
|
|
FILE_REF* frp = rp->lookup_file(fip);
|
|
|
|
if (frp) {
|
|
|
|
atp->upload_notify_app(fip, frp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-19 04:29:26 +00:00
|
|
|
void ACTIVE_TASK_SET::init() {
|
|
|
|
for (unsigned int i=0; i<active_tasks.size(); i++) {
|
|
|
|
ACTIVE_TASK* atp = active_tasks[i];
|
|
|
|
atp->init(atp->result);
|
|
|
|
atp->scheduler_state = CPU_SCHED_PREEMPTED;
|
2009-04-15 06:22:53 +00:00
|
|
|
atp->read_task_state_file();
|
2006-06-19 04:29:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-03 19:35:33 +00:00
|
|
|
#endif
|
|
|
|
|