Intel® Software Guard Extensions (Intel® SGX)
Discussion board focused on hardware-based isolation and memory encryption to provide extended code protection in solutions.

Vtune profiling support in SGX enclave

wei__changzheng
Beginner
629 Views

Hi,

I noticed that there is a piece of code of function __create_enclave in psw (urts/urts_com.h), so what is the propose of this code below? Is it helpful for vtune profiling in sgx enclave? How can I enable the isVTuneProfiling flag?

    __itt_init_ittlib(NULL, __itt_group_none);
    bool isVTuneProfiling;
    if(__itt_get_ittapi_global()->api_initialized && __itt_get_ittapi_global()->lib)
        isVTuneProfiling = true;
    else
        isVTuneProfiling = false;

    bool is_SGX_DBG_OPTIN_set = false;
    is_SGX_DBG_OPTIN_set = is_SGX_DBG_OPTIN_variable_set();
    if (isVTuneProfiling || is_SGX_DBG_OPTIN_set)
    {
        SE_TRACE(SE_TRACE_DEBUG, "VTune is profiling or SGX_DBG_OPTIN is set\n");

        bool thread_updated;
        thread_updated = enclave->update_debug_flag(1);

        if(thread_updated == false)
        {
            SE_TRACE(SE_TRACE_DEBUG, "Failed to update debug OPTIN bit\n");
        }
        else
        {
            SE_TRACE(SE_TRACE_DEBUG, "Updated debug OPTIN bit\n");
        }

        if (isVTuneProfiling)
        {
            uint64_t enclave_start_addr;
            uint64_t enclave_end_addr;
            const char* enclave_path;
            enclave_start_addr = (uint64_t) loader.get_start_addr();
            enclave_end_addr = enclave_start_addr + (uint64_t) metadata->enclave_size -1;

            SE_TRACE(SE_TRACE_DEBUG, "Invoking VTune's module mapping API __itt_module_load \n");
            SE_TRACE(SE_TRACE_DEBUG, "Enclave_start_addr==0x%llx\n", enclave_start_addr);
            SE_TRACE(SE_TRACE_DEBUG, "Enclave_end_addr==0x%llx\n", enclave_end_addr);

            enclave_path = (const char*)file.name;
            SE_TRACE(SE_TRACE_DEBUG, "Enclave_path==%s\n",  enclave_path);
            __itt_module_load((void*)enclave_start_addr, (void*) enclave_end_addr, enclave_path);
        }
    }

 

 
0 Kudos
1 Reply
Francisco_C_Intel
629 Views

[edit for phrasing/clarity]

The implementation in the SGX URTS to enable VTune to profile enclaves is what you copy+pasted. 

Page 20 of https://01.org/sites/default/files/documentation/intel_sgx_sdk_developer_reference_for_linux_os_pdf.pdf has more info on how to profile enclaves using VTune.

Francisco

 

0 Kudos
Reply