epc_probe.py 992 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python3
  2. # Use the external cpuid program (which must already be installed) to
  3. # determine the maximum amount of Enclave Page Cache (EPC) supported by
  4. # the system. This value is often configurable in your BIOS, but not at
  5. # runtime.
  6. import re
  7. import subprocess
  8. import sys
  9. def get_max_epc_bytes():
  10. max_epc_bytes = 0
  11. subleaf = 2
  12. while True:
  13. ret = subprocess.run(["cpuid", "-1", "-l", "0x12", "-s",
  14. str(subleaf)], capture_output=True)
  15. if ret.returncode != 0:
  16. print("Unable to run cpuid", file=sys.stderr)
  17. sys.exit(1)
  18. match = re.search(r'section size\s*=\s*0x([0-9a-fA-F]+)',
  19. str(ret.stdout))
  20. if match is None:
  21. break
  22. max_epc_bytes += int(match.group(1), 16)
  23. subleaf += 1
  24. return max_epc_bytes
  25. if __name__ == "__main__":
  26. max_epc_bytes = get_max_epc_bytes()
  27. print("Max EPC available:",
  28. format(max_epc_bytes / (1<<30), ".2f"), "GiB")