config.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. if (i == my_node_num) {
  67. g_teems_config.my_weight = nw.weight;
  68. }
  69. }
  70. g_teems_config.tot_weight = cumul_weight;
  71. // Concatenate the *_smaller vectors to the ends of the
  72. // g_teems_config.*_nodes vectors. This way, each node has a list
  73. // of nodes of each role starting with itself and "looping around".
  74. // This should make the communication pattern have less of a
  75. // bottleneck.
  76. g_teems_config.ingestion_nodes.insert(
  77. g_teems_config.ingestion_nodes.end(),
  78. ing_smaller.begin(),
  79. ing_smaller.end());
  80. g_teems_config.routing_nodes.insert(
  81. g_teems_config.routing_nodes.end(),
  82. rte_smaller.begin(),
  83. rte_smaller.end());
  84. g_teems_config.storage_nodes.insert(
  85. g_teems_config.storage_nodes.end(),
  86. str_smaller.begin(),
  87. str_smaller.end());
  88. // Initialize the threadpool and the pseudorandom bytes pools
  89. threadpool_init(nthreads);
  90. PRB_pool_init(nthreads);
  91. if (!route_init()) {
  92. return false;
  93. }
  94. return comms_init_nodestate(apinodeconfigs, num_nodes, my_node_num);
  95. }
  96. void ecall_close()
  97. {
  98. PRB_pool_shutdown();
  99. threadpool_shutdown();
  100. }