config.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. g_teems_config.storage_map.clear();
  35. for (nodenum_t i=0; i<num_nodes; ++i) {
  36. NodeWeight nw;
  37. nw.startweight = cumul_weight;
  38. // Weights only matter for routing nodes
  39. nw.weight = 0;
  40. if (apinodeconfigs[i].roles & ROLE_INGESTION) {
  41. g_teems_config.num_ingestion_nodes += 1;
  42. if (i < my_node_num) {
  43. ing_smaller.push_back(i);
  44. } else {
  45. g_teems_config.ingestion_nodes.push_back(i);
  46. }
  47. }
  48. if (apinodeconfigs[i].roles & ROLE_ROUTING) {
  49. nw.weight = apinodeconfigs[i].weight;
  50. g_teems_config.num_routing_nodes += 1;
  51. if (i < my_node_num) {
  52. rte_smaller.push_back(i);
  53. } else {
  54. g_teems_config.routing_nodes.push_back(i);
  55. }
  56. }
  57. if (apinodeconfigs[i].roles & ROLE_STORAGE) {
  58. g_teems_config.num_storage_nodes += 1;
  59. if (i < my_node_num) {
  60. str_smaller.push_back(i);
  61. } else {
  62. g_teems_config.storage_nodes.push_back(i);
  63. }
  64. g_teems_config.storage_map.push_back(i);
  65. }
  66. cumul_weight += nw.weight;
  67. g_teems_config.weights.push_back(nw);
  68. g_teems_config.roles.push_back(apinodeconfigs[i].roles);
  69. if (i == my_node_num) {
  70. g_teems_config.my_weight = nw.weight;
  71. }
  72. }
  73. g_teems_config.tot_weight = cumul_weight;
  74. // Concatenate the *_smaller vectors to the ends of the
  75. // g_teems_config.*_nodes vectors. This way, each node has a list
  76. // of nodes of each role starting with itself and "looping around".
  77. // This should make the communication pattern have less of a
  78. // bottleneck.
  79. g_teems_config.ingestion_nodes.insert(
  80. g_teems_config.ingestion_nodes.end(),
  81. ing_smaller.begin(),
  82. ing_smaller.end());
  83. g_teems_config.routing_nodes.insert(
  84. g_teems_config.routing_nodes.end(),
  85. rte_smaller.begin(),
  86. rte_smaller.end());
  87. g_teems_config.storage_nodes.insert(
  88. g_teems_config.storage_nodes.end(),
  89. str_smaller.begin(),
  90. str_smaller.end());
  91. // Initialize the threadpool and the pseudorandom bytes pools
  92. threadpool_init(nthreads);
  93. PRB_pool_init(nthreads);
  94. if (!route_init()) {
  95. return false;
  96. }
  97. return comms_init_nodestate(apinodeconfigs, num_nodes, my_node_num);
  98. }
  99. void ecall_close()
  100. {
  101. PRB_pool_shutdown();
  102. threadpool_shutdown();
  103. }