renderer/native: Add udev rule to select primary GPU

Sometimes the automatically selected primary GPU isn't suitable with no
way to make an well educated guess to do it better. To make it possible
for the user to override the automatically calculated default, make it
possible to override it using a udev rule.

E.g. to select /dev/dri/card1 as the primary GPU, add a file e.g.
/usr/lib/udev/rules.d/61-mutter-primary-gpu.rules (path my vary
depending on distribution) containing the fellowing line:

ENV{DEVNAME}=="/dev/dri/card1", TAG+="mutter-device-preferred-primary"

Reboot or manual triggering of udev rules to make it take effect may be
required.

Related: https://gitlab.gnome.org/GNOME/mutter/merge_requests/1057

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1562

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1562>
This commit is contained in:
Jonas Ådahl 2020-11-14 10:41:23 +01:00 committed by Marge Bot
parent 83360a4aed
commit d622960429
5 changed files with 49 additions and 3 deletions

View File

@ -373,6 +373,9 @@ create_gpu_from_udev_device (MetaBackendNative *native,
if (meta_is_udev_device_requires_modifiers (device))
flags |= META_KMS_DEVICE_FLAG_REQUIRES_MODIFIERS;
if (meta_is_udev_device_preferred_primary (device))
flags |= META_KMS_DEVICE_FLAG_PREFERRED_PRIMARY;
device_path = g_udev_device_get_device_file (device);
kms_device = meta_kms_create_device (native->kms, device_path, flags,

View File

@ -57,6 +57,7 @@ typedef enum _MetaKmsDeviceFlag
META_KMS_DEVICE_FLAG_BOOT_VGA = 1 << 0,
META_KMS_DEVICE_FLAG_PLATFORM_DEVICE = 1 << 1,
META_KMS_DEVICE_FLAG_REQUIRES_MODIFIERS = 1 << 2,
META_KMS_DEVICE_FLAG_PREFERRED_PRIMARY = 1 << 3,
} MetaKmsDeviceFlag;
typedef enum _MetaKmsPlaneType MetaKmsPlaneType;

View File

@ -64,6 +64,7 @@
#include "backends/native/meta-drm-buffer-import.h"
#include "backends/native/meta-drm-buffer.h"
#include "backends/native/meta-gpu-kms.h"
#include "backends/native/meta-kms-device.h"
#include "backends/native/meta-kms-update.h"
#include "backends/native/meta-kms-utils.h"
#include "backends/native/meta-kms.h"
@ -3752,6 +3753,21 @@ choose_primary_gpu_unchecked (MetaBackend *backend,
*/
for (allow_sw = 0; allow_sw < 2; allow_sw++)
{
/* First check if one was explicitly configured. */
for (l = gpus; l; l = l->next)
{
MetaGpuKms *gpu_kms = META_GPU_KMS (l->data);
MetaKmsDevice *kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
if (meta_kms_device_get_flags (kms_device) &
META_KMS_DEVICE_FLAG_PREFERRED_PRIMARY)
{
g_message ("GPU %s selected primary given udev rule",
meta_gpu_kms_get_file_path (gpu_kms));
return gpu_kms;
}
}
/* Prefer a platform device */
for (l = gpus; l; l = l->next)
{
@ -3760,7 +3776,11 @@ choose_primary_gpu_unchecked (MetaBackend *backend,
if (meta_gpu_kms_is_platform_device (gpu_kms) &&
(allow_sw == 1 ||
gpu_kms_is_hardware_rendering (renderer_native, gpu_kms)))
return gpu_kms;
{
g_message ("Integrated GPU %s selected as primary",
meta_gpu_kms_get_file_path (gpu_kms));
return gpu_kms;
}
}
/* Otherwise a device we booted with */
@ -3771,7 +3791,11 @@ choose_primary_gpu_unchecked (MetaBackend *backend,
if (meta_gpu_kms_is_boot_vga (gpu_kms) &&
(allow_sw == 1 ||
gpu_kms_is_hardware_rendering (renderer_native, gpu_kms)))
return gpu_kms;
{
g_message ("Boot VGA GPU %s selected as primary",
meta_gpu_kms_get_file_path (gpu_kms));
return gpu_kms;
}
}
/* Fall back to any device */
@ -3781,7 +3805,11 @@ choose_primary_gpu_unchecked (MetaBackend *backend,
if (allow_sw == 1 ||
gpu_kms_is_hardware_rendering (renderer_native, gpu_kms))
return gpu_kms;
{
g_message ("GPU %s selected as primary",
meta_gpu_kms_get_file_path (gpu_kms));
return gpu_kms;
}
}
}

View File

@ -95,6 +95,18 @@ meta_is_udev_device_requires_modifiers (GUdevDevice *device)
return g_strv_contains (tags, "mutter-device-requires-kms-modifiers");
}
gboolean
meta_is_udev_device_preferred_primary (GUdevDevice *device)
{
const char * const * tags;
tags = g_udev_device_get_tags (device);
if (!tags)
return FALSE;
return g_strv_contains (tags, "mutter-device-preferred-primary");
}
gboolean
meta_udev_is_drm_device (MetaUdev *udev,
GUdevDevice *device)

View File

@ -34,6 +34,8 @@ gboolean meta_is_udev_device_boot_vga (GUdevDevice *device);
gboolean meta_is_udev_device_requires_modifiers (GUdevDevice *device);
gboolean meta_is_udev_device_preferred_primary (GUdevDevice *device);
gboolean meta_udev_is_drm_device (MetaUdev *udev,
GUdevDevice *device);