Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Public Member Functions | Private Member Functions | Private Attributes | List of all members
GpuPlugin Class Reference

Dobby GPU plugin. More...

#include <GpuPlugin.h>

Inheritance diagram for GpuPlugin:
Inheritance graph
[legend]
Collaboration diagram for GpuPlugin:
Collaboration graph
[legend]

Public Member Functions

 GpuPlugin (std::shared_ptr< rt_dobby_schema > &containerConfig, const std::shared_ptr< DobbyRdkPluginUtils > &utils, const std::string &rootfsPath)
 
std::string name () const override
 Should return the name of the plugin. More...
 
unsigned hookHints () const override
 Should return a bitfield of the hook points implemented by the plugin. More...
 
bool createRuntime () override
 we use the createRuntime point to create a cgroup and put the containered process into it. More...
 
bool postStop () override
 We use the postStop point to remove the cgroup directory created in the createRuntime phase. More...
 
std::vector< std::string > getDependencies () const override
 Should return the names of the plugins this plugin depends on. More...
 
- Public Member Functions inherited from RdkPluginBase
virtual bool postInstallation ()
 
virtual bool preCreation ()
 
virtual bool createContainer ()
 
virtual bool postStart ()
 
virtual bool postHalt ()
 

Private Member Functions

std::string getGpuCgroupMountPoint ()
 Attempts to get the mount point of the gpu cgroup filesystem. More...
 
bool setupContainerGpuLimit (const std::string cgroupDirPath, pid_t containerPid, int memoryLimit)
 Creates a gpu cgroup for the container and moves the container into it. More...
 
bool bindMountGpuCgroup (const std::string &source, const std::string &target)
 

Private Attributes

const std::string mName
 
std::shared_ptr< rt_dobby_schema > mContainerConfig
 
const std::shared_ptr< DobbyRdkPluginUtilsmUtils
 

Additional Inherited Members

- Public Types inherited from IDobbyRdkPlugin
enum  HintFlags : unsigned {
  PostInstallationFlag = (1 << 0) , PreCreationFlag = (1 << 1) , CreateRuntimeFlag = (1 << 2) , CreateContainerFlag = (1 << 3) ,
  PostStartFlag = (1 << 5) , PostHaltFlag = (1 << 6) , PostStopFlag = (1 << 7) , Unknown = 0
}
 Bit flags that should be returned by hookHints. More...
 

Detailed Description

Dobby GPU plugin.

Sets the gpu memory limits for a given container.

This plugin simply creates a gpu cgroup for the container, sets the limit and then moves the containered process into it.

This is effectively what crun does for all the other limits, but it doesn't know about the custom gpu cgroup as that is an extension to the default cgroups.

Member Function Documentation

◆ createRuntime()

bool GpuPlugin::createRuntime ( )
overridevirtual

we use the createRuntime point to create a cgroup and put the containered process into it.

The amount of memory to assign is read from the plugin's data section in the bundle config.

The cgroup is given the same name as the container.

Returns
true if successful, otherwise false.

Reimplemented from RdkPluginBase.

◆ getDependencies()

std::vector< std::string > GpuPlugin::getDependencies ( ) const
overridevirtual

Should return the names of the plugins this plugin depends on.

This can be used to determine the order in which the plugins should be processed when running hooks.

Returns
Names of the plugins this plugin depends on.

Reimplemented from RdkPluginBase.

◆ getGpuCgroupMountPoint()

std::string GpuPlugin::getGpuCgroupMountPoint ( )
private

Attempts to get the mount point of the gpu cgroup filesystem.

This scans the mount table looking for the cgroups mount, if this fails it's pretty fatal.

This is typically "/sys/fs/cgroup/gpu".

Returns
a string to the gpu cgroup path.

◆ hookHints()

unsigned GpuPlugin::hookHints ( ) const
overridevirtual

Should return a bitfield of the hook points implemented by the plugin.

Only bits that are set will be called as hooks. This is to optimise the implementation of the hook code to ensure we don't waste time trying to run hooks that don't do anything

The value returned should be constant for the lifetime of the class

Returns
bitmask of the HintFlags bits.

Implements IDobbyRdkPlugin.

◆ name()

std::string GpuPlugin::name ( ) const
inlineoverridevirtual

Should return the name of the plugin.

Returns
string with the name of the hook.

Implements IDobbyRdkPlugin.

◆ postStop()

bool GpuPlugin::postStop ( )
overridevirtual

We use the postStop point to remove the cgroup directory created in the createRuntime phase.

The directory will have the same name as the container id.

Returns
true if successful, otherwise false.

Reimplemented from RdkPluginBase.

◆ setupContainerGpuLimit()

bool GpuPlugin::setupContainerGpuLimit ( const std::string  cgroupDirPath,
pid_t  containerPid,
int  memoryLimit 
)
private

Creates a gpu cgroup for the container and moves the container into it.

The cgroup is given the same name as the container.

Warning
This requires a version of crun with the following PR: https://github.com/containers/crun/pull/609 to ensure cgroup controllers are correctly mounted. Without the PR applied, the GPU cgroup is mounted incorrectly, see https://github.com/containers/crun/issues/625 for more info
Parameters
[in]cgroupDirPathPath to the gpu cgroup directory.
[in]containerPidThe pid of the process in the container.
[in]memoryLimitThe memory limit set in the bundle config.
Returns
true if successful, otherwise false.

The documentation for this class was generated from the following files: