Is there a way to measure cache misses and paging in SGX? I'd like to measure both L3 misses and EPC misses (that lead to paging). In , the author talks about profiling the programs and measuring cache misses (Section 7) but does not explain how he does it.
I figured out I can measure the total number of allocated (and freed) pages in the linux-sgx-driver by counting invocations of sgx_alloc_page_fast in sgx_page_cache.c. That, unfortunately, is a sum for all the enclaves since the driver starts and includes initialization of enclaves. Is there a way to profile particular function invocations?
I also tried to use VTune with sgx-hotspots. That gives "Precise Clockticks" per function and also shows that sgx_encl_add_page and sgx_fault_page consume a lot of CPU but, again, it's for the whole program and the init phase is a great part of the results. Can I somehow filter the results for a specific time span?
 A Memory Encryption Engine Suitable for General Purpose Processors https://eprint.iacr.org/2016/204.pdf
Hello Kai, visibility into SGX enclaves by external software is extremely limited by design to maintain security.
Note that Fortanix has patched Intel's Linux SGX driver and written an app, sgxtop, that works with their version of the driver to report memory usage. The source code for the Fortanix tools is open source in Github, https://github.com/fortanix/linux-sgx-driver and https://github.com/fortanix/sgxtop. For more information on these tools, please refer to their respective gits or contact Fortanix.
It seems that these tools provide memory usage and paging statistics for enclaves as a whole but do not get inside the enclaves like what you are trying to do. As I wrote earlier, being able to get inside the enclave would violate their security properties. This is what it means for the EPC to be protected memory.
Hello Kai, the feedback that I received is that it is possible to measure enclave cache misses as long you run the enclave in DEBUG mode. Unfortunately, I do not have more specific VTune guidance. I recommend to post your question in the VTune forum, https://community.intel.com/t5/Analyzers-Intel-VTune-Profiler/bd-p/analyzers, where they should be able to help you further if needed.