@@ -9,7 +9,7 @@ bool start_task(task_func_t func);
99bool restore_tasks ();
1010
1111// Global EID shared by multiple threads
12- sgx_enclave_id_t global_eid;
12+ sgx_enclave_id_t global_eid = 0 ;
1313// Pointor to configure instance
1414Config *p_config = NULL ;
1515// Map to record specific task
@@ -447,6 +447,10 @@ int process_run()
447447 std::string srd_ratio_str;
448448 EnclaveData *ed = EnclaveData::get_instance ();
449449 crust::DataBase *db = NULL ;
450+ bool is_restart = false ;
451+ bool has_recover_option = false ;
452+ json::JSON wl_json;
453+ std::string wl_str;
450454 p_log->info (" WorkerPID = %d\n " , worker_pid);
451455
452456 // Init conifigure
@@ -549,7 +553,8 @@ int process_run()
549553 goto cleanup;
550554 }
551555
552- p_log->info (" Workload information:\n %s\n " , ed->gen_workload ().c_str ());
556+ is_restart = true ;
557+ wl_str = ed->gen_workload ();
553558
554559 if (!offline_chain_mode)
555560 {
@@ -597,7 +602,6 @@ int process_run()
597602 p_log->info (" Mrenclave is '%s'\n " , id_info[" mrenclave" ].ToString ().c_str ());
598603 }
599604 }
600- p_log->info (" Restore enclave data successfully, sworker is running now.\n " );
601605 }
602606 }
603607 db = crust::DataBase::get_instance ();
@@ -609,7 +613,15 @@ int process_run()
609613 double srd_ratio = 0.0 ;
610614 sstream >> srd_ratio;
611615 p_config->set_srd_ratio (srd_ratio);
612- p_log->info (" Recover user defined srd ratio:%s successfully!\n " , float_to_string (srd_ratio).c_str ());
616+ if (is_restart)
617+ {
618+ if (wl_json.size () <= 0 )
619+ {
620+ wl_json = json::JSON::Load (wl_str);
621+ }
622+ wl_json[WL_SRD][WL_SRD_RATIO] = srd_ratio;
623+ }
624+ has_recover_option = true ;
613625 }
614626
615627 // Get srd remaining task
@@ -619,6 +631,15 @@ int process_run()
619631 size_t srd_task_remain = 0 ;
620632 sstream >> srd_task_remain;
621633 srd_task = std::max (srd_task, srd_task_remain);
634+ if (is_restart)
635+ {
636+ if (wl_json.size () <= 0 )
637+ {
638+ wl_json = json::JSON::Load (wl_str);
639+ }
640+ wl_json[WL_SRD][WL_SRD_REMAINING_TASK] = srd_task;
641+ }
642+ has_recover_option = true ;
622643 }
623644
624645 // Restore or add srd task
@@ -645,6 +666,49 @@ int process_run()
645666 }
646667 }
647668
669+ // Print recovered workload
670+ if (is_restart)
671+ {
672+ if (has_recover_option)
673+ {
674+ std::string srd_info;
675+ srd_info.append (" {\n " )
676+ .append (" \" " WL_SRD_COMPLETE " \" : " ).append (std::to_string (wl_json[WL_SRD][WL_SRD_COMPLETE].ToInt ())).append (" ,\n " )
677+ .append (" \" " WL_SRD_REMAINING_TASK " \" : " ).append (std::to_string (wl_json[WL_SRD][WL_SRD_REMAINING_TASK].ToInt ())).append (" ,\n " )
678+ .append (" \" " WL_SRD_RATIO " \" : " ).append (float_to_string (wl_json[WL_SRD][WL_SRD_RATIO].ToFloat ())).append (" ,\n " )
679+ .append (" \" " WL_DISK_AVAILABLE_FOR_SRD " \" : " ).append (std::to_string (wl_json[WL_SRD][WL_DISK_AVAILABLE_FOR_SRD].ToInt ())).append (" ,\n " )
680+ .append (" \" " WL_DISK_AVAILABLE " \" : " ).append (std::to_string (wl_json[WL_SRD][WL_DISK_AVAILABLE].ToInt ())).append (" ,\n " )
681+ .append (" \" " WL_DISK_VOLUME " \" : " ).append (std::to_string (wl_json[WL_SRD][WL_DISK_VOLUME].ToInt ())).append (" \n " )
682+ .append (" }" );
683+ // Get file info
684+ json::JSON file_info = wl_json[WL_FILES];
685+ json::JSON n_file_info;
686+ char buf[128 ];
687+ int space_num = 0 ;
688+ for (auto it = file_info.ObjectRange ().begin (); it != file_info.ObjectRange ().end (); it++)
689+ {
690+ space_num = std::max (space_num, (int )it->first .size ());
691+ }
692+ for (auto it = file_info.ObjectRange ().begin (); it != file_info.ObjectRange ().end (); it++)
693+ {
694+ memset (buf, 0 , sizeof (buf));
695+ sprintf (buf, " %s{ \" num\" : %-6ld, \" size\" : %ld }" ,
696+ std::string (space_num - it->first .size (), ' ' ).c_str (), it->second [" num" ].ToInt (), it->second [" size" ].ToInt ());
697+ n_file_info[it->first ] = std::string (buf);
698+ }
699+ wl_json[WL_SRD] = srd_info;
700+ wl_json[WL_FILES] = n_file_info;
701+ wl_str = wl_json.dump ();
702+ replace (wl_str, " \" {" , " {" );
703+ replace (wl_str, " : \" " , " : " );
704+ replace (wl_str, " }\" " , " }" );
705+ replace (wl_str, " \\ n" , " \n " );
706+ remove_char (wl_str, ' \\ ' );
707+ }
708+ p_log->info (" Workload information:\n %s\n " , wl_str.c_str ());
709+ p_log->info (" Restore enclave data successfully, sworker is running now.\n " );
710+ }
711+
648712 // Restore sealed file information
649713 ed->restore_sealed_file_info ();
650714
@@ -749,7 +813,10 @@ int process_run()
749813 // Destroy enclave
750814 // TODO: Fix me, why destory enclave leads to coredump
751815 p_log->info (" Destroy enclave for exit...\n " );
752- sgx_destroy_enclave (global_eid);
816+ if (global_eid != 0 )
817+ {
818+ sgx_destroy_enclave (global_eid);
819+ }
753820
754821 return return_status;
755822}
0 commit comments