my_rtrm.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  1. #include "my_rtrm.h"
  2. #include "idag_defs.h"
  3. #include "libfunctions.h"
  4. #include "noc_functions.h"
  5. #include "sig_aux.h"
  6. #include "controller_core.h"
  7. #include "common_core.h"
  8. #include "signal_handlers.h"
  9. #include "scc_signals.h"
  10. #include "idag_defs.h"
  11. #include "paxos_signal_handlers.h"
  12. #include "apps.h"
  13. #ifdef PLAT_SCC
  14. int idag_mask[X_max*Y_max];
  15. int low_voltage_core[X_max*Y_max];
  16. int timer_schedule[X_max*Y_max];
  17. volatile int *manager_result_out;
  18. volatile int *index_bottom;
  19. RCCE_FLAG flag_data_written;
  20. RCCE_FLAG proposal_number_lock;
  21. int num_idags_x = 1; //FIXME
  22. #else
  23. int X_max, Y_max;
  24. int *pid_num = NULL;
  25. int *idag_mask = NULL;
  26. int *low_voltage_core = NULL;
  27. int *timer_schedule = NULL;
  28. int *manager_result_out = NULL;
  29. int *index_bottom = NULL;
  30. int num_idags_x;
  31. sem_t *flag_data_written;
  32. sem_t *scc_lock;
  33. sem_t *proposal_number_lock;
  34. #endif
  35. int node_id = -1;
  36. int my_idag = -1;
  37. int num_idags = 0;
  38. int DDS_count = 0;
  39. int my_cores_count = 0;
  40. int nodes_ended_cnt = 0;
  41. int nodes_initialised = 0;
  42. int stats_replied = 0;
  43. int paxos_stats_replied = 0;
  44. int num_apps_terminated = 0;
  45. int num_apps = 0;
  46. int idags_replied = 0;
  47. int index_top = 0;
  48. int last_index_bottom = 0;
  49. int NUES;
  50. int manager_to_fail = -1;
  51. int *sig_array = NULL;
  52. int *data_array = NULL;
  53. int *idag_id_arr = NULL;
  54. int *proposal_number_global;
  55. char paxos_scen[MAX_STR_NAME_SIZE];
  56. char app_input_file[MAX_STR_NAME_SIZE];
  57. FILE *log_file = NULL;
  58. FILE *init_ack_file = NULL;
  59. core_states state;
  60. inter_list **core_inter_head;
  61. inter_list **core_inter_tail;
  62. inter_list *init_pending_head;
  63. inter_list *init_pending_tail;
  64. app my_app;
  65. metrics my_stats = {0,0,0,0,0,0,0,0};
  66. metrics total_stats = {0,0,0,0,0,0,0,0};
  67. metrics paxos_node_stats = {0,0,0,0,0,0,0,0};
  68. metrics paxos_total_stats = {0,0,0,0,0,0,0,0};
  69. DDS_list *DDS = NULL;
  70. DDS_list *DDS_tail = NULL;
  71. core_list *my_cores = NULL;
  72. core_list *my_cores_tail = NULL;
  73. time_t cur_time;
  74. timer_t timerid;
  75. timer_t inter_timer;
  76. timer_t controller_timer;
  77. timer_t epfd_timer;
  78. timer_t pfd_timer;
  79. struct tm *cur_t;
  80. struct sigevent sev;
  81. struct itimerspec its;
  82. struct itimerspec chk_timer;
  83. struct timeval time_val;
  84. /* Dimos variables */
  85. int PREPARE_ACCEPT_SENT = 0;
  86. int controllers_replied = 0;
  87. int delay = 500;
  88. char *tabs;
  89. #ifdef PLAT_SCC
  90. int RCCE_APP(int argc, char *argv[]) {
  91. char error_str[64];
  92. int error, str_len, sig_array_local[LINE_SIZE];
  93. RCCE_init(&argc, &argv);
  94. node_id = RCCE_ue();
  95. #else
  96. int main(int argc, char *argv[]) {
  97. int segment_id;
  98. #endif
  99. int num_of_bytes;
  100. int i;
  101. int j;
  102. int k;
  103. int c;
  104. int one_idag;
  105. int one_core;
  106. int app_cnt = 0;
  107. int time_passed = -1;
  108. int time_next;
  109. int init_core;
  110. int timer_init_null = 0;
  111. int executed_app_type_number = 0; /* Used for the initialization of init_app type */
  112. int executed_app_array_size = 0; /* Used for the initialization of init_app type */
  113. int Selfopt_Radius,Selfopt_Rounds,Max_SelfOpt_Interval_MS;
  114. float avg_cluster_util;
  115. char scen_directory[MAX_STR_NAME_SIZE];
  116. char scen_num[MAX_STR_NAME_SIZE];
  117. char idag_defs_file_name[MAX_STR_NAME_SIZE];
  118. char app_input_file_name[MAX_STR_NAME_SIZE];
  119. char time_log_file_name[MAX_STR_NAME_SIZE];
  120. char init_ack_file_name[MAX_STR_NAME_SIZE];
  121. inter_list *tmp_inter_list;
  122. inter_list *tmp_inter_prev;
  123. inter_list *tmp_pending_head;
  124. FILE *app_input;
  125. FILE *time_log;
  126. struct tm start_time_of_day, *end_time_of_day;
  127. pid_t p;
  128. DDS_list *tmp_DDS;
  129. core_list *tmp_cores_list;
  130. struct timeval time_val;
  131. setvbuf(stdout, NULL, _IONBF, 0);
  132. if (argc < 21) {
  133. printf("USAGE: ./my_rtrm <options>\n\n");
  134. printf("options:\n");
  135. printf("\t-d <scen_dir> : <scen_dir> = Directory of all scenarios.\n");
  136. printf("\t-n <scen_num> : <scen_num> = Scenario number to be executed.\n");
  137. printf("\t-i <idag_defs> : <idag_defs> = File with the definitions of grid and idags.\n");
  138. printf("\t-a <app_input> : <app_input> = File with application characteristics.\n");
  139. printf("\t-p <paxos_scen> : <paxos_scen> = File with failure characteristics.\n");
  140. printf("\t-x X : X = X * 6 will be the horizontal dimension of the grid.\n");
  141. printf("\t-y Y : Y = Y * 8 will be the vertical dimension of the grid.\n");
  142. printf("\t-t <app_type> : <app_type> M for MATRIX_MUL, S for SVM, F for FFT, A for Artificial \n");
  143. printf("\t-r <region_r> : Selfopt radius \n");
  144. printf("\t-u <rounds> : Selfopt rounds \n");
  145. exit(0);
  146. }
  147. /* Put h last in getopt in order to work correctly */
  148. while ((c = getopt(argc, argv, "d:n:i:x:y:a:p:t:r:u:h")) != -1){
  149. switch(c){
  150. case 'd':
  151. strcpy(scen_directory, optarg);
  152. if (node_id == 0)
  153. printf("Scenario directory : %s...\n",scen_directory);
  154. break;
  155. case 'n':
  156. strcpy(scen_num, optarg);
  157. if (node_id == 0)
  158. printf("Scenario number : %s...\n",scen_num);
  159. break;
  160. case 'i':
  161. strcpy(idag_defs_file_name,optarg);
  162. if (node_id == 0)
  163. printf("Idag definitions file name : %s...\n",idag_defs_file_name);
  164. break;
  165. case 'x':
  166. #ifdef PLAT_LINUX
  167. X_max = atoi(optarg) * 6;
  168. #endif
  169. if (node_id == 0)
  170. printf("X = %d...\n",X_max);
  171. break;
  172. case 'y':
  173. #ifdef PLAT_LINUX
  174. Y_max = atoi(optarg) * 8;
  175. #endif
  176. if (node_id == 0)
  177. printf("Y = %d...\n",Y_max);
  178. break;
  179. case 'r':
  180. Selfopt_Radius = atoi(optarg);
  181. if (node_id == 0)
  182. printf("Selfopt_Radius = %d...\n",Selfopt_Radius);
  183. break;
  184. case 'u':
  185. Selfopt_Rounds = atoi(optarg);
  186. if (node_id == 0)
  187. printf("Selfopt_Rounds = %d...\n",Selfopt_Rounds);
  188. Max_SelfOpt_Interval_MS = LEAST_SELF_OPT_INTERVAL_MS;
  189. for (i=1; i<Selfopt_Rounds; i++) {
  190. Max_SelfOpt_Interval_MS = 2 * Max_SelfOpt_Interval_MS;
  191. }
  192. break;
  193. case 'a':
  194. strcpy(app_input_file, optarg);
  195. if (node_id == 0)
  196. printf("Application input file %s...\n",app_input_file);
  197. break;
  198. case 'p':
  199. strcpy(paxos_scen, optarg);
  200. if (node_id == 0)
  201. printf("Paxos scenario file name %s...\n", paxos_scen);
  202. break;
  203. case 't':
  204. if (!strcmp(optarg,"M")) { /* FIXME merge 10.7.2017 executed_app and executed_app_type_number */
  205. executed_app = MATRIX_MUL;
  206. executed_app_type_number = 0;
  207. executed_app_array_size = MATRIX_ARRAY_SIZE;
  208. //printf("Input application type is Matrix mul\n");
  209. } else if (!strcmp(optarg,"S")) {
  210. executed_app = SVM;
  211. executed_app_type_number = 1;
  212. executed_app_array_size = SVM_ARRAY_SIZE;
  213. //printf("Input application type is SVM\n");
  214. } else if (!strcmp(optarg,"F")) {
  215. executed_app = FFT;
  216. executed_app_type_number = 2;
  217. executed_app_array_size = FFT_ARRAY_SIZE;
  218. //printf("Input application type is FFT\n");
  219. } else if (!strcmp(optarg,"A")) {
  220. executed_app = ARTIFICIAL;
  221. executed_app_type_number = 3;
  222. //printf("Input application type is FFT\n");
  223. } else {
  224. printf("Input application type is wrong. Options are M,S,F\n");
  225. }
  226. break;
  227. /*
  228. if (cur_agent.app_type == 0)
  229. executed_app = MATRIX_MUL;
  230. else if (cur_agent.app_type == 1)
  231. executed_app = SVM;
  232. else if (cur_agent.app_type == 2)
  233. executed_app = FFT;
  234. */
  235. case 'h':
  236. printf("USAGE: ./my_rtrm <options>\n\n");
  237. printf("options:\n");
  238. printf("\t-d <scen_dir> : <scen_dir> = Directory of all scenarios.\n");
  239. printf("\t-n <scen_num> : <scen_num> = Scenario number to be executed.\n");
  240. printf("\t-i <idag_defs> : <idag_defs> = File with the definitions of grid and idags.\n");
  241. printf("\t-a <app_input> : <app_input> = File with application characteristics.\n");
  242. printf("\t-p <paxos_scen> : <paxos_scen> = File with failure characteristics.\n");
  243. printf("\t-x X : X = X * 6 will be the horizontal dimension of the grid.\n");
  244. printf("\t-y Y : Y = Y * 8 will be the vertical dimension of the grid.\n");
  245. printf("\t-t <app_type> : <app_type> M for MATRIX_MUL, S for SVM, F for FFT \n");
  246. printf("\t-r <region_r> : Selfopt radius \n");
  247. printf("\t-u <rounds> : Selfopt rounds \n");
  248. exit(0);
  249. break;
  250. }
  251. }
  252. #ifdef PLAT_SCC
  253. NUES = RCCE_num_ues();
  254. RCCE_flag_alloc(&flag_data_written);
  255. RCCE_flag_write(&flag_data_written, RCCE_FLAG_UNSET, node_id);
  256. RCCE_flag_alloc(&proposal_number_lock);
  257. RCCE_flag_write(&proposal_number_lock, RCCE_FLAG_UNSET, node_id);
  258. sig_array = (int *) RCCE_malloc(MAX_SIGNAL_LIST_LEN * LINE_SIZE * sizeof(int));//NUES * NUES
  259. data_array = (int *) RCCE_malloc(MAX_DATA_LIST_LEN * LINE_SIZE * sizeof(int));
  260. #ifndef ARTIFICIAL_APPS_SIM
  261. if (executed_app == MATRIX_MUL) {
  262. num_of_bytes = NUES * MAX_ARRAY_SIZE * sizeof(int);
  263. } else if (executed_app == SVM) {
  264. num_of_bytes = NUES * SVM_ARRAY_SIZE * sizeof(float);
  265. } else if (executed_app == FFT) {
  266. num_of_bytes = NUES * FFT_ARRAY_SIZE * sizeof(float);
  267. }
  268. manager_result_out = (volatile int*) RCCE_shmalloc(num_of_bytes);
  269. #endif
  270. num_of_bytes = NUES * sizeof(int);
  271. index_bottom = (volatile int*) RCCE_shmalloc(num_of_bytes);
  272. proposal_number_global = (int *)RCCE_shmalloc(sizeof(int *));
  273. *proposal_number_global = 0;
  274. for (i=0; i<LINE_SIZE; i++)
  275. sig_array_local[i] = NO_SIG;
  276. for (i=0; i<MAX_SIGNAL_LIST_LEN; i++) {
  277. error = RCCE_put((t_vcharp)(&sig_array[i*LINE_SIZE]), (t_vcharp)(&sig_array_local[0]), LINE_SIZE * sizeof(int), node_id);
  278. if (error != RCCE_SUCCESS) {
  279. RCCE_error_string(error, error_str, &str_len);
  280. fprintf(log_file,"I got an error in put 2 with descr %s\n",error_str);
  281. fflush(log_file);
  282. }
  283. }
  284. #else
  285. idag_mask = (int *) malloc(X_max*Y_max*sizeof(int));
  286. low_voltage_core = (int *) malloc(X_max*Y_max*sizeof(int));
  287. timer_schedule = (int *) malloc(X_max*Y_max*sizeof(int));
  288. NUES = X_max * Y_max;
  289. node_id = 0;
  290. num_of_bytes = NUES * sizeof(pid_t);
  291. segment_id = shmget (IPC_PRIVATE, num_of_bytes, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  292. pid_num = (int *) shmat (segment_id, NULL, 0);
  293. num_of_bytes = NUES * MAX_SIGNAL_LIST_LEN * LINE_SIZE * sizeof(int);
  294. segment_id = shmget (IPC_PRIVATE, num_of_bytes, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  295. sig_array = (int *) shmat (segment_id, NULL, 0); //(int *) RCCE_malloc(MAX_SIGNAL_LIST_LEN * LINE_SIZE * sizeof(int));//NUES * NUES
  296. for (i = 0; i < MAX_SIGNAL_LIST_LEN*LINE_SIZE; i++) {
  297. sig_array[i] = NO_SIG;
  298. }
  299. num_of_bytes = NUES * MAX_DATA_LIST_LEN * LINE_SIZE * sizeof(int);
  300. segment_id = shmget (IPC_PRIVATE, num_of_bytes, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  301. data_array = (int *) shmat (segment_id, NULL, 0); //(int *) RCCE_malloc(3 * LINE_SIZE * sizeof(int));
  302. if (executed_app == MATRIX_MUL) {
  303. num_of_bytes = NUES * MAX_ARRAY_SIZE * sizeof(int);
  304. } else if (executed_app == SVM) {
  305. num_of_bytes = NUES * SVM_ARRAY_SIZE * sizeof(int);
  306. } else if (executed_app == FFT) {
  307. num_of_bytes = NUES * FFT_ARRAY_SIZE * sizeof(float);
  308. }
  309. segment_id = shmget (IPC_PRIVATE, num_of_bytes, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  310. manager_result_out = (int *) shmat (segment_id, NULL, 0); //(volatile int*) RCCE_shmalloc(num_of_bytes);
  311. num_of_bytes = NUES * sizeof(int);
  312. segment_id = shmget (IPC_PRIVATE, num_of_bytes, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  313. index_bottom = (int *) shmat (segment_id, NULL, 0); //(volatile int*) RCCE_shmalloc(num_of_bytes);
  314. //for (i=0; i<LINE_SIZE; i++)
  315. // sig_array_local[i] = NO_SIG;
  316. //#if defined(BASIC_PAXOS)
  317. num_of_bytes = sizeof(sem_t *);
  318. if ((segment_id = shmget(IPC_PRIVATE, num_of_bytes, IPC_CREAT | S_IRUSR | S_IWUSR)) < 0){
  319. printf("Unable to allocate shared memory!\n");
  320. exit(1);
  321. }
  322. proposal_number_lock = (sem_t *) shmat (segment_id, NULL, 0);
  323. if (sem_init(proposal_number_lock, 1, 1) == -1){
  324. printf("I am %d error\n",node_id);
  325. perror("sem_init");
  326. }
  327. num_of_bytes = sizeof(sem_t *);
  328. if ((segment_id = shmget(IPC_PRIVATE, num_of_bytes, IPC_CREAT | S_IRUSR | S_IWUSR)) < 0){
  329. printf("Unable to allocate shared memory!\n");
  330. exit(1);
  331. }
  332. num_of_bytes = sizeof(int *);
  333. if ((segment_id = shmget(IPC_PRIVATE, num_of_bytes, IPC_CREAT | S_IRUSR | S_IWUSR)) < 0){
  334. printf("Unable to allocate shared memory!\n");
  335. exit(1);
  336. }
  337. proposal_number_global = (int *) shmat (segment_id, NULL, 0);
  338. *proposal_number_global = 0;
  339. //#endif
  340. num_of_bytes = NUES * sizeof(sem_t);
  341. segment_id = shmget (IPC_PRIVATE, num_of_bytes, IPC_CREAT | S_IRUSR | S_IWUSR);
  342. scc_lock = (sem_t *) shmat (segment_id, NULL, 0);
  343. if (sem_init(&scc_lock[node_id], 1, 1) == -1){
  344. printf("I am %d error\n",node_id);
  345. perror("sem_init");
  346. }
  347. segment_id = shmget (IPC_PRIVATE, num_of_bytes,
  348. IPC_CREAT | S_IRUSR | S_IWUSR);
  349. flag_data_written = (sem_t *) shmat (segment_id, NULL, 0);
  350. if (sem_init(&flag_data_written[node_id], 1, 0) == -1){
  351. printf("I am %d error\n",node_id);
  352. perror("sem_init");
  353. }
  354. #endif
  355. init_speedup_structs();
  356. core_inter_head = (inter_list **) malloc(X_max*Y_max*sizeof(inter_list *));
  357. core_inter_tail = (inter_list **) malloc(X_max*Y_max*sizeof(inter_list *));
  358. for (i=0; i<X_max*Y_max; i++){
  359. core_inter_head[i] = NULL;
  360. core_inter_tail[i] = NULL;
  361. timer_schedule[i] = 0;
  362. }
  363. read_idag_defs(scen_directory, scen_num, idag_defs_file_name, paxos_scen);
  364. global_idag_defs();
  365. /* Initialise structs for mapping of scc coordinates to normal ones*/
  366. create_scc2grid_mapping(scen_directory, scen_num);
  367. create_grid2scc_mapping(scen_directory, scen_num);
  368. initialize_PAXOS_data(scen_directory,scen_num);
  369. #ifdef MANAGER
  370. if (manager_to_fail == -1){
  371. time_t t;
  372. srand((unsigned) time(&t));
  373. manager_to_fail = rand() % 8;
  374. //printf("MANAGER TO FAIL IS OF APP %d\n",manager_to_fail);
  375. }
  376. #endif
  377. /* Create rest of idags and assign only their node id */
  378. #ifdef PLAT_LINUX
  379. printf("I an idag with node_id = %d, pid = %d\n",0,getpid());
  380. for (i=1; i < num_idags; i++) {
  381. p = fork();
  382. if (p == 0) {
  383. node_id = idag_id_arr[i];
  384. idle_agent_actions(scen_directory,scen_num,Selfopt_Radius,Max_SelfOpt_Interval_MS);
  385. printf("I am newly created idag with i = %d and node_id = %d\n",i,node_id);
  386. fflush(stdout);
  387. break;
  388. }
  389. }
  390. #endif
  391. if ((node_id != idag_id_arr[0]) && (is_core_idag(node_id) == 1)) {
  392. #ifndef PLAT_LINUX
  393. idle_agent_actions(scen_directory,scen_num);
  394. #else
  395. idle_agent_actions(scen_directory,scen_num,Selfopt_Radius,Max_SelfOpt_Interval_MS);
  396. #endif
  397. } else if (node_id != idag_id_arr[0]) {
  398. common_node_actions(scen_directory,scen_num,Selfopt_Radius,Max_SelfOpt_Interval_MS);
  399. } else {
  400. index_bottom[node_id] = 0;
  401. install_signal_handlers();
  402. #ifdef PLAT_LINUX
  403. sig_SEGV_enable();
  404. #endif
  405. sev.sigev_notify = SIGEV_SIGNAL;
  406. sev.sigev_signo = SIG_TIMER;
  407. sev.sigev_value.sival_ptr = &timerid;
  408. if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1) printf("timer_create error\n");
  409. if (my_cores == NULL) {
  410. my_cores = (core_list *) malloc(sizeof(core_list));
  411. my_cores_tail = my_cores;
  412. }
  413. my_cores_count++;
  414. my_cores_tail->core_id = node_id;
  415. my_cores_tail->offered_to = -1;
  416. my_cores_tail->next = NULL;
  417. DDS = (DDS_list *) malloc(sizeof(DDS_list));
  418. DDS->agent_id = node_id;
  419. DDS->next = NULL;
  420. DDS_tail = DDS;
  421. DDS_count++;
  422. for (i = 0; i < NUES; i++)
  423. if (node_id != i && idag_mask[i] == node_id){
  424. if (my_cores == NULL) {
  425. my_cores = (core_list *) malloc(sizeof(core_list));
  426. my_cores_tail = my_cores;
  427. } else {
  428. my_cores_tail->next = (core_list *) malloc(sizeof(core_list));
  429. my_cores_tail = my_cores_tail->next;
  430. }
  431. my_cores_count++;
  432. my_cores_tail->core_id = i;
  433. my_cores_tail->offered_to = -1;
  434. my_cores_tail->next = NULL;
  435. #ifdef PLAT_LINUX
  436. p = fork();
  437. if (p==0) {
  438. node_id = i;
  439. common_node_actions(scen_directory,scen_num,Selfopt_Radius,Max_SelfOpt_Interval_MS);
  440. }
  441. #endif
  442. }
  443. DDS->num_of_cores = my_cores_count;
  444. log_file = create_log_file(node_id, 0, scen_directory, scen_num);
  445. setbuf(log_file, NULL);
  446. fprintf(log_file,"Selfopt_Radius = %d Selfopt_Rounds = %d Max_SelfOpt_Interval_MS = %d\n",Selfopt_Radius,Selfopt_Rounds,Max_SelfOpt_Interval_MS);
  447. if (node_id == 0) {
  448. #ifdef RESOURCE_ALGO_ORIG
  449. printf("Resource algo is original\n");
  450. fprintf(log_file,"Resource algo is original\n");
  451. #elif RESOURCE_ALGO_UPDATED
  452. printf("Resource algo is updated\n");
  453. fprintf(log_file,"Resource algo is updated\n");
  454. #elif RESOURCE_ALGO_UPDATED_GENEROUS
  455. printf("Resource algo is updated generous\n");
  456. fprintf(log_file,"Resource algo is updated generous\n");
  457. #else
  458. printf("Resource algo not chosen. Fallback to original\n");
  459. fprintf(log_file,"Resource algo not chosen. Fallback to original\n");
  460. #endif
  461. }
  462. alive = (int *)malloc(X_max*Y_max*sizeof(int));
  463. suspected = (int *)malloc(X_max*Y_max*sizeof(int));
  464. for (i = 0; i < X_max*Y_max; i++){
  465. alive[i] = 0;
  466. suspected[i] = 0;
  467. }
  468. printf("DELAY = %d\n",delay);
  469. #if defined(EPFD) || defined(tEPFD)
  470. sev.sigev_notify = SIGEV_SIGNAL;
  471. sev.sigev_signo = SIG_EPFD_TIMER;
  472. sev.sigev_value.sival_ptr = &epfd_timer;
  473. if (timer_create(CLOCK_REALTIME, &sev, &epfd_timer) == -1)
  474. printf("timer_create error\n");
  475. else
  476. fprintf(log_file,"I succesfully created epfd_timer\n");
  477. #endif
  478. #if defined(PFD) || defined(tPFD)
  479. sev.sigev_notify = SIGEV_SIGNAL;
  480. sev.sigev_signo = SIG_PFD_TIMER;
  481. sev.sigev_value.sival_ptr = &pfd_timer;
  482. if (timer_create(CLOCK_REALTIME, &sev, &pfd_timer) == -1)
  483. printf("timer_create error\n");
  484. else
  485. fprintf(log_file,"I succesfully created pfd_timer\n");
  486. #endif
  487. cur_time = time(NULL);
  488. cur_t = localtime(&cur_time);
  489. fprintf(log_file, "[%d:%d:%d]: Initialized node_id=%d\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,node_id);
  490. #ifdef PLAT_SCC
  491. RCCE_barrier(&RCCE_COMM_WORLD);
  492. #else
  493. sleep(1);
  494. #endif
  495. for (tmp_cores_list = my_cores->next; tmp_cores_list != NULL; tmp_cores_list = tmp_cores_list->next) {
  496. one_core = tmp_cores_list->core_id;
  497. if (core_inter_head[one_core] == NULL){
  498. core_inter_head[one_core] = (inter_list *) malloc(sizeof(inter_list));
  499. core_inter_tail[one_core] = core_inter_head[one_core];
  500. } else {
  501. core_inter_tail[one_core]->next = (inter_list *) malloc(sizeof(inter_list));
  502. core_inter_tail[one_core] = core_inter_tail[one_core]->next;
  503. }
  504. core_inter_tail[one_core]->type = INIT_CORE;
  505. core_inter_tail[one_core]->next = NULL;
  506. scc_kill(one_core, SIG_INIT, core_inter_head[one_core]);
  507. }
  508. while (nodes_initialised != my_cores_count-1) {
  509. scc_pause();
  510. scc_signals_check();
  511. }
  512. #ifdef PLAT_SCC
  513. RCCE_barrier(&RCCE_COMM_WORLD);
  514. #else
  515. sleep(1);
  516. #endif
  517. printf("End of initialisation\n");
  518. //print_grid();
  519. /* Open the Time Log File*/
  520. #ifdef PLAT_SCC
  521. strcpy(time_log_file_name, "/shared/herc/");
  522. #else
  523. strcpy(time_log_file_name, "../");
  524. #endif
  525. strcat(time_log_file_name,scen_directory);
  526. strcat(time_log_file_name ,"/");
  527. strcat(time_log_file_name ,scen_num);
  528. strcat(time_log_file_name, "/times_log.txt");
  529. printf("Time Log File Path = %s ... ",time_log_file_name);
  530. fflush(stdout);
  531. fprintf(log_file,"time log file path = %s\n",time_log_file_name);
  532. if ((time_log = fopen(time_log_file_name, "w")) == NULL){
  533. printf("Error!\n");
  534. fflush(stdout);
  535. perror("open time_log");
  536. }else{
  537. printf("Success!\n");
  538. fflush(stdout);
  539. }
  540. /* done */
  541. /* Init app file is kept in linux for compatibility of result gathering scripts */
  542. #ifdef PLAT_SCC
  543. strcpy(init_ack_file_name, "/shared/herc/");
  544. #else
  545. strcpy(init_ack_file_name, "../");
  546. #endif
  547. strcat(init_ack_file_name, scen_directory);
  548. strcat(init_ack_file_name, "/");
  549. strcat(init_ack_file_name, scen_num);
  550. strcat(init_ack_file_name, "/init_ack.txt");
  551. //printf("file path = %s\n",app_input_file_name);
  552. if ((init_ack_file = fopen(init_ack_file_name, "w")) == NULL){
  553. printf("Cannot open input file with file path = %s ",init_ack_file_name);
  554. perror("open app_input");
  555. }
  556. /* Open the Application Input File*/
  557. #ifdef PLAT_SCC
  558. strcpy(app_input_file_name, "/shared/herc/");
  559. #else
  560. strcpy(app_input_file_name, "../");
  561. #endif
  562. strcat(app_input_file_name, scen_directory);
  563. strcat(app_input_file_name, "/");
  564. strcat(app_input_file_name, scen_num);
  565. strcat(app_input_file_name, "/inputs/");
  566. strcat(app_input_file_name, app_input_file);
  567. printf("App Input File Path = %s ...",app_input_file_name);
  568. fprintf(log_file,"file path = %s\n",app_input_file_name);
  569. if ((app_input = fopen(app_input_file_name, "r")) == NULL){
  570. printf("Error!\n");
  571. perror("open app_input");
  572. }else{
  573. printf("Success!\n");
  574. fflush(stdout);
  575. }
  576. /* done */
  577. fscanf(app_input,"%d",&time_next);
  578. state = IDLE_CHK_APP_FILE;
  579. its.it_interval.tv_sec = 0;
  580. its.it_interval.tv_nsec = 0;
  581. its.it_value.tv_sec = 0;
  582. its.it_value.tv_nsec = 10 * MS;
  583. if (timer_settime(timerid, 0, &its, NULL) == -1) perror("timer_settime error9");
  584. gettimeofday(&time_val, NULL);
  585. cur_t = localtime(&time_val.tv_sec);
  586. start_time_of_day = *cur_t;
  587. while (state != IDAG_ENDING)
  588. if (state == IDLE_IDAG) {
  589. scc_pause();
  590. scc_signals_check();
  591. if (num_apps_terminated == num_apps) {
  592. state = USER_INPUT;
  593. fprintf(log_file,"All apps terminated. Switching to USER_INPUT\n");
  594. } else if (!timer_init_null && init_pending_head != NULL) {
  595. its.it_value.tv_sec = 10;
  596. its.it_value.tv_nsec = 0;
  597. if (timer_settime(timerid, 0, &its, NULL) == -1) perror("timer_settime error9");
  598. timer_init_null = 1;
  599. }
  600. } else if (state == IDLE_IDAG_INIT_SEND) {
  601. signals_enable();
  602. tmp_inter_prev = NULL;
  603. tmp_pending_head = init_pending_head;
  604. while (tmp_pending_head != NULL) {
  605. init_core = tmp_pending_head->data.new_app.num_of_cores;
  606. for (tmp_inter_list = core_inter_head[init_core]; tmp_inter_list != NULL; tmp_inter_list = tmp_inter_list->next)
  607. if (tmp_inter_list->type == INIT_APP) break;
  608. if (tmp_inter_list == NULL) {
  609. fprintf(log_file,"I am sending an aborted init_app to %d with id %d\n",init_core,tmp_pending_head->data.new_app.id);
  610. if (core_inter_head[init_core] == NULL){
  611. core_inter_head[init_core] = (inter_list *) malloc(sizeof(inter_list));
  612. core_inter_tail[init_core] = core_inter_head[init_core];
  613. } else {
  614. core_inter_tail[init_core]->next = (inter_list *) malloc(sizeof(inter_list));
  615. core_inter_tail[init_core] = core_inter_tail[init_core]->next;
  616. }
  617. core_inter_tail[init_core]->type = INIT_APP;
  618. core_inter_tail[init_core]->data.new_app = tmp_pending_head->data.new_app;
  619. core_inter_tail[init_core]->data.new_app.num_of_cores = 0;
  620. core_inter_tail[init_core]->next = NULL;
  621. if (core_inter_head[init_core]->next == NULL) {
  622. //kill(pid_num[sender_id],SIG_INIT_APP);
  623. scc_kill(init_core, SIG_INIT_APP, core_inter_head[init_core]);
  624. my_stats.msg_count++;
  625. my_stats.distance += distance(node_id,init_core);
  626. }
  627. if (tmp_inter_prev == NULL) {
  628. tmp_inter_list = init_pending_head;
  629. init_pending_head = init_pending_head->next;
  630. tmp_pending_head = init_pending_head;
  631. //free(tmp_inter_list);
  632. } else {
  633. tmp_inter_list = tmp_inter_prev->next;
  634. tmp_inter_prev->next = tmp_inter_list->next;
  635. tmp_pending_head = tmp_inter_prev->next;
  636. if (tmp_inter_prev->next == NULL) init_pending_tail = tmp_inter_prev;
  637. }
  638. free(tmp_inter_list);
  639. } else {
  640. tmp_inter_prev = tmp_pending_head;
  641. tmp_pending_head = tmp_pending_head->next;
  642. }
  643. }
  644. timer_init_null = 0;
  645. state = IDLE_IDAG;
  646. fprintf(log_file,"I exit this fuck\n");
  647. } else if (state == IDLE_CHK_APP_FILE) {
  648. scc_pause();
  649. scc_signals_check();
  650. } else if (state == CHK_APP_FILE) {
  651. signals_disable();
  652. time_passed++;
  653. //if (time_for_farman > 0) time_for_farman -= 10;a
  654. //printf("time passed=%d | time next=%d\n",time_passed,time_next);
  655. if (time_next == time_passed) {
  656. fscanf(app_input,"%d",&init_core);
  657. num_apps++;
  658. fprintf(log_file,"idag_mask[%d] = %d\n",init_core,idag_mask[init_core]);
  659. if (idag_mask[init_core] == init_core){
  660. fprintf(log_file,"init_core %d is a controller. New init_core = %d\n",init_core,init_core+1);
  661. printf("init_core %d is a controller. New init_core = %d\n",init_core,init_core+1);
  662. init_core++;
  663. }
  664. printf("time = %d, id = %d\n",time_passed,app_cnt);
  665. gettimeofday(&time_val, NULL);
  666. cur_t = localtime(&time_val.tv_sec);
  667. fprintf(log_file, "[%d:%d:%d]: Initialising app_id=%d\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,app_cnt);
  668. fprintf(time_log, "[%d:%d:%d:%ld] app_id=%d\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,time_val.tv_usec,app_cnt);
  669. fflush(time_log);
  670. for (tmp_inter_list = core_inter_head[init_core]; tmp_inter_list != NULL; tmp_inter_list = tmp_inter_list->next)
  671. if (tmp_inter_list->type == INIT_APP) break;
  672. signals_enable();
  673. if (tmp_inter_list == NULL) {
  674. if (core_inter_head[init_core] == NULL){
  675. core_inter_head[init_core] = (inter_list *) malloc(sizeof(inter_list));
  676. core_inter_tail[init_core] = core_inter_head[init_core];
  677. } else {
  678. core_inter_tail[init_core]->next = (inter_list *) malloc(sizeof(inter_list));
  679. core_inter_tail[init_core] = core_inter_tail[init_core]->next;
  680. }
  681. core_inter_tail[init_core]->type = INIT_APP;
  682. #ifndef ARTIFICIAL_APPS_SIM
  683. /* FIXME scanned for old app inputs compatibility reasons but it is discarded */
  684. fscanf(app_input,"%d",&core_inter_tail[init_core]->data.new_app.array_size);
  685. core_inter_tail[init_core]->data.new_app.array_size = executed_app_array_size;
  686. #else
  687. fscanf(app_input,"%f",&core_inter_tail[init_core]->data.new_app.var);
  688. fscanf(app_input,"%f",&core_inter_tail[init_core]->data.new_app.A);
  689. #endif
  690. fscanf(app_input,"%d",&core_inter_tail[init_core]->data.new_app.workld);
  691. core_inter_tail[init_core]->data.new_app.app_type = executed_app_type_number;
  692. /* FIXME for the time being, do not scan for app type. All apps are of the same type, read from argv */
  693. core_inter_tail[init_core]->data.new_app.id = app_cnt++;
  694. core_inter_tail[init_core]->data.new_app.num_of_cores = 0;
  695. core_inter_tail[init_core]->next = NULL;
  696. /*printf("time = %d, id = %d, workld = %d\n",time_passed,core_inter_tail[init_core]->data.new_app.id,core_inter_tail[init_core]->data.new_app.workld);
  697. gettimeofday(&time_val, NULL);
  698. cur_t = localtime(&time_val.tv_sec);
  699. fprintf(log_file, "[%d:%d:%d]: Initialising app_id=%d\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,core_inter_tail[init_core]->data.new_app.id);
  700. fflush(log_file);
  701. fprintf(time_log, "[%d:%d:%d:%ld] app_id=%d\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,time_val.tv_usec,core_inter_tail[init_core]->data.new_app.id);
  702. fflush(time_log);*/
  703. if (core_inter_head[init_core]->next == NULL) {
  704. //kill(pid_num[init_core],SIG_INIT_APP);
  705. scc_kill(init_core, SIG_INIT_APP, core_inter_head[init_core]);
  706. my_stats.msg_count++;
  707. my_stats.distance += distance(node_id,init_core);
  708. }
  709. } else {
  710. if (init_pending_head == NULL){
  711. init_pending_head = (inter_list *) malloc(sizeof(inter_list));
  712. init_pending_tail = init_pending_head;
  713. } else {
  714. init_pending_tail->next = (inter_list *) malloc(sizeof(inter_list));
  715. init_pending_tail = init_pending_tail->next;
  716. }
  717. init_pending_tail->type = INIT_APP;
  718. /* FIXME scanned for old app inputs compatibility reasons but it is discarded */
  719. #ifndef ARTIFICIAL_APPS_SIM
  720. fscanf(app_input,"%d",&init_pending_tail->data.new_app.array_size);
  721. init_pending_tail->data.new_app.array_size = executed_app_array_size;
  722. #else
  723. fscanf(app_input,"%f",&init_pending_tail->data.new_app.var);
  724. fscanf(app_input,"%f",&init_pending_tail->data.new_app.A);
  725. #endif
  726. fscanf(app_input,"%d",&init_pending_tail->data.new_app.workld);
  727. core_inter_tail[init_core]->data.new_app.app_type = executed_app_type_number;
  728. /* FIXME for the time being, do not scan for app type. All apps are of the same type, read from argv */
  729. init_pending_tail->data.new_app.id = app_cnt++;
  730. init_pending_tail->data.new_app.num_of_cores = init_core;
  731. init_pending_tail->next = NULL;
  732. }
  733. if (fscanf(app_input,"%d",&time_next) == EOF) {
  734. //state = USER_INPUT;
  735. state = IDLE_IDAG;
  736. time_passed = -1;
  737. } else {
  738. its.it_value.tv_sec = 0;
  739. its.it_value.tv_nsec = 10 * MS;
  740. if (timer_settime(timerid, 0, &its, NULL) == -1) printf("timer_settime error11\n");
  741. state = IDLE_CHK_APP_FILE;
  742. }
  743. } else {
  744. state = IDLE_CHK_APP_FILE;
  745. its.it_value.tv_sec = 0;
  746. its.it_value.tv_nsec = 10 * MS;
  747. if (timer_settime(timerid, 0, &its, NULL) == -1) printf("timer_settime error92\n");
  748. }
  749. signals_enable();
  750. } else if (state == USER_INPUT) {
  751. //while (num_apps_terminated != num_apps) {//pause(); my_cores_count
  752. // scc_pause();
  753. // scc_signals_check();
  754. //}
  755. #ifndef IDAG_SLEEP
  756. for (k=0; k<15000; k++) {
  757. #else
  758. for (k=0; k<20; k++) {
  759. #endif
  760. scc_pause();
  761. scc_signals_check();
  762. }
  763. for (j=0; j<num_idags; j++) {
  764. one_idag = idag_id_arr[j];
  765. fprintf(log_file, "Sending to controller core %d\n",one_idag);
  766. if (one_idag != idag_id_arr[0]) {
  767. if (core_inter_head[one_idag] == NULL){
  768. core_inter_head[one_idag] = (inter_list *) malloc(sizeof(inter_list));
  769. core_inter_tail[one_idag] = core_inter_head[one_idag];
  770. } else {
  771. core_inter_tail[one_idag]->next = (inter_list *) malloc(sizeof(inter_list));
  772. core_inter_tail[one_idag] = core_inter_tail[one_idag]->next;
  773. }
  774. core_inter_tail[one_idag]->type = DEBUG_IDAG_REQ_DDS;
  775. core_inter_tail[one_idag]->data.reg.C = -1;
  776. core_inter_tail[one_idag]->data.reg.r = 0;
  777. core_inter_tail[one_idag]->next = NULL;
  778. if (core_inter_head[one_idag]->next == NULL)
  779. scc_kill(one_idag, SIG_REQ_DDS, core_inter_head[one_idag]);
  780. else {
  781. fprintf(log_file,"interaction in debug req dds is %d\n",core_inter_head[one_idag]->type);
  782. }
  783. } else {
  784. printf("Number of agents in region = %d\n",DDS_count);
  785. tmp_DDS = DDS;
  786. i=0;
  787. while (tmp_DDS != NULL) {
  788. printf("Agent no %d is %d with %d cores\n",i,tmp_DDS->agent_id,tmp_DDS->num_of_cores);
  789. tmp_DDS = tmp_DDS->next;
  790. i++;
  791. }
  792. }
  793. }
  794. while (idags_replied < num_idags - 1) {
  795. scc_pause();
  796. scc_signals_check();
  797. }
  798. fprintf(log_file,"killing\n");
  799. for (i=1; i<num_idags; i++){
  800. printf("i am killing %d\n",idag_id_arr[i]);
  801. one_core = idag_id_arr[i];
  802. if (core_inter_head[one_core] == NULL){
  803. core_inter_head[one_core] = (inter_list *) malloc(sizeof(inter_list));
  804. core_inter_tail[one_core] = core_inter_head[one_core];
  805. } else {
  806. core_inter_tail[one_core]->next = (inter_list *) malloc(sizeof(inter_list));
  807. core_inter_tail[one_core] = core_inter_tail[one_core]->next;
  808. fprintf(log_file,"I am still doing smth with idag %d interaction = %d\n",one_core,core_inter_head[one_core]->type);
  809. }
  810. core_inter_tail[one_core]->type = TERMINATION_STATS;
  811. core_inter_tail[one_core]->next = NULL;
  812. signals_disable();
  813. scc_kill(one_core, SIG_TERMINATE, core_inter_head[one_core]);
  814. signals_enable();
  815. }
  816. tmp_cores_list = my_cores;
  817. my_cores = my_cores->next;
  818. free(tmp_cores_list);
  819. inter_list tmp_inter_list;
  820. for (; my_cores != NULL; my_cores = my_cores->next) {
  821. tmp_cores_list = my_cores;
  822. one_core = my_cores->core_id;
  823. if (core_inter_head[one_core] == NULL){
  824. core_inter_head[one_core] = (inter_list *) malloc(sizeof(inter_list));
  825. core_inter_tail[one_core] = core_inter_head[one_core];
  826. } else {
  827. core_inter_tail[one_core]->next = (inter_list *) malloc(sizeof(inter_list));
  828. core_inter_tail[one_core] = core_inter_tail[one_core]->next;
  829. fprintf(log_file,"I am still doing smth with my node %d interaction = %d\n",one_core,core_inter_head[one_core]->type);
  830. }
  831. core_inter_tail[one_core]->type = TERMINATION_STATS;
  832. core_inter_tail[one_core]->next = NULL;
  833. //kill(pid_num[one_core], SIG_TERMINATE);
  834. signals_disable();
  835. scc_kill(one_core, SIG_TERMINATE, core_inter_head[one_core]);
  836. signals_enable();
  837. /* 8.7.2016 Paxos Stats */
  838. tmp_inter_list.next = NULL;
  839. tmp_inter_list.type = PAXOS_STATS_REQ;
  840. scc_kill(one_core, SIG_PAXOS_STATS_REQ, &tmp_inter_list);
  841. paxos_node_stats.msg_count++;
  842. paxos_node_stats.distance += distance(node_id,one_core);
  843. my_stats.msg_count++;
  844. my_stats.distance += distance(node_id,one_core);
  845. free(tmp_cores_list);
  846. }
  847. state = IDAG_ENDING;
  848. } else {
  849. printf("my_rtrm.c : Unknown state node_id = %d state = %d\n",node_id,state);
  850. state = IDLE_IDAG;
  851. }
  852. while (state == IDAG_ENDING) {
  853. scc_pause();
  854. scc_signals_check();
  855. if (stats_replied == my_cores_count+num_idags-2 && paxos_stats_replied == my_cores_count+num_idags-2) state = TERMINATED;
  856. }
  857. #ifdef PLAT_LINUX
  858. for (i=0; i<my_cores_count-1; i++)
  859. wait(NULL); //wait for children
  860. for (i=0; i<num_idags-1; i++)
  861. wait(NULL);//wait for the other idags
  862. #endif
  863. total_stats.msg_count += my_stats.msg_count;
  864. total_stats.message_size += my_stats.message_size;
  865. total_stats.distance += my_stats.distance;
  866. total_stats.app_turnaround += my_stats.app_turnaround;
  867. total_stats.comp_effort += my_stats.comp_effort;
  868. total_stats.cores_utilized += my_stats.cores_utilized;
  869. total_stats.times_accessed += my_stats.times_accessed;
  870. paxos_total_stats.msg_count += paxos_node_stats.msg_count;
  871. paxos_total_stats.fd_msg_count += paxos_node_stats.fd_msg_count;
  872. avg_cluster_util = (float) my_stats.cores_utilized / (my_stats.times_accessed * (my_cores_count-1));
  873. printf("I am %d with cores_utilized = %d times_accessed = %d my_cores_count = %d and avg_cluster_util = %0.2f\n",
  874. node_id,my_stats.cores_utilized,my_stats.times_accessed,my_cores_count,avg_cluster_util);
  875. fprintf(log_file,"cores_utilized = %d times_accessed = %d my_cores_count = %d and avg_cluster_util = %0.2f\n",
  876. my_stats.cores_utilized,my_stats.times_accessed,my_cores_count,avg_cluster_util);
  877. gettimeofday(&time_val, NULL);
  878. end_time_of_day = localtime(&time_val.tv_sec);
  879. fprintf(log_file,"================= DRTRM STATS ==================\n");
  880. fprintf(log_file,"Total message count = %lld\n",total_stats.msg_count);
  881. fprintf(log_file,"Total message size = %d\n",total_stats.message_size);
  882. fprintf(log_file,"Total distance = %d\n",total_stats.distance);
  883. fprintf(log_file,"Total app turnaround time = %d\n",total_stats.app_turnaround);
  884. fprintf(log_file,"Total computational effort = %d\n",total_stats.comp_effort);
  885. fprintf(log_file,"Total cores_utilized = %d\n",total_stats.cores_utilized);
  886. fprintf(log_file,"Total times_accessed = %d\n",total_stats.times_accessed);
  887. fprintf(log_file,"================= PAXOS STATS ==================\n");
  888. fprintf(log_file,"Total message count = %lld\n",paxos_total_stats.msg_count);
  889. printf("================= DRTRM STATS ==================\n");
  890. printf("Total message count = %lld\n",total_stats.msg_count);
  891. printf("Total message size = %d\n",total_stats.message_size);
  892. printf("Total distance = %d\n",total_stats.distance);
  893. printf("Total app turnaround time = %d\n",total_stats.app_turnaround);
  894. printf("Total computational effort = %d\n",total_stats.comp_effort);
  895. printf("Total cores_utilized = %d\n",total_stats.cores_utilized);
  896. printf("Total times_accessed = %d\n",total_stats.times_accessed);
  897. printf("================= PAXOS STATS ==================\n");
  898. printf("Start Time: [%d:%d:%d]\n",start_time_of_day.tm_hour,start_time_of_day.tm_min,start_time_of_day.tm_sec);
  899. printf("End Time: [%d:%d:%d]\n",end_time_of_day->tm_hour,end_time_of_day->tm_min,end_time_of_day->tm_sec);
  900. #ifdef PFD
  901. printf("Perfect Failure Detector\n");
  902. #elif tPFD
  903. printf("tweaked Perfect Failure Detector\n");
  904. #endif
  905. printf("PAXOS Total message count = %lld\n",paxos_total_stats.msg_count);\
  906. printf("Failure Detection Total message count = %d\n",paxos_total_stats.fd_msg_count);
  907. for (i=0; i<NUES; i++){
  908. free(core_inter_head[i]);
  909. free(core_inter_tail[i]);
  910. }
  911. free(core_inter_head);
  912. free(core_inter_tail);
  913. #ifdef PLAT_SCC
  914. RCCE_flag_free(&flag_data_written);
  915. RCCE_free((t_vcharp) sig_array);
  916. RCCE_free((t_vcharp) data_array);
  917. RCCE_free((t_vcharp) proposal_number_global);
  918. fclose(init_ack_file);
  919. #else
  920. shmdt(pid_num);
  921. for (i=0; i<NUES; i++) {
  922. sem_destroy(&flag_data_written[i]);
  923. sem_destroy(&scc_lock[i]);
  924. }
  925. shmdt(flag_data_written);
  926. shmdt(scc_lock);
  927. shmdt(manager_result_out);
  928. shmdt(index_bottom);
  929. #endif
  930. cur_time = time(NULL);
  931. cur_t = localtime(&cur_time);
  932. fprintf(log_file, "[%d:%d:%d]: I ended well\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec);
  933. fclose(log_file);
  934. printf("[%d:%d:%d]: I ended well\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec);
  935. //}
  936. }
  937. return 0;
  938. }