2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2003-08-12 20:28:55 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
2003-08-12 20:28:55 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
2007-10-09 11:35:47 +00:00
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#ifndef _TASK_
|
|
|
|
#define _TASK_
|
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#ifndef _WIN32
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <vector>
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
|
|
|
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "client_types.h"
|
2007-05-11 03:49:25 +00:00
|
|
|
#include "common_defs.h"
|
2003-05-07 23:42:17 +00:00
|
|
|
#include "app_ipc.h"
|
2006-09-08 19:27:42 +00:00
|
|
|
#include "procinfo.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
|
2002-12-06 07:33:45 +00:00
|
|
|
class CLIENT_STATE;
|
|
|
|
typedef int PROCESS_ID;
|
|
|
|
|
2005-10-03 18:05:58 +00:00
|
|
|
#define MAX_STDERR_LEN 65536
|
|
|
|
// The stderr output of an application is truncated to this length
|
|
|
|
// before sending to server,
|
|
|
|
// to protect against apps that write unbounded amounts.
|
|
|
|
|
2002-12-05 19:13:06 +00:00
|
|
|
|
2002-12-06 07:33:45 +00:00
|
|
|
// Represents a task in progress.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2004-05-21 20:06:34 +00:00
|
|
|
// "CPU time" refers to the sum over all episodes.
|
|
|
|
// (not counting the "lost" time after the last checkpoint
|
|
|
|
// in episodes before the current one)
|
|
|
|
//
|
2004-05-12 21:21:09 +00:00
|
|
|
// When an active task is created, it is assigned a "slot"
|
|
|
|
// which determines the directory it runs in.
|
|
|
|
// This doesn't change over the life of the active task;
|
|
|
|
// thus the task can use the slot directory for temp files
|
|
|
|
// that BOINC doesn't know about.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
class ACTIVE_TASK {
|
2007-06-27 20:09:18 +00:00
|
|
|
int _task_state;
|
2002-04-30 22:22:54 +00:00
|
|
|
public:
|
2002-06-06 18:42:01 +00:00
|
|
|
#ifdef _WIN32
|
2007-11-29 19:48:04 +00:00
|
|
|
HANDLE pid_handle, shm_handle;
|
2007-02-20 18:25:04 +00:00
|
|
|
bool kill_all_children();
|
2002-06-06 18:42:01 +00:00
|
|
|
#endif
|
2004-08-31 21:02:17 +00:00
|
|
|
SHMEM_SEG_NAME shmem_seg_name;
|
2002-04-30 22:22:54 +00:00
|
|
|
RESULT* result;
|
|
|
|
WORKUNIT* wup;
|
|
|
|
APP_VERSION* app_version;
|
|
|
|
PROCESS_ID pid;
|
2006-09-08 19:27:42 +00:00
|
|
|
PROCINFO procinfo;
|
|
|
|
|
|
|
|
int slot; // subdirectory of slots/ where this runs
|
2007-01-24 21:20:57 +00:00
|
|
|
inline int task_state() {
|
|
|
|
return _task_state;
|
|
|
|
}
|
|
|
|
void set_task_state(int, const char*);
|
2004-06-30 01:10:22 +00:00
|
|
|
int scheduler_state;
|
|
|
|
int next_scheduler_state; // temp
|
2002-04-30 22:22:54 +00:00
|
|
|
int signal;
|
2002-08-05 00:29:34 +00:00
|
|
|
double fraction_done;
|
2002-12-06 07:33:45 +00:00
|
|
|
// App's estimate of how much of the work unit is done.
|
|
|
|
// Passed from the application via an API call;
|
|
|
|
// will be zero if the app doesn't use this call
|
2006-08-22 20:58:57 +00:00
|
|
|
double debt_interval_start_cpu_time;
|
|
|
|
// CPU time when adjust_debts() last ran
|
2004-05-21 20:06:34 +00:00
|
|
|
double episode_start_cpu_time;
|
|
|
|
// CPU time at the start of current episode
|
2006-08-22 20:58:57 +00:00
|
|
|
double run_interval_start_wall_time;
|
|
|
|
// Wall time at the start of the current run interval
|
2002-08-05 00:29:34 +00:00
|
|
|
double checkpoint_cpu_time;
|
2004-05-21 20:06:34 +00:00
|
|
|
// CPU at the last checkpoint
|
2006-06-15 23:15:27 +00:00
|
|
|
double checkpoint_wall_time;
|
|
|
|
// wall time at the last checkpoint
|
2002-08-05 00:29:34 +00:00
|
|
|
double current_cpu_time;
|
2004-05-21 20:06:34 +00:00
|
|
|
// most recent CPU time reported by app
|
2002-12-06 07:33:45 +00:00
|
|
|
int current_disk_usage(double&);
|
|
|
|
// disk used by output files and temp files of this task
|
2007-06-14 23:08:43 +00:00
|
|
|
char slot_dir[256]; // directory where process runs (relative)
|
|
|
|
char slot_path[512]; // same, absolute
|
|
|
|
// This is used only to run graphics apps
|
|
|
|
// (that way don't have to worry about top-level dirs
|
|
|
|
// being non-readable, etc).
|
2003-05-21 23:23:42 +00:00
|
|
|
double max_cpu_time; // abort if total CPU exceeds this
|
|
|
|
double max_disk_usage; // abort if disk usage (in+out+temp) exceeds this
|
2003-05-28 19:56:53 +00:00
|
|
|
double max_mem_usage; // abort if memory usage exceeds this
|
2004-07-02 04:49:17 +00:00
|
|
|
bool have_trickle_down;
|
2005-04-28 23:19:58 +00:00
|
|
|
bool send_upload_file_status;
|
2006-10-03 22:50:13 +00:00
|
|
|
bool too_large; // working set too large to run now
|
2007-06-25 11:46:15 +00:00
|
|
|
bool needs_shmem; // waiting for a free shared memory segment
|
2005-08-17 22:08:35 +00:00
|
|
|
int want_network;
|
2006-02-01 22:41:03 +00:00
|
|
|
// This task wants to do network comm (for F@h)
|
|
|
|
// this is passed via share-memory message (app_status channel)
|
2008-01-13 00:12:14 +00:00
|
|
|
double abort_time;
|
|
|
|
// when we sent an abort message to this app
|
|
|
|
// kill it 5 seconds later if it doesn't exit
|
2008-05-05 00:51:20 +00:00
|
|
|
double quit_time;
|
|
|
|
// when we sent a quit message; kill if still there after 10 sec
|
|
|
|
int premature_exit_count;
|
|
|
|
|
2003-05-08 18:11:05 +00:00
|
|
|
APP_CLIENT_SHM app_client_shm; // core/app shared mem
|
2004-09-13 05:27:28 +00:00
|
|
|
MSG_QUEUE graphics_request_queue;
|
|
|
|
MSG_QUEUE process_control_queue;
|
2008-05-16 22:52:09 +00:00
|
|
|
bool coprocs_reserved;
|
|
|
|
void reserve_coprocs();
|
|
|
|
void free_coprocs();
|
2003-05-08 18:11:05 +00:00
|
|
|
|
|
|
|
// info related to app's graphics mode (win, screensaver, etc.)
|
2004-07-18 04:41:27 +00:00
|
|
|
//
|
|
|
|
int graphics_mode_acked; // mode acked by app
|
2007-10-11 11:02:48 +00:00
|
|
|
int graphics_mode_before_ss; // mode before last screensaver request
|
2006-12-06 20:59:29 +00:00
|
|
|
double graphics_mode_ack_timeout;
|
2007-03-23 18:48:06 +00:00
|
|
|
|
|
|
|
#ifdef SIM
|
|
|
|
double cpu_time_left;
|
|
|
|
#endif
|
|
|
|
|
2007-10-24 00:44:42 +00:00
|
|
|
#if (defined (__APPLE__) && (defined(__i386__) || defined(__x86_64__)))
|
2006-02-06 23:44:05 +00:00
|
|
|
// PowerPC apps emulated on i386 Macs crash if running graphics
|
|
|
|
int powerpc_emulated_on_i386;
|
|
|
|
int is_native_i386_app(char*);
|
|
|
|
#endif
|
2004-11-17 19:19:26 +00:00
|
|
|
GRAPHICS_MSG graphics_msg;
|
|
|
|
void request_graphics_mode(GRAPHICS_MSG&);
|
2003-10-31 22:37:46 +00:00
|
|
|
int request_reread_prefs();
|
2005-05-20 00:48:52 +00:00
|
|
|
int request_reread_app_info();
|
2003-05-09 20:33:57 +00:00
|
|
|
void check_graphics_mode_ack();
|
2003-11-02 22:51:49 +00:00
|
|
|
int link_user_files();
|
2004-08-31 21:02:17 +00:00
|
|
|
int get_shmem_seg_name();
|
2007-01-23 17:24:43 +00:00
|
|
|
bool runnable() {
|
2007-01-24 21:20:57 +00:00
|
|
|
return _task_state == PROCESS_UNINITIALIZED
|
|
|
|
|| _task_state == PROCESS_EXECUTING
|
|
|
|
|| _task_state == PROCESS_SUSPENDED;
|
2007-01-23 17:24:43 +00:00
|
|
|
}
|
2003-05-07 23:42:17 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
ACTIVE_TASK();
|
2004-02-04 23:18:14 +00:00
|
|
|
~ACTIVE_TASK();
|
2002-04-30 22:22:54 +00:00
|
|
|
int init(RESULT*);
|
2004-09-04 05:21:33 +00:00
|
|
|
void close_process_handles();
|
2005-02-25 21:31:46 +00:00
|
|
|
void cleanup_task();
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2005-06-25 23:54:07 +00:00
|
|
|
int start(bool first_time); // start a process
|
|
|
|
int request_exit();
|
|
|
|
// ask the process to exit gracefully,
|
|
|
|
// i.e. by sending a <quit> message
|
2006-02-03 20:48:48 +00:00
|
|
|
int request_abort(); // send "abort" message
|
2004-08-23 22:06:48 +00:00
|
|
|
bool process_exists();
|
2006-12-07 17:30:48 +00:00
|
|
|
int kill_task(bool restart);
|
2005-06-25 23:54:07 +00:00
|
|
|
// Kill process forcibly,
|
|
|
|
// Unix: send a SIGKILL signal, Windows: TerminateProcess()
|
2006-12-07 17:30:48 +00:00
|
|
|
// if restart is true, arrange for resulted to get restarted;
|
|
|
|
// otherwise it ends with an error
|
2005-06-25 23:54:07 +00:00
|
|
|
int suspend();
|
|
|
|
// ask a process to stop executing (but stay in mem)
|
|
|
|
// Done by sending it a <suspend> message
|
|
|
|
int unsuspend();
|
|
|
|
// Undo a suspend: send a <resume> message
|
|
|
|
int abort_task(int exit_status, const char*);
|
|
|
|
// can be called whether or not process exists
|
2004-08-23 22:06:48 +00:00
|
|
|
bool has_task_exited(); // return true if this task has exited
|
2004-08-06 23:17:59 +00:00
|
|
|
int preempt(bool quit_task); // preempt (via suspend or quit) a running task
|
2007-02-02 17:12:07 +00:00
|
|
|
int resume_or_start(bool);
|
2005-08-17 22:08:35 +00:00
|
|
|
void send_network_available();
|
2004-08-09 19:06:47 +00:00
|
|
|
#ifdef _WIN32
|
2005-12-09 07:50:35 +00:00
|
|
|
void handle_exited_app(unsigned long);
|
2004-08-09 19:06:47 +00:00
|
|
|
#else
|
2005-12-09 07:50:35 +00:00
|
|
|
void handle_exited_app(int stat);
|
2004-08-09 19:06:47 +00:00
|
|
|
#endif
|
2007-11-27 21:54:17 +00:00
|
|
|
void handle_premature_exit(bool&);
|
2003-05-22 20:47:56 +00:00
|
|
|
|
2003-05-28 19:56:53 +00:00
|
|
|
bool check_max_disk_exceeded();
|
|
|
|
|
2004-08-24 21:44:54 +00:00
|
|
|
bool get_app_status_msg();
|
|
|
|
bool get_trickle_up_msg();
|
2007-05-15 20:29:26 +00:00
|
|
|
double est_cpu_time_to_completion(bool for_work_fetch);
|
2002-12-05 21:56:33 +00:00
|
|
|
bool read_stderr_file();
|
2004-04-04 01:59:47 +00:00
|
|
|
bool finish_file_present();
|
2003-05-29 18:28:02 +00:00
|
|
|
bool supports_graphics();
|
2004-08-31 21:02:17 +00:00
|
|
|
int write_app_init_file();
|
2004-01-04 06:48:40 +00:00
|
|
|
int move_trickle_file();
|
2005-04-27 06:55:28 +00:00
|
|
|
int handle_upload_files();
|
2005-04-28 23:19:58 +00:00
|
|
|
void upload_notify_app(const FILE_INFO*, const FILE_REF*);
|
2006-06-14 18:04:12 +00:00
|
|
|
int copy_output_files();
|
2002-06-06 18:42:01 +00:00
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
int write(MIOFILE&);
|
2007-06-14 23:08:43 +00:00
|
|
|
int write_gui(MIOFILE&);
|
2004-06-12 04:45:36 +00:00
|
|
|
int parse(MIOFILE&);
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ACTIVE_TASK_SET {
|
|
|
|
public:
|
2004-06-30 18:17:21 +00:00
|
|
|
typedef std::vector<ACTIVE_TASK*> active_tasks_v;
|
2003-08-12 20:28:55 +00:00
|
|
|
active_tasks_v active_tasks;
|
2002-04-30 22:22:54 +00:00
|
|
|
ACTIVE_TASK* lookup_pid(int);
|
2003-08-12 20:28:55 +00:00
|
|
|
ACTIVE_TASK* lookup_result(RESULT*);
|
2006-06-19 04:29:26 +00:00
|
|
|
void init();
|
2005-06-07 19:22:50 +00:00
|
|
|
bool poll();
|
2004-08-06 23:17:59 +00:00
|
|
|
void suspend_all(bool leave_apps_in_memory=true);
|
2002-04-30 22:22:54 +00:00
|
|
|
void unsuspend_all();
|
2004-08-23 22:06:48 +00:00
|
|
|
bool is_task_executing();
|
2003-10-19 02:54:35 +00:00
|
|
|
void request_tasks_exit(PROJECT* p=0);
|
|
|
|
int wait_for_exit(double, PROJECT* p=0);
|
|
|
|
int exit_tasks(PROJECT* p=0);
|
|
|
|
void kill_tasks(PROJECT* p=0);
|
|
|
|
int abort_project(PROJECT*);
|
2004-08-03 09:50:24 +00:00
|
|
|
bool get_msgs();
|
2003-05-22 20:47:56 +00:00
|
|
|
bool check_app_exited();
|
2003-06-06 21:23:14 +00:00
|
|
|
bool check_rsc_limits_exceeded();
|
2005-05-05 22:28:17 +00:00
|
|
|
bool check_quit_timeout_exceeded();
|
2007-03-15 23:01:51 +00:00
|
|
|
bool is_slot_in_use(int);
|
|
|
|
bool is_slot_dir_in_use(char*);
|
2004-06-30 01:10:22 +00:00
|
|
|
int get_free_slot();
|
2004-07-08 03:38:52 +00:00
|
|
|
void send_heartbeats();
|
|
|
|
void send_trickle_downs();
|
2005-06-07 19:22:50 +00:00
|
|
|
void report_overdue();
|
2005-04-28 23:19:58 +00:00
|
|
|
void handle_upload_files();
|
|
|
|
void upload_notify_app(FILE_INFO*);
|
2006-02-01 22:41:03 +00:00
|
|
|
bool want_network(); // does any task want network?
|
|
|
|
void network_available(); // notify tasks that network is available
|
2006-01-25 19:02:01 +00:00
|
|
|
void free_mem();
|
2006-06-15 05:14:39 +00:00
|
|
|
bool slot_taken(int);
|
2006-09-05 19:00:59 +00:00
|
|
|
void get_memory_usage();
|
2003-05-08 18:11:05 +00:00
|
|
|
|
2007-09-25 16:04:45 +00:00
|
|
|
// graphics-related functions
|
2004-07-18 04:41:27 +00:00
|
|
|
void graphics_poll();
|
2004-09-13 05:27:28 +00:00
|
|
|
void process_control_poll();
|
2003-10-31 22:37:46 +00:00
|
|
|
void request_reread_prefs(PROJECT*);
|
2005-05-20 00:48:52 +00:00
|
|
|
void request_reread_app_info();
|
2003-05-07 23:42:17 +00:00
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
int write(MIOFILE&);
|
|
|
|
int parse(MIOFILE&);
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|