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
|
|
|
|
2010-09-24 20:02:42 +00:00
|
|
|
#ifndef _APP_H_
|
|
|
|
#define _APP_H_
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#ifndef _WIN32
|
2009-02-26 00:23:23 +00:00
|
|
|
#include <cstdio>
|
2002-04-30 22:22:54 +00:00
|
|
|
#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
|
|
|
|
2010-09-24 20:37:45 +00:00
|
|
|
#define ABORT_TIMEOUT 60
|
|
|
|
// if we send app <abort> request, wait this long before killing it.
|
|
|
|
// This gives it time to download symbol files (which can be several MB)
|
|
|
|
// and write stack trace to stderr
|
|
|
|
#define QUIT_TIMEOUT 10
|
|
|
|
// Same, for <quit>. Shorter because no stack trace is generated
|
|
|
|
|
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
|
|
|
|
|
2010-09-24 20:37:45 +00:00
|
|
|
struct CLIENT_STATE;
|
2002-12-06 07:33:45 +00:00
|
|
|
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.
|
|
|
|
|
2010-04-01 05:54:29 +00:00
|
|
|
// Represents a job in progress.
|
2008-10-04 23:44:24 +00:00
|
|
|
|
2010-04-01 05:54:29 +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.
|
2008-10-04 23:44:24 +00:00
|
|
|
|
2009-12-21 19:20:28 +00:00
|
|
|
struct ACTIVE_TASK {
|
2002-06-06 18:42:01 +00:00
|
|
|
#ifdef _WIN32
|
2010-04-23 22:31:08 +00:00
|
|
|
HANDLE process_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;
|
|
|
|
|
2010-04-01 05:54:29 +00:00
|
|
|
// START OF ITEMS SAVED IN STATE FILE
|
2009-01-23 00:02:39 +00:00
|
|
|
int _task_state;
|
2008-10-04 23:44:24 +00:00
|
|
|
int slot;
|
2010-04-01 05:54:29 +00:00
|
|
|
// subdirectory of slots/ where this runs
|
2002-08-05 00:29:34 +00:00
|
|
|
double checkpoint_cpu_time;
|
2010-04-01 05:54:29 +00:00
|
|
|
// CPU at the last checkpoint
|
|
|
|
// 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)
|
2009-01-23 00:02:39 +00:00
|
|
|
double checkpoint_elapsed_time;
|
2010-04-01 05:54:29 +00:00
|
|
|
// elapsed time at last checkpoint
|
2011-04-26 17:02:09 +00:00
|
|
|
double checkpoint_fraction_done;
|
|
|
|
// fraction done at last checkpoint
|
|
|
|
double checkpoint_fraction_done_elapsed_time;
|
|
|
|
// fraction done elapsed time at last checkpoint
|
2002-08-05 00:29:34 +00:00
|
|
|
double current_cpu_time;
|
2010-04-01 05:54:29 +00:00
|
|
|
// most recent CPU time reported by app
|
2010-03-05 21:13:53 +00:00
|
|
|
bool once_ran_edf;
|
2009-01-23 00:02:39 +00:00
|
|
|
|
2010-04-01 05:54:29 +00:00
|
|
|
// END OF ITEMS SAVED IN STATE FILE
|
2009-01-23 00:02:39 +00:00
|
|
|
|
2011-04-26 17:02:09 +00:00
|
|
|
double fraction_done;
|
|
|
|
// 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_elapsed_time;
|
|
|
|
// elapsed time when fraction done was last reported
|
2009-01-23 00:02:39 +00:00
|
|
|
int scheduler_state;
|
|
|
|
int next_scheduler_state; // temp
|
|
|
|
int signal;
|
|
|
|
double run_interval_start_wall_time;
|
2010-04-01 05:54:29 +00:00
|
|
|
// Wall time at the start of the current run interval
|
2009-01-23 00:02:39 +00:00
|
|
|
double checkpoint_wall_time;
|
2010-04-01 05:54:29 +00:00
|
|
|
// wall time at the last checkpoint
|
2008-12-02 17:48:29 +00:00
|
|
|
double elapsed_time;
|
2010-04-01 05:54:29 +00:00
|
|
|
// current total elapsed (running) time
|
2011-09-16 19:16:12 +00:00
|
|
|
double bytes_sent;
|
|
|
|
// reported by the app if it does network I/O
|
|
|
|
double bytes_received;
|
2008-10-04 23:44:24 +00:00
|
|
|
char slot_dir[256];
|
2010-04-01 05:54:29 +00:00
|
|
|
// directory where process runs (relative)
|
2008-10-04 23:44:24 +00:00
|
|
|
char slot_path[512];
|
2010-04-01 05:54:29 +00:00
|
|
|
// 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).
|
2009-02-26 17:51:38 +00:00
|
|
|
double max_elapsed_time;
|
2010-04-01 05:54:29 +00:00
|
|
|
// abort if elapsed time exceeds this
|
2008-10-04 23:44:24 +00:00
|
|
|
double max_disk_usage;
|
2010-04-01 05:54:29 +00:00
|
|
|
// abort if disk usage (in+out+temp) exceeds this
|
2008-10-04 23:44:24 +00:00
|
|
|
double max_mem_usage;
|
2010-04-01 05:54:29 +00:00
|
|
|
// 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;
|
2008-10-04 23:44:24 +00:00
|
|
|
bool too_large;
|
2010-04-01 05:54:29 +00:00
|
|
|
// 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;
|
2010-04-01 05:54:29 +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;
|
2010-04-01 05:54:29 +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;
|
|
|
|
int premature_exit_count;
|
2010-04-01 05:54:29 +00:00
|
|
|
// when we sent a quit message; kill if still there after 10 sec
|
2011-01-19 16:46:55 +00:00
|
|
|
bool overdue_checkpoint;
|
|
|
|
// running past end of time slice because not checkpointed;
|
|
|
|
// when we do checkpoint, reschedule
|
|
|
|
double last_deadline_miss_time;
|
2008-05-05 00:51:20 +00:00
|
|
|
|
2008-10-04 23:44:24 +00:00
|
|
|
APP_CLIENT_SHM app_client_shm;
|
2010-04-01 05:54:29 +00:00
|
|
|
// core/app shared mem segment
|
2004-09-13 05:27:28 +00:00
|
|
|
MSG_QUEUE graphics_request_queue;
|
|
|
|
MSG_QUEUE process_control_queue;
|
2011-09-02 20:47:05 +00:00
|
|
|
std::vector<int> other_pids;
|
|
|
|
// IDs of processes that are part of this task
|
|
|
|
// but not descendants of the main process
|
|
|
|
// (e.g. VMs created by vboxwrapper)
|
|
|
|
// These are communicated via the app_status message channel
|
2011-12-26 03:30:32 +00:00
|
|
|
char web_graphics_url[256];
|
2009-01-23 00:02:39 +00:00
|
|
|
|
|
|
|
void set_task_state(int, const char*);
|
|
|
|
inline int task_state() {
|
|
|
|
return _task_state;
|
|
|
|
}
|
2003-05-08 18:11:05 +00:00
|
|
|
|
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
|
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-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
|
|
|
|
2011-04-26 17:02:09 +00:00
|
|
|
int current_disk_usage(double&);
|
|
|
|
// disk used by output files and temp files of this task
|
2009-05-28 19:26:27 +00:00
|
|
|
void get_free_slot(RESULT*);
|
2005-06-25 23:54:07 +00:00
|
|
|
int start(bool first_time); // start a process
|
2008-10-04 23:44:24 +00:00
|
|
|
|
2011-06-17 04:18:28 +00:00
|
|
|
// Termination stuff.
|
|
|
|
// Terminology:
|
|
|
|
// "kill": forcibly kill the main process and all its descendants.
|
|
|
|
// (note: on Windows secure mode, we can't kill the descendants)
|
|
|
|
// "request exit": send a request-exit message, and enumerate descendants.
|
|
|
|
// If after 15 secs any processes remain, kill them
|
|
|
|
// called from:
|
|
|
|
// task preemption
|
|
|
|
// project detach or reset
|
|
|
|
// implementation:
|
|
|
|
// sends msg, sets quit_time, state QUIT_PENDING;
|
|
|
|
// get list of descendants
|
|
|
|
// normal exit handled in handle_premature_exit()
|
|
|
|
// timeout handled in ACTIVE_TASK_SET::poll()
|
|
|
|
// "abort_task": like request exit,
|
|
|
|
// but the app is supposed to write a stack trace to stderr
|
|
|
|
// called from: rsc exceeded; got ack of running task;
|
|
|
|
// intermediate upload failure
|
|
|
|
// client exiting w/ abort_jobs_on_exit set
|
|
|
|
//
|
|
|
|
int request_exit();
|
|
|
|
int request_abort();
|
2006-12-07 17:30:48 +00:00
|
|
|
int kill_task(bool restart);
|
2010-04-01 05:54:29 +00:00
|
|
|
// Kill process forcibly,
|
|
|
|
// otherwise it ends with an error
|
|
|
|
// Unix: send a SIGKILL signal, Windows: TerminateProcess()
|
2011-06-17 04:18:28 +00:00
|
|
|
// if restart is true, arrange for result to get restarted;
|
|
|
|
int abort_task(int exit_status, const char*);
|
|
|
|
// can be called whether or not process exists
|
|
|
|
|
|
|
|
|
|
|
|
// Implementation stuff related to termination
|
|
|
|
//
|
|
|
|
std::vector<int> descendants;
|
|
|
|
bool process_exists();
|
|
|
|
bool has_task_exited();
|
|
|
|
// return true if this task has exited
|
2008-10-04 23:44:24 +00:00
|
|
|
|
2005-06-25 23:54:07 +00:00
|
|
|
int suspend();
|
2010-04-01 05:54:29 +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 unsuspend();
|
2010-04-01 05:54:29 +00:00
|
|
|
// Undo a suspend: send a <resume> message
|
2009-01-23 00:02:39 +00:00
|
|
|
int preempt(int preempt_type);
|
2010-04-01 05:54:29 +00:00
|
|
|
// 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();
|
2011-12-26 03:30:32 +00:00
|
|
|
void get_graphics_msg();
|
2010-11-17 20:04:58 +00:00
|
|
|
double est_dur();
|
2011-10-05 22:16:02 +00:00
|
|
|
int read_stderr_file();
|
2004-04-04 01:59:47 +00:00
|
|
|
bool finish_file_present();
|
2009-12-13 05:16:40 +00:00
|
|
|
bool temporary_exit_file_present(double&);
|
2011-09-11 17:26:31 +00:00
|
|
|
void init_app_init_data(APP_INIT_DATA&);
|
|
|
|
int write_app_init_file(APP_INIT_DATA&);
|
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();
|
2011-08-03 19:47:26 +00:00
|
|
|
int setup_file(FILE_INFO*, FILE_REF&, char*, bool, bool);
|
|
|
|
bool must_copy_file(FILE_REF&, bool);
|
2009-04-15 06:22:53 +00:00
|
|
|
void write_task_state_file();
|
|
|
|
void read_task_state_file();
|
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&);
|
2011-08-09 21:44:14 +00:00
|
|
|
int parse(XML_PARSER&);
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
2010-04-01 05:54:29 +00:00
|
|
|
// Represents the set of all jobs in progress
|
2008-10-04 23:44:24 +00:00
|
|
|
|
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();
|
2010-03-02 01:24:03 +00:00
|
|
|
void suspend_all(int reason);
|
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*);
|
2009-04-15 06:22:53 +00:00
|
|
|
void 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-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
|
|
|
|
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&);
|
2011-08-09 21:44:14 +00:00
|
|
|
int parse(XML_PARSER&);
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
2011-02-16 20:41:19 +00:00
|
|
|
extern double exclusive_app_running; // last time an exclusive app was running
|
|
|
|
extern double exclusive_gpu_app_running;
|
2010-05-12 18:14:30 +00:00
|
|
|
extern int gpu_suspend_reason;
|
2010-01-19 00:03:38 +00:00
|
|
|
extern double non_boinc_cpu_usage;
|
2009-12-10 23:26:35 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#endif
|