2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2003-08-12 20:28:55 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2003-08-12 20:28:55 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
2009-01-23 00:02:39 +00:00
|
|
|
// values for preempt_type
|
|
|
|
//
|
|
|
|
#define REMOVE_NEVER 0
|
|
|
|
#define REMOVE_MAYBE_USER 1
|
|
|
|
#define REMOVE_MAYBE_SCHED 2
|
|
|
|
#define REMOVE_ALWAYS 3
|
|
|
|
|
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
|
|
|
|
2008-10-04 23:44:24 +00:00
|
|
|
/// Represents a job in progress.
|
|
|
|
|
|
|
|
/// 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 {
|
|
|
|
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;
|
|
|
|
|
2009-01-23 00:02:39 +00:00
|
|
|
//// START OF ITEMS SAVED IN STATE FILE
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
int _task_state;
|
2008-10-04 23:44:24 +00:00
|
|
|
/// subdirectory of slots/ where this runs
|
|
|
|
int slot;
|
2008-12-03 19:50:06 +00:00
|
|
|
/// CPU at the last checkpoint
|
2008-10-04 23:44:24 +00:00
|
|
|
/// Note: "CPU time" refers to the sum over all episodes.
|
|
|
|
/// (not counting the "lost" time after the last checkpoint
|
|
|
|
/// in episodes before the current one)
|
2008-12-02 17:48:29 +00:00
|
|
|
/// TODO: debt should be based on FLOPs, not CPU time
|
2008-10-04 23:44:24 +00:00
|
|
|
/// CPU time at the start of current episode
|
2002-08-05 00:29:34 +00:00
|
|
|
double checkpoint_cpu_time;
|
2009-01-23 00:02:39 +00:00
|
|
|
/// elapsed time at last checkpoint
|
|
|
|
double checkpoint_elapsed_time;
|
|
|
|
/// 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
|
|
|
|
double fraction_done;
|
2008-10-04 23:44:24 +00:00
|
|
|
/// most recent CPU time reported by app
|
2002-08-05 00:29:34 +00:00
|
|
|
double current_cpu_time;
|
2009-01-23 00:02:39 +00:00
|
|
|
|
|
|
|
//// END OF ITEMS SAVED IN STATE FILE
|
|
|
|
|
|
|
|
int scheduler_state;
|
|
|
|
int next_scheduler_state; // temp
|
|
|
|
int signal;
|
|
|
|
double episode_start_cpu_time;
|
|
|
|
/// Wall time at the start of the current run interval
|
|
|
|
double run_interval_start_wall_time;
|
|
|
|
/// wall time at the last checkpoint
|
|
|
|
double checkpoint_wall_time;
|
2008-12-02 17:48:29 +00:00
|
|
|
/// current total elapsed (running) time
|
|
|
|
double elapsed_time;
|
2008-10-04 23:44:24 +00:00
|
|
|
/// disk used by output files and temp files of this task
|
2002-12-06 07:33:45 +00:00
|
|
|
int current_disk_usage(double&);
|
2008-10-04 23:44:24 +00:00
|
|
|
/// directory where process runs (relative)
|
|
|
|
char slot_dir[256];
|
|
|
|
/// 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).
|
|
|
|
char slot_path[512];
|
|
|
|
/// abort if total CPU exceeds this
|
|
|
|
double max_cpu_time;
|
|
|
|
/// abort if disk usage (in+out+temp) exceeds this
|
|
|
|
double max_disk_usage;
|
|
|
|
/// abort if memory usage exceeds this
|
|
|
|
double max_mem_usage;
|
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;
|
2008-10-04 23:44:24 +00:00
|
|
|
/// working set too large to run now
|
|
|
|
bool too_large;
|
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;
|
2008-10-04 23:44:24 +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;
|
2008-10-04 23:44:24 +00:00
|
|
|
/// 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;
|
2008-10-04 23:44:24 +00:00
|
|
|
/// when we sent a quit message; kill if still there after 10 sec
|
2008-05-05 00:51:20 +00:00
|
|
|
int premature_exit_count;
|
|
|
|
|
2008-10-04 23:44:24 +00:00
|
|
|
/// core/app shared mem segment
|
|
|
|
APP_CLIENT_SHM app_client_shm;
|
2004-09-13 05:27:28 +00:00
|
|
|
MSG_QUEUE graphics_request_queue;
|
|
|
|
MSG_QUEUE process_control_queue;
|
2009-01-23 00:02:39 +00:00
|
|
|
|
|
|
|
void set_task_state(int, const char*);
|
|
|
|
inline int task_state() {
|
|
|
|
return _task_state;
|
|
|
|
}
|
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
|
|
|
//
|
2008-10-04 23:44:24 +00:00
|
|
|
/// mode acked by app
|
|
|
|
int graphics_mode_acked;
|
|
|
|
/// mode before last screensaver request
|
|
|
|
int graphics_mode_before_ss;
|
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*);
|
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();
|
2008-10-04 23:44:24 +00:00
|
|
|
/// Kill process forcibly,
|
|
|
|
|
|
|
|
/// Unix: send a SIGKILL signal, Windows: TerminateProcess()
|
|
|
|
/// if restart is true, arrange for resulted to get restarted;
|
|
|
|
/// otherwise it ends with an error
|
2006-12-07 17:30:48 +00:00
|
|
|
int kill_task(bool restart);
|
2008-10-04 23:44:24 +00:00
|
|
|
/// tell a process to stop executing (but stay in mem)
|
|
|
|
|
|
|
|
/// Done by sending it a <suspend> message
|
2005-06-25 23:54:07 +00:00
|
|
|
int suspend();
|
2008-10-04 23:44:24 +00:00
|
|
|
/// Undo a suspend: send a <resume> message
|
2005-06-25 23:54:07 +00:00
|
|
|
int unsuspend();
|
2008-10-04 23:44:24 +00:00
|
|
|
/// can be called whether or not process exists
|
2005-06-25 23:54:07 +00:00
|
|
|
int abort_task(int exit_status, const char*);
|
2008-10-04 23:44:24 +00:00
|
|
|
/// return true if this task has exited
|
|
|
|
bool has_task_exited();
|
|
|
|
/// preempt (via suspend or quit) a running task
|
2009-01-23 00:02:39 +00:00
|
|
|
int preempt(int preempt_type);
|
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();
|
2008-12-02 03:58:32 +00:00
|
|
|
double est_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
|
|
|
};
|
|
|
|
|
2008-10-04 23:44:24 +00:00
|
|
|
/// Represents the set of all jobs in progress
|
|
|
|
|
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();
|
2008-09-29 16:47:10 +00:00
|
|
|
bool exclusive_app_running;
|
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
|