app_ipc.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. // This file is part of BOINC.
  2. // http://boinc.berkeley.edu
  3. // Copyright (C) 2008 University of California
  4. //
  5. // BOINC is free software; you can redistribute it and/or modify it
  6. // under the terms of the GNU Lesser General Public License
  7. // as published by the Free Software Foundation,
  8. // either version 3 of the License, or (at your option) any later version.
  9. //
  10. // BOINC is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. // See the GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef BOINC_APP_IPC_H
  18. #define BOINC_APP_IPC_H
  19. #ifdef __cplusplus
  20. #include <vector>
  21. #include <string>
  22. #include <cstdio>
  23. #include "filesys.h"
  24. #include "hostinfo.h"
  25. #include "proxy_info.h"
  26. #include "prefs.h"
  27. #include "common_defs.h"
  28. // Communication between the core client and the BOINC app library.
  29. // This code is linked into both core client and app lib.
  30. //
  31. // Some apps may involve separate "coordinator" and "worker" programs.
  32. // The coordinator runs one or more worker programs in sequence,
  33. // and don't do work themselves.
  34. //
  35. // Includes the following:
  36. // - shared memory (APP_CLIENT_SHM)
  37. // - main init file
  38. // - fd init file
  39. // - graphics init file
  40. // - conversion of symbolic links
  41. // Shared memory is a set of MSG_CHANNELs.
  42. // First byte of a channel is nonzero if
  43. // the channel contains an unread data.
  44. // This is set by the sender and cleared by the receiver.
  45. // The sender doesn't write if the flag is set.
  46. // Remaining 1023 bytes contain data.
  47. //
  48. #define MSG_CHANNEL_SIZE 1024
  49. struct MSG_CHANNEL {
  50. char buf[MSG_CHANNEL_SIZE];
  51. bool get_msg(char*); // returns a message and clears pending flag
  52. inline bool has_msg() {
  53. return buf[0]?true:false;
  54. }
  55. bool send_msg(const char*); // if there is not a message in the segment,
  56. // writes specified message and sets pending flag
  57. void send_msg_overwrite(const char*);
  58. // write message, overwriting any msg already there
  59. };
  60. struct SHARED_MEM {
  61. MSG_CHANNEL process_control_request;
  62. // core->app
  63. // <quit/>
  64. // <suspend/>
  65. // <resume/>
  66. MSG_CHANNEL process_control_reply;
  67. // app->core
  68. MSG_CHANNEL graphics_request;
  69. // core->app
  70. // not currently used
  71. MSG_CHANNEL graphics_reply;
  72. // app->core
  73. // <web_graphics_url>
  74. // <remote_desktop_addr>
  75. MSG_CHANNEL heartbeat;
  76. // core->app
  77. // <heartbeat/> sent every second, even while app is suspended
  78. // <wss> app's current working set size
  79. // <max_wss> max working set size
  80. MSG_CHANNEL app_status;
  81. // app->core
  82. // status message every second, of the form
  83. // <current_cpu_time>...
  84. // <checkpoint_cpu_time>...
  85. // <working_set_size>...
  86. // <fraction_done> ...
  87. MSG_CHANNEL trickle_up;
  88. // app->core
  89. // <have_new_trickle_up/>
  90. MSG_CHANNEL trickle_down;
  91. // core->app
  92. // <have_new_trickle_down/>
  93. };
  94. // MSG_QUEUE provides a queuing mechanism for shared-mem messages
  95. // (which don't have one otherwise)
  96. //
  97. struct MSG_QUEUE {
  98. std::vector<std::string> msgs;
  99. char name[256];
  100. double last_block; // last time we found message channel full
  101. void init(char*);
  102. void msg_queue_send(const char*, MSG_CHANNEL& channel);
  103. void msg_queue_poll(MSG_CHANNEL& channel);
  104. int msg_queue_purge(const char*);
  105. bool timeout(double);
  106. };
  107. #define DEFAULT_CHECKPOINT_PERIOD 300
  108. #define SHM_PREFIX "shm_"
  109. #define QUIT_PREFIX "quit_"
  110. class APP_CLIENT_SHM {
  111. public:
  112. SHARED_MEM *shm;
  113. void reset_msgs(); // resets all messages and clears their flags
  114. APP_CLIENT_SHM();
  115. };
  116. #ifdef _WIN32
  117. typedef char SHMEM_SEG_NAME[256];
  118. #else
  119. typedef int SHMEM_SEG_NAME;
  120. #endif
  121. // parsed version of main init file
  122. // If you add anything here, update copy()
  123. //
  124. struct APP_INIT_DATA {
  125. int major_version; // BOINC client version info
  126. int minor_version;
  127. int release;
  128. int app_version;
  129. char app_name[256];
  130. char symstore[256]; // symstore URL (Windows)
  131. char acct_mgr_url[256];
  132. // if client is using account manager, its URL
  133. char* project_preferences;
  134. // project prefs XML
  135. int userid;
  136. // project's DB ID for this user/team/host
  137. int teamid;
  138. int hostid;
  139. char user_name[256];
  140. char team_name[256];
  141. char project_dir[256]; // where project files are stored on host
  142. char boinc_dir[MAXPATHLEN]; // BOINC data directory
  143. char wu_name[256]; // workunit name
  144. char result_name[256];
  145. char authenticator[256]; // user's authenticator
  146. int slot; // the slot this job is running in (0, 1, ...)
  147. int client_pid; // process ID of BOINC client
  148. double user_total_credit;
  149. double user_expavg_credit;
  150. double host_total_credit;
  151. double host_expavg_credit;
  152. double resource_share_fraction; // this project's resource share frac
  153. HOST_INFO host_info;
  154. PROXY_INFO proxy_info; // in case app wants to use network
  155. GLOBAL_PREFS global_prefs;
  156. double starting_elapsed_time; // elapsed time, counting previous episodes
  157. bool using_sandbox; // client is using account-based sandboxing
  158. bool vm_extensions_disabled;
  159. // client has already been notified that the VM extensions of
  160. // the processor have been disabled
  161. // info about the WU
  162. double rsc_fpops_est;
  163. double rsc_fpops_bound;
  164. double rsc_memory_bound;
  165. double rsc_disk_bound;
  166. double computation_deadline;
  167. // the following are used for compound apps,
  168. // where each stage of the computation is a fixed fraction of the total.
  169. //
  170. double fraction_done_start;
  171. double fraction_done_end;
  172. // info for GPU apps
  173. //
  174. char gpu_type[64];
  175. int gpu_device_num;
  176. int gpu_opencl_dev_index;
  177. double gpu_usage; // APP_VERSION.gpu_usage.usage
  178. // info for multicore apps: how many cores to use
  179. //
  180. double ncpus;
  181. // client configuration info
  182. //
  183. bool vbox_window; // whether to open a console window for VM apps
  184. // list of files in the app version (for wrappers)
  185. //
  186. std::vector<std::string> app_files;
  187. // Items used by the BOINC runtime system
  188. //
  189. double checkpoint_period; // recommended checkpoint period
  190. SHMEM_SEG_NAME shmem_seg_name;
  191. double wu_cpu_time; // cpu time from previous episodes
  192. APP_INIT_DATA();
  193. APP_INIT_DATA(const APP_INIT_DATA&); // copy constructor
  194. APP_INIT_DATA &operator=(const APP_INIT_DATA&);
  195. void copy(const APP_INIT_DATA&); // actually do the copy here
  196. void clear();
  197. ~APP_INIT_DATA();
  198. };
  199. struct GRAPHICS_INFO {
  200. int xsize;
  201. int ysize;
  202. double refresh_period;
  203. };
  204. typedef struct GRAPHICS_INFO GRAPHICS_INFO;
  205. int write_init_data_file(FILE* f, APP_INIT_DATA&);
  206. int parse_init_data_file(FILE* f, APP_INIT_DATA&);
  207. int write_graphics_file(FILE* f, GRAPHICS_INFO* gi);
  208. int parse_graphics_file(FILE* f, GRAPHICS_INFO* gi);
  209. // filenames used in the slot directory
  210. //
  211. #define INIT_DATA_FILE "init_data.xml"
  212. #define BOINC_FINISH_CALLED_FILE "boinc_finish_called"
  213. #define TEMPORARY_EXIT_FILE "boinc_temporary_exit"
  214. #define TRICKLE_UP_FILENAME "trickle_up.xml"
  215. #define STDERR_FILE "stderr.txt"
  216. #define STDOUT_FILE "stdout.txt"
  217. #define LOCKFILE "boinc_lockfile"
  218. #define UPLOAD_FILE_REQ_PREFIX "boinc_ufr_"
  219. #define UPLOAD_FILE_STATUS_PREFIX "boinc_ufs_"
  220. // other filenames
  221. #define PROJECT_DIR "projects"
  222. extern int boinc_link(const char* phys_name, const char* logical_name);
  223. extern int boinc_resolve_filename_s(const char*, std::string&);
  224. extern std::string resolve_soft_link(const char* project_dir, const char* file);
  225. extern void url_to_project_dir(char* url, char* dir, int dirsize);
  226. extern "C" {
  227. #endif
  228. extern int boinc_resolve_filename(const char*, char*, int len);
  229. #ifdef __cplusplus
  230. } // extern "C" {
  231. #endif
  232. #endif