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
|
2004-08-11 11:30:25 +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.
|
2005-01-20 23:22:22 +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.
|
|
|
|
//
|
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/>.
|
2004-08-11 11:30:25 +00:00
|
|
|
|
|
|
|
// monitoring and process control of running apps
|
|
|
|
|
|
|
|
#include "cpp.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
2007-02-20 16:27:15 +00:00
|
|
|
#include "win_util.h"
|
2009-08-22 17:00:19 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define snprintf _snprintf
|
|
|
|
#endif
|
2008-01-08 19:45:28 +00:00
|
|
|
#ifndef STATUS_SUCCESS
|
|
|
|
#define STATUS_SUCCESS 0x0 // may be in ntstatus.h
|
|
|
|
#endif
|
|
|
|
#ifndef STATUS_DLL_INIT_FAILED
|
|
|
|
#define STATUS_DLL_INIT_FAILED 0xC0000142 // may be in ntstatus.h
|
|
|
|
#endif
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
#else
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2008-07-09 11:08:53 +00:00
|
|
|
#include <string>
|
2004-08-11 11:30:25 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#if HAVE_SYS_IPC_H
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#endif
|
2004-08-11 15:27:46 +00:00
|
|
|
#if HAVE_SYS_RESOURCE_H
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#endif
|
2011-09-27 19:45:27 +00:00
|
|
|
#if HAVE_CSIGNAL
|
2005-11-21 18:34:44 +00:00
|
|
|
#include <csignal>
|
2011-09-27 19:45:27 +00:00
|
|
|
#elif HAVE_SYS_SIGNAL_H
|
2004-08-11 11:30:25 +00:00
|
|
|
#include <sys/signal.h>
|
2011-09-27 19:45:27 +00:00
|
|
|
#elif HAVE_SIGNAL_H
|
2005-11-21 18:34:44 +00:00
|
|
|
#include <signal.h>
|
2004-08-11 11:30:25 +00:00
|
|
|
#endif
|
2004-08-11 15:27:46 +00:00
|
|
|
#if HAVE_SYS_WAIT_H
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2008-07-01 21:27:25 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
#include "filesys.h"
|
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "util.h"
|
2007-02-21 16:26:51 +00:00
|
|
|
#include "str_util.h"
|
2004-08-11 11:30:25 +00:00
|
|
|
#include "parse.h"
|
|
|
|
#include "shmem.h"
|
|
|
|
#include "client_msgs.h"
|
|
|
|
#include "client_state.h"
|
|
|
|
#include "file_names.h"
|
2011-09-02 18:23:13 +00:00
|
|
|
#include "proc_control.h"
|
2007-10-05 16:47:07 +00:00
|
|
|
#include "sandbox.h"
|
2004-08-11 11:30:25 +00:00
|
|
|
|
|
|
|
#include "app.h"
|
|
|
|
|
2010-09-24 20:02:42 +00:00
|
|
|
// Do periodic checks on running apps:
|
|
|
|
// - 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
|
|
|
|
//
|
|
|
|
bool ACTIVE_TASK_SET::poll() {
|
|
|
|
bool action;
|
|
|
|
unsigned int i;
|
|
|
|
static double last_time = 0;
|
|
|
|
if (gstate.now - last_time < TASK_POLL_PERIOD) return false;
|
|
|
|
last_time = gstate.now;
|
|
|
|
|
|
|
|
action = check_app_exited();
|
|
|
|
send_heartbeats();
|
|
|
|
send_trickle_downs();
|
|
|
|
process_control_poll();
|
|
|
|
action |= check_rsc_limits_exceeded();
|
|
|
|
get_msgs();
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
ACTIVE_TASK* atp = active_tasks[i];
|
|
|
|
if (atp->task_state() == PROCESS_ABORT_PENDING) {
|
|
|
|
if (gstate.now > atp->abort_time + ABORT_TIMEOUT) {
|
|
|
|
atp->kill_task(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (atp->task_state() == PROCESS_QUIT_PENDING) {
|
|
|
|
if (gstate.now > atp->quit_time + QUIT_TIMEOUT) {
|
|
|
|
atp->kill_task(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
gstate.set_client_state_dirty("ACTIVE_TASK_SET::poll");
|
|
|
|
}
|
|
|
|
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2010-05-24 23:14:48 +00:00
|
|
|
#if 0
|
2010-05-20 17:50:00 +00:00
|
|
|
// deprecated; TerminateProcessById() doesn't work if
|
|
|
|
// the process is running as a different user
|
|
|
|
//
|
2007-02-20 18:25:04 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
bool ACTIVE_TASK::kill_all_children() {
|
2011-01-06 23:09:13 +00:00
|
|
|
unsigned int i,j;
|
2007-02-20 18:25:04 +00:00
|
|
|
std::vector<PROCINFO> ps;
|
|
|
|
std::vector<PROCINFO> tps;
|
|
|
|
|
2010-05-24 23:14:48 +00:00
|
|
|
procinfo_setup(ps);
|
2007-02-20 18:25:04 +00:00
|
|
|
|
|
|
|
PROCINFO pi;
|
|
|
|
pi.id = pid;
|
|
|
|
tps.push_back(pi);
|
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
for (i=0; i < tps.size(); i++) {
|
|
|
|
PROCINFO tp = tps[i];
|
|
|
|
for (j=0; j < ps.size(); j++) {
|
|
|
|
PROCINFO p = ps[j];
|
2007-02-20 18:25:04 +00:00
|
|
|
if (tp.id == p.parentid) {
|
|
|
|
if (TerminateProcessById(p.id)) {
|
|
|
|
tps.push_back(p);
|
|
|
|
}
|
|
|
|
}
|
2011-01-06 23:09:13 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-20 18:25:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-24 23:14:48 +00:00
|
|
|
#endif
|
2007-02-20 18:25:04 +00:00
|
|
|
|
2004-08-23 22:06:48 +00:00
|
|
|
// Send a quit message.
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
|
|
|
int ACTIVE_TASK::request_exit() {
|
2004-08-24 21:44:54 +00:00
|
|
|
if (!app_client_shm.shm) return 1;
|
2004-09-13 05:27:28 +00:00
|
|
|
process_control_queue.msg_queue_send(
|
2011-01-06 23:09:13 +00:00
|
|
|
"<quit/>",
|
2004-09-13 05:27:28 +00:00
|
|
|
app_client_shm.shm->process_control_request
|
|
|
|
);
|
2011-06-17 04:18:28 +00:00
|
|
|
set_task_state(PROCESS_QUIT_PENDING, "request_exit()");
|
2008-05-05 00:51:20 +00:00
|
|
|
quit_time = gstate.now;
|
2011-06-17 04:18:28 +00:00
|
|
|
get_descendants(pid, descendants);
|
2004-08-11 11:30:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-03 20:48:48 +00:00
|
|
|
// Send an abort message.
|
|
|
|
//
|
|
|
|
int ACTIVE_TASK::request_abort() {
|
|
|
|
if (!app_client_shm.shm) return 1;
|
|
|
|
process_control_queue.msg_queue_send(
|
2011-01-06 23:09:13 +00:00
|
|
|
"<abort/>",
|
2006-02-03 20:48:48 +00:00
|
|
|
app_client_shm.shm->process_control_request
|
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-31 23:39:50 +00:00
|
|
|
static void kill_app_process(int pid) {
|
2004-08-11 11:30:25 +00:00
|
|
|
#ifdef _WIN32
|
2011-05-31 23:39:50 +00:00
|
|
|
HANDLE h = OpenProcess(READ_CONTROL | PROCESS_TERMINATE, false, pid);
|
2011-05-31 23:44:39 +00:00
|
|
|
if (h == NULL) return;
|
2011-05-31 23:39:50 +00:00
|
|
|
TerminateProcess(h, 1);
|
|
|
|
CloseHandle(h);
|
2004-08-11 11:30:25 +00:00
|
|
|
#else
|
2007-02-28 16:10:17 +00:00
|
|
|
#ifdef SANDBOX
|
2007-10-05 16:47:07 +00:00
|
|
|
kill_via_switcher(pid);
|
2007-02-28 16:10:17 +00:00
|
|
|
#endif
|
2006-07-22 18:24:01 +00:00
|
|
|
kill(pid, SIGKILL);
|
2004-08-11 11:30:25 +00:00
|
|
|
#endif
|
2011-05-31 23:39:50 +00:00
|
|
|
}
|
|
|
|
|
2011-06-17 04:18:28 +00:00
|
|
|
static inline void kill_processes(vector<int> pids) {
|
|
|
|
for (unsigned int i=0; i<pids.size(); i++) {
|
|
|
|
kill_app_process(pids[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-31 23:39:50 +00:00
|
|
|
// Kill the task (and descendants) by OS-specific means.
|
|
|
|
//
|
|
|
|
int ACTIVE_TASK::kill_task(bool restart) {
|
|
|
|
vector<int>pids;
|
2011-06-01 00:00:30 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
// On Win, in protected mode we won't be able to get
|
|
|
|
// handles for the descendant processes;
|
|
|
|
// all we can do is terminate the main process,
|
|
|
|
// using the handle we got when we created it.
|
|
|
|
//
|
2011-06-07 20:55:31 +00:00
|
|
|
if (g_use_sandbox) {
|
|
|
|
TerminateProcess(process_handle, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-06-01 00:00:30 +00:00
|
|
|
#endif
|
2011-05-31 23:39:50 +00:00
|
|
|
get_descendants(pid, pids);
|
|
|
|
pids.push_back(pid);
|
2011-06-17 04:18:28 +00:00
|
|
|
kill_processes(pids);
|
2008-08-16 20:59:53 +00:00
|
|
|
cleanup_task();
|
2011-01-06 23:09:13 +00:00
|
|
|
if (restart) {
|
|
|
|
set_task_state(PROCESS_UNINITIALIZED, "kill_task");
|
2009-12-14 19:24:06 +00:00
|
|
|
char buf[256];
|
|
|
|
sprintf(buf, "restarting %s", result->name);
|
2011-01-06 23:09:13 +00:00
|
|
|
gstate.request_schedule_cpus(buf);
|
|
|
|
} else {
|
|
|
|
set_task_state(PROCESS_ABORTED, "kill_task");
|
|
|
|
}
|
2006-07-22 18:24:01 +00:00
|
|
|
return 0;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
|
2004-08-23 22:06:48 +00:00
|
|
|
// We have sent a quit request to the process; see if it's exited.
|
2004-08-11 11:30:25 +00:00
|
|
|
// This is called when the core client exits,
|
|
|
|
// or when a project is detached or reset
|
|
|
|
//
|
2004-08-23 22:06:48 +00:00
|
|
|
bool ACTIVE_TASK::has_task_exited() {
|
2004-08-11 11:30:25 +00:00
|
|
|
bool exited = false;
|
2004-08-23 22:06:48 +00:00
|
|
|
|
|
|
|
if (!process_exists()) return true;
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
unsigned long exit_code;
|
2010-04-23 22:31:08 +00:00
|
|
|
if (GetExitCodeProcess(process_handle, &exit_code)) {
|
2004-08-11 11:30:25 +00:00
|
|
|
if (exit_code != STILL_ACTIVE) {
|
|
|
|
exited = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2005-08-04 00:12:50 +00:00
|
|
|
if (waitpid(pid, 0, WNOHANG) == pid) {
|
2004-08-11 11:30:25 +00:00
|
|
|
exited = true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (exited) {
|
2007-01-24 21:20:57 +00:00
|
|
|
set_task_state(PROCESS_EXITED, "has_task_exited");
|
2005-02-25 21:31:46 +00:00
|
|
|
cleanup_task();
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
return exited;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-25 19:20:45 +00:00
|
|
|
static void limbo_message(ACTIVE_TASK& at) {
|
2007-11-05 15:03:16 +00:00
|
|
|
#ifdef _WIN32
|
2007-12-03 17:46:07 +00:00
|
|
|
if (at.result->exit_status == STATUS_DLL_INIT_FAILED) {
|
2007-11-05 15:03:16 +00:00
|
|
|
msg_printf(at.result->project, MSG_INFO,
|
|
|
|
"Task %s exited with a DLL initialization error.",
|
|
|
|
at.result->name
|
|
|
|
);
|
|
|
|
msg_printf(at.result->project, MSG_INFO,
|
|
|
|
"If this happens repeatedly you may need to reboot your computer."
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
msg_printf(at.result->project, MSG_INFO,
|
|
|
|
"Task %s exited with zero status but no 'finished' file",
|
|
|
|
at.result->name
|
|
|
|
);
|
|
|
|
msg_printf(at.result->project, MSG_INFO,
|
|
|
|
"If this happens repeatedly you may need to reset the project."
|
|
|
|
);
|
|
|
|
#ifdef _WIN32
|
|
|
|
}
|
|
|
|
#endif
|
2004-08-25 19:20:45 +00:00
|
|
|
}
|
|
|
|
|
2011-09-27 17:20:31 +00:00
|
|
|
// the job just exited. If it's a GPU job,
|
|
|
|
// clear the "schedule_backoff" field of all other jobs
|
|
|
|
// that use the GPU type, in case they're waiting for GPU RAM
|
|
|
|
//
|
|
|
|
static void clear_schedule_backoffs(ACTIVE_TASK* atp) {
|
2010-04-18 05:29:29 +00:00
|
|
|
int rt = atp->result->avp->rsc_type();
|
|
|
|
if (rt == RSC_TYPE_CPU) return;
|
|
|
|
for (unsigned int i=0; i<gstate.results.size(); i++) {
|
|
|
|
RESULT* rp = gstate.results[i];
|
|
|
|
if (rp->avp->rsc_type() == rt) {
|
|
|
|
rp->schedule_backoff = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-17 04:18:28 +00:00
|
|
|
// handle a task that exited prematurely (i.e. no finish file)
|
2007-07-20 23:42:20 +00:00
|
|
|
//
|
2007-11-27 21:54:17 +00:00
|
|
|
void ACTIVE_TASK::handle_premature_exit(bool& will_restart) {
|
2011-06-17 04:18:28 +00:00
|
|
|
switch (task_state()) {
|
|
|
|
case PROCESS_QUIT_PENDING:
|
2007-11-27 21:54:17 +00:00
|
|
|
set_task_state(PROCESS_UNINITIALIZED, "handle_premature_exit");
|
2007-07-20 23:42:20 +00:00
|
|
|
will_restart = true;
|
2011-06-17 04:18:28 +00:00
|
|
|
kill_processes(descendants);
|
|
|
|
return;
|
|
|
|
case PROCESS_ABORT_PENDING:
|
|
|
|
set_task_state(PROCESS_UNINITIALIZED, "handle_premature_exit");
|
|
|
|
will_restart = false;
|
|
|
|
kill_processes(descendants);
|
2007-07-20 23:42:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-11-27 21:54:17 +00:00
|
|
|
// otherwise keep count of exits;
|
|
|
|
// restart it unless this happens 100 times w/o a checkpoint
|
2007-07-20 23:42:20 +00:00
|
|
|
//
|
|
|
|
premature_exit_count++;
|
|
|
|
if (premature_exit_count > 100) {
|
2007-11-27 21:54:17 +00:00
|
|
|
set_task_state(PROCESS_ABORTED, "handle_premature_exit");
|
2007-07-20 23:42:20 +00:00
|
|
|
result->exit_status = ERR_TOO_MANY_EXITS;
|
2008-02-10 05:17:57 +00:00
|
|
|
gstate.report_result_error(*result, "too many exit(0)s");
|
2007-11-27 21:54:17 +00:00
|
|
|
result->set_state(RESULT_ABORTED, "handle_premature_exit");
|
2007-07-20 23:42:20 +00:00
|
|
|
} else {
|
|
|
|
will_restart = true;
|
|
|
|
limbo_message(*this);
|
2007-11-27 21:54:17 +00:00
|
|
|
set_task_state(PROCESS_UNINITIALIZED, "handle_premature_exit");
|
2007-07-20 23:42:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-24 19:31:49 +00:00
|
|
|
// deal with a process that has exited, for whatever reason:
|
|
|
|
// - completion
|
|
|
|
// - crash
|
|
|
|
// - preemption via quit
|
2004-08-23 22:06:48 +00:00
|
|
|
//
|
2004-08-11 11:30:25 +00:00
|
|
|
#ifdef _WIN32
|
2005-12-09 07:50:35 +00:00
|
|
|
void ACTIVE_TASK::handle_exited_app(unsigned long exit_code) {
|
2006-06-14 18:04:12 +00:00
|
|
|
#else
|
|
|
|
void ACTIVE_TASK::handle_exited_app(int stat) {
|
|
|
|
#endif
|
2007-01-24 19:31:49 +00:00
|
|
|
bool will_restart = false;
|
|
|
|
|
|
|
|
if (log_flags.task_debug) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[task] Process for %s exited",
|
2007-01-24 19:31:49 +00:00
|
|
|
result->name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2005-04-05 00:32:24 +00:00
|
|
|
get_app_status_msg();
|
2004-08-24 21:44:54 +00:00
|
|
|
get_trickle_up_msg();
|
2005-03-30 21:11:49 +00:00
|
|
|
result->final_cpu_time = current_cpu_time;
|
2009-03-11 22:01:38 +00:00
|
|
|
result->final_elapsed_time = elapsed_time;
|
2007-01-24 21:20:57 +00:00
|
|
|
if (task_state() == PROCESS_ABORT_PENDING) {
|
|
|
|
set_task_state(PROCESS_ABORTED, "handle_exited_app");
|
2004-08-11 11:30:25 +00:00
|
|
|
} else {
|
2006-06-14 18:04:12 +00:00
|
|
|
#ifdef _WIN32
|
2007-01-24 19:31:49 +00:00
|
|
|
result->exit_status = exit_code;
|
2007-11-05 15:03:16 +00:00
|
|
|
switch(exit_code) {
|
2007-11-27 21:54:17 +00:00
|
|
|
case STATUS_SUCCESS:
|
|
|
|
// if another process killed the app, it looks like exit(0).
|
|
|
|
// So check for the finish file
|
|
|
|
//
|
|
|
|
if (finish_file_present()) {
|
2007-11-05 15:03:16 +00:00
|
|
|
set_task_state(PROCESS_EXITED, "handle_exited_app");
|
|
|
|
break;
|
2007-11-27 21:54:17 +00:00
|
|
|
}
|
2009-12-13 05:16:40 +00:00
|
|
|
double x;
|
|
|
|
if (temporary_exit_file_present(x)) {
|
2010-08-28 20:57:46 +00:00
|
|
|
if (log_flags.task_debug) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"[task] task called temporary_exit(%f)", x
|
|
|
|
);
|
|
|
|
}
|
2009-12-13 05:16:40 +00:00
|
|
|
set_task_state(PROCESS_UNINITIALIZED, "temporary exit");
|
|
|
|
will_restart = true;
|
|
|
|
result->schedule_backoff = gstate.now + x;
|
|
|
|
break;
|
|
|
|
}
|
2007-11-27 21:54:17 +00:00
|
|
|
handle_premature_exit(will_restart);
|
|
|
|
break;
|
2008-01-08 19:45:28 +00:00
|
|
|
case 0xc000013a: // control-C??
|
|
|
|
case 0x40010004: // vista shutdown?? can someone explain this?
|
2007-11-27 21:54:17 +00:00
|
|
|
case STATUS_DLL_INIT_FAILED:
|
|
|
|
// This can happen because:
|
2008-01-14 19:59:16 +00:00
|
|
|
// - The OS is shutting down, and attempting to start
|
|
|
|
// any new application fails automatically.
|
2007-11-27 21:54:17 +00:00
|
|
|
// - The OS has run out of desktop heap
|
2008-01-14 19:59:16 +00:00
|
|
|
// - (reportedly) The computer has just come out of hibernation
|
2007-11-27 21:54:17 +00:00
|
|
|
//
|
|
|
|
handle_premature_exit(will_restart);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
char szError[1024];
|
|
|
|
set_task_state(PROCESS_EXITED, "handle_exited_app");
|
|
|
|
gstate.report_result_error(
|
|
|
|
*result,
|
|
|
|
"%s - exit code %d (0x%x)",
|
|
|
|
windows_format_error_string(exit_code, szError, sizeof(szError)),
|
|
|
|
exit_code, exit_code
|
|
|
|
);
|
|
|
|
if (log_flags.task_debug) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[task] Process for %s exited",
|
2007-11-27 21:54:17 +00:00
|
|
|
result->name
|
|
|
|
);
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[task] exit code %d (0x%x): %s",
|
2007-11-27 21:54:17 +00:00
|
|
|
exit_code, exit_code,
|
|
|
|
windows_format_error_string(exit_code, szError, sizeof(szError))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (WIFEXITED(stat)) {
|
2007-04-05 10:46:24 +00:00
|
|
|
result->exit_status = WEXITSTATUS(stat);
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2005-01-21 23:26:36 +00:00
|
|
|
if (result->exit_status) {
|
2007-02-15 21:11:05 +00:00
|
|
|
set_task_state(PROCESS_EXITED, "handle_exited_app");
|
2004-08-11 11:30:25 +00:00
|
|
|
gstate.report_result_error(
|
2004-10-07 19:18:37 +00:00
|
|
|
*result,
|
2007-06-04 20:32:47 +00:00
|
|
|
"process exited with code %d (0x%x, %d)",
|
|
|
|
result->exit_status, result->exit_status,
|
|
|
|
(-1<<8)|result->exit_status
|
2004-08-11 11:30:25 +00:00
|
|
|
);
|
|
|
|
} else {
|
2007-11-27 21:54:17 +00:00
|
|
|
if (finish_file_present()) {
|
|
|
|
set_task_state(PROCESS_EXITED, "handle_exited_app");
|
|
|
|
} else {
|
|
|
|
handle_premature_exit(will_restart);
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2010-09-17 03:57:47 +00:00
|
|
|
double x;
|
|
|
|
if (temporary_exit_file_present(x)) {
|
|
|
|
if (log_flags.task_debug) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"[task] task called temporary_exit(%f)", x
|
|
|
|
);
|
|
|
|
}
|
|
|
|
set_task_state(PROCESS_UNINITIALIZED, "temporary exit");
|
|
|
|
will_restart = true;
|
|
|
|
result->schedule_backoff = gstate.now + x;
|
|
|
|
} else {
|
|
|
|
if (log_flags.task_debug) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"[task] process exited with status %d\n",
|
|
|
|
result->exit_status
|
|
|
|
);
|
|
|
|
}
|
2006-06-22 19:40:30 +00:00
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
} else if (WIFSIGNALED(stat)) {
|
2004-10-07 19:18:37 +00:00
|
|
|
int got_signal = WTERMSIG(stat);
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2007-01-24 19:31:49 +00:00
|
|
|
if (log_flags.task_debug) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[task] process got signal %d", signal
|
2007-01-24 19:31:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
// if the process was externally killed, allow it to restart.
|
|
|
|
//
|
2004-11-18 22:18:00 +00:00
|
|
|
switch (got_signal) {
|
2004-08-11 11:30:25 +00:00
|
|
|
case SIGHUP:
|
|
|
|
case SIGINT:
|
|
|
|
case SIGQUIT:
|
|
|
|
case SIGKILL:
|
|
|
|
case SIGTERM:
|
|
|
|
case SIGSTOP:
|
2007-01-24 19:31:49 +00:00
|
|
|
will_restart = true;
|
2007-01-24 21:20:57 +00:00
|
|
|
set_task_state(PROCESS_UNINITIALIZED, "handle_exited_app");
|
2004-08-25 19:20:45 +00:00
|
|
|
limbo_message(*this);
|
2007-01-24 19:31:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result->exit_status = stat;
|
2007-01-24 21:20:57 +00:00
|
|
|
set_task_state(PROCESS_WAS_SIGNALED, "handle_exited_app");
|
2007-01-24 19:31:49 +00:00
|
|
|
signal = got_signal;
|
|
|
|
gstate.report_result_error(
|
|
|
|
*result, "process got signal %d", signal
|
2006-06-22 19:40:30 +00:00
|
|
|
);
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
} else {
|
2007-01-23 17:24:43 +00:00
|
|
|
result->exit_status = -1;
|
2007-01-24 21:20:57 +00:00
|
|
|
set_task_state(PROCESS_EXIT_UNKNOWN, "handle_exited_app");
|
2007-01-23 17:24:43 +00:00
|
|
|
gstate.report_result_error(*result, "process exit, unknown");
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(result->project, MSG_INTERNAL_ERROR,
|
2007-01-24 19:31:49 +00:00
|
|
|
"process exited for unknown reason"
|
2007-01-23 17:24:43 +00:00
|
|
|
);
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2006-06-14 18:04:12 +00:00
|
|
|
#endif
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
|
2008-08-16 20:59:53 +00:00
|
|
|
cleanup_task();
|
|
|
|
|
2010-06-02 18:21:30 +00:00
|
|
|
if (config.exit_after_finish) {
|
2008-08-16 20:59:53 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2007-01-24 19:31:49 +00:00
|
|
|
if (!will_restart) {
|
|
|
|
copy_output_files();
|
2011-10-05 22:16:02 +00:00
|
|
|
int retval = read_stderr_file();
|
|
|
|
if (retval) {
|
|
|
|
msg_printf(result->project, MSG_INTERNAL_ERROR,
|
|
|
|
"read_stderr_file(): %s", boincerror(retval)
|
|
|
|
);
|
|
|
|
}
|
2009-05-28 19:26:27 +00:00
|
|
|
client_clean_out_dir(slot_dir, "handle_exited_app()");
|
2011-09-27 17:20:31 +00:00
|
|
|
clear_schedule_backoffs(this);
|
|
|
|
// clear scheduling backoffs of jobs waiting for GPU
|
2006-06-14 18:04:12 +00:00
|
|
|
}
|
2005-12-09 07:50:35 +00:00
|
|
|
gstate.request_schedule_cpus("application exited");
|
2006-08-11 04:16:23 +00:00
|
|
|
gstate.request_work_fetch("application exited");
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ACTIVE_TASK::finish_file_present() {
|
|
|
|
char path[256];
|
2006-03-03 21:34:03 +00:00
|
|
|
sprintf(path, "%s/%s", slot_dir, BOINC_FINISH_CALLED_FILE);
|
2006-01-20 20:58:33 +00:00
|
|
|
return (boinc_file_exists(path) != 0);
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
|
2009-12-13 05:16:40 +00:00
|
|
|
bool ACTIVE_TASK::temporary_exit_file_present(double& x) {
|
|
|
|
char path[256];
|
|
|
|
sprintf(path, "%s/%s", slot_dir, TEMPORARY_EXIT_FILE);
|
|
|
|
FILE* f = fopen(path, "r");
|
|
|
|
if (!f) return false;
|
2009-12-14 05:26:21 +00:00
|
|
|
int y;
|
2009-12-13 05:16:40 +00:00
|
|
|
int n = fscanf(f, "%d", &y);
|
|
|
|
fclose(f);
|
|
|
|
if (n != 1 || y < 0 || y > 86400) {
|
|
|
|
x = 300;
|
|
|
|
} else {
|
|
|
|
x = y;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
void ACTIVE_TASK_SET::send_trickle_downs() {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
bool sent;
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2004-08-23 22:06:48 +00:00
|
|
|
if (!atp->process_exists()) continue;
|
2004-08-11 11:30:25 +00:00
|
|
|
if (atp->have_trickle_down) {
|
2004-08-24 21:44:54 +00:00
|
|
|
if (!atp->app_client_shm.shm) continue;
|
2004-08-11 11:30:25 +00:00
|
|
|
sent = atp->app_client_shm.shm->trickle_down.send_msg("<have_trickle_down/>\n");
|
|
|
|
if (sent) atp->have_trickle_down = false;
|
|
|
|
}
|
2005-04-28 23:19:58 +00:00
|
|
|
if (atp->send_upload_file_status) {
|
|
|
|
if (!atp->app_client_shm.shm) continue;
|
|
|
|
sent = atp->app_client_shm.shm->trickle_down.send_msg("<upload_file_status/>\n");
|
|
|
|
if (sent) atp->send_upload_file_status = false;
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ACTIVE_TASK_SET::send_heartbeats() {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
2011-01-06 23:09:13 +00:00
|
|
|
char buf[1024];
|
|
|
|
double ar = gstate.available_ram();
|
2004-08-11 11:30:25 +00:00
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2004-08-23 22:06:48 +00:00
|
|
|
if (!atp->process_exists()) continue;
|
2004-08-24 21:44:54 +00:00
|
|
|
if (!atp->app_client_shm.shm) continue;
|
2011-01-06 23:09:13 +00:00
|
|
|
snprintf(buf, sizeof(buf), "<heartbeat/>"
|
|
|
|
"<wss>%e</wss>"
|
|
|
|
"<max_wss>%e</max_wss>",
|
|
|
|
atp->procinfo.working_set_size, ar
|
|
|
|
);
|
2011-03-20 07:04:32 +00:00
|
|
|
if (gstate.network_suspended) {
|
|
|
|
strcat(buf, "<network_suspended/>");
|
|
|
|
}
|
2008-08-22 04:50:30 +00:00
|
|
|
bool sent = atp->app_client_shm.shm->heartbeat.send_msg(buf);
|
2011-04-14 01:04:10 +00:00
|
|
|
if (log_flags.heartbeat_debug) {
|
2008-08-22 04:50:30 +00:00
|
|
|
if (sent) {
|
|
|
|
msg_printf(atp->result->project, MSG_INFO,
|
2011-04-14 01:04:10 +00:00
|
|
|
"[heartbeat] Heartbeat sent to task %s",
|
2008-08-22 04:50:30 +00:00
|
|
|
atp->result->name
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
msg_printf(atp->result->project, MSG_INFO,
|
2011-04-14 01:04:10 +00:00
|
|
|
"[heartbeat] Heartbeat to task %s failed, previous message unread",
|
2008-08-22 04:50:30 +00:00
|
|
|
atp->result->name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-13 05:27:28 +00:00
|
|
|
void ACTIVE_TASK_SET::process_control_poll() {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
|
|
|
if (!atp->process_exists()) continue;
|
|
|
|
if (!atp->app_client_shm.shm) continue;
|
2006-12-09 00:10:53 +00:00
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
// if app has had the same message in its send buffer for 180 sec,
|
|
|
|
// assume it's hung and restart it
|
|
|
|
//
|
|
|
|
if (atp->process_control_queue.timeout(180)) {
|
2007-06-04 20:32:47 +00:00
|
|
|
if (log_flags.task_debug) {
|
2009-02-23 04:54:04 +00:00
|
|
|
msg_printf(atp->result->project, MSG_INFO,
|
2007-06-04 20:32:47 +00:00
|
|
|
"Restarting %s - message timeout", atp->result->name
|
|
|
|
);
|
|
|
|
}
|
2011-01-06 23:09:13 +00:00
|
|
|
atp->kill_task(true);
|
|
|
|
} else {
|
|
|
|
atp->process_control_queue.msg_queue_poll(
|
|
|
|
atp->app_client_shm.shm->process_control_request
|
|
|
|
);
|
|
|
|
}
|
2004-09-13 05:27:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-23 22:06:48 +00:00
|
|
|
// See if any processes have exited
|
|
|
|
//
|
2004-08-11 11:30:25 +00:00
|
|
|
bool ACTIVE_TASK_SET::check_app_exited() {
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
unsigned long exit_code;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2004-08-23 22:06:48 +00:00
|
|
|
if (!atp->process_exists()) continue;
|
2010-04-23 22:31:08 +00:00
|
|
|
if (GetExitCodeProcess(atp->process_handle, &exit_code)) {
|
2004-08-11 11:30:25 +00:00
|
|
|
if (exit_code != STILL_ACTIVE) {
|
|
|
|
found = true;
|
|
|
|
atp->handle_exited_app(exit_code);
|
|
|
|
}
|
2005-11-09 01:51:36 +00:00
|
|
|
} else {
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.task_debug) {
|
|
|
|
char errmsg[1024];
|
2009-02-23 04:54:04 +00:00
|
|
|
msg_printf(atp->result->project, MSG_INFO,
|
2010-04-29 20:32:51 +00:00
|
|
|
"[task] task %s GetExitCodeProcess() failed - %s GLE %d (0x%x)",
|
2006-11-01 23:36:13 +00:00
|
|
|
atp->result->name,
|
|
|
|
windows_format_error_string(
|
|
|
|
GetLastError(), errmsg, sizeof(errmsg)
|
|
|
|
),
|
2006-06-22 19:40:30 +00:00
|
|
|
GetLastError(), GetLastError()
|
|
|
|
);
|
|
|
|
}
|
2006-11-01 23:36:13 +00:00
|
|
|
|
|
|
|
// The process doesn't seem to be there.
|
|
|
|
// Mark task as aborted so we don't check it again.
|
|
|
|
//
|
2007-01-24 21:20:57 +00:00
|
|
|
atp->set_task_state(PROCESS_ABORTED, "check_app_exited");
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2005-08-04 00:12:50 +00:00
|
|
|
int pid, stat;
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2009-11-11 00:28:51 +00:00
|
|
|
if ((pid = waitpid(-1, &stat, WNOHANG)) > 0) {
|
2004-08-11 11:30:25 +00:00
|
|
|
atp = lookup_pid(pid);
|
|
|
|
if (!atp) {
|
2005-10-09 05:53:35 +00:00
|
|
|
// if we're running benchmarks, exited process
|
2005-12-09 07:50:35 +00:00
|
|
|
// is probably a benchmark process; don't show error
|
2005-10-09 05:53:35 +00:00
|
|
|
//
|
2007-04-03 17:16:39 +00:00
|
|
|
if (!gstate.are_cpu_benchmarks_running() && log_flags.task_debug) {
|
2009-10-05 22:42:06 +00:00
|
|
|
msg_printf(NULL, MSG_INTERNAL_ERROR,
|
2009-02-23 04:54:04 +00:00
|
|
|
"Process %d not found\n", pid
|
|
|
|
);
|
2005-10-09 05:53:35 +00:00
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-09-22 21:08:26 +00:00
|
|
|
atp->handle_exited_app(stat);
|
2004-08-11 11:30:25 +00:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
#endif
|
2004-09-24 22:19:02 +00:00
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if an app has exceeded its maximum disk usage, abort it
|
|
|
|
//
|
|
|
|
bool ACTIVE_TASK::check_max_disk_exceeded() {
|
|
|
|
double disk_usage;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = current_disk_usage(disk_usage);
|
|
|
|
if (retval) {
|
2009-02-23 04:54:04 +00:00
|
|
|
msg_printf(this->wup->project, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"Can't get task disk usage: %s", boincerror(retval)
|
|
|
|
);
|
2004-08-11 11:30:25 +00:00
|
|
|
} else {
|
|
|
|
if (disk_usage > max_disk_usage) {
|
|
|
|
msg_printf(
|
|
|
|
result->project, MSG_INFO,
|
2006-10-06 19:16:59 +00:00
|
|
|
"Aborting task %s: exceeded disk limit: %.2fMB > %.2fMB\n",
|
|
|
|
result->name, disk_usage/MEGA, max_disk_usage/MEGA
|
2004-08-11 11:30:25 +00:00
|
|
|
);
|
2005-06-25 23:54:07 +00:00
|
|
|
abort_task(ERR_RSC_LIMIT_EXCEEDED, "Maximum disk usage exceeded");
|
2004-08-11 11:30:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if any of the active tasks have exceeded their
|
|
|
|
// resource limits on disk, CPU time or memory
|
|
|
|
//
|
|
|
|
bool ACTIVE_TASK_SET::check_rsc_limits_exceeded() {
|
2006-10-02 23:42:38 +00:00
|
|
|
unsigned int i;
|
2004-08-11 11:30:25 +00:00
|
|
|
ACTIVE_TASK *atp;
|
2004-11-15 21:20:58 +00:00
|
|
|
static double last_disk_check_time = 0;
|
2005-11-23 03:23:13 +00:00
|
|
|
bool do_disk_check = false;
|
|
|
|
bool did_anything = false;
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
double ram_left = gstate.available_ram();
|
|
|
|
double max_ram = gstate.max_available_ram();
|
2006-10-02 23:42:38 +00:00
|
|
|
|
2006-06-13 20:27:35 +00:00
|
|
|
// Some slot dirs have lots of files,
|
|
|
|
// so only check every min(disk_interval, 300) secs
|
2005-11-23 03:23:13 +00:00
|
|
|
//
|
2006-06-13 20:27:35 +00:00
|
|
|
double min_interval = gstate.global_prefs.disk_interval;
|
|
|
|
if (min_interval < 300) min_interval = 300;
|
|
|
|
if (gstate.now > last_disk_check_time + min_interval) {
|
2005-11-23 03:23:13 +00:00
|
|
|
do_disk_check = true;
|
|
|
|
}
|
2006-10-02 23:42:38 +00:00
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2007-01-24 21:20:57 +00:00
|
|
|
if (atp->task_state() != PROCESS_EXECUTING) continue;
|
2011-05-25 21:16:45 +00:00
|
|
|
if (!atp->result->non_cpu_intensive() && (atp->elapsed_time > atp->max_elapsed_time)) {
|
2011-01-06 23:09:13 +00:00
|
|
|
msg_printf(atp->result->project, MSG_INFO,
|
|
|
|
"Aborting task %s: exceeded elapsed time limit %.2f (%.2fG/%.2fG)",
|
|
|
|
atp->result->name, atp->max_elapsed_time,
|
2010-05-19 19:48:57 +00:00
|
|
|
atp->result->wup->rsc_fpops_bound/1e9,
|
|
|
|
atp->result->avp->flops/1e9
|
2011-01-06 23:09:13 +00:00
|
|
|
);
|
|
|
|
atp->abort_task(ERR_RSC_LIMIT_EXCEEDED, "Maximum elapsed time exceeded");
|
|
|
|
did_anything = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (atp->procinfo.working_set_size_smoothed > max_ram) {
|
|
|
|
msg_printf(atp->result->project, MSG_INFO,
|
|
|
|
"Aborting task %s: exceeded memory limit %.2fMB > %.2fMB\n",
|
|
|
|
atp->result->name,
|
|
|
|
atp->procinfo.working_set_size_smoothed/MEGA, max_ram/MEGA
|
|
|
|
);
|
|
|
|
atp->abort_task(ERR_RSC_LIMIT_EXCEEDED, "Maximum memory exceeded");
|
|
|
|
did_anything = true;
|
|
|
|
continue;
|
|
|
|
}
|
2006-10-02 23:42:38 +00:00
|
|
|
if (do_disk_check && atp->check_max_disk_exceeded()) {
|
2005-11-23 03:23:13 +00:00
|
|
|
did_anything = true;
|
2011-01-06 23:09:13 +00:00
|
|
|
continue;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2011-01-06 23:09:13 +00:00
|
|
|
ram_left -= atp->procinfo.working_set_size_smoothed;
|
|
|
|
}
|
|
|
|
if (ram_left < 0) {
|
|
|
|
gstate.request_schedule_cpus("RAM usage limit exceeded");
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2005-11-23 03:23:13 +00:00
|
|
|
if (do_disk_check) {
|
|
|
|
last_disk_check_time = gstate.now;
|
|
|
|
}
|
|
|
|
return did_anything;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
|
2006-02-03 20:48:48 +00:00
|
|
|
// If process is running, send it an "abort" message,
|
2007-01-11 00:20:58 +00:00
|
|
|
// Set a flag so that if it doesn't exit within 5 seconds,
|
2006-02-03 20:48:48 +00:00
|
|
|
// kill it by OS-specific mechanism (e.g. KILL signal).
|
|
|
|
// This is done when app has exceeded CPU, disk, or mem limits,
|
|
|
|
// or when the user has requested it.
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
2005-06-25 23:54:07 +00:00
|
|
|
int ACTIVE_TASK::abort_task(int exit_status, const char* msg) {
|
2007-01-24 21:20:57 +00:00
|
|
|
if (task_state() == PROCESS_EXECUTING || task_state() == PROCESS_SUSPENDED) {
|
|
|
|
set_task_state(PROCESS_ABORT_PENDING, "abort_task");
|
2006-02-03 20:48:48 +00:00
|
|
|
abort_time = gstate.now;
|
2011-01-06 23:09:13 +00:00
|
|
|
request_abort();
|
2011-06-17 04:18:28 +00:00
|
|
|
get_descendants(pid, descendants);
|
2004-08-11 11:30:25 +00:00
|
|
|
} else {
|
2007-01-24 21:20:57 +00:00
|
|
|
set_task_state(PROCESS_ABORTED, "abort_task");
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2005-06-25 23:54:07 +00:00
|
|
|
result->exit_status = exit_status;
|
2004-10-07 19:18:37 +00:00
|
|
|
gstate.report_result_error(*result, msg);
|
2007-01-24 21:20:57 +00:00
|
|
|
result->set_state(RESULT_ABORTED, "abort_task");
|
2004-08-11 11:30:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for the stderr file, copy to result record
|
|
|
|
//
|
2011-10-05 22:16:02 +00:00
|
|
|
int ACTIVE_TASK::read_stderr_file() {
|
2011-05-17 00:31:41 +00:00
|
|
|
char* buf1, *buf2;
|
2004-08-11 11:30:25 +00:00
|
|
|
char path[256];
|
|
|
|
|
2007-10-23 14:50:02 +00:00
|
|
|
// truncate stderr output to the last 63KB;
|
2007-06-22 22:18:28 +00:00
|
|
|
// it's unlikely that more than that will be useful
|
|
|
|
//
|
|
|
|
int max_len = 63*1024;
|
2006-03-03 21:34:03 +00:00
|
|
|
sprintf(path, "%s/%s", slot_dir, STDERR_FILE);
|
2011-10-05 22:16:02 +00:00
|
|
|
if (!boinc_file_exists(path)) return 0;
|
2011-05-17 00:31:41 +00:00
|
|
|
if (read_file_malloc(path, buf1, max_len, !config.stderr_head)) {
|
2011-10-05 22:16:02 +00:00
|
|
|
return ERR_MALLOC;
|
2010-01-12 18:39:59 +00:00
|
|
|
}
|
2011-05-17 00:31:41 +00:00
|
|
|
buf2 = (char*)malloc(2*max_len);
|
2011-10-05 22:16:02 +00:00
|
|
|
if (!buf2) {
|
|
|
|
free(buf1);
|
|
|
|
return ERR_MALLOC;
|
|
|
|
}
|
2011-05-25 16:40:19 +00:00
|
|
|
non_ascii_escape(buf1, buf2, 2*max_len);
|
2007-06-22 22:18:28 +00:00
|
|
|
result->stderr_out += "<stderr_txt>\n";
|
2011-05-17 00:31:41 +00:00
|
|
|
result->stderr_out += buf2;
|
2007-06-22 22:18:28 +00:00
|
|
|
result->stderr_out += "\n</stderr_txt>\n";
|
2011-10-05 22:16:02 +00:00
|
|
|
free(buf1);
|
|
|
|
free(buf2);
|
|
|
|
return 0;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// tell a running app to reread project preferences.
|
|
|
|
// This is called when project prefs change,
|
|
|
|
// or when a user file has finished downloading.
|
|
|
|
//
|
|
|
|
int ACTIVE_TASK::request_reread_prefs() {
|
|
|
|
int retval;
|
2011-09-11 17:26:31 +00:00
|
|
|
APP_INIT_DATA aid;
|
2004-08-11 11:30:25 +00:00
|
|
|
|
|
|
|
link_user_files();
|
|
|
|
|
2011-09-11 17:26:31 +00:00
|
|
|
init_app_init_data(aid);
|
|
|
|
retval = write_app_init_file(aid);
|
2004-08-11 11:30:25 +00:00
|
|
|
if (retval) return retval;
|
2005-05-20 00:48:52 +00:00
|
|
|
graphics_request_queue.msg_queue_send(
|
|
|
|
xml_graphics_modes[MODE_REREAD_PREFS],
|
|
|
|
app_client_shm.shm->graphics_request
|
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// tell a running app to reread the app_info file
|
|
|
|
// (e.g. because proxy settings have changed: this is for F@h)
|
|
|
|
//
|
|
|
|
int ACTIVE_TASK::request_reread_app_info() {
|
2011-09-11 17:26:31 +00:00
|
|
|
APP_INIT_DATA aid;
|
|
|
|
init_app_init_data(aid);
|
|
|
|
int retval = write_app_init_file(aid);
|
2005-05-20 00:48:52 +00:00
|
|
|
if (retval) return retval;
|
|
|
|
process_control_queue.msg_queue_send(
|
|
|
|
"<reread_app_info/>",
|
|
|
|
app_client_shm.shm->process_control_request
|
2004-08-11 11:30:25 +00:00
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// tell all running apps of a project to reread prefs
|
|
|
|
//
|
|
|
|
void ACTIVE_TASK_SET::request_reread_prefs(PROJECT* project) {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
|
|
|
if (atp->result->project != project) continue;
|
2004-08-23 22:06:48 +00:00
|
|
|
if (!atp->process_exists()) continue;
|
2004-08-11 11:30:25 +00:00
|
|
|
atp->request_reread_prefs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-20 00:48:52 +00:00
|
|
|
void ACTIVE_TASK_SET::request_reread_app_info() {
|
|
|
|
for (unsigned int i=0; i<active_tasks.size(); i++) {
|
|
|
|
ACTIVE_TASK* atp = active_tasks[i];
|
|
|
|
if (!atp->process_exists()) continue;
|
|
|
|
atp->request_reread_app_info();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2011-06-17 04:18:28 +00:00
|
|
|
// send quit message to all tasks in the project
|
2004-08-11 11:30:25 +00:00
|
|
|
// (or all tasks, if proj==0).
|
|
|
|
// If they don't exit in 5 seconds,
|
|
|
|
// send them a kill signal and wait up to 5 more seconds to exit.
|
|
|
|
// This is called when the core client exits,
|
|
|
|
// or when a project is detached or reset
|
|
|
|
//
|
|
|
|
int ACTIVE_TASK_SET::exit_tasks(PROJECT* proj) {
|
2011-05-20 05:38:22 +00:00
|
|
|
if (log_flags.task_debug) {
|
|
|
|
msg_printf(NULL, MSG_INFO, "[task_debug] requesting tasks to exit");
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
request_tasks_exit(proj);
|
|
|
|
|
2011-02-23 04:48:09 +00:00
|
|
|
// Wait 15 seconds for them to exit normally; if they don't then kill them
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
2011-02-23 04:48:09 +00:00
|
|
|
if (wait_for_exit(MAX_EXIT_TIME, proj)) {
|
2011-05-20 05:38:22 +00:00
|
|
|
if (log_flags.task_debug) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"[task_debug] all tasks haven't exited after %d sec; killing them",
|
|
|
|
MAX_EXIT_TIME
|
|
|
|
);
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
kill_tasks(proj);
|
2011-05-20 05:38:22 +00:00
|
|
|
if (wait_for_exit(5, proj)) {
|
|
|
|
if (log_flags.task_debug) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"[task_debug] tasks still not exited after 5 secs; giving up"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (log_flags.task_debug) {
|
|
|
|
msg_printf(NULL, MSG_INFO, "[task_debug] all tasks exited");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (log_flags.task_debug) {
|
|
|
|
msg_printf(NULL, MSG_INFO, "[task_debug] all tasks exited");
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// get final checkpoint_cpu_times
|
|
|
|
//
|
|
|
|
get_msgs();
|
|
|
|
|
2005-04-14 04:25:56 +00:00
|
|
|
gstate.request_schedule_cpus("exit_tasks");
|
2004-08-11 11:30:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait up to wait_time seconds for processes to exit
|
|
|
|
// If proj is zero, wait for all processes, else that project's
|
|
|
|
// NOTE: it's bad form to sleep, but it would be complex to avoid it here
|
|
|
|
//
|
|
|
|
int ACTIVE_TASK_SET::wait_for_exit(double wait_time, PROJECT* proj) {
|
|
|
|
bool all_exited;
|
|
|
|
unsigned int i,n;
|
|
|
|
ACTIVE_TASK *atp;
|
|
|
|
|
|
|
|
for (i=0; i<10; i++) {
|
|
|
|
all_exited = true;
|
|
|
|
|
|
|
|
for (n=0; n<active_tasks.size(); n++) {
|
|
|
|
atp = active_tasks[n];
|
|
|
|
if (proj && atp->wup->project != proj) continue;
|
2004-08-23 22:06:48 +00:00
|
|
|
if (!atp->has_task_exited()) {
|
2004-08-11 11:30:25 +00:00
|
|
|
all_exited = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (all_exited) return 0;
|
|
|
|
boinc_sleep(wait_time/10.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERR_NOT_EXITED;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ACTIVE_TASK_SET::abort_project(PROJECT* project) {
|
|
|
|
vector<ACTIVE_TASK*>::iterator task_iter;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
|
|
|
|
exit_tasks(project);
|
|
|
|
task_iter = active_tasks.begin();
|
|
|
|
while (task_iter != active_tasks.end()) {
|
|
|
|
atp = *task_iter;
|
|
|
|
if (atp->result->project == project) {
|
|
|
|
task_iter = active_tasks.erase(task_iter);
|
|
|
|
delete atp;
|
|
|
|
} else {
|
|
|
|
task_iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// suspend all currently running tasks
|
2006-11-01 23:36:13 +00:00
|
|
|
// called only from CLIENT_STATE::suspend_tasks(),
|
|
|
|
// e.g. because on batteries, time of day, benchmarking, CPU throttle, etc.
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
2010-03-02 01:24:03 +00:00
|
|
|
void ACTIVE_TASK_SET::suspend_all(int reason) {
|
2009-01-23 00:02:39 +00:00
|
|
|
for (unsigned int i=0; i<active_tasks.size(); i++) {
|
2008-10-27 20:17:22 +00:00
|
|
|
ACTIVE_TASK* atp = active_tasks[i];
|
2007-01-24 21:20:57 +00:00
|
|
|
if (atp->task_state() != PROCESS_EXECUTING) continue;
|
2010-03-02 01:24:03 +00:00
|
|
|
switch (reason) {
|
2010-03-10 18:59:40 +00:00
|
|
|
case SUSPEND_REASON_CPU_THROTTLE:
|
2011-01-06 23:09:13 +00:00
|
|
|
// if we're doing CPU throttling, don't bother suspending apps
|
|
|
|
// that don't use a full CPU
|
|
|
|
//
|
2011-06-17 19:16:07 +00:00
|
|
|
if (atp->result->dont_throttle()) continue;
|
2011-01-06 23:09:13 +00:00
|
|
|
if (atp->app_version->avg_ncpus < 1) continue;
|
2009-01-23 00:02:39 +00:00
|
|
|
atp->preempt(REMOVE_NEVER);
|
2010-03-02 01:24:03 +00:00
|
|
|
break;
|
|
|
|
case SUSPEND_REASON_BENCHMARKS:
|
|
|
|
atp->preempt(REMOVE_NEVER);
|
|
|
|
break;
|
2010-03-10 18:59:40 +00:00
|
|
|
case SUSPEND_REASON_CPU_USAGE:
|
2010-09-28 21:48:31 +00:00
|
|
|
// If we're suspending because of non-BOINC CPU load,
|
|
|
|
// don't remove from memory.
|
|
|
|
// Some systems do a security check when apps are launched,
|
|
|
|
// which uses a lot of CPU.
|
|
|
|
// Avoid going into a preemption loop.
|
|
|
|
//
|
2011-05-25 21:16:45 +00:00
|
|
|
if (atp->result->non_cpu_intensive()) break;
|
2010-09-28 21:48:31 +00:00
|
|
|
atp->preempt(REMOVE_NEVER);
|
|
|
|
break;
|
2010-03-02 01:24:03 +00:00
|
|
|
default:
|
2009-01-23 00:02:39 +00:00
|
|
|
atp->preempt(REMOVE_MAYBE_USER);
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-02 17:12:07 +00:00
|
|
|
// resume all currently scheduled tasks
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
|
|
|
void ACTIVE_TASK_SET::unsuspend_all() {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2004-08-23 22:06:48 +00:00
|
|
|
if (atp->scheduler_state != CPU_SCHED_SCHEDULED) continue;
|
2007-01-24 21:20:57 +00:00
|
|
|
if (atp->task_state() == PROCESS_UNINITIALIZED) {
|
2004-08-11 11:30:25 +00:00
|
|
|
if (atp->start(false)) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(atp->wup->project, MSG_INTERNAL_ERROR,
|
2006-01-17 22:48:09 +00:00
|
|
|
"Couldn't restart task %s", atp->result->name
|
2004-08-11 11:30:25 +00:00
|
|
|
);
|
|
|
|
}
|
2007-01-24 21:20:57 +00:00
|
|
|
} else if (atp->task_state() == PROCESS_SUSPENDED) {
|
2004-08-23 22:06:48 +00:00
|
|
|
atp->unsuspend();
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if any tasks are running
|
2004-08-23 22:06:48 +00:00
|
|
|
// called if benchmarking and waiting for suspends to happen
|
2009-03-24 16:57:28 +00:00
|
|
|
// or the system needs to suspend itself so we are suspending
|
|
|
|
// the applications
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
2004-08-23 22:06:48 +00:00
|
|
|
bool ACTIVE_TASK_SET::is_task_executing() {
|
2004-08-11 11:30:25 +00:00
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK* atp;
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2007-01-24 21:20:57 +00:00
|
|
|
if (atp->task_state() == PROCESS_EXECUTING) {
|
2004-08-11 11:30:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-02-25 21:31:46 +00:00
|
|
|
// Send quit message to all app processes
|
2004-08-11 11:30:25 +00:00
|
|
|
// This is called when the core client exits,
|
|
|
|
// or when a project is detached or reset
|
|
|
|
//
|
|
|
|
void ACTIVE_TASK_SET::request_tasks_exit(PROJECT* proj) {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK *atp;
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
|
|
|
if (proj && atp->wup->project != proj) continue;
|
2004-08-23 22:06:48 +00:00
|
|
|
if (!atp->process_exists()) continue;
|
2004-08-11 11:30:25 +00:00
|
|
|
atp->request_exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-23 22:06:48 +00:00
|
|
|
// Send kill signal to all app processes
|
2004-08-11 11:30:25 +00:00
|
|
|
// Don't wait for them to exit
|
|
|
|
//
|
|
|
|
void ACTIVE_TASK_SET::kill_tasks(PROJECT* proj) {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK *atp;
|
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
|
|
|
if (proj && atp->wup->project != proj) continue;
|
2004-08-23 22:06:48 +00:00
|
|
|
if (!atp->process_exists()) continue;
|
2006-12-07 17:30:48 +00:00
|
|
|
atp->kill_task(false);
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-25 23:54:07 +00:00
|
|
|
// send a <suspend> message
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
|
|
|
int ACTIVE_TASK::suspend() {
|
2004-08-24 21:44:54 +00:00
|
|
|
if (!app_client_shm.shm) return 0;
|
2011-01-06 23:09:13 +00:00
|
|
|
if (task_state() != PROCESS_EXECUTING) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"Internal error: expected process %s to be executing", result->name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
int n = process_control_queue.msg_queue_purge("<resume/>");
|
|
|
|
if (n == 0) {
|
|
|
|
process_control_queue.msg_queue_send(
|
|
|
|
"<suspend/>",
|
|
|
|
app_client_shm.shm->process_control_request
|
|
|
|
);
|
|
|
|
}
|
2007-01-24 21:20:57 +00:00
|
|
|
set_task_state(PROCESS_SUSPENDED, "suspend");
|
2004-08-11 11:30:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// resume a suspended task
|
|
|
|
//
|
|
|
|
int ACTIVE_TASK::unsuspend() {
|
2004-08-24 21:44:54 +00:00
|
|
|
if (!app_client_shm.shm) return 0;
|
2011-01-06 23:09:13 +00:00
|
|
|
if (task_state() != PROCESS_SUSPENDED) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"Internal error: expected process %s to be suspended", result->name
|
|
|
|
);
|
|
|
|
}
|
2006-09-07 17:59:34 +00:00
|
|
|
if (log_flags.cpu_sched) {
|
2007-01-24 22:55:00 +00:00
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"[cpu_sched] Resuming %s", result->name
|
|
|
|
);
|
2006-08-02 16:57:09 +00:00
|
|
|
}
|
2011-01-06 23:09:13 +00:00
|
|
|
int n = process_control_queue.msg_queue_purge("<suspend/>");
|
|
|
|
if (n == 0) {
|
|
|
|
process_control_queue.msg_queue_send(
|
|
|
|
"<resume/>",
|
|
|
|
app_client_shm.shm->process_control_request
|
|
|
|
);
|
|
|
|
}
|
2007-01-24 21:20:57 +00:00
|
|
|
set_task_state(PROCESS_EXECUTING, "unsuspend");
|
2004-08-11 11:30:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-17 22:08:35 +00:00
|
|
|
void ACTIVE_TASK::send_network_available() {
|
|
|
|
if (!app_client_shm.shm) return;
|
|
|
|
process_control_queue.msg_queue_send(
|
|
|
|
"<network_available/>",
|
|
|
|
app_client_shm.shm->process_control_request
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
// See if the app has placed a new message in shared mem
|
|
|
|
// (with CPU done, frac done etc.)
|
|
|
|
// If so parse it and return true.
|
|
|
|
//
|
2004-08-24 21:44:54 +00:00
|
|
|
bool ACTIVE_TASK::get_app_status_msg() {
|
2004-08-11 11:30:25 +00:00
|
|
|
char msg_buf[MSG_CHANNEL_SIZE];
|
2006-03-23 22:48:29 +00:00
|
|
|
double fd;
|
2011-09-07 22:45:00 +00:00
|
|
|
int other_pid;
|
2011-09-16 19:16:12 +00:00
|
|
|
double dtemp;
|
2004-08-11 11:30:25 +00:00
|
|
|
|
2005-03-30 21:11:49 +00:00
|
|
|
if (!app_client_shm.shm) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
2006-01-17 22:48:09 +00:00
|
|
|
"Task %s: no shared memory segment", result->name
|
2005-03-30 21:11:49 +00:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2005-11-30 22:52:23 +00:00
|
|
|
if (!app_client_shm.shm->app_status.get_msg(msg_buf)) {
|
2005-03-30 21:11:49 +00:00
|
|
|
return false;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2006-11-21 00:45:22 +00:00
|
|
|
if (log_flags.app_msg_receive) {
|
2009-02-23 04:54:04 +00:00
|
|
|
msg_printf(this->wup->project, MSG_INFO,
|
2006-11-21 00:45:22 +00:00
|
|
|
"[app_msg_receive] got msg from slot %d: %s", slot, msg_buf
|
2006-11-01 23:36:13 +00:00
|
|
|
);
|
2006-07-20 20:42:26 +00:00
|
|
|
}
|
2006-02-01 22:41:03 +00:00
|
|
|
want_network = 0;
|
2006-03-23 22:48:29 +00:00
|
|
|
current_cpu_time = checkpoint_cpu_time = 0.0;
|
|
|
|
if (parse_double(msg_buf, "<fraction_done>", fd)) {
|
|
|
|
// fraction_done will be reported as zero
|
|
|
|
// until the app's first call to boinc_fraction_done().
|
|
|
|
// So ignore zeros.
|
|
|
|
//
|
2011-04-18 16:32:57 +00:00
|
|
|
if (fd) {
|
|
|
|
fraction_done = fd;
|
|
|
|
fraction_done_elapsed_time = elapsed_time;
|
|
|
|
}
|
2006-03-23 22:48:29 +00:00
|
|
|
}
|
2005-11-30 22:52:23 +00:00
|
|
|
parse_double(msg_buf, "<current_cpu_time>", current_cpu_time);
|
|
|
|
parse_double(msg_buf, "<checkpoint_cpu_time>", checkpoint_cpu_time);
|
|
|
|
parse_double(msg_buf, "<fpops_per_cpu_sec>", result->fpops_per_cpu_sec);
|
|
|
|
parse_double(msg_buf, "<fpops_cumulative>", result->fpops_cumulative);
|
|
|
|
parse_double(msg_buf, "<intops_per_cpu_sec>", result->intops_per_cpu_sec);
|
|
|
|
parse_double(msg_buf, "<intops_cumulative>", result->intops_cumulative);
|
2011-09-16 19:16:12 +00:00
|
|
|
if (parse_double(msg_buf, "<bytes_sent>", dtemp)) {
|
|
|
|
if (dtemp > bytes_sent) {
|
|
|
|
daily_xfer_history.add(dtemp - bytes_sent, true);
|
|
|
|
}
|
|
|
|
bytes_sent = dtemp;
|
|
|
|
}
|
|
|
|
if (parse_double(msg_buf, "<bytes_received>", dtemp)) {
|
|
|
|
if (dtemp > bytes_received) {
|
|
|
|
daily_xfer_history.add(dtemp - bytes_received, false);
|
|
|
|
}
|
|
|
|
bytes_received = dtemp;
|
|
|
|
}
|
2006-02-01 22:41:03 +00:00
|
|
|
parse_int(msg_buf, "<want_network>", want_network);
|
2011-09-07 22:45:00 +00:00
|
|
|
if (parse_int(msg_buf, "<other_pid>", other_pid)) {
|
2011-09-02 20:47:05 +00:00
|
|
|
// for now, we handle only one of these
|
|
|
|
other_pids.clear();
|
2011-09-07 22:45:00 +00:00
|
|
|
other_pids.push_back(other_pid);
|
2011-09-02 20:47:05 +00:00
|
|
|
}
|
2007-01-23 17:24:43 +00:00
|
|
|
if (current_cpu_time < 0) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"app reporting negative CPU: %f", current_cpu_time
|
|
|
|
);
|
|
|
|
current_cpu_time = 0;
|
|
|
|
}
|
|
|
|
if (checkpoint_cpu_time < 0) {
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"app reporting negative checkpoint CPU: %f", checkpoint_cpu_time
|
|
|
|
);
|
|
|
|
checkpoint_cpu_time = 0;
|
|
|
|
}
|
2005-03-30 21:11:49 +00:00
|
|
|
return true;
|
2004-08-24 21:44:54 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 03:30:32 +00:00
|
|
|
void ACTIVE_TASK::get_graphics_msg() {
|
|
|
|
char msg_buf[MSG_CHANNEL_SIZE];
|
|
|
|
|
|
|
|
if (!app_client_shm.shm) return;
|
|
|
|
if (app_client_shm.shm->graphics_reply.get_msg(msg_buf)) {
|
|
|
|
parse_str(msg_buf, "<web_graphics_url>", web_graphics_url, sizeof(web_graphics_url));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-24 21:44:54 +00:00
|
|
|
bool ACTIVE_TASK::get_trickle_up_msg() {
|
|
|
|
char msg_buf[MSG_CHANNEL_SIZE];
|
|
|
|
bool found = false;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (!app_client_shm.shm) return false;
|
2004-08-11 11:30:25 +00:00
|
|
|
if (app_client_shm.shm->trickle_up.get_msg(msg_buf)) {
|
|
|
|
if (match_tag(msg_buf, "<have_new_trickle_up/>")) {
|
2011-04-14 01:04:10 +00:00
|
|
|
if (log_flags.app_msg_receive) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"[app_msg_receive] got msg from slot %d: %s", slot, msg_buf
|
|
|
|
);
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
retval = move_trickle_file();
|
|
|
|
if (!retval) {
|
2005-08-15 05:08:42 +00:00
|
|
|
wup->project->trickle_up_pending = true;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
2005-04-27 06:55:28 +00:00
|
|
|
if (match_tag(msg_buf, "<have_new_upload_file/>")) {
|
2011-04-14 01:04:10 +00:00
|
|
|
if (log_flags.app_msg_receive) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"[app_msg_receive] got msg from slot %d: %s", slot, msg_buf
|
|
|
|
);
|
|
|
|
}
|
2005-04-27 06:55:28 +00:00
|
|
|
handle_upload_files();
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2011-11-09 23:50:09 +00:00
|
|
|
// check for msgs from active tasks,
|
|
|
|
// and update their elapsed time and other info
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
2009-04-15 06:22:53 +00:00
|
|
|
void ACTIVE_TASK_SET::get_msgs() {
|
2004-08-11 11:30:25 +00:00
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK *atp;
|
2004-10-21 21:52:33 +00:00
|
|
|
double old_time;
|
2008-12-02 17:48:29 +00:00
|
|
|
static double last_time=0;
|
|
|
|
double delta_t;
|
|
|
|
if (last_time) {
|
|
|
|
delta_t = gstate.now - last_time;
|
2009-02-05 20:16:28 +00:00
|
|
|
|
|
|
|
// Normally this is called every second.
|
|
|
|
// If delta_t is > 10, we'll assume that a period of hibernation
|
2009-02-05 21:48:42 +00:00
|
|
|
// or suspension happened, and treat it as zero.
|
|
|
|
// If negative, must be clock reset. Ignore.
|
2009-02-05 20:16:28 +00:00
|
|
|
//
|
2009-02-05 21:48:42 +00:00
|
|
|
if (delta_t > 10 || delta_t < 0) {
|
2009-02-05 20:16:28 +00:00
|
|
|
delta_t = 0;
|
|
|
|
}
|
2008-12-02 17:48:29 +00:00
|
|
|
} else {
|
|
|
|
delta_t = 0;
|
|
|
|
}
|
|
|
|
last_time = gstate.now;
|
|
|
|
|
2004-08-11 11:30:25 +00:00
|
|
|
for (i=0; i<active_tasks.size(); i++) {
|
|
|
|
atp = active_tasks[i];
|
2004-08-23 22:06:48 +00:00
|
|
|
if (!atp->process_exists()) continue;
|
2004-08-11 11:30:25 +00:00
|
|
|
old_time = atp->checkpoint_cpu_time;
|
2009-01-14 22:31:50 +00:00
|
|
|
if (atp->task_state() == PROCESS_EXECUTING) {
|
2008-12-02 17:48:29 +00:00
|
|
|
atp->elapsed_time += delta_t;
|
|
|
|
}
|
2004-08-24 21:44:54 +00:00
|
|
|
if (atp->get_app_status_msg()) {
|
2004-08-11 11:30:25 +00:00
|
|
|
if (old_time != atp->checkpoint_cpu_time) {
|
2009-12-14 19:24:06 +00:00
|
|
|
char buf[256];
|
|
|
|
sprintf(buf, "%s checkpointed", atp->result->name);
|
2011-01-19 16:46:55 +00:00
|
|
|
if (atp->overdue_checkpoint) {
|
|
|
|
gstate.request_schedule_cpus(buf);
|
|
|
|
}
|
2006-06-15 23:15:27 +00:00
|
|
|
atp->checkpoint_wall_time = gstate.now;
|
2007-07-20 23:42:20 +00:00
|
|
|
atp->premature_exit_count = 0;
|
2008-12-02 17:48:29 +00:00
|
|
|
atp->checkpoint_elapsed_time = atp->elapsed_time;
|
2011-04-26 17:02:09 +00:00
|
|
|
atp->checkpoint_fraction_done = atp->fraction_done;
|
|
|
|
atp->checkpoint_fraction_done_elapsed_time = atp->fraction_done_elapsed_time;
|
2011-04-14 01:04:10 +00:00
|
|
|
if (log_flags.checkpoint_debug) {
|
2006-06-23 16:36:17 +00:00
|
|
|
msg_printf(atp->wup->project, MSG_INFO,
|
2011-04-14 01:04:10 +00:00
|
|
|
"[checkpoint] result %s checkpointed",
|
2006-06-23 16:36:17 +00:00
|
|
|
atp->result->name
|
|
|
|
);
|
2011-04-14 01:04:10 +00:00
|
|
|
} else if (log_flags.task_debug) {
|
2007-02-22 16:33:37 +00:00
|
|
|
msg_printf(atp->wup->project, MSG_INFO,
|
2011-04-14 01:04:10 +00:00
|
|
|
"[task] result %s checkpointed",
|
2007-02-22 16:33:37 +00:00
|
|
|
atp->result->name
|
|
|
|
);
|
2006-06-23 16:36:17 +00:00
|
|
|
}
|
2009-04-15 06:22:53 +00:00
|
|
|
atp->write_task_state_file();
|
2006-06-23 16:36:17 +00:00
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2007-06-28 11:09:07 +00:00
|
|
|
atp->get_trickle_up_msg();
|
2011-12-26 03:30:32 +00:00
|
|
|
atp->get_graphics_msg();
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2009-04-15 06:22:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// write checkpoint state to a file in the slot dir
|
|
|
|
// (this avoids rewriting the state file on each checkpoint)
|
|
|
|
//
|
|
|
|
void ACTIVE_TASK::write_task_state_file() {
|
|
|
|
char path[1024];
|
|
|
|
sprintf(path, "%s/%s", slot_dir, TASK_STATE_FILENAME);
|
|
|
|
FILE* f = fopen(path, "w");
|
|
|
|
if (!f) return;
|
|
|
|
fprintf(f,
|
|
|
|
"<active_task>\n"
|
|
|
|
" <project_master_url>%s</project_master_url>\n"
|
|
|
|
" <result_name>%s</result_name>\n"
|
|
|
|
" <checkpoint_cpu_time>%f</checkpoint_cpu_time>\n"
|
|
|
|
" <checkpoint_elapsed_time>%f</checkpoint_elapsed_time>\n"
|
2009-09-13 00:53:11 +00:00
|
|
|
" <fraction_done>%f</fraction_done>\n"
|
2009-04-15 06:22:53 +00:00
|
|
|
"</active_task>\n",
|
|
|
|
result->project->master_url,
|
|
|
|
result->name,
|
|
|
|
checkpoint_cpu_time,
|
2009-09-13 00:53:11 +00:00
|
|
|
checkpoint_elapsed_time,
|
|
|
|
fraction_done
|
2009-04-15 06:22:53 +00:00
|
|
|
);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// called on startup; read the task state file in case it's more recent
|
|
|
|
// then the main state file
|
|
|
|
//
|
|
|
|
void ACTIVE_TASK::read_task_state_file() {
|
|
|
|
char buf[4096], path[1024], s[1024];
|
|
|
|
sprintf(path, "%s/%s", slot_dir, TASK_STATE_FILENAME);
|
|
|
|
FILE* f = fopen(path, "r");
|
|
|
|
if (!f) return;
|
|
|
|
buf[0] = 0;
|
|
|
|
fread(buf, 1, 4096, f);
|
|
|
|
fclose(f);
|
|
|
|
buf[4095] = 0;
|
|
|
|
double x;
|
|
|
|
// sanity checks - project and result name must match
|
|
|
|
//
|
|
|
|
if (!parse_str(buf, "<project_master_url>", s, sizeof(s))) {
|
2010-05-25 18:48:53 +00:00
|
|
|
msg_printf(wup->project, MSG_INTERNAL_ERROR,
|
|
|
|
"no project URL in task state file"
|
|
|
|
);
|
2009-04-15 06:22:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (strcmp(s, result->project->master_url)) {
|
2010-05-25 18:48:53 +00:00
|
|
|
msg_printf(wup->project, MSG_INTERNAL_ERROR,
|
|
|
|
"wrong project URL in task state file"
|
|
|
|
);
|
2009-04-15 06:22:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!parse_str(buf, "<result_name>", s, sizeof(s))) {
|
2010-05-25 18:48:53 +00:00
|
|
|
msg_printf(wup->project, MSG_INTERNAL_ERROR,
|
|
|
|
"no task name in task state file"
|
|
|
|
);
|
2009-04-15 06:22:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (strcmp(s, result->name)) {
|
2010-05-25 18:48:53 +00:00
|
|
|
msg_printf(wup->project, MSG_INTERNAL_ERROR,
|
|
|
|
"wrong task name in task state file"
|
|
|
|
);
|
2009-04-15 06:22:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (parse_double(buf, "<checkpoint_cpu_time>", x)) {
|
|
|
|
if (x > checkpoint_cpu_time) {
|
|
|
|
checkpoint_cpu_time = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (parse_double(buf, "<checkpoint_elapsed_time>", x)) {
|
|
|
|
if (x > checkpoint_elapsed_time) {
|
|
|
|
checkpoint_elapsed_time = x;
|
|
|
|
}
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|