config.cpp 3.7 KB

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