drm/xe: Allocate dedicated workqueue for SR-IOV workers
authorMichal Wajdeczko <michal.wajdeczko@intel.com>
Thu, 4 Jan 2024 22:20:22 +0000 (23:20 +0100)
committerMichal Wajdeczko <michal.wajdeczko@intel.com>
Fri, 5 Jan 2024 15:25:52 +0000 (16:25 +0100)
We plan to use several workers where we might be running long
operations. Allocate dedicated workqueue to avoid undesired
interaction with non-virtualized workers.

Reviewed-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
Link: https://lore.kernel.org/r/20240104222031.277-2-michal.wajdeczko@intel.com
Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
drivers/gpu/drm/xe/xe_device.c
drivers/gpu/drm/xe/xe_device_types.h
drivers/gpu/drm/xe/xe_sriov.c
drivers/gpu/drm/xe/xe_sriov.h

index 86867d42d53298197d051bd747b1a86909678075..004e65544e8d823d319570dc1cbd03974cbf68c7 100644 (file)
@@ -438,6 +438,10 @@ int xe_device_probe(struct xe_device *xe)
 
        xe_pat_init_early(xe);
 
+       err = xe_sriov_init(xe);
+       if (err)
+               return err;
+
        xe->info.mem_region_mask = 1;
        err = xe_display_init_nommio(xe);
        if (err)
index 71f23ac365e669270dae74914905e85443fba4cb..163d889d407bc8a2e3958a68911eb4225b4939bf 100644 (file)
@@ -321,6 +321,8 @@ struct xe_device {
        struct {
                /** @sriov.__mode: SR-IOV mode (Don't access directly!) */
                enum xe_sriov_mode __mode;
+               /** @sriov.wq: workqueue used by the virtualization workers */
+               struct workqueue_struct *wq;
        } sriov;
 
        /** @clients: drm clients info */
index 42a0e0c917a091a72f86e1b4a95faf8a4c9ec425..f295d91886b129f3222352bd7ec81bd30e037b94 100644 (file)
@@ -3,6 +3,8 @@
  * Copyright © 2023 Intel Corporation
  */
 
+#include <drm/drm_managed.h>
+
 #include "xe_assert.h"
 #include "xe_sriov.h"
 
@@ -53,3 +55,33 @@ void xe_sriov_probe_early(struct xe_device *xe, bool has_sriov)
                drm_info(&xe->drm, "Running in %s mode\n",
                         xe_sriov_mode_to_string(xe_device_sriov_mode(xe)));
 }
+
+static void fini_sriov(struct drm_device *drm, void *arg)
+{
+       struct xe_device *xe = arg;
+
+       destroy_workqueue(xe->sriov.wq);
+       xe->sriov.wq = NULL;
+}
+
+/**
+ * xe_sriov_init - Initialize SR-IOV specific data.
+ * @xe: the &xe_device to initialize
+ *
+ * In this function we create dedicated workqueue that will be used
+ * by the SR-IOV specific workers.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int xe_sriov_init(struct xe_device *xe)
+{
+       if (!IS_SRIOV(xe))
+               return 0;
+
+       xe_assert(xe, !xe->sriov.wq);
+       xe->sriov.wq = alloc_workqueue("xe-sriov-wq", 0, 0);
+       if (!xe->sriov.wq)
+               return -ENOMEM;
+
+       return drmm_add_action_or_reset(&xe->drm, fini_sriov, xe);
+}
index 5af73a3172b03c3d7583cf8edb788d128c933147..1545552162c9e8b619936c2b734cb51cca410fff 100644 (file)
@@ -13,6 +13,7 @@
 const char *xe_sriov_mode_to_string(enum xe_sriov_mode mode);
 
 void xe_sriov_probe_early(struct xe_device *xe, bool has_sriov);
+int xe_sriov_init(struct xe_device *xe);
 
 static inline enum xe_sriov_mode xe_device_sriov_mode(struct xe_device *xe)
 {