00001 // This file is part of BOINC. 00002 // http://boinc.berkeley.edu 00003 // Copyright (C) 2008 University of California 00004 // 00005 // BOINC is free software; you can redistribute it and/or modify it 00006 // under the terms of the GNU Lesser General Public License 00007 // as published by the Free Software Foundation, 00008 // either version 3 of the License, or (at your option) any later version. 00009 // 00010 // BOINC is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00013 // See the GNU Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with BOINC. If not, see <http://www.gnu.org/licenses/>. 00017 00018 #ifndef _TASK_ 00019 #define _TASK_ 00020 00021 #ifndef _WIN32 00022 #include <stdio.h> 00023 #include <vector> 00024 #endif 00025 00026 #include "client_types.h" 00027 #include "common_defs.h" 00028 #include "app_ipc.h" 00029 #include "procinfo.h" 00030 00031 class CLIENT_STATE; 00032 typedef int PROCESS_ID; 00033 00034 #define MAX_STDERR_LEN 65536 00035 // The stderr output of an application is truncated to this length 00036 // before sending to server, 00037 // to protect against apps that write unbounded amounts. 00038 00039 00041 00047 00048 class ACTIVE_TASK { 00049 int _task_state; 00050 public: 00051 #ifdef _WIN32 00052 HANDLE pid_handle, shm_handle; 00053 bool kill_all_children(); 00054 #endif 00055 SHMEM_SEG_NAME shmem_seg_name; 00056 RESULT* result; 00057 WORKUNIT* wup; 00058 APP_VERSION* app_version; 00059 PROCESS_ID pid; 00060 PROCINFO procinfo; 00061 00063 int slot; 00064 inline int task_state() { 00065 return _task_state; 00066 } 00067 void set_task_state(int, const char*); 00068 int scheduler_state; 00069 int next_scheduler_state; // temp 00070 int signal; 00072 00075 double fraction_done; 00077 00081 double debt_interval_start_cpu_time; 00083 double episode_start_cpu_time; 00085 double run_interval_start_wall_time; 00087 double checkpoint_cpu_time; 00089 double checkpoint_wall_time; 00091 double current_cpu_time; 00093 int current_disk_usage(double&); 00095 char slot_dir[256]; 00097 00101 char slot_path[512]; 00103 double max_cpu_time; 00105 double max_disk_usage; 00107 double max_mem_usage; 00108 bool have_trickle_down; 00109 bool send_upload_file_status; 00111 bool too_large; 00112 bool needs_shmem; // waiting for a free shared memory segment 00113 int want_network; 00115 00117 double abort_time; 00119 00121 double quit_time; 00123 int premature_exit_count; 00124 00126 APP_CLIENT_SHM app_client_shm; 00127 MSG_QUEUE graphics_request_queue; 00128 MSG_QUEUE process_control_queue; 00129 bool coprocs_reserved; 00130 void reserve_coprocs(); 00131 void free_coprocs(); 00132 00133 // info related to app's graphics mode (win, screensaver, etc.) 00134 // 00136 int graphics_mode_acked; 00138 int graphics_mode_before_ss; 00139 double graphics_mode_ack_timeout; 00140 00141 #ifdef SIM 00142 double cpu_time_left; 00143 #endif 00144 00145 #if (defined (__APPLE__) && (defined(__i386__) || defined(__x86_64__))) 00146 // PowerPC apps emulated on i386 Macs crash if running graphics 00147 int powerpc_emulated_on_i386; 00148 int is_native_i386_app(char*); 00149 #endif 00150 GRAPHICS_MSG graphics_msg; 00151 void request_graphics_mode(GRAPHICS_MSG&); 00152 int request_reread_prefs(); 00153 int request_reread_app_info(); 00154 void check_graphics_mode_ack(); 00155 int link_user_files(); 00156 int get_shmem_seg_name(); 00157 bool runnable() { 00158 return _task_state == PROCESS_UNINITIALIZED 00159 || _task_state == PROCESS_EXECUTING 00160 || _task_state == PROCESS_SUSPENDED; 00161 } 00162 00163 ACTIVE_TASK(); 00164 ~ACTIVE_TASK(); 00165 int init(RESULT*); 00166 void cleanup_task(); 00167 00168 int start(bool first_time); // start a process 00169 int request_exit(); 00170 // ask the process to exit gracefully, 00171 // i.e. by sending a <quit> message 00172 int request_abort(); // send "abort" message 00173 bool process_exists(); 00175 00179 int kill_task(bool restart); 00181 00183 int suspend(); 00185 int unsuspend(); 00187 int abort_task(int exit_status, const char*); 00189 bool has_task_exited(); 00191 int preempt(bool quit_task); 00192 int resume_or_start(bool); 00193 void send_network_available(); 00194 #ifdef _WIN32 00195 void handle_exited_app(unsigned long); 00196 #else 00197 void handle_exited_app(int stat); 00198 #endif 00199 void handle_premature_exit(bool&); 00200 00201 bool check_max_disk_exceeded(); 00202 00203 bool get_app_status_msg(); 00204 bool get_trickle_up_msg(); 00205 double est_cpu_time_to_completion(bool for_work_fetch); 00206 bool read_stderr_file(); 00207 bool finish_file_present(); 00208 bool supports_graphics(); 00209 int write_app_init_file(); 00210 int move_trickle_file(); 00211 int handle_upload_files(); 00212 void upload_notify_app(const FILE_INFO*, const FILE_REF*); 00213 int copy_output_files(); 00214 00215 int write(MIOFILE&); 00216 int write_gui(MIOFILE&); 00217 int parse(MIOFILE&); 00218 }; 00219 00221 00222 class ACTIVE_TASK_SET { 00223 public: 00224 typedef std::vector<ACTIVE_TASK*> active_tasks_v; 00225 active_tasks_v active_tasks; 00226 ACTIVE_TASK* lookup_pid(int); 00227 ACTIVE_TASK* lookup_result(RESULT*); 00228 void init(); 00229 bool poll(); 00230 void suspend_all(bool leave_apps_in_memory=true); 00231 void unsuspend_all(); 00232 bool is_task_executing(); 00233 void request_tasks_exit(PROJECT* p=0); 00234 int wait_for_exit(double, PROJECT* p=0); 00235 int exit_tasks(PROJECT* p=0); 00236 void kill_tasks(PROJECT* p=0); 00237 int abort_project(PROJECT*); 00238 bool get_msgs(); 00239 bool check_app_exited(); 00240 bool check_rsc_limits_exceeded(); 00241 bool check_quit_timeout_exceeded(); 00242 bool is_slot_in_use(int); 00243 bool is_slot_dir_in_use(char*); 00244 int get_free_slot(); 00245 void send_heartbeats(); 00246 void send_trickle_downs(); 00247 void report_overdue(); 00248 void handle_upload_files(); 00249 void upload_notify_app(FILE_INFO*); 00250 bool want_network(); // does any task want network? 00251 void network_available(); // notify tasks that network is available 00252 void free_mem(); 00253 bool slot_taken(int); 00254 void get_memory_usage(); 00255 bool exclusive_app_running; 00256 00257 // graphics-related functions 00258 void graphics_poll(); 00259 void process_control_poll(); 00260 void request_reread_prefs(PROJECT*); 00261 void request_reread_app_info(); 00262 00263 int write(MIOFILE&); 00264 int parse(MIOFILE&); 00265 }; 00266 00267 #endif
1.5.6