Переглянути джерело

Start the threadpool and the pseudo-random bytes pools

Ian Goldberg 1 рік тому
батько
коміт
2a0106d4da

+ 3 - 3
App/appconfig.cpp

@@ -58,7 +58,7 @@ static bool hextobuf(unsigned char *buf, const char *str, size_t len)
 }
 
 bool config_parse(Config &config, const std::string configstr,
-    const std::string &myname)
+    const std::string &myname, threadid_t nthreads)
 {
     bool found_my_node = false;
     bool found_params = false;
@@ -160,8 +160,8 @@ bool config_parse(Config &config, const std::string configstr,
         apinodeconfigs[i].weight = config.nodes[i].weight;
         apinodeconfigs[i].roles = config.nodes[i].roles;
     }
-    ret &= ecall_config_load(&apiparams, apinodeconfigs.data(),
-        num_nodes, config.my_node_num);
+    ret &= ecall_config_load(nthreads, &apiparams,
+        apinodeconfigs.data(), num_nodes, config.my_node_num);
     if (!ret) {
         std::cerr << "Loading config into enclave failed\n";
     }

+ 1 - 1
App/appconfig.hpp

@@ -33,6 +33,6 @@ struct Config {
 };
 
 bool config_parse(Config &config, const std::string configstr,
-    const std::string &myname);
+    const std::string &myname, threadid_t nthreads);
 
 #endif

+ 2 - 1
App/teems.cpp

@@ -231,7 +231,7 @@ int main(int argc, char **argv)
 
     Config config;
 
-    if (!config_parse(config, configstr, myname)) {
+    if (!config_parse(config, configstr, myname, nthreads)) {
         exit(1);
     }
 
@@ -255,6 +255,7 @@ int main(int argc, char **argv)
     t.join();
 
     // All done
+    ecall_close();
     g_netio = NULL;
     sgx_destroy_enclave(global_eid);
 

+ 3 - 0
Enclave/Enclave.edl

@@ -17,10 +17,13 @@ enclave {
             [in,size=610] const sgx_sealed_data_t *insealedpriv);
 
         public bool ecall_config_load(
+            threadid_t nthreads,
             [in] struct EnclaveAPIParams *apiparams,
             [in,count=num_nodes] struct EnclaveAPINodeConfig *apinodeconfigs,
             nodenum_t num_nodes, nodenum_t my_node_num);
 
+        public void ecall_close();
+
         public bool ecall_comms_start();
 
         public bool ecall_message(

+ 0 - 1
Enclave/OblivAlgs/utils.hpp

@@ -129,7 +129,6 @@
    * and join inter-thread communication.  A parent thread has to specify
    * the exact thread id of the child thread it dispatches work to. */
 
-  typedef size_t threadid_t;
   extern thread_local threadid_t g_thread_id;
 
   /* Create the threadpool, with numthreads-1 additional threads (numbered

+ 14 - 1
Enclave/config.cpp

@@ -1,13 +1,16 @@
 #include "Enclave_t.h"
 #include "comms.hpp"
 #include "config.hpp"
+#include "utils.hpp"
 
 Config g_teems_config;
 
-bool ecall_config_load(EnclaveAPIParams *apiparams,
+bool ecall_config_load(threadid_t nthreads,
+    EnclaveAPIParams *apiparams,
     EnclaveAPINodeConfig *apinodeconfigs,
     nodenum_t num_nodes, nodenum_t my_node_num)
 {
+    g_teems_config.nthreads = nthreads;
     g_teems_config.num_nodes = num_nodes;
     g_teems_config.num_ingestion_nodes = 0;
     g_teems_config.num_routing_nodes = 0;
@@ -77,5 +80,15 @@ bool ecall_config_load(EnclaveAPIParams *apiparams,
         str_smaller.begin(),
         str_smaller.end());
 
+    // Initialize the threadpool and the pseudorandom bytes pools
+    threadpool_init(nthreads);
+    PRB_pool_init(nthreads);
+
     return comms_init_nodestate(apinodeconfigs, num_nodes, my_node_num);
 }
+
+void ecall_close()
+{
+    PRB_pool_shutdown();
+    threadpool_shutdown();
+}

+ 1 - 0
Enclave/config.hpp

@@ -15,6 +15,7 @@ struct NodeWeight {
 };
 
 struct Config {
+    threadid_t nthreads;
     nodenum_t num_nodes;
     nodenum_t num_ingestion_nodes;
     nodenum_t num_routing_nodes;

+ 1 - 0
Enclave/enclave_api.h

@@ -3,6 +3,7 @@
 
 #include "sgx_tcrypto.h"
 
+typedef uint16_t threadid_t;
 typedef uint16_t nodenum_t;
 
 struct EnclaveAPIParams {

+ 9 - 3
Untrusted/Untrusted.cpp

@@ -225,16 +225,22 @@ bool ecall_identity_key_load(sgx_ec256_public_t* outpub,
     return ret;
 }
 
-bool ecall_config_load(struct EnclaveAPIParams *apiparams,
+bool ecall_config_load(threadid_t nthreads,
+    struct EnclaveAPIParams *apiparams,
     struct EnclaveAPINodeConfig *apinodeconfigs,
     nodenum_t num_nodes, nodenum_t my_node_num)
 {
     bool ret;
-    ecall_config_load(global_eid, &ret, apiparams, apinodeconfigs,
-        num_nodes, my_node_num);
+    ecall_config_load(global_eid, &ret, nthreads, apiparams,
+        apinodeconfigs, num_nodes, my_node_num);
     return ret;
 }
 
+void ecall_close()
+{
+    ecall_close(global_eid);
+}
+
 bool ecall_comms_start()
 {
     bool ret;

+ 4 - 1
Untrusted/Untrusted.hpp

@@ -18,10 +18,13 @@ void ecall_identity_key_new(sgx_ec256_public_t* outpub,
 bool ecall_identity_key_load(sgx_ec256_public_t* outpub,
     const sgx_sealed_data_t* insealedpriv);
 
-bool ecall_config_load(struct EnclaveAPIParams *apiparams,
+bool ecall_config_load(threadid_t nthreads,
+    struct EnclaveAPIParams *apiparams,
     struct EnclaveAPINodeConfig *apinodeconfigs,
     nodenum_t num_nodes, nodenum_t my_node_num);
 
+void ecall_close();
+
 bool ecall_comms_start();
 
 bool ecall_message(nodenum_t node_num, uint32_t message_len);