How to check is application running under OpenOnload?

2.3k Views Asked by At

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?

3

There are 3 best solutions below

1
Rost On BEST ANSWER

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;
}
0
Kethiri Sundar On

Just search the symbol "onload_is_present" using the default shared object search order and if onload is pre-loaded it will return a valid address.

bool IsOnloadPresent()
{
   void* pIsOnloadPresent = dlsym(RTLD_DEFAULT, "onload_is_present");
   if(pIsOnloadPresent == NULL)
       return false;
   return true;
}
0
korst1k On

You need to use:

#include <onload/extensions.h>

int onload_is_present(void)

Description

If the application is linked with libonload_ext, but not running with Onload this will return 0. If the application is running with Onload this will return 1.

From Onload Extensions API