From 0f8f9f3dab5185717cba2747585419351a2c9fe3 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 22 Sep 2008 17:52:41 +0000 Subject: [PATCH] - API: in boinc_exit(), release the lockfile only if we're the main program (otherwise we didn't lock it in the first place, and a crash results). From Artyom Sharov. - scheduler: add support for the GCL simulator, which uses special versions of backend programs that use virtual time, and that wait for signals instead of sleep()ing. To compile: make clean configure CXXFLAGS="-DGCL_SIMULATOR" make svn path=/trunk/boinc/; revision=16036 --- sched/feeder.C | 25 +++++++++++++------------ sched/hr_info.C | 10 ++++------ sched/pymw_assimilator.C | 1 + sched/sched_util.C | 34 ++++++++++++++++++++++++++++++++++ sched/sched_util.h | 7 +++++++ sched/transitioner.C | 21 +++++++++++---------- sched/trickle_handler.C | 5 +++-- sched/validator.C | 23 +++++++++-------------- 8 files changed, 82 insertions(+), 44 deletions(-) diff --git a/sched/feeder.C b/sched/feeder.C index bcddb2eb78..bf4c10741f 100644 --- a/sched/feeder.C +++ b/sched/feeder.C @@ -114,6 +114,9 @@ using std::vector; #include "sched_util.h" #include "sched_msgs.h" #include "hr_info.h" +#ifdef GCL_SIMULATOR +#include "gcl_simulator.h" +#endif #define DEFAULT_SLEEP_INTERVAL 5 @@ -143,7 +146,6 @@ int napps; HR_INFO hr_info; bool using_hr; // true iff any app is using HR -bool simulation = false; void signal_handler(int) { log_messages.printf(MSG_NORMAL, "Signaled by simulator\n"); @@ -508,15 +510,16 @@ void feeder_loop() { bool action = scan_work_array(work_items); ssp->ready = true; if (!action) { - if (simulation) { - signal(SIGUSR2, signal_handler); - pause(); - } else { - log_messages.printf(MSG_DEBUG, - "No action; sleeping %.2f sec\n", sleep_interval - ); - boinc_sleep(sleep_interval); - } +#ifdef GCL_SIMULATOR + log_messages.printf(MSG_DEBUG, "Waiting for signal\n"); + signal(SIGUSR2, simulator_signal_handler); + pause(); +#else + log_messages.printf(MSG_DEBUG, + "No action; sleeping %.2f sec\n", sleep_interval + ); + boinc_sleep(sleep_interval); +#endif } else { if (config.job_size_matching) { update_stats(); @@ -653,8 +656,6 @@ int main(int argc, char** argv) { sprintf(mod_select_clause, "and workunit.id %% %d = %d ", n, j); } else if (!strcmp(argv[i], "-sleep_interval")) { sleep_interval = atof(argv[++i]); - } else if (!strcmp(argv[i], "-simulator")) { - simulation = true; } else { log_messages.printf(MSG_CRITICAL, "bad cmdline arg: %s\n", argv[i] diff --git a/sched/hr_info.C b/sched/hr_info.C index 153f9f5d9a..91162b1219 100644 --- a/sched/hr_info.C +++ b/sched/hr_info.C @@ -58,15 +58,13 @@ int HR_INFO::read_file() { double x; for (i=1; i. + // A sample assimilator that: // 1) if success, copy the output file(s) to a directory // 2) if failure, append a message to an error log diff --git a/sched/sched_util.C b/sched/sched_util.C index c4c5f8feab..f0edaa9547 100644 --- a/sched/sched_util.C +++ b/sched/sched_util.C @@ -292,4 +292,38 @@ int count_unsent_results(int& n, int appid) { } +#ifdef GCL_SIMULATOR + +void simulator_signal_handler(int signum){ + FILE *fsim; + char currenttime[64]; + fsim = fopen("../simulator/sim_time.txt","r"); + if(fsim){ + fscanf(fsim, "%f", &simtime); + fclose(fsim); + } + log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL, + "Invoked by the simulator at time %.0f... \n", simtime + ); +} + +int itime() { + return (int) simtime; +} + +void continue_simulation(const char *daemonname){ + char daemonfile[64]; + sprintf(daemonfile,"../simulator/sim_%s",daemonname); + FILE *fsimlok=fopen(strcat(daemonfile,".lok"),"w"); + if(fsimlok){ + fclose(fsimlok); + FILE *fsim=fopen(strcat(daemonfile,".txt"),"w"); + if (fsim){ + fclose(fsim); + } + } + remove(strcat(daemonfile,".lok")); +} +#endif + const char *BOINC_RCSID_affa6ef1e4 = "$Id$"; diff --git a/sched/sched_util.h b/sched/sched_util.h index 8bbfded8ff..0769b0b688 100644 --- a/sched/sched_util.h +++ b/sched/sched_util.h @@ -19,6 +19,7 @@ #define SCHED_UTIL_H #include "boinc_db.h" +#include "util.h" // "average credit" uses an exponential decay so that recent // activity is weighted more heavily. @@ -77,4 +78,10 @@ extern double fpops_to_credit(double fpops, double intops); extern int count_workunits(int&, const char* query); extern int count_unsent_results(int&, int appid); + +#ifdef GCL_SIMULATOR +extern void simulator_signal_handler(int signum); +extern void continue_simulation(const char *daemonname); +#endif + #endif diff --git a/sched/transitioner.C b/sched/transitioner.C index b70f04e6c6..754af527bf 100644 --- a/sched/transitioner.C +++ b/sched/transitioner.C @@ -44,6 +44,9 @@ using namespace std; #include "sched_config.h" #include "sched_util.h" #include "sched_msgs.h" +#ifdef GCL_SIMULATOR +#include "gcl_simulator.h" +#endif #define LOCKFILE "transitioner.out" #define PIDFILE "transitioner.pid" @@ -60,7 +63,6 @@ R_RSA_PRIVATE_KEY key; int mod_n, mod_i; bool do_mod = false; bool one_pass = false; -bool simulation = false; void signal_handler(int) { log_messages.printf(MSG_NORMAL, "Signaled by simulator\n"); @@ -649,13 +651,14 @@ void main_loop() { log_messages.printf(MSG_DEBUG, "doing a pass\n"); if (!do_pass()) { if (one_pass) break; - if (simulation) { - signal(SIGUSR2, signal_handler); - pause(); - } else { - log_messages.printf(MSG_DEBUG, "sleeping %d\n", SLEEP_INTERVAL); - sleep(SLEEP_INTERVAL); - } +#ifdef GCL_SIMULATOR + continue_simulation("transitioner"); + signal(SIGUSR2, simulator_signal_handler); + pause(); +#else + log_messages.printf(MSG_DEBUG, "sleeping %d\n", SLEEP_INTERVAL); + sleep(SLEEP_INTERVAL); +#endif } } } @@ -674,8 +677,6 @@ int main(int argc, char** argv) { mod_n = atoi(argv[++i]); mod_i = atoi(argv[++i]); do_mod = true; - } else if (!strcmp(argv[i], "-simulator")) { - simulation = true; } } if (!one_pass) check_stop_daemons(); diff --git a/sched/trickle_handler.C b/sched/trickle_handler.C index 98aad19968..f26bac46d6 100644 --- a/sched/trickle_handler.C +++ b/sched/trickle_handler.C @@ -96,9 +96,10 @@ bool do_trickle_scan() { int main_loop(bool one_pass) { int retval; bool did_something; - char buf[256]; - retval = boinc_db.open(config.db_name, config.db_host, config.db_user, config.db_passwd); + retval = boinc_db.open( + config.db_name, config.db_host, config.db_user, config.db_passwd + ); if (retval) { log_messages.printf(MSG_CRITICAL, "boinc_db.open failed: %d\n", retval); exit(1); diff --git a/sched/validator.C b/sched/validator.C index 704b3dc59a..18db1f7192 100644 --- a/sched/validator.C +++ b/sched/validator.C @@ -52,6 +52,9 @@ using namespace std; #include "sched_msgs.h" #include "validator.h" #include "validate_util.h" +#ifdef GCL_SIMULATOR +#include "gcl_simulator.h" +#endif #define LOCKFILE "validate.out" #define PIDFILE "validate.pid" @@ -87,14 +90,8 @@ double max_claimed_credit = 0; bool grant_claimed_credit = false; bool update_credited_job = false; bool credit_from_wu = false; -bool simulation = false; WORKUNIT* g_wup; -void signal_handler(int) { - log_messages.printf(MSG_NORMAL, "Signaled by simulator\n"); - return; -} - bool is_unreplicated(WORKUNIT& wu) { return (wu.target_nresults == 1 && app.target_nresults > 1); } @@ -660,12 +657,12 @@ int main_loop() { did_something = do_validate_scan(); if (!did_something) { if (one_pass) break; - if (simulation) { - signal(SIGUSR2, signal_handler); - pause(); - } else { - sleep(sleep_interval); - } +#ifdef GCL_SIMULATOR + signal(SIGUSR2, simulator_signal_handler); + pause(); +#else + sleep(sleep_interval); +#endif } } return 0; @@ -735,8 +732,6 @@ int main(int argc, char** argv) { update_credited_job = true; } else if (!strcmp(argv[i], "-credit_from_wu")) { credit_from_wu = true; - } else if (!strcmp(argv[i], "-simulator")) { - simulation = true; } else { fprintf(stderr, "Invalid option '%s'\nTry `%s --help` for more information\n", argv[i], argv[0]); log_messages.printf(MSG_CRITICAL, "unrecognized arg: %s\n", argv[i]);