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.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"
|
2003-05-07 23:42:17 +00:00
|
|
|
#include "app_ipc.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
|
2002-12-06 07:33:45 +00:00
|
|
|
class CLIENT_STATE;
|
|
|
|
typedef int PROCESS_ID;
|
|
|
|
|
2004-08-23 22:06:48 +00:00
|
|
|
// process states of an ACTIVE_TASK
|
|
|
|
//
|
2002-12-05 19:13:06 +00:00
|
|
|
#define PROCESS_UNINITIALIZED 0
|
2004-08-23 22:06:48 +00:00
|
|
|
|
|
|
|
// states in which the process exists
|
|
|
|
#define PROCESS_EXECUTING 1
|
|
|
|
// process is running, as far as we know
|
|
|
|
#define PROCESS_SUSPENDED 9
|
|
|
|
// we've sent it a "suspend" message
|
|
|
|
#define PROCESS_ABORT_PENDING 5
|
|
|
|
// process exceeded limits; killed it, waiting to exit
|
|
|
|
|
|
|
|
// states in which the process has exited
|
2002-12-05 19:13:06 +00:00
|
|
|
#define PROCESS_EXITED 2
|
|
|
|
#define PROCESS_WAS_SIGNALED 3
|
|
|
|
#define PROCESS_EXIT_UNKNOWN 4
|
2002-12-06 07:33:45 +00:00
|
|
|
#define PROCESS_ABORTED 6
|
2004-08-23 22:06:48 +00:00
|
|
|
// aborted process has exited
|
2002-12-06 07:33:45 +00:00
|
|
|
#define PROCESS_COULDNT_START 7
|
2004-04-04 01:59:47 +00:00
|
|
|
#define PROCESS_IN_LIMBO 8
|
2004-08-23 22:06:48 +00:00
|
|
|
// process exited zero, but no finish file; leave the task there.
|
2002-12-05 19:13:06 +00:00
|
|
|
|
2004-08-23 22:06:48 +00:00
|
|
|
// CPU scheduler states of an ACTIVE_TASK
|
2004-06-30 01:10:22 +00:00
|
|
|
#define CPU_SCHED_UNINITIALIZED 0
|
|
|
|
#define CPU_SCHED_PREEMPTED 1
|
2004-08-23 22:06:48 +00:00
|
|
|
#define CPU_SCHED_SCHEDULED 2
|
2004-06-30 01:10:22 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-12-06 07:33:45 +00:00
|
|
|
// Represents a task in progress.
|
|
|
|
// The execution of a task may be divided into many "episodes"
|
|
|
|
// (if the host is turned off/on, e.g.)
|
|
|
|
// A task may checkpoint now and then.
|
|
|
|
// Each episode begins with the state of the last checkpoint.
|
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 {
|
|
|
|
public:
|
2002-06-06 18:42:01 +00:00
|
|
|
#ifdef _WIN32
|
2003-03-18 19:37:09 +00:00
|
|
|
HANDLE pid_handle, thread_handle, quitRequestEvent, shm_handle;
|
2003-03-17 19:24:38 +00:00
|
|
|
#else
|
2004-08-31 21:02:17 +00:00
|
|
|
//key_t shm_key;
|
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;
|
|
|
|
int slot; // which slot (determines directory)
|
2005-01-21 23:26:36 +00:00
|
|
|
int task_state;
|
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
|
2004-10-21 02:18:11 +00:00
|
|
|
#if 0
|
2003-06-06 21:23:14 +00:00
|
|
|
double frac_rate_of_change;
|
2003-11-06 20:27:07 +00:00
|
|
|
// How much the percent done changes per second,
|
|
|
|
// based on a recent exponential weighted average
|
2003-06-06 21:23:14 +00:00
|
|
|
double last_frac_done, recent_change;
|
2003-11-06 20:27:07 +00:00
|
|
|
double last_frac_update;
|
2004-10-21 02:18:11 +00:00
|
|
|
#endif
|
2004-06-30 01:10:22 +00:00
|
|
|
double cpu_time_at_last_sched;
|
|
|
|
// CPU time when CPU scheduler last ran
|
2004-05-21 20:06:34 +00:00
|
|
|
double episode_start_cpu_time;
|
|
|
|
// CPU time at the start of current episode
|
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
|
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
|
2004-12-14 20:28:13 +00:00
|
|
|
double vm_bytes;
|
|
|
|
// virtual memory used
|
|
|
|
double rss_bytes;
|
|
|
|
// resident set size
|
2002-12-06 07:33:45 +00:00
|
|
|
int current_disk_usage(double&);
|
|
|
|
// disk used by output files and temp files of this task
|
2002-08-24 00:41:25 +00:00
|
|
|
char slot_dir[256]; // directory where process runs
|
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;
|
2004-08-06 23:17:59 +00:00
|
|
|
bool pending_suspend_via_quit; // waiting for task to suspend via quit
|
2002-12-06 07:33:45 +00:00
|
|
|
|
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;
|
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
|
2003-05-08 18:11:05 +00:00
|
|
|
int graphics_mode_before_ss; // mode before last screensaver request
|
2004-09-13 05:27:28 +00:00
|
|
|
bool is_ss_app;
|
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();
|
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
|
|
|
|
2003-05-22 20:47:56 +00:00
|
|
|
int start(bool first_time); // start the task running
|
|
|
|
int request_exit(); // Send a SIGQUIT signal or equivalent
|
2004-08-23 22:06:48 +00:00
|
|
|
bool process_exists();
|
2003-05-22 20:47:56 +00:00
|
|
|
int kill_task(); // send a SIGKILL signal or equivalent
|
|
|
|
int suspend(); // send a SIGSTOP signal or equivalent
|
|
|
|
int unsuspend(); // send a SIGCONT signal or equivalent
|
2005-02-16 23:17:43 +00:00
|
|
|
int abort_task(const char*); // flag as abort pending and send kill signal
|
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
|
2004-06-30 01:10:22 +00:00
|
|
|
int resume_or_start();
|
2004-08-09 19:06:47 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
bool handle_exited_app(unsigned long);
|
|
|
|
#else
|
2004-09-22 21:08:26 +00:00
|
|
|
bool handle_exited_app(int stat);
|
2004-08-09 19:06:47 +00:00
|
|
|
#endif
|
2003-05-22 20:47:56 +00:00
|
|
|
|
2003-05-28 19:56:53 +00:00
|
|
|
bool check_max_cpu_exceeded();
|
|
|
|
bool check_max_disk_exceeded();
|
|
|
|
bool check_max_mem_exceeded();
|
|
|
|
|
2004-08-24 21:44:54 +00:00
|
|
|
bool get_app_status_msg();
|
|
|
|
bool get_trickle_up_msg();
|
2004-10-20 21:11:29 +00:00
|
|
|
double est_cpu_time_to_completion();
|
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*);
|
2002-06-06 18:42:01 +00:00
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
int write(MIOFILE&);
|
|
|
|
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
|
|
|
int remove(ACTIVE_TASK*);
|
|
|
|
ACTIVE_TASK* lookup_pid(int);
|
2003-08-12 20:28:55 +00:00
|
|
|
ACTIVE_TASK* lookup_result(RESULT*);
|
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();
|
2004-06-30 01:10:22 +00:00
|
|
|
int restart_tasks(int max_tasks);
|
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();
|
2004-08-06 23:17:59 +00:00
|
|
|
bool vm_limit_exceeded(double);
|
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*);
|
2003-05-08 18:11:05 +00:00
|
|
|
|
|
|
|
// screensaver-related functions
|
2004-09-13 05:27:28 +00:00
|
|
|
ACTIVE_TASK* get_ss_app();
|
2003-05-08 18:11:05 +00:00
|
|
|
void save_app_modes();
|
|
|
|
void hide_apps();
|
|
|
|
void restore_apps();
|
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
|