Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to capture the time duration inside an enclave? #1003

Open
li0926 opened this issue Jan 5, 2024 · 4 comments
Open

How to capture the time duration inside an enclave? #1003

li0926 opened this issue Jan 5, 2024 · 4 comments

Comments

@li0926
Copy link

li0926 commented Jan 5, 2024

I'm new to intel sgx. I need an accurate timekeeper in enclave, preferably down to the millisecond.

  1. I trying to use std::chrono.
    I write #include <chrono> in enclave.cpp and test it inside an enclave function, but the error is reported as below:
Enclave/Enclave.cpp:476:24: error: ‘std::chrono’ has not been declared
  476 |     auto begin1 = std::chrono::high_resolution_clock::now();
      |                        ^~~~~~
  1. I trying to use time.h.
    I write #include <time.h> in enclave.cpp, but it still gives me the following error:
Enclave/Enclave.cpp:482:5: error: ‘time’ was not declared in this scope
  482 |     time(&t1);
      |     ^~~~

The Enclave_Link_Flags in makefile:

Enclave_Link_Flags :=  $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \
	$(SgxSSL_Link_Libraries) \
	-L/opt/intel/sgxsdk/lib64 \
	-L/opt/gmp/6.1.2/lib \
	$(Enclave_Security_Link_Flags) \
	-L$(SGX_LIBRARY_PATH) \
    -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \
	-Wl,--whole-archive  -l$(Trts_Library_Name) -Wl,--no-whole-archive \
	-Wl,--start-group -lsgx_tstdc -lsgx_tgmp -lsgx_pthread -lsgx_tcxx -l$(Crypto_Library_Name) -l$(Service_Library_Name) \
	-l$(SGX_TVL_Library_Name) -lsgx_ttls -Wl,--end-group \
	-Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \
	-Wl,-pie,-eenclave_entry -Wl,--export-dynamic  \
	-Wl,--defsym,__ImageBase=0 -Wl,--gc-sections   \
	-Wl,--version-script=Enclave/Enclave.lds
@lzha101
Copy link
Contributor

lzha101 commented Jan 10, 2024

There is no trust time support inside SGX enclaves. If you want to use time, an ocall is required. And you should be aware that the time cannot be trusted.

@li0926
Copy link
Author

li0926 commented Jan 10, 2024

There is no trust time support inside SGX enclaves. If you want to use time, an ocall is required. And you should be aware that the time cannot be trusted.

I'm not looking for a trust time, I just want to log the time to test the efficiency of running some functions within the enclave.

@lzha101
Copy link
Contributor

lzha101 commented Jan 10, 2024

OK. Perhaps you can try to use the rdtsc instruction to monitor the performance for your case. This instruction is accessible inside enclaves if your platform supports SGX2.

@jinghe-INTC
Copy link
Contributor

You can also try Intel® VTune™ Profiler, and the stand-alone version is recommended. It is able to collect the CPU time in clockticks of each functions even inside a SGX enclave, in GUI or CLI.
To do the measurement, your application don't need any change but should be built in debug configuration.
And you need to register an account to have a 31-day free trial first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants