config.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include "Enclave_t.h"
  2. #include "comms.hpp"
  3. #include "config.hpp"
  4. #include "utils.hpp"
  5. #include "route.hpp"
  6. Config g_teems_config;
  7. bool ecall_config_load(threadid_t nthreads, bool private_routing,
  8. EnclaveAPIParams *apiparams,
  9. EnclaveAPINodeConfig *apinodeconfigs,
  10. nodenum_t num_nodes, nodenum_t my_node_num)
  11. {
  12. g_teems_config.nthreads = nthreads;
  13. g_teems_config.num_nodes = num_nodes;
  14. g_teems_config.num_ingestion_nodes = 0;
  15. g_teems_config.num_routing_nodes = 0;
  16. g_teems_config.num_storage_nodes = 0;
  17. g_teems_config.my_node_num = my_node_num;
  18. g_teems_config.user_count = apiparams->user_count;
  19. g_teems_config.msg_size = apiparams->msg_size;
  20. g_teems_config.m_priv_out = apiparams->m_priv_out;
  21. g_teems_config.m_priv_in = apiparams->m_priv_in;
  22. g_teems_config.m_pub_out = apiparams->m_pub_out;
  23. g_teems_config.m_pub_in = apiparams->m_pub_in;
  24. g_teems_config.private_routing = private_routing;
  25. // Temporary vectors to store node numbers for nodes of different
  26. // types, where the node numbers are smaller than our own node
  27. // number
  28. std::vector<nodenum_t> ing_smaller, rte_smaller, str_smaller;
  29. uint16_t cumul_weight = 0;
  30. g_teems_config.weights.clear();
  31. g_teems_config.ingestion_nodes.clear();
  32. g_teems_config.routing_nodes.clear();
  33. g_teems_config.storage_nodes.clear();
  34. for (nodenum_t i=0; i<num_nodes; ++i) {
  35. NodeWeight nw;
  36. nw.startweight = cumul_weight;
  37. nw.weight = apinodeconfigs[i].weight;
  38. if (apinodeconfigs[i].roles & ROLE_INGESTION) {
  39. g_teems_config.num_ingestion_nodes += 1;
  40. if (i < my_node_num) {
  41. ing_smaller.push_back(i);
  42. } else {
  43. g_teems_config.ingestion_nodes.push_back(i);
  44. }
  45. }
  46. if (apinodeconfigs[i].roles & ROLE_ROUTING) {
  47. g_teems_config.num_routing_nodes += 1;
  48. if (i < my_node_num) {
  49. rte_smaller.push_back(i);
  50. } else {
  51. g_teems_config.routing_nodes.push_back(i);
  52. }
  53. }
  54. if (apinodeconfigs[i].roles & ROLE_STORAGE) {
  55. g_teems_config.num_storage_nodes += 1;
  56. if (i < my_node_num) {
  57. str_smaller.push_back(i);
  58. } else {
  59. g_teems_config.storage_nodes.push_back(i);
  60. }
  61. }
  62. cumul_weight += nw.weight;
  63. g_teems_config.weights.push_back(nw);
  64. if (i == my_node_num) {
  65. g_teems_config.my_weight = nw.weight;
  66. }
  67. }
  68. g_teems_config.tot_weight = cumul_weight;
  69. // Concatenate the *_smaller vectors to the ends of the
  70. // g_teems_config.*_nodes vectors. This way, each node has a list
  71. // of nodes of each role starting with itself and "looping around".
  72. // This should make the communication pattern have less of a
  73. // bottleneck.
  74. g_teems_config.ingestion_nodes.insert(
  75. g_teems_config.ingestion_nodes.end(),
  76. ing_smaller.begin(),
  77. ing_smaller.end());
  78. g_teems_config.routing_nodes.insert(
  79. g_teems_config.routing_nodes.end(),
  80. rte_smaller.begin(),
  81. rte_smaller.end());
  82. g_teems_config.storage_nodes.insert(
  83. g_teems_config.storage_nodes.end(),
  84. str_smaller.begin(),
  85. str_smaller.end());
  86. // Initialize the threadpool and the pseudorandom bytes pools
  87. threadpool_init(nthreads);
  88. PRB_pool_init(nthreads);
  89. if (!route_init()) {
  90. return false;
  91. }
  92. return comms_init_nodestate(apinodeconfigs, num_nodes, my_node_num);
  93. }
  94. void ecall_close()
  95. {
  96. PRB_pool_shutdown();
  97. threadpool_shutdown();
  98. }