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"
|
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
|
2005-11-21 18:34:44 +00:00
|
|
|
#ifdef HAVE_CSIGNAL
|
|
|
|
#include <csignal>
|
|
|
|
#elif defined(HAVE_SYS_SIGNAL_H)
|
2004-08-11 11:30:25 +00:00
|
|
|
#include <sys/signal.h>
|
2005-11-21 18:34:44 +00:00
|
|
|
#elif defined(HAVE_SIGNAL_H)
|
|
|
|
#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"
|
2007-02-20 16:27:15 +00:00
|
|
|
#include "procinfo.h"
|
2007-10-05 16:47:07 +00:00
|
|
|
#include "sandbox.h"
|
2004-08-11 11:30:25 +00:00
|
|
|
|
|
|
|
#include "app.h"
|
|
|
|
|
2007-02-20 18:25:04 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
bool ACTIVE_TASK::kill_all_children() {
|
|
|
|
unsigned int i,j;
|
|
|
|
std::vector<PROCINFO> ps;
|
|
|
|
std::vector<PROCINFO> tps;
|
|
|
|
|
|
|
|
procinfo_setup(ps);
|
|
|
|
|
|
|
|
PROCINFO pi;
|
|
|
|
pi.id = pid;
|
|
|
|
tps.push_back(pi);
|
|
|
|
|
|
|
|
for (i=0; i < tps.size(); i++) {
|
|
|
|
PROCINFO tp = tps[i];
|
|
|
|
for (j=0; j < ps.size(); j++) {
|
|
|
|
PROCINFO p = ps[j];
|
|
|
|
if (tp.id == p.parentid) {
|
|
|
|
if (TerminateProcessById(p.id)) {
|
|
|
|
tps.push_back(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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(
|
2006-02-03 20:48:48 +00:00
|
|
|
"<quit/>",
|
2004-09-13 05:27:28 +00:00
|
|
|
app_client_shm.shm->process_control_request
|
|
|
|
);
|
2008-05-05 00:51:20 +00:00
|
|
|
quit_time = gstate.now;
|
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(
|
|
|
|
"<abort/>",
|
|
|
|
app_client_shm.shm->process_control_request
|
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Kill the task by OS-specific means.
|
2004-08-11 11:30:25 +00:00
|
|
|
//
|
2006-12-07 17:30:48 +00:00
|
|
|
int ACTIVE_TASK::kill_task(bool restart) {
|
2004-08-11 11:30:25 +00:00
|
|
|
#ifdef _WIN32
|
2007-02-20 18:25:04 +00:00
|
|
|
TerminateProcessById(pid);
|
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);
|
|
|
|
// Also kill app directly, just to be safe
|
|
|
|
//
|
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
|
2008-08-16 20:59:53 +00:00
|
|
|
cleanup_task();
|
2006-12-07 17:30:48 +00:00
|
|
|
if (restart) {
|
2007-01-24 21:20:57 +00:00
|
|
|
set_task_state(PROCESS_UNINITIALIZED, "kill_task");
|
2006-12-07 17:30:48 +00:00
|
|
|
gstate.request_enforce_schedule("Task restart");
|
|
|
|
} else {
|
2007-01-24 21:20:57 +00:00
|
|
|
set_task_state(PROCESS_ABORTED, "kill_task");
|
2006-12-07 17:30:48 +00:00
|
|
|
}
|
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;
|
|
|
|
if (GetExitCodeProcess(pid_handle, &exit_code)) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-11-27 21:54:17 +00:00
|
|
|
// handle a task that exited prematurely (i.e. the job isn't done)
|
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) {
|
|
|
|
// if it exited because we sent it a quit message, don't count
|
2007-07-20 23:42:20 +00:00
|
|
|
//
|
|
|
|
if (task_state() == 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;
|
|
|
|
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,
|
|
|
|
"[task_debug] Process for %s exited",
|
|
|
|
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;
|
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
|
|
|
}
|
|
|
|
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,
|
|
|
|
"[task_debug] Process for %s exited",
|
|
|
|
result->name
|
|
|
|
);
|
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"[task_debug] exit code %d (0x%x): %s",
|
|
|
|
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
|
|
|
}
|
2006-06-22 19:40:30 +00:00
|
|
|
if (log_flags.task_debug) {
|
2007-01-24 19:31:49 +00:00
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"[task_debug] exit status %d\n",
|
2006-06-22 19:40:30 +00:00
|
|
|
result->exit_status
|
|
|
|
);
|
|
|
|
}
|
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,
|
|
|
|
"[task_debug] process got signal %d", signal
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
if (gstate.exit_after_finish) {
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2007-01-24 19:31:49 +00:00
|
|
|
if (!will_restart) {
|
|
|
|
copy_output_files();
|
|
|
|
read_stderr_file();
|
2008-01-14 18:32:20 +00:00
|
|
|
client_clean_out_dir(slot_dir);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2006-10-03 17:14:56 +00:00
|
|
|
char buf[256];
|
|
|
|
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;
|
2006-10-03 17:14:56 +00:00
|
|
|
sprintf(buf, "<heartbeat/>"
|
|
|
|
"<wss>%f</wss>"
|
|
|
|
"<max_wss>%f</max_wss>",
|
|
|
|
atp->procinfo.working_set_size, ar
|
|
|
|
);
|
2008-08-22 04:50:30 +00:00
|
|
|
bool sent = atp->app_client_shm.shm->heartbeat.send_msg(buf);
|
|
|
|
if (log_flags.app_msg_send) {
|
|
|
|
if (sent) {
|
|
|
|
msg_printf(atp->result->project, MSG_INFO,
|
|
|
|
"[app_msg_send] sent heartbeat to %s",
|
|
|
|
atp->result->name
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
msg_printf(atp->result->project, MSG_INFO,
|
|
|
|
"[app_msg_send] failed to send heartbeat to %s",
|
|
|
|
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
|
|
|
|
2007-03-04 02:30:48 +00:00
|
|
|
// if app has had the same message in its send buffer for 180 sec,
|
2006-12-09 00:10:53 +00:00
|
|
|
// 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) {
|
|
|
|
msg_printf(NULL, MSG_INFO,
|
|
|
|
"Restarting %s - message timeout", atp->result->name
|
|
|
|
);
|
|
|
|
}
|
2006-12-09 00:10:53 +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;
|
2004-08-11 11:30:25 +00:00
|
|
|
if (GetExitCodeProcess(atp->pid_handle, &exit_code)) {
|
|
|
|
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];
|
|
|
|
msg_printf(0, MSG_INFO,
|
2006-11-01 23:36:13 +00:00
|
|
|
"[task_debug] task %s GetExitCodeProcess() failed - %s GLE %d (0x%x)",
|
|
|
|
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
|
|
|
|
2005-08-04 00:12:50 +00:00
|
|
|
if ((pid = waitpid(0, &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) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(NULL, MSG_INTERNAL_ERROR, "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) {
|
2007-01-25 23:39:06 +00:00
|
|
|
msg_printf(0, 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
|
|
|
|
2006-10-02 23:42:38 +00:00
|
|
|
double ram_left = gstate.available_ram();
|
|
|
|
double max_ram = gstate.max_available_ram();
|
|
|
|
|
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;
|
2006-10-02 23:42:38 +00:00
|
|
|
if (atp->current_cpu_time > atp->max_cpu_time) {
|
|
|
|
msg_printf(atp->result->project, MSG_INFO,
|
|
|
|
"Aborting task %s: exceeded CPU time limit %f\n",
|
|
|
|
atp->result->name, atp->max_cpu_time
|
|
|
|
);
|
|
|
|
atp->abort_task(ERR_RSC_LIMIT_EXCEEDED, "Maximum CPU time exceeded");
|
|
|
|
did_anything = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (atp->procinfo.working_set_size_smoothed > max_ram) {
|
|
|
|
msg_printf(atp->result->project, MSG_INFO,
|
2006-10-06 19:16:59 +00:00
|
|
|
"Aborting task %s: exceeded memory limit %.2fMB > %.2fMB\n",
|
|
|
|
atp->result->name,
|
|
|
|
atp->procinfo.working_set_size_smoothed/MEGA, max_ram/MEGA
|
2006-10-02 23:42:38 +00:00
|
|
|
);
|
|
|
|
atp->abort_task(ERR_RSC_LIMIT_EXCEEDED, "Maximum memory exceeded");
|
|
|
|
did_anything = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (do_disk_check && atp->check_max_disk_exceeded()) {
|
2005-11-23 03:23:13 +00:00
|
|
|
did_anything = true;
|
2006-10-02 23:42:38 +00:00
|
|
|
continue;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2006-10-02 23:42:38 +00:00
|
|
|
ram_left -= atp->procinfo.working_set_size_smoothed;
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
2006-10-02 23:42:38 +00:00
|
|
|
if (ram_left < 0) {
|
|
|
|
gstate.request_schedule_cpus("RAM usage limit exceeded");
|
|
|
|
}
|
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;
|
|
|
|
request_abort();
|
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
|
|
|
|
//
|
|
|
|
bool ACTIVE_TASK::read_stderr_file() {
|
2005-02-08 00:53:26 +00:00
|
|
|
std::string stderr_file;
|
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);
|
2007-06-22 22:18:28 +00:00
|
|
|
if (!boinc_file_exists(path)) return false;
|
2007-10-23 14:50:02 +00:00
|
|
|
if (read_file_string(path, stderr_file, max_len, true)) return false;
|
2007-06-22 22:18:28 +00:00
|
|
|
|
|
|
|
result->stderr_out += "<stderr_txt>\n";
|
|
|
|
result->stderr_out += stderr_file;
|
|
|
|
result->stderr_out += "\n</stderr_txt>\n";
|
|
|
|
return true;
|
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;
|
|
|
|
|
|
|
|
link_user_files();
|
|
|
|
|
2004-08-31 21:02:17 +00:00
|
|
|
retval = write_app_init_file();
|
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() {
|
|
|
|
int retval = write_app_init_file();
|
|
|
|
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
|
|
|
|
|
|
|
// send quit signal to all tasks in the project
|
|
|
|
// (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) {
|
|
|
|
request_tasks_exit(proj);
|
|
|
|
|
|
|
|
// Wait 5 seconds for them to exit normally; if they don't then kill them
|
|
|
|
//
|
|
|
|
if (wait_for_exit(5, proj)) {
|
|
|
|
kill_tasks(proj);
|
|
|
|
}
|
|
|
|
wait_for_exit(5, proj);
|
|
|
|
|
|
|
|
// 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++;
|
|
|
|
}
|
|
|
|
}
|
2008-12-31 23:07:59 +00:00
|
|
|
project->clear_perm();
|
2004-08-11 11:30:25 +00:00
|
|
|
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
|
|
|
//
|
2008-10-27 20:17:22 +00:00
|
|
|
void ACTIVE_TASK_SET::suspend_all(bool cpu_throttle) {
|
2004-08-11 11:30:25 +00:00
|
|
|
unsigned int i;
|
2008-10-27 20:17:22 +00:00
|
|
|
bool leave_in_mem;
|
|
|
|
|
|
|
|
if (cpu_throttle) {
|
|
|
|
leave_in_mem = true;
|
|
|
|
} else {
|
|
|
|
leave_in_mem = gstate.global_prefs.leave_apps_in_memory;
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
for (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;
|
2008-10-27 20:17:22 +00:00
|
|
|
if (cpu_throttle) {
|
|
|
|
// if we're doing CPU throttling, don't bother suspending apps
|
|
|
|
// that don't use a full CPU
|
|
|
|
//
|
|
|
|
if (atp->result->project->non_cpu_intensive) continue;
|
|
|
|
if (atp->app_version->avg_ncpus < 1) continue;
|
|
|
|
}
|
|
|
|
atp->preempt(!leave_in_mem);
|
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
|
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;
|
2007-01-24 21:20:57 +00:00
|
|
|
if (task_state() != PROCESS_EXECUTING) {
|
2008-10-27 20:17:22 +00:00
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"Internal error: expected process %s to be executing", result->name
|
|
|
|
);
|
2006-11-21 00:45:22 +00:00
|
|
|
}
|
|
|
|
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;
|
2007-01-24 21:20:57 +00:00
|
|
|
if (task_state() != PROCESS_SUSPENDED) {
|
2008-10-27 20:17:22 +00:00
|
|
|
msg_printf(result->project, MSG_INFO,
|
|
|
|
"Internal error: expected process %s to be suspended", result->name
|
|
|
|
);
|
2006-11-21 00:45:22 +00:00
|
|
|
}
|
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
|
|
|
}
|
2006-11-21 00:45:22 +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;
|
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) {
|
2006-11-01 23:36:13 +00:00
|
|
|
msg_printf(NULL, 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.
|
|
|
|
//
|
|
|
|
if (fd) fraction_done = fd;
|
|
|
|
}
|
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);
|
2006-02-01 22:41:03 +00:00
|
|
|
parse_int(msg_buf, "<want_network>", want_network);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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/>")) {
|
|
|
|
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/>")) {
|
|
|
|
handle_upload_files();
|
|
|
|
}
|
2004-08-11 11:30:25 +00:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for msgs from active tasks.
|
|
|
|
// Return true if any of them has changed its checkpoint_cpu_time
|
|
|
|
// (since in that case we need to write state file)
|
|
|
|
//
|
|
|
|
bool ACTIVE_TASK_SET::get_msgs() {
|
|
|
|
unsigned int i;
|
|
|
|
ACTIVE_TASK *atp;
|
2004-10-21 21:52:33 +00:00
|
|
|
double old_time;
|
2004-08-11 11:30:25 +00:00
|
|
|
bool action = false;
|
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;
|
|
|
|
} 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;
|
2008-12-02 17:48:29 +00:00
|
|
|
if (atp->scheduler_state == CPU_SCHED_SCHEDULED) {
|
|
|
|
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) {
|
2006-06-15 23:15:27 +00:00
|
|
|
gstate.request_enforce_schedule("Checkpoint reached");
|
|
|
|
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;
|
2004-08-11 11:30:25 +00:00
|
|
|
action = true;
|
2006-06-23 16:36:17 +00:00
|
|
|
if (log_flags.task_debug) {
|
|
|
|
msg_printf(atp->wup->project, MSG_INFO,
|
2006-09-07 20:39:25 +00:00
|
|
|
"[task_debug] result %s checkpointed",
|
2006-06-23 16:36:17 +00:00
|
|
|
atp->result->name
|
|
|
|
);
|
2007-02-22 16:33:37 +00:00
|
|
|
} else if (log_flags.checkpoint_debug) {
|
|
|
|
msg_printf(atp->wup->project, MSG_INFO,
|
|
|
|
"[checkpoint_debug] result %s checkpointed",
|
|
|
|
atp->result->name
|
|
|
|
);
|
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();
|
2004-08-11 11:30:25 +00:00
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_10ca137461 = "$Id$";
|