gen_enclave_config.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. PRIVATE_ROUTE: Private (True) / Public (False) route
  15. PRO: PRivate Out
  16. PRI: PRivate In
  17. PUO: PUblic Out
  18. PUI: PUblic 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, PRIVATE_ROUTE=True, PRO=1, PRI=1, PUO=1, PUI=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 = PRO
  26. if not PRIVATE_ROUTE:
  27. num_out_mult = PUO
  28. num_in_mult = PRI
  29. if not PRIVATE_ROUTE:
  30. num_in_mult = PUI
  31. # Storage and Ingestion data stored per_client = 52 bytes
  32. heap_size += clients_per_server * (B + 60)
  33. # 2 Buffers of clients_per_server items of B size each, plus 1 of
  34. # size (clients_per_server + M) items, for private routing
  35. heap_size += (clients_per_server * B * 2) * num_out_mult
  36. heap_size += ((clients_per_server + M) * B) * num_in_mult
  37. # Additional buffers for public routing
  38. wn_size = max(clients_per_server, 2*(M-1)**2)
  39. # Round up to a multiple of M
  40. colsort_size = int((wn_size + M - 1) / M) * M
  41. if not PRIVATE_ROUTE:
  42. heap_size += (colsort_size * B * 3) + (2 * (M-1)**2 * B * 2)
  43. # num_WN_to_precompute times size of each WN
  44. heap_size += (num_WN_to_precompute * num_out_mult * \
  45. (wn_size * math.ceil(math.log(wn_size,2) + 1) * 8))
  46. heap_size_page_aligned = math.ceil(heap_size/4096) * 4096
  47. return heap_size_page_aligned
  48. def generate_config(N, M, T, B, PRIVATE_ROUTE=True, PRO=1, PRI=1, PUO=1, PUI=1, num_WN_to_precompute=12):
  49. cf = open(CONFIG_FILE, 'w+')
  50. heap_size_page_aligned = get_heap_size(N, M, T, B, PRIVATE_ROUTE,
  51. PRO, PRI, PUO, PUI, num_WN_to_precompute)
  52. hex_heap_size = hex(heap_size_page_aligned)
  53. enclave_config = '''<!-- Please refer to User's Guide for the explanation of each field -->
  54. <EnclaveConfiguration>
  55. <ProdID>0</ProdID>
  56. <ISVSVN>0</ISVSVN>
  57. <StackMaxSize>0x40000</StackMaxSize>
  58. <HeapMaxSize>{H}</HeapMaxSize>
  59. <TCSNum>32</TCSNum>
  60. <TCSPolicy>1</TCSPolicy>
  61. <DisableDebug>0</DisableDebug>
  62. <MiscSelect>0</MiscSelect>
  63. <MiscMask>0xFFFFFFFF</MiscMask>
  64. </EnclaveConfiguration>
  65. '''.format(H = hex_heap_size)
  66. #print (enclave_config)
  67. cf.write(enclave_config)
  68. cf.close()
  69. if __name__ == "__main__":
  70. if len(sys.argv) != 5:
  71. print("Incorrect usage!\n")
  72. print("./gen_enclave_config.py expects 4 parameters.")
  73. print("Usage: ./gen_enclave_config.py <N = number of clients> <M = number of servers> <T = number of threads> <B = message_size>")
  74. exit()
  75. n = int(sys.argv[1])
  76. m = int(sys.argv[2])
  77. t = int(sys.argv[3])
  78. b = int(sys.argv[4])
  79. generate_config(n, m, t, b)