epc_probe.py 1002 B

1234567891011121314151617181920212223242526272829303132333435
  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 os
  7. import re
  8. import subprocess
  9. import sys
  10. def get_max_epc_bytes():
  11. max_epc_bytes = 0
  12. subleaf = 2
  13. while True:
  14. ret = subprocess.run(["cpuid", "-1", "-l", "0x12", "-s",
  15. str(subleaf)], capture_output=True)
  16. if ret.returncode != 0:
  17. print("Unable to run cpuid", file=sys.stderr)
  18. sys.exit(1)
  19. match = re.search(r'section size\s*=\s*0x([0-9a-fA-F]+)',
  20. str(ret.stdout))
  21. if match is None:
  22. break
  23. max_epc_bytes += int(match.group(1), 16)
  24. subleaf += 1
  25. return max_epc_bytes
  26. if __name__ == "__main__":
  27. max_epc_bytes = get_max_epc_bytes()
  28. print("Max EPC available:",
  29. format(max_epc_bytes / (1<<30), ".2f"), "GiB")