Files
externals/linux/include/ActivMiddleware/ActivBase/Linux/OnloadHelper.h
T
2023-12-15 13:15:08 -05:00

184 lines
4.6 KiB
C++

/**
* @file include/ActivMiddleware/ActivBase/Linux/OnloadHelper.h
*
* @brief Header file for the OnloadHelper class.
*/
#if (!defined ACTIV_BASE_LINUX_ONLOAD_HELPER_H)
#define ACTIV_BASE_LINUX_ONLOAD_HELPER_H
#include "ActivMiddleware/ActivBase/External.h"
#include "ActivMiddleware/Misc/DynamicLibraryLoader.h"
struct onload_stat;
namespace Activ
{
//! Forward declarations.
class ProcessorAffinity;
//! Onload helper class.
class OnloadHelper
{
public:
//! Default constructor.
ACTIV_BASE_API OnloadHelper();
//! Is onload available.
ACTIV_BASE_API bool IsAvailable() const;
//! Is this process onloaded.
ACTIV_BASE_API static bool IsProcessOnloaded();
/**
* @brief Does the interface refer to a device that supports onload?
*
* @param interfaceName
*
* @retval true if supported, false otherwise.
*/
ACTIV_BASE_API static bool IsSfcInterface(const String &interfaceName);
//! Get version.
const String &GetVersion() const;
/**
* @brief Disable for this process.
*
* @throw std::exception
*/
ACTIV_BASE_API static void DisableForThisProcess();
/**
* @brief Disable spinning for this thread.
*
* @throw std::exception
*/
ACTIV_BASE_API static void DisableSpinningForThisThread();
/**
* @brief Set thread stack name (enables onload for this thread).
*
* @param stackName
*
* @throw std::exception
*/
ACTIV_BASE_API void SetThreadStackName(const String &stackName) const;
/**
* @brief Configure ideal receive channel.
*
* @param processorAffinity
*
* @throw std::exception
*/
ACTIV_BASE_API void ConfigureIdealReceiveChannel(const ProcessorAffinity &processorAffinity) const;
/**
* @brief Configure receive channel.
*
* @param receiveChannel
*
* @throw std::exception
*/
ACTIV_BASE_API void ConfigureReceiveChannel(const uint16_t receiveChannel) const;
/**
* @brief Set option.
*
* @param optionName
* @param value
*
* @throw std::exception
*/
ACTIV_BASE_API void SetOption(const String &optionName, const uint64_t value) const;
/**
* @brief Is socket onloaded.
*
* @param socket
*
* @return true if the socket is onload accelerated, false otherwise.
*/
ACTIV_BASE_API bool IsSocketOnloaded(SOCKET socket) const;
/**
* @brief Get socket stack name.
*
* @param socket
*
* @return The name of the stack the socket belongs to. Empty if not accelerated.
*/
ACTIV_BASE_API const String GetSocketStackName(SOCKET socket) const;
/**
* @brief Move socket to current onload stack.
*
* @param socket
*/
ACTIV_BASE_API void MoveSocketToCurrentStack(SOCKET socket) const;
/**
* @brief Move socket to new onload stack.
*
* @param socket
* @param stackName
* @param receiveChannnel
*/
ACTIV_BASE_API void MoveSocketToStack(SOCKET socket, const String &stackName, const uint64_t receiveChannnel) const;
/**
* @brief Get the ideal receive channel for this ProcessorAffinity.
*
* @param processAffinity
*
* @return the ideal receive channel for this ProcessorAffinity.
*
* @throw StringException.
*/
ACTIV_BASE_API static uint16_t GetIdealReceiveChannel(const ProcessorAffinity &processAffinity);
private:
typedef int (onload_set_stacknameF)(int, int, const char* );
typedef int (onload_stack_opt_set_intF)(const char*, int64_t);
typedef int (onload_thread_set_spinF)(int, int);
typedef int (onload_fd_statF)(int, onload_stat *);
typedef int (onload_stackname_saveF)();
typedef int (onload_stackname_restoreF)();
typedef int (onload_move_fdF)(int);
ACTIV_DECLARE_DLL_FUNCTION(onload_set_stackname, onload_set_stacknameF, false);
ACTIV_DECLARE_DLL_FUNCTION(onload_stack_opt_set_int, onload_stack_opt_set_intF, false);
ACTIV_DECLARE_DLL_FUNCTION(onload_thread_set_spin, onload_thread_set_spinF, false);
ACTIV_DECLARE_DLL_FUNCTION(onload_fd_stat, onload_fd_statF, false);
ACTIV_DECLARE_DLL_FUNCTION(onload_stackname_save, onload_stackname_saveF, false);
ACTIV_DECLARE_DLL_FUNCTION(onload_stackname_restore, onload_stackname_restoreF, false);
ACTIV_DECLARE_DLL_FUNCTION(onload_move_fd, onload_move_fdF, false);
typedef DynamicLibraryLoader<Boost::mpl::vector<
onload_set_stackname,
onload_stack_opt_set_int,
onload_thread_set_spin,
onload_fd_stat,
onload_stackname_save,
onload_stackname_restore,
onload_move_fd>
> OnloadLoader;
const OnloadLoader m_onloadLoader;
const String m_onloadVersion;
};
// ---------------------------------------------------------------------------------------------------------------------------------
inline const String &OnloadHelper::GetVersion() const
{
return m_onloadVersion;
}
} // namespace Activ
#endif // (!defined ACTIV_BASE_LINUX_ONLOAD_HELPER_H)