config.cpp 3.4 KB

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