[Spice-commits] common/Makefile.am common/meson.build common/udev.c common/udev.h configure.ac .gitlab-ci.yml m4/spice-deps.m4 meson.build

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Oct 17 09:44:40 UTC 2023


 .gitlab-ci.yml     |    1 
 common/Makefile.am |    3 ++
 common/meson.build |    2 +
 common/udev.c      |   78 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/udev.h      |   33 ++++++++++++++++++++++
 configure.ac       |    1 
 m4/spice-deps.m4   |   12 ++++++++
 meson.build        |    7 ++++
 8 files changed, 137 insertions(+)

New commits:
commit bb8f66983af6b7f38dc80efa6b6ca8f34c2ab85e
Author: Vivek Kasireddy <vivek.kasireddy at intel.com>
Date:   Tue Oct 17 00:23:12 2023 -0700

    common: Add a udev helper to identify GPU Vendor
    
    Given that libudev is widely available on many Linux distros, we
    can use the relevant APIs to iterate over all the devices associated
    with the drm subsystem to figure out if a specific vendor GPU
    is available or not.
    
    This capability (identifying GPU Vendor) is useful to determine
    whether to launch Gstreamer pipeline using h/w accelerated
    plugins. On systems where libudev is not available (Windows,
    MacOS, etc) we'd have to make this determination based on the
    availability of the relevant plugins in the Gstreamer registry.
    
    Cc: Frediano Ziglio <freddy77 at gmail.com>
    Cc: Gerd Hoffmann <kraxel at redhat.com>
    Cc: Marc-André Lureau <marcandre.lureau at redhat.com>
    Cc: Dongwon Kim <dongwon.kim at intel.com>
    Cc: Hazwan Arif Mazlan <hazwan.arif.mazlan at intel.com>
    Cc: Jin Chung Teng <jin.chung.teng at intel.com>
    Signed-off-by: Vivek Kasireddy <vivek.kasireddy at intel.com>
    Acked-by: Frediano Ziglio <freddy77 at gmail.com>

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index cfa6e72..4e4de75 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -48,4 +48,5 @@ make-win:
     LDFLAGS='-fsanitize=address -lasan'
     mingw64-configure --enable-extra-checks
   - make
+  - export LANG=en_US.UTF-8
   - make LOG_COMPILER=wine check || (cat tests/test-suite.log && exit 1)
diff --git a/common/Makefile.am b/common/Makefile.am
index 1318400..4f75428 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -52,6 +52,8 @@ libspice_common_la_SOURCES =		\
 	rop3.h				\
 	snd_codec.c			\
 	snd_codec.h			\
+	udev.c				\
+	udev.h				\
 	utils.c				\
 	utils.h				\
 	verify.h			\
@@ -108,6 +110,7 @@ AM_CPPFLAGS =				\
 
 libspice_common_la_LIBADD =				\
 	$(SPICE_COMMON_LIBS)				\
+	$(UDEV_LIBS)					\
 	$(NULL)
 
 MARSHALLERS_DEPS =					\
diff --git a/common/meson.build b/common/meson.build
index 09e3ea7..63bd2db 100644
--- a/common/meson.build
+++ b/common/meson.build
@@ -39,6 +39,8 @@ spice_common_sources = [
   'snd_codec.h',
   'utils.c',
   'utils.h',
+  'udev.c',
+  'udev.h',
   'verify.h',
   'recorder.h'
 ]
diff --git a/common/udev.c b/common/udev.c
new file mode 100644
index 0000000..800a4ab
--- /dev/null
+++ b/common/udev.c
@@ -0,0 +1,78 @@
+/*
+   Copyright (C) 2023 Intel Corporation.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <config.h>
+#include "udev.h"
+
+#ifdef HAVE_UDEV
+#include <libudev.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+GpuVendor spice_udev_detect_gpu(int gpu_vendor)
+{
+    struct udev *udev;
+    struct udev_device *drm_dev, *pci_dev;
+    struct udev_enumerate *udev_enum;
+    struct udev_list_entry *entry, *devices;
+    const char *path, *vendor_id;
+    GpuVendor vendor = VENDOR_GPU_NOTDETECTED;
+
+    udev = udev_new();
+    if (!udev) {
+        return VENDOR_GPU_UNKNOWN;
+    }
+
+    udev_enum = udev_enumerate_new(udev);
+    if (udev_enum) {
+        udev_enumerate_add_match_subsystem(udev_enum, "drm");
+        udev_enumerate_add_match_sysname(udev_enum, "card[0-9]");
+        udev_enumerate_scan_devices(udev_enum);
+        devices = udev_enumerate_get_list_entry(udev_enum);
+
+        udev_list_entry_foreach(entry, devices) {
+            path = udev_list_entry_get_name(entry);
+            drm_dev = udev_device_new_from_syspath(udev, path);
+            if (!drm_dev) {
+                continue;
+            }
+
+            pci_dev = udev_device_get_parent_with_subsystem_devtype(drm_dev,
+                                                                    "pci", NULL);
+            if (pci_dev) {
+                vendor_id = udev_device_get_sysattr_value(pci_dev, "vendor");
+                if (vendor_id && strtol(vendor_id, NULL, 16) == gpu_vendor) {
+                    vendor = VENDOR_GPU_DETECTED;
+                    udev_device_unref(drm_dev);
+                    break;
+                }
+            }
+            udev_device_unref(drm_dev);
+        }
+        udev_enumerate_unref(udev_enum);
+    }
+    udev_unref(udev);
+
+    return vendor;
+}
+#else
+GpuVendor spice_udev_detect_gpu(int gpu_vendor)
+{
+    return VENDOR_GPU_UNKNOWN;
+}
+#endif
+
diff --git a/common/udev.h b/common/udev.h
new file mode 100644
index 0000000..389bb3f
--- /dev/null
+++ b/common/udev.h
@@ -0,0 +1,33 @@
+/*
+   Copyright (C) 2023 Intel Corporation.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#pragma once
+#include <spice/macros.h>
+
+#define INTEL_VENDOR_ID 0x8086
+
+typedef enum {
+    VENDOR_GPU_UNKNOWN,
+    VENDOR_GPU_DETECTED,
+    VENDOR_GPU_NOTDETECTED,
+} GpuVendor;
+
+SPICE_BEGIN_DECLS
+
+GpuVendor spice_udev_detect_gpu(int gpu_vendor);
+
+SPICE_END_DECLS
diff --git a/configure.ac b/configure.ac
index 0d4c22b..42e873d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -61,6 +61,7 @@ SPICE_CHECK_GLIB2
 SPICE_CHECK_OPUS
 SPICE_CHECK_OPENSSL
 SPICE_CHECK_GDK_PIXBUF
+SPICE_CHECK_UDEV
 
 SPICE_COMMON_CFLAGS='$(PIXMAN_CFLAGS) $(SMARTCARD_CFLAGS) $(GLIB2_CFLAGS) $(OPUS_CFLAGS) $(OPENSSL_CFLAGS)'
 SPICE_COMMON_CFLAGS="$SPICE_COMMON_CFLAGS -DG_LOG_DOMAIN=\\\"Spice\\\""
diff --git a/m4/spice-deps.m4 b/m4/spice-deps.m4
index e11fc4e..6a07ee6 100644
--- a/m4/spice-deps.m4
+++ b/m4/spice-deps.m4
@@ -302,6 +302,18 @@ AC_DEFUN([SPICE_CHECK_OPENSSL], [
     PKG_CHECK_MODULES(OPENSSL, openssl)
 ])
 
+# SPICE_CHECK_UDEV
+# -----------------
+# Check for the availability of libudev. If found, it will help to determine
+# if a given vendor GPU is available or not.
+#------------------
+AC_DEFUN([SPICE_CHECK_UDEV], [
+    PKG_CHECK_MODULES([UDEV], [libudev], [have_udev=yes],[have_udev=no])
+    if test "x$have_udev" = "xyes"; then
+      AC_DEFINE([HAVE_UDEV], 1, [whether libudev is available to identify GPU])
+    fi
+])
+
 # SPICE_CHECK_INSTRUMENTATION
 # -----------------
 # Check for the availability of an instrumentation library.
diff --git a/meson.build b/meson.build
index eeccecd..1018769 100644
--- a/meson.build
+++ b/meson.build
@@ -147,6 +147,13 @@ if smartcard_dep.found()
   spice_common_config_data.set('USE_SMARTCARD', '1')
 endif
 
+# udev check
+udev_dep = dependency('libudev', required : false)
+if udev_dep.found()
+  spice_common_deps += udev_dep
+  spice_common_config_data.set('HAVE_UDEV', '1')
+endif
+
 #
 # global C defines
 #


More information about the Spice-commits mailing list