gen_enclave_config.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/python3
  2. import math
  3. import sys
  4. ###############################################################################
  5. # CONFIGS TO SET:
  6. CONFIG_FILE = "Enclave/Enclave.config.xml"
  7. ###############################################################################
  8. '''
  9. Generate a manifest file with:
  10. N: number of clients
  11. M: number of servers
  12. T: number of threads for each server
  13. B: msg_size
  14. TOKEN_CHANNEL: Token channel (True) / ID channel (False) routing
  15. TOKO: TOken channel Out
  16. TOKI: TOken channel In
  17. IDO: ID channel Out
  18. IDI: ID channel In
  19. num_WN_to_precompute: The default num_WN_to_precompute is 12 in App/start.cpp
  20. '''
  21. def get_heap_size(N, M, T, B, TOKEN_CHANNEL=True, TOKO=1, TOKI=1, IDO=1, IDI=1, num_WN_to_precompute=12):
  22. clients_per_server = math.ceil(N/M)
  23. # Base heap of 2 MB per thread
  24. heap_size = 2000000 * T
  25. num_out_mult = TOKO
  26. if not TOKEN_CHANNEL:
  27. num_out_mult = IDO
  28. num_in_mult = TOKI
  29. if not TOKEN_CHANNEL:
  30. num_in_mult = IDI
  31. # Storage and Ingestion data stored per_client
  32. heap_size += clients_per_server * 100
  33. heap_size += (clients_per_server + M * M) * (B+8)
  34. # 2 Buffers of clients_per_server items of B size each, plus 1 of
  35. # size (clients_per_server + M * M) items, for token channel routing
  36. heap_size += (clients_per_server * B * 2) * num_out_mult
  37. heap_size += ((clients_per_server + M * M) * B) * num_in_mult
  38. # Additional buffers for ID channel routing
  39. # Round (M-1)^2 up to a multiple of M
  40. round1b_size = (M-1)*M
  41. wn_size = max(clients_per_server + M*M, 2*round1b_size)
  42. # Round up to a multiple of M
  43. colsort_size = int((wn_size + M - 1) / M) * M
  44. if not TOKEN_CHANNEL:
  45. heap_size += (colsort_size * B * 3) + (2 * round1b_size * B)
  46. # num_WN_to_precompute times size of each WN
  47. heap_size += (num_WN_to_precompute * num_out_mult * \
  48. (wn_size * math.ceil(math.log(wn_size,2) + 1) * 9))
  49. heap_size_page_aligned = math.ceil(heap_size/4096) * 4096
  50. return heap_size_page_aligned
  51. def generate_config(N, M, T, B, TOKEN_CHANNEL=True, TOKO=1, TOKI=1, IDO=1, IDI=1, num_WN_to_precompute=12):
  52. cf = open(CONFIG_FILE, 'w+')
  53. heap_size_page_aligned = get_heap_size(N, M, T, B, TOKEN_CHANNEL,
  54. TOKO, TOKI, IDO, IDI, num_WN_to_precompute)
  55. hex_heap_size = hex(heap_size_page_aligned)
  56. enclave_config = '''<!-- Please refer to User's Guide for the explanation of each field -->
  57. <EnclaveConfiguration>
  58. <ProdID>0</ProdID>
  59. <ISVSVN>0</ISVSVN>
  60. <StackMaxSize>0x40000</StackMaxSize>
  61. <HeapMaxSize>{H}</HeapMaxSize>
  62. <TCSNum>32</TCSNum>
  63. <TCSPolicy>1</TCSPolicy>
  64. <DisableDebug>0</DisableDebug>
  65. <MiscSelect>0</MiscSelect>
  66. <MiscMask>0xFFFFFFFF</MiscMask>
  67. </EnclaveConfiguration>
  68. '''.format(H = hex_heap_size)
  69. #print (enclave_config)
  70. cf.write(enclave_config)
  71. cf.close()
  72. if __name__ == "__main__":
  73. if len(sys.argv) != 5:
  74. print("Incorrect usage!\n")
  75. print("./gen_enclave_config.py expects 4 parameters.")
  76. print("Usage: ./gen_enclave_config.py <N = number of clients> <M = number of servers> <T = number of threads> <B = message_size>")
  77. exit()
  78. n = int(sys.argv[1])
  79. m = int(sys.argv[2])
  80. t = int(sys.argv[3])
  81. b = int(sys.argv[4])
  82. generate_config(n, m, t, b)