2003-06-11 23:36:48 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-04-30 22:22:54 +00:00
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
2003-06-11 23:36:48 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-08-12 20:28:55 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
2003-08-12 20:28:55 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-08-12 20:28:55 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
2002-12-05 19:13:06 +00:00
|
|
|
// Possible states of a process in an ACTIVE_TASK
|
|
|
|
#define PROCESS_UNINITIALIZED 0
|
|
|
|
#define PROCESS_RUNNING 1
|
|
|
|
#define PROCESS_EXITED 2
|
|
|
|
#define PROCESS_WAS_SIGNALED 3
|
|
|
|
#define PROCESS_EXIT_UNKNOWN 4
|
2002-12-06 07:33:45 +00:00
|
|
|
#define PROCESS_ABORT_PENDING 5
|
|
|
|
// process exceeded limits; killed it, waiting to exit
|
|
|
|
#define PROCESS_ABORTED 6
|
|
|
|
// process has exited
|
|
|
|
#define PROCESS_COULDNT_START 7
|
2004-04-04 01:59:47 +00:00
|
|
|
#define PROCESS_IN_LIMBO 8
|
|
|
|
// process exited zero, but no finish file.
|
|
|
|
// Leave it there.
|
2002-12-05 19:13:06 +00:00
|
|
|
|
2004-06-30 01:10:22 +00:00
|
|
|
// Possible scheduler states of an ACTIVE_TASK
|
|
|
|
#define CPU_SCHED_UNINITIALIZED 0
|
|
|
|
#define CPU_SCHED_PREEMPTED 1
|
|
|
|
#define CPU_SCHED_RUNNING 2
|
|
|
|
|
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
|
|
|
|
key_t shm_key;
|
2002-06-06 18:42:01 +00:00
|
|
|
#endif
|
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)
|
|
|
|
int 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 exit_status;
|
|
|
|
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
|
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-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-07-26 22:23:16 +00:00
|
|
|
double vm_size;
|
|
|
|
// most recent virtual memory used in kbytes
|
|
|
|
double resident_set_size;
|
|
|
|
// most recent resident set size in kbytes
|
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;
|
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
|
|
|
|
|
|
|
|
// info related to app's graphics mode (win, screensaver, etc.)
|
2004-07-18 04:41:27 +00:00
|
|
|
// NOTE: because of the way message-passing works,
|
|
|
|
// request_graphics_mode() sets a variable (graphic_mode_requested).
|
|
|
|
// ACTIVE_TASK_SET::poll_graphics() tries to send this,
|
|
|
|
// and sets graphics_mode_sent when it succeeds.
|
|
|
|
//
|
|
|
|
int graphics_mode_requested; // mode to send
|
|
|
|
int graphics_mode_sent; // mode actually sent
|
|
|
|
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
|
2003-05-09 20:33:57 +00:00
|
|
|
void request_graphics_mode(int);
|
2004-07-18 04:41:27 +00:00
|
|
|
bool send_graphics_mode(int);
|
2003-10-31 22:37:46 +00:00
|
|
|
int request_reread_prefs();
|
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();
|
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*);
|
|
|
|
|
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
|
|
|
|
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
|
2004-03-31 23:39:12 +00:00
|
|
|
int abort_task(char*); // flag as abort pending and send kill signal
|
2003-05-22 20:47:56 +00:00
|
|
|
bool task_exited(); // return true if this task has exited
|
2004-06-30 01:10:22 +00:00
|
|
|
int preempt();
|
|
|
|
int resume_or_start();
|
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();
|
|
|
|
|
2003-11-25 17:17:21 +00:00
|
|
|
void estimate_frac_rate_of_change(double);
|
2004-08-03 09:50:24 +00:00
|
|
|
bool get_msg();
|
2002-11-20 20:14:48 +00:00
|
|
|
double est_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();
|
2003-10-31 22:37:46 +00:00
|
|
|
int write_app_init_file(APP_INIT_DATA&);
|
2004-01-04 06:48:40 +00:00
|
|
|
int move_trickle_file();
|
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*);
|
2002-04-30 22:22:54 +00:00
|
|
|
bool poll();
|
|
|
|
void suspend_all();
|
|
|
|
void unsuspend_all();
|
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();
|
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();
|
2003-05-08 18:11:05 +00:00
|
|
|
|
|
|
|
// screensaver-related functions
|
2004-07-18 04:41:27 +00:00
|
|
|
//ACTIVE_TASK* get_graphics_capable_app();
|
|
|
|
ACTIVE_TASK* get_app_graphics_mode_requested(int req_mode);
|
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();
|
2003-10-31 22:37:46 +00:00
|
|
|
void request_reread_prefs(PROJECT*);
|
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
|