You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/07/01 21:13:05 UTC

[1/2] mesos git commit: Added 'nvidia-uvm-tools' as optional control device for Nvidia GPUs.

Repository: mesos
Updated Branches:
  refs/heads/master 2a49ae261 -> cf859492e


Added 'nvidia-uvm-tools' as optional control device for Nvidia GPUs.

As part of this, we also generalized the method for enumerating the
GPU control devices which should be accessible inside a container.
Now it should be easier to add new control devices as they appear in
the future.

Review: https://reviews.apache.org/r/49530/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/cf859492
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/cf859492
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/cf859492

Branch: refs/heads/master
Commit: cf859492e7af64f66b5025c218af4c140d7afe06
Parents: 16252d7
Author: Kevin Klues <kl...@gmail.com>
Authored: Fri Jul 1 13:48:04 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Fri Jul 1 14:12:12 2016 -0700

----------------------------------------------------------------------
 .../mesos/isolators/gpu/isolator.cpp            | 74 ++++++++++++--------
 .../mesos/isolators/gpu/isolator.hpp            |  7 +-
 2 files changed, 46 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/cf859492/src/slave/containerizer/mesos/isolators/gpu/isolator.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/gpu/isolator.cpp b/src/slave/containerizer/mesos/isolators/gpu/isolator.cpp
index 2bf7fe2..d407cab 100644
--- a/src/slave/containerizer/mesos/isolators/gpu/isolator.cpp
+++ b/src/slave/containerizer/mesos/isolators/gpu/isolator.cpp
@@ -73,13 +73,11 @@ NvidiaGpuIsolatorProcess::NvidiaGpuIsolatorProcess(
     const Flags& _flags,
     const string& _hierarchy,
     const NvidiaGpuAllocator& _allocator,
-    const cgroups::devices::Entry& uvmDeviceEntry,
-    const cgroups::devices::Entry& ctlDeviceEntry)
+    const map<Path, cgroups::devices::Entry>& _controlDeviceEntries)
   : flags(_flags),
     hierarchy(_hierarchy),
     allocator(_allocator),
-    NVIDIA_CTL_DEVICE_ENTRY(ctlDeviceEntry),
-    NVIDIA_UVM_DEVICE_ENTRY(uvmDeviceEntry) {}
+    controlDeviceEntries(_controlDeviceEntries) {}
 
 
 Try<Isolator*> NvidiaGpuIsolatorProcess::create(
@@ -116,21 +114,26 @@ Try<Isolator*> NvidiaGpuIsolatorProcess::create(
         hierarchy.error());
   }
 
-  // Create the device entries for
-  // `/dev/nvidiactl` and `/dev/nvidia-uvm`.
+  // Create device entries for `/dev/nvidiactl` and
+  // `/dev/nvidia-uvm`. Optionally create a device entry for
+  // `/dev/nvidia-uvm-tools` if it exists.
+  map<Path, cgroups::devices::Entry> deviceEntries;
+
   Try<dev_t> device = os::stat::rdev("/dev/nvidiactl");
   if (device.isError()) {
     return Error("Failed to obtain device ID for '/dev/nvidiactl': " +
                  device.error());
   }
 
-  cgroups::devices::Entry ctlDeviceEntry;
-  ctlDeviceEntry.selector.type = Entry::Selector::Type::CHARACTER;
-  ctlDeviceEntry.selector.major = major(device.get());
-  ctlDeviceEntry.selector.minor = minor(device.get());
-  ctlDeviceEntry.access.read = true;
-  ctlDeviceEntry.access.write = true;
-  ctlDeviceEntry.access.mknod = true;
+  cgroups::devices::Entry entry;
+  entry.selector.type = Entry::Selector::Type::CHARACTER;
+  entry.selector.major = major(device.get());
+  entry.selector.minor = minor(device.get());
+  entry.access.read = true;
+  entry.access.write = true;
+  entry.access.mknod = true;
+
+  deviceEntries[Path("/dev/nvidiactl")] = entry;
 
   device = os::stat::rdev("/dev/nvidia-uvm");
   if (device.isError()) {
@@ -138,21 +141,33 @@ Try<Isolator*> NvidiaGpuIsolatorProcess::create(
                  device.error());
   }
 
-  cgroups::devices::Entry uvmDeviceEntry;
-  uvmDeviceEntry.selector.type = Entry::Selector::Type::CHARACTER;
-  uvmDeviceEntry.selector.major = major(device.get());
-  uvmDeviceEntry.selector.minor = minor(device.get());
-  uvmDeviceEntry.access.read = true;
-  uvmDeviceEntry.access.write = true;
-  uvmDeviceEntry.access.mknod = true;
+  entry.selector.type = Entry::Selector::Type::CHARACTER;
+  entry.selector.major = major(device.get());
+  entry.selector.minor = minor(device.get());
+  entry.access.read = true;
+  entry.access.write = true;
+  entry.access.mknod = true;
+
+  deviceEntries[Path("/dev/nvidia-uvm")] = entry;
+
+  device = os::stat::rdev("/dev/nvidia-uvm-tools");
+  if (device.isSome()) {
+    entry.selector.type = Entry::Selector::Type::CHARACTER;
+    entry.selector.major = major(device.get());
+    entry.selector.minor = minor(device.get());
+    entry.access.read = true;
+    entry.access.write = true;
+    entry.access.mknod = true;
+
+    deviceEntries[Path("/dev/nvidia-uvm-tools")] = entry;
+  }
 
   process::Owned<MesosIsolatorProcess> process(
       new NvidiaGpuIsolatorProcess(
           flags,
           hierarchy.get(),
           components.allocator,
-          ctlDeviceEntry,
-          uvmDeviceEntry));
+          deviceEntries));
 
   return new MesosIsolator(process);
 }
@@ -233,23 +248,20 @@ Future<Option<ContainerLaunchInfo>> NvidiaGpuIsolatorProcess::prepare(
   infos[containerId] = new Info(
       containerId, path::join(flags.cgroups_root, containerId.value()));
 
-  // Grant access to /dev/nvidiactl and /dev/nvida-uvm.
+  // Grant access to all `controlDeviceEntries`.
   //
   // This allows standard NVIDIA tools like `nvidia-smi` to be
   // used within the container even if no GPUs are allocated.
   // Without these devices, these tools fail abnormally.
-  map<string, const cgroups::devices::Entry> entries = {
-    { "/dev/nvidiactl", NVIDIA_CTL_DEVICE_ENTRY },
-    { "/dev/nvidia-uvm", NVIDIA_UVM_DEVICE_ENTRY },
-  };
-
-  foreachkey (const string& device, entries) {
+  foreachkey (const Path& devicePath, controlDeviceEntries) {
     Try<Nothing> allow = cgroups::devices::allow(
-        hierarchy, infos[containerId]->cgroup, entries[device]);
+        hierarchy,
+        infos[containerId]->cgroup,
+        controlDeviceEntries.at(devicePath));
 
     if (allow.isError()) {
       return Failure("Failed to grant cgroups access to"
-                     " '" + device + "': " + allow.error());
+                     " '" + stringify(devicePath) + "': " + allow.error());
     }
   }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/cf859492/src/slave/containerizer/mesos/isolators/gpu/isolator.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/gpu/isolator.hpp b/src/slave/containerizer/mesos/isolators/gpu/isolator.hpp
index a673410..ceb3795 100644
--- a/src/slave/containerizer/mesos/isolators/gpu/isolator.hpp
+++ b/src/slave/containerizer/mesos/isolators/gpu/isolator.hpp
@@ -24,6 +24,7 @@
 
 #include <stout/hashmap.hpp>
 #include <stout/option.hpp>
+#include <stout/path.hpp>
 #include <stout/try.hpp>
 
 #include "linux/cgroups.hpp"
@@ -104,8 +105,7 @@ private:
       const Flags& _flags,
       const std::string& hierarchy,
       const NvidiaGpuAllocator& _allocator,
-      const cgroups::devices::Entry& ctlDeviceEntry,
-      const cgroups::devices::Entry& uvmDeviceEntry);
+      const map<Path, cgroups::devices::Entry>& _controlDeviceEntries);
 
   process::Future<Nothing> _update(
       const ContainerID& containerId,
@@ -131,8 +131,7 @@ private:
 
   NvidiaGpuAllocator allocator;
 
-  const cgroups::devices::Entry NVIDIA_CTL_DEVICE_ENTRY;
-  const cgroups::devices::Entry NVIDIA_UVM_DEVICE_ENTRY;
+  const map<Path, cgroups::devices::Entry> controlDeviceEntries;
 };
 
 } // namespace slave {


[2/2] mesos git commit: Added comparison operator for Path in stout.

Posted by bm...@apache.org.
Added comparison operator for Path in stout.


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/16252d74
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/16252d74
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/16252d74

Branch: refs/heads/master
Commit: 16252d7449019b92e6ba9cd2d02a8436ccb3b430
Parents: 2a49ae2
Author: Benjamin Mahler <bm...@apache.org>
Authored: Fri Jul 1 14:10:35 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Fri Jul 1 14:12:12 2016 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/path.hpp | 36 ++++++++++++++++++++++++++++++
 3rdparty/stout/tests/path_tests.cpp   | 24 ++++++++++++++++++++
 2 files changed, 60 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/16252d74/3rdparty/stout/include/stout/path.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/path.hpp b/3rdparty/stout/include/stout/path.hpp
index 1b8326f..0ca13c6 100644
--- a/3rdparty/stout/include/stout/path.hpp
+++ b/3rdparty/stout/include/stout/path.hpp
@@ -254,6 +254,42 @@ public:
 };
 
 
+inline bool operator==(const Path& left, const Path& right)
+{
+  return left.value == right.value;
+}
+
+
+inline bool operator!=(const Path& left, const Path& right)
+{
+  return !(left == right);
+}
+
+
+inline bool operator<(const Path& left, const Path& right)
+{
+  return left.value < right.value;
+}
+
+
+inline bool operator>(const Path& left, const Path& right)
+{
+  return right < left;
+}
+
+
+inline bool operator<=(const Path& left, const Path& right)
+{
+  return !(left > right);
+}
+
+
+inline bool operator>=(const Path& left, const Path& right)
+{
+  return !(left < right);
+}
+
+
 inline std::ostream& operator<<(
     std::ostream& stream,
     const Path& path)

http://git-wip-us.apache.org/repos/asf/mesos/blob/16252d74/3rdparty/stout/tests/path_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/path_tests.cpp b/3rdparty/stout/tests/path_tests.cpp
index 6dff5e7..8275e38 100644
--- a/3rdparty/stout/tests/path_tests.cpp
+++ b/3rdparty/stout/tests/path_tests.cpp
@@ -167,6 +167,30 @@ TEST(PathTest, Absolute)
 }
 
 
+TEST(PathTest, Comparison)
+{
+  EXPECT_TRUE(Path("a") == Path("a"));
+  EXPECT_FALSE(Path("a") == Path("b"));
+
+  EXPECT_TRUE(Path("a") != Path("b"));
+  EXPECT_FALSE(Path("a") != Path("a"));
+
+  EXPECT_TRUE(Path("a") < Path("b"));
+  EXPECT_FALSE(Path("b") < Path("a"));
+
+  EXPECT_TRUE(Path("a") <= Path("b"));
+  EXPECT_TRUE(Path("a") <= Path("a"));
+  EXPECT_FALSE(Path("b") <= Path("a"));
+
+  EXPECT_TRUE(Path("b") > Path("a"));
+  EXPECT_FALSE(Path("a") > Path("a"));
+
+  EXPECT_TRUE(Path("b") >= Path("a"));
+  EXPECT_TRUE(Path("b") >= Path("b"));
+  EXPECT_FALSE(Path("a") >= Path("b"));
+}
+
+
 class PathFileTest : public TemporaryDirectoryTest {};