[lxc-devel] [lxd/master] Report GPU mdev

stgraber on Github lxc-bot at linuxcontainers.org
Thu Jul 9 22:31:39 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200709/b2c9d0c0/attachment-0001.bin>
-------------- next part --------------
From 28c604ddc62ea7fe2ec42f4cf1590fe27e9cb26d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 9 Jul 2020 18:15:47 -0400
Subject: [PATCH 1/4] doc/api-extensions: Fix escaping
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 doc/api-extensions.md | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/doc/api-extensions.md b/doc/api-extensions.md
index f009352b91..c07c3df1f6 100644
--- a/doc/api-extensions.md
+++ b/doc/api-extensions.md
@@ -1096,13 +1096,13 @@ It introduces the new `--type` flag when creating custom storage volumes, and ac
 
 ## clustering\_failure\_domains
 
-This extension adds a new `failure_domain` field to the `PUT /1.0/cluster/<node>` API,
+This extension adds a new `failure\_domain` field to the `PUT /1.0/cluster/<node>` API,
 which can be used to set the failure domain of a node.
 
 ## container\_syscall\_filtering\_allow\_deny\_syntax
 A number of new syscalls related container configuration keys were updated.
 
- * `security.syscalls.deny_default`
- * `security.syscalls.deny_compat`
+ * `security.syscalls.deny\_default`
+ * `security.syscalls.deny\_compat`
  * `security.syscalls.deny`
  * `security.syscalls.allow`

From eecb24c0505e3a35cfd52c2d8bb766d416a307a0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 9 Jul 2020 18:17:05 -0400
Subject: [PATCH 2/4] share/api: Add GPU mdev
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 shared/api/resource.go | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/shared/api/resource.go b/shared/api/resource.go
index 4ccefc43eb..cee376ceb9 100644
--- a/shared/api/resource.go
+++ b/shared/api/resource.go
@@ -96,6 +96,9 @@ type ResourcesGPUCard struct {
 	SRIOV  *ResourcesGPUCardSRIOV  `json:"sriov,omitempty" yaml:"sriov,omitempty"`
 	Nvidia *ResourcesGPUCardNvidia `json:"nvidia,omitempty" yaml:"nvidia,omitempty"`
 
+	// API extension: resources_gpu_mdev
+	Mdev map[string]ResourcesGPUCardMdev `json:"mdev,omitempty" yaml:"mdev,omitempty"`
+
 	NUMANode   uint64 `json:"numa_node" yaml:"numa_node"`
 	PCIAddress string `json:"pci_address,omitempty" yaml:"pci_address,omitempty"`
 
@@ -145,6 +148,15 @@ type ResourcesGPUCardNvidia struct {
 	CardDevice string `json:"card_device" yaml:"card_device"`
 }
 
+// ResourcesGPUCardMdev represents the mediated devices configuration of the GPU
+// API extension: resources_gpu_mdev
+type ResourcesGPUCardMdev struct {
+	API         string   `json:"api" yaml:"api"`
+	Available   uint64   `json:"available" yaml:"available"`
+	Description string   `json:"description" yaml:"description"`
+	Devices     []string `json:"devices" yaml:"devices"`
+}
+
 // ResourcesNetwork represents the network cards available on the system
 // API extension: resources_v2
 type ResourcesNetwork struct {

From 9e51647af8d075eabec6260ff562ef76119eb97c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 9 Jul 2020 18:17:15 -0400
Subject: [PATCH 3/4] lxd/resources: Add GPU mdev
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/resources/gpu.go | 68 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/lxd/resources/gpu.go b/lxd/resources/gpu.go
index a2d972d5e1..5e94c8943f 100644
--- a/lxd/resources/gpu.go
+++ b/lxd/resources/gpu.go
@@ -309,6 +309,74 @@ func gpuAddDeviceInfo(devicePath string, nvidiaCards map[string]*api.ResourcesGP
 		card.DRM = &drm
 	}
 
+	// DRM information
+	mdevPath := filepath.Join(devicePath, "mdev_supported_types")
+	if sysfsExists(mdevPath) {
+		card.Mdev = map[string]api.ResourcesGPUCardMdev{}
+
+		// List all the devices
+		entries, err := ioutil.ReadDir(mdevPath)
+		if err != nil {
+			return errors.Wrapf(err, "Failed to list \"%s\"", mdevPath)
+		}
+
+		// Fill in the struct
+		for _, entry := range entries {
+			mdev := api.ResourcesGPUCardMdev{}
+			entryName := entry.Name()
+			entryPath := filepath.Join(mdevPath, entryName)
+
+			// API
+			apiPath := filepath.Join(entryPath, "device_api")
+			if sysfsExists(apiPath) {
+				api, err := ioutil.ReadFile(apiPath)
+				if err != nil {
+					return errors.Wrapf(err, "Failed to read \"%s\"", apiPath)
+				}
+
+				mdev.API = strings.TrimSpace(string(api))
+			}
+
+			// Available
+			availablePath := filepath.Join(entryPath, "available_instances")
+			if sysfsExists(availablePath) {
+				available, err := readUint(availablePath)
+				if err != nil {
+					return errors.Wrapf(err, "Failed to read \"%s\"", availablePath)
+				}
+
+				mdev.Available = available
+			}
+
+			// Description
+			descriptionPath := filepath.Join(entryPath, "description")
+			if sysfsExists(descriptionPath) {
+				description, err := ioutil.ReadFile(descriptionPath)
+				if err != nil {
+					return errors.Wrapf(err, "Failed to read \"%s\"", descriptionPath)
+				}
+
+				mdev.Description = strings.TrimSpace(string(description))
+			}
+
+			// Devices
+			mdevDevicesPath := filepath.Join(entryPath, "devices")
+			if sysfsExists(mdevDevicesPath) {
+				devs, err := ioutil.ReadDir(mdevDevicesPath)
+				if err != nil {
+					return errors.Wrapf(err, "Failed to list \"%s\"", mdevDevicesPath)
+				}
+
+				mdev.Devices = []string{}
+				for _, dev := range devs {
+					mdev.Devices = append(mdev.Devices, dev.Name())
+				}
+			}
+
+			card.Mdev[entryName] = mdev
+		}
+	}
+
 	return nil
 }
 

From 1361ad37ceb29e0a50ba66d8ffcea2531c60228e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 9 Jul 2020 18:17:26 -0400
Subject: [PATCH 4/4] api: Add GPU mdev
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 doc/api-extensions.md | 3 +++
 shared/version/api.go | 1 +
 2 files changed, 4 insertions(+)

diff --git a/doc/api-extensions.md b/doc/api-extensions.md
index c07c3df1f6..97945491d1 100644
--- a/doc/api-extensions.md
+++ b/doc/api-extensions.md
@@ -1106,3 +1106,6 @@ A number of new syscalls related container configuration keys were updated.
  * `security.syscalls.deny\_compat`
  * `security.syscalls.deny`
  * `security.syscalls.allow`
+
+## resources\_gpu\_mdev
+Expose available mediated device profiles and devices in /1.0/resources.
diff --git a/shared/version/api.go b/shared/version/api.go
index 52744904a4..a4b1431b59 100644
--- a/shared/version/api.go
+++ b/shared/version/api.go
@@ -217,6 +217,7 @@ var APIExtensions = []string{
 	"usedby_consistency",
 	"custom_block_volumes",
 	"clustering_failure_domains",
+	"resources_gpu_mdev",
 }
 
 // APIExtensionsCount returns the number of available API extensions.


More information about the lxc-devel mailing list