|
@@ -0,0 +1,35 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+
|
|
|
+# Use the external cpuid program (which must already be installed) to
|
|
|
+# determine the maximum amount of Enclave Page Cache (EPC) supported by
|
|
|
+# the system. This value is often configurable in your BIOS, but not at
|
|
|
+# runtime.
|
|
|
+
|
|
|
+import os
|
|
|
+import re
|
|
|
+import subprocess
|
|
|
+import sys
|
|
|
+
|
|
|
+def get_max_epc_bytes():
|
|
|
+ max_epc_bytes = 0
|
|
|
+ subleaf = 2
|
|
|
+ while True:
|
|
|
+ ret = subprocess.run(["cpuid", "-1", "-l", "0x12", "-s",
|
|
|
+ str(subleaf)], capture_output=True)
|
|
|
+ if ret.returncode != 0:
|
|
|
+ print("Unable to run cpuid", file=sys.stderr)
|
|
|
+ sys.exit(1)
|
|
|
+ match = re.search(r'section size\s*=\s*0x([0-9a-fA-F]+)',
|
|
|
+ str(ret.stdout))
|
|
|
+ if match is None:
|
|
|
+ break
|
|
|
+ max_epc_bytes += int(match.group(1), 16)
|
|
|
+ subleaf += 1
|
|
|
+
|
|
|
+ return max_epc_bytes
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ max_epc_bytes = get_max_epc_bytes()
|
|
|
+ print("Max EPC available:",
|
|
|
+ format(max_epc_bytes / (1<<30), ".2f"), "GiB")
|