c++linuxnetwork-programmingsystemopenonload

How to check is application running under OpenOnload?


I need to check whether my application is accelerated by running under OpenOnload or not. The restriction is that no Onload specific API can be used - app is not linked with Onload extensions library.

How this can be done?


Solution

  • OpenOnload can be detected by pre-loaded shared library presence libonload.so.

    In this case your application environment will contain LD_PRELOAD=libonload.so string.

    Or you can just enumerate all loaded shared libraries and check for libonload.so.

    #include <string>
    #include <fstream>
    #include <iostream>
    
    // Checks is specific SO loaded in current process.
    bool is_so_loaded(const std::string& so_name)
    {
        const std::string proc_path = "/proc/self/maps";
        std::ifstream proc(proc_path);
    
        std::string str;
        while (std::getline(proc, str))
        {
            if (str.find(so_name) != std::string::npos) return true;
        }
    
        return false;
    }
    
    int main()
    {
        std::cout
            << "Running with OpenOnload: "
            << (is_so_loaded("/libonload.so") ? "Yes" : "No")
            << std::endl;
        return 0;
    }