Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
GpuPlugin.h
1 /*
2 * If not stated otherwise in this file or this component's LICENSE file the
3 * following copyright and licenses apply:
4 *
5 * Copyright 2020 Sky UK
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 
20 #ifndef GPUPLUGIN_H
21 #define GPUPLUGIN_H
22 
23 #include <RdkPluginBase.h>
24 
25 #include <sys/types.h>
26 #include <netinet/in.h>
27 
28 #include <unistd.h>
29 #include <string>
30 #include <memory>
31 
44 class GpuPlugin : public RdkPluginBase
45 {
46 public:
47  GpuPlugin(std::shared_ptr<rt_dobby_schema> &containerConfig,
48  const std::shared_ptr<DobbyRdkPluginUtils> &utils,
49  const std::string &rootfsPath);
50 
51 public:
52  inline std::string name() const override
53  {
54  return mName;
55  };
56 
57  unsigned hookHints() const override;
58 
59 public:
60  bool createRuntime() override;
61  bool postStop() override;
62 
63 public:
64  std::vector<std::string> getDependencies() const override;
65 
66 private:
67  std::string getGpuCgroupMountPoint();
68 
69  bool setupContainerGpuLimit(const std::string cgroupDirPath,
70  pid_t containerPid,
71  int memoryLimit);
72 
73  bool bindMountGpuCgroup(const std::string &source,
74  const std::string &target);
75 
76 private:
77  const std::string mName;
78  std::shared_ptr<rt_dobby_schema> mContainerConfig;
79  const std::shared_ptr<DobbyRdkPluginUtils> mUtils;
80 };
81 
82 #endif // !defined(GPUPLUGIN_H)
Dobby GPU plugin.
Definition: GpuPlugin.h:45
std::vector< std::string > getDependencies() const override
Should return the names of the plugins this plugin depends on.
Definition: GpuPlugin.cpp:146
bool postStop() override
We use the postStop point to remove the cgroup directory created in the createRuntime phase.
Definition: GpuPlugin.cpp:105
std::string getGpuCgroupMountPoint()
Attempts to get the mount point of the gpu cgroup filesystem.
Definition: GpuPlugin.cpp:172
bool setupContainerGpuLimit(const std::string cgroupDirPath, pid_t containerPid, int memoryLimit)
Creates a gpu cgroup for the container and moves the container into it.
Definition: GpuPlugin.cpp:240
bool createRuntime() override
we use the createRuntime point to create a cgroup and put the containered process into it.
Definition: GpuPlugin.cpp:63
std::string name() const override
Should return the name of the plugin.
Definition: GpuPlugin.h:52
unsigned hookHints() const override
Should return a bitfield of the hook points implemented by the plugin.
Definition: GpuPlugin.cpp:43
Basic object that provides the default overrides for a plugin.
Definition: RdkPluginBase.h:34