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_
|
|
|
|
|
2002-06-06 18:42:01 +00:00
|
|
|
#include "windows_cpp.h"
|
|
|
|
#ifdef _WIN32
|
2002-10-06 00:43:54 +00:00
|
|
|
#include <afxwin.h>
|
2002-06-06 18:42:01 +00:00
|
|
|
#endif
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <vector>
|
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
|
2002-12-05 19:13:06 +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
|
|
|
//
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
// How much the percent done changes per second, based
|
|
|
|
// on a recent exponential weighted average
|
|
|
|
double last_frac_done, recent_change;
|
|
|
|
time_t last_frac_update;
|
2002-08-05 00:29:34 +00:00
|
|
|
double starting_cpu_time;
|
2002-12-06 07:33:45 +00:00
|
|
|
// total CPU time at the start of current episode
|
2002-08-05 00:29:34 +00:00
|
|
|
double checkpoint_cpu_time;
|
2002-12-06 07:33:45 +00:00
|
|
|
// total CPU at the last checkpoint
|
2002-08-05 00:29:34 +00:00
|
|
|
double current_cpu_time;
|
2002-12-06 07:33:45 +00:00
|
|
|
// most recent total CPU time reported by app
|
2003-05-28 19:56:53 +00:00
|
|
|
double working_set_size;
|
2003-06-06 21:23:14 +00:00
|
|
|
// most recent size of RAM working set in bytes
|
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
|
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
|
2003-05-09 21:54:23 +00:00
|
|
|
time_t last_status_msg_time;
|
2003-05-08 18:11:05 +00:00
|
|
|
|
|
|
|
// info related to app's graphics mode (win, screensaver, etc.)
|
|
|
|
int graphics_requested_mode; // our last request to this app
|
|
|
|
int graphics_request_time; // when we sent it
|
|
|
|
int graphics_acked_mode; // most recent mode reported by app
|
|
|
|
int graphics_mode_before_ss; // mode before last screensaver request
|
2003-05-09 20:33:57 +00:00
|
|
|
void request_graphics_mode(int);
|
|
|
|
void check_graphics_mode_ack();
|
2003-05-07 23:42:17 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
ACTIVE_TASK();
|
|
|
|
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
|
2003-05-28 19:56:53 +00:00
|
|
|
int abort(); // 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
|
|
|
|
|
2003-05-28 19:56:53 +00:00
|
|
|
bool check_max_cpu_exceeded();
|
|
|
|
bool check_max_disk_exceeded();
|
|
|
|
bool check_max_mem_exceeded();
|
|
|
|
|
2003-05-22 20:47:56 +00:00
|
|
|
int get_cpu_time_via_shmem(time_t);
|
|
|
|
int get_cpu_time_via_os();
|
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();
|
2003-05-29 18:28:02 +00:00
|
|
|
bool supports_graphics();
|
2002-06-06 18:42:01 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
int write(FILE*);
|
|
|
|
int parse(FILE*, CLIENT_STATE*);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ACTIVE_TASK_SET {
|
|
|
|
public:
|
2003-08-12 20:28:55 +00:00
|
|
|
typedef vector<ACTIVE_TASK*> active_tasks_v;
|
|
|
|
active_tasks_v active_tasks;
|
2002-04-30 22:22:54 +00:00
|
|
|
int insert(ACTIVE_TASK*);
|
|
|
|
int remove(ACTIVE_TASK*);
|
2003-03-11 22:18:01 +00:00
|
|
|
int wait_for_exit(double);
|
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*);
|
2002-04-30 22:22:54 +00:00
|
|
|
bool poll();
|
|
|
|
void suspend_all();
|
|
|
|
void unsuspend_all();
|
|
|
|
int restart_tasks();
|
2003-03-11 22:18:01 +00:00
|
|
|
void request_tasks_exit();
|
2003-05-22 20:47:56 +00:00
|
|
|
int exit_tasks();
|
2003-03-11 22:18:01 +00:00
|
|
|
void kill_tasks();
|
2003-05-22 20:47:56 +00:00
|
|
|
void get_cpu_times();
|
|
|
|
bool check_app_exited();
|
2003-06-06 21:23:14 +00:00
|
|
|
bool check_rsc_limits_exceeded();
|
2002-08-26 22:14:06 +00:00
|
|
|
int get_free_slot(int total_slots);
|
2003-05-08 18:11:05 +00:00
|
|
|
|
|
|
|
// screensaver-related functions
|
|
|
|
ACTIVE_TASK* get_graphics_capable_app();
|
|
|
|
ACTIVE_TASK* get_app_requested(int req_mode);
|
|
|
|
void save_app_modes();
|
|
|
|
void hide_apps();
|
|
|
|
void restore_apps();
|
2003-05-09 20:33:57 +00:00
|
|
|
void check_graphics_mode_ack();
|
2003-05-07 23:42:17 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
int write(FILE*);
|
|
|
|
int parse(FILE*, CLIENT_STATE*);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|