This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch main
in repository entrance.
View the commit online.
commit 21b74530c2a681913fec6dd8cda1560422bfe8ed
Author: Alastair Poole <[email protected]>
AuthorDate: Wed Dec 2 14:45:07 2026 +0000
daemon: request high AMDGPU performance for the Wayland greeter
---
README.md | 8 ++
src/auth/Auth.cpp | 4 +
src/auth/Auth.h | 2 +
src/common/Configuration.h | 1 +
src/daemon/AmdgpuPerformance.cpp | 191 +++++++++++++++++++++++++++++++++++++++
src/daemon/AmdgpuPerformance.h | 33 +++++++
src/daemon/Display.cpp | 1 +
src/daemon/Greeter.cpp | 13 +++
src/daemon/Greeter.h | 3 +
src/daemon/meson.build | 1 +
10 files changed, 257 insertions(+)
diff --git a/README.md b/README.md
index 935f3ce..5f5d0d5 100644
--- a/README.md
+++ b/README.md
@@ -85,6 +85,14 @@ default greeter. Set `DisplayServer=wayland` under `[General]` to select the
Wayland greeter in that build.
[Wayland setup and troubleshooting](src/compositor/README.md#wayland-greeter)
+The bundled Wayland greeter automatically requests AMDGPU's `high`
+performance level when the compositor opens a single primary DRM card and
+that card uses AMDGPU. The policy affects the whole GPU while active.
+Entrance restores the previous level before launching or resuming the
+desktop and when the greeter or its compositor exits. To disable this
+behavior, set `AmdgpuForcePerformance=false` under `[Wayland]` in
+`/etc/entrance.conf`.
+
## Greeter settings
Open **Settings** at the top left to choose a theme, adjust the UI scale
diff --git a/src/auth/Auth.cpp b/src/auth/Auth.cpp
index 1d7075a..6daf657 100644
--- a/src/auth/Auth.cpp
+++ b/src/auth/Auth.cpp
@@ -441,6 +441,10 @@ namespace Entrance {
d->childWatcher.start(d->child);
}
+ pid_t Auth::helperPid() const {
+ return d->child;
+ }
+
void Auth::stop() {
Entrance_Child_Exit result;
if (entrance_child_stop(&d->child, &result))
diff --git a/src/auth/Auth.h b/src/auth/Auth.h
index d6581a3..2f8b3aa 100644
--- a/src/auth/Auth.h
+++ b/src/auth/Auth.h
@@ -23,6 +23,7 @@
#include <cstddef>
#include <functional>
+#include <sys/types.h>
#include <QtCore/QObject>
@@ -127,6 +128,7 @@ namespace Entrance {
* Indicates that we do not need the process anymore.
*/
void stop();
+ pid_t helperPid() const;
struct Callbacks {
std::function<void()> requestChanged;
diff --git a/src/common/Configuration.h b/src/common/Configuration.h
index 2b15913..6c8b744 100644
--- a/src/common/Configuration.h
+++ b/src/common/Configuration.h
@@ -71,6 +71,7 @@ namespace Entrance {
);
Section(Wayland,
+ Entry(AmdgpuForcePerformance, bool, true, _S("Request high AMDGPU performance while the bundled Wayland greeter runs"));
Entry(CompositorCommand, QString, _S(WAYLAND_COMPOSITOR_COMMAND), _S("Path of the Wayland compositor to execute when starting the greeter"));
Entry(SessionDir, QStringList, {_S("/usr/local/share/wayland-sessions"),
_S("/usr/share/wayland-sessions")}, _S("Comma-separated list of directories containing available Wayland sessions"));
diff --git a/src/daemon/AmdgpuPerformance.cpp b/src/daemon/AmdgpuPerformance.cpp
new file mode 100644
index 0000000..f9cd5e1
--- /dev/null
+++ b/src/daemon/AmdgpuPerformance.cpp
@@ -0,0 +1,191 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include "AmdgpuPerformance.h"
+#include "entrance_constants.h"
+
+#ifdef __linux__
+#include <QDebug>
+#include <QDir>
+#include <QFile>
+#include <QFileInfo>
+
+#include <fcntl.h>
+#include <sys/file.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+#include <unistd.h>
+
+namespace {
+
+QString processPath(pid_t pid)
+{
+ return QStringLiteral("/proc/%1").arg(pid);
+}
+
+QList<pid_t> children(pid_t pid)
+{
+ QFile file(processPath(pid) + QStringLiteral("/task/%1/children").arg(pid));
+ QList<pid_t> result;
+ if (file.open(QIODevice::ReadOnly)) {
+ for (const auto &entry : file.readAll().simplified().split(' ')) {
+ const auto child = entry.toInt();
+ if (child > 0)
+ result.append(child);
+ }
+ }
+ return result;
+}
+
+bool isCompositor(pid_t pid)
+{
+ const QFileInfo executable(processPath(pid) + QStringLiteral("/exe"));
+ return executable.symLinkTarget()
+ == QStringLiteral(LIBEXEC_INSTALL_DIR "/entrance/compositor/entrance_compositor");
+}
+
+QString performanceControl(pid_t compositor)
+{
+ const QDir descriptors(processPath(compositor) + QStringLiteral("/fd"));
+ QString card;
+ for (const auto &entry : descriptors.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot)) {
+ struct stat info;
+ if (stat(QFile::encodeName(entry.filePath()).constData(), &info) != 0
+ || !S_ISCHR(info.st_mode) || major(info.st_rdev) != 226)
+ continue;
+
+ const auto node = QFileInfo(QStringLiteral("/sys/dev/char/%1:%2")
+ .arg(major(info.st_rdev)).arg(minor(info.st_rdev))).canonicalFilePath();
+ bool primary = false;
+ const auto name = QFileInfo(node).fileName();
+ if (name.startsWith(QStringLiteral("card")))
+ name.mid(4).toUInt(&primary);
+ if (!primary)
+ continue;
+ if (!card.isEmpty() && card != node)
+ return {};
+ card = node;
+ }
+
+ const auto device = card + QStringLiteral("/device");
+ if (card.isEmpty() || QFileInfo(QFileInfo(device + QStringLiteral("/driver")).symLinkTarget()).fileName()
+ != QStringLiteral("amdgpu"))
+ return {};
+ return device + QStringLiteral("/power_dpm_force_performance_level");
+}
+
+bool setPerformanceLevel(int fd, const QByteArray &value)
+{
+ const auto line = value + '\n';
+ return pwrite(fd, line.constData(), line.size(), 0) == line.size();
+}
+
+}
+#endif
+
+namespace Entrance {
+
+AmdgpuPerformance::AmdgpuPerformance()
+{
+ m_timer.setInterval(250);
+ QObject::connect(&m_timer, &QTimer::timeout, &m_timer, [this] { update(); });
+}
+
+AmdgpuPerformance::~AmdgpuPerformance()
+{
+ restore();
+}
+
+void AmdgpuPerformance::watch(pid_t helper)
+{
+#ifdef __linux__
+ if (helper > 0) {
+ m_helper = helper;
+ m_discoveryDeadline.setRemainingTime(15000);
+ m_timer.start();
+ update();
+ }
+#else
+ Q_UNUSED(helper)
+#endif
+}
+
+void AmdgpuPerformance::update()
+{
+#ifdef __linux__
+ if (m_compositor) {
+ if (!isCompositor(m_compositor))
+ restore();
+ return;
+ }
+
+ if (m_discoveryDeadline.hasExpired()) {
+ restore();
+ return;
+ }
+
+ // The authentication helper starts the Wayland launcher, which starts the compositor.
+ for (const auto launcher : children(m_helper)) {
+ for (const auto child : children(launcher)) {
+ if (!isCompositor(child))
+ continue;
+ const auto path = performanceControl(child);
+ if (path.isEmpty())
+ continue;
+
+ const int fd = open(QFile::encodeName(path).constData(), O_RDWR | O_CLOEXEC);
+ if (fd < 0) {
+ qWarning() << "Could not open AMDGPU performance control" << path;
+ m_timer.stop();
+ return;
+ }
+ // Keep two greeters on the same card from saving and restoring each other's settings.
+ if (flock(fd, LOCK_EX | LOCK_NB) != 0) {
+ close(fd);
+ return;
+ }
+
+ char buffer[64];
+ const auto size = pread(fd, buffer, sizeof(buffer), 0);
+ const auto previous = size > 0 && size < static_cast<ssize_t>(sizeof(buffer))
+ ? QByteArray(buffer, size).trimmed() : QByteArray();
+ if (previous != "auto" && previous != "low" && previous != "high"
+ && previous != "manual" && previous != "profile_standard"
+ && previous != "profile_min_sclk" && previous != "profile_min_mclk"
+ && previous != "profile_peak") {
+ qWarning() << "Could not read a restorable AMDGPU performance level" << path;
+ close(fd);
+ m_timer.stop();
+ return;
+ }
+ if (previous != "high" && !setPerformanceLevel(fd, "high")) {
+ qWarning() << "Could not request high AMDGPU performance" << path;
+ close(fd);
+ m_timer.stop();
+ return;
+ }
+
+ m_compositor = child;
+ m_fd = fd;
+ m_previous = previous;
+ return;
+ }
+ }
+#endif
+}
+
+void AmdgpuPerformance::restore()
+{
+ m_timer.stop();
+#ifdef __linux__
+ if (m_fd >= 0) {
+ if (m_previous != "high" && !setPerformanceLevel(m_fd, m_previous))
+ qWarning() << "Could not restore AMDGPU performance level to" << m_previous;
+ close(m_fd);
+ m_fd = -1;
+ }
+#endif
+ m_compositor = 0;
+ m_helper = 0;
+ m_previous.clear();
+}
+
+}
diff --git a/src/daemon/AmdgpuPerformance.h b/src/daemon/AmdgpuPerformance.h
new file mode 100644
index 0000000..a43055b
--- /dev/null
+++ b/src/daemon/AmdgpuPerformance.h
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#ifndef ENTRANCE_AMDGPU_PERFORMANCE_H
+#define ENTRANCE_AMDGPU_PERFORMANCE_H
+
+#include <QByteArray>
+#include <QDeadlineTimer>
+#include <QTimer>
+#include <sys/types.h>
+
+namespace Entrance {
+
+class AmdgpuPerformance {
+public:
+ AmdgpuPerformance();
+ ~AmdgpuPerformance();
+
+ void watch(pid_t helper);
+ void restore();
+
+private:
+ void update();
+
+ QTimer m_timer;
+ QDeadlineTimer m_discoveryDeadline;
+ pid_t m_helper { 0 };
+ pid_t m_compositor { 0 };
+ int m_fd { -1 };
+ QByteArray m_previous;
+};
+
+}
+
+#endif
diff --git a/src/daemon/Display.cpp b/src/daemon/Display.cpp
index 0b78499..f93f4a8 100644
--- a/src/daemon/Display.cpp
+++ b/src/daemon/Display.cpp
@@ -542,6 +542,7 @@ namespace Entrance {
m_bootLogin = false;
if (success) {
+ m_greeter->restoreGpuPerformance();
qDebug() << "Authentication for user " << user << " successful";
if (!m_reuseSessionId.isNull()) {
diff --git a/src/daemon/Greeter.cpp b/src/daemon/Greeter.cpp
index 418722f..d469be6 100644
--- a/src/daemon/Greeter.cpp
+++ b/src/daemon/Greeter.cpp
@@ -231,7 +231,13 @@ namespace Entrance {
return true;
}
+ void Greeter::restoreGpuPerformance() {
+ m_gpuPerformance.restore();
+ }
+
void Greeter::stop() {
+ restoreGpuPerformance();
+
// check flag
if (!m_started)
return;
@@ -271,6 +277,11 @@ namespace Entrance {
m_started = success;
// log message
+ if (success && m_display->displayServerType() == ENTRANCE_DISPLAY_WAYLAND
+ && mainConfig.Wayland.AmdgpuForcePerformance.get()) {
+ m_gpuPerformance.watch(m_auth->helperPid());
+ }
+
if (success)
qDebug() << "Greeter session started successfully";
else
@@ -287,6 +298,8 @@ namespace Entrance {
}
void Greeter::onHelperFinished(Auth::HelperExitStatus status) {
+ restoreGpuPerformance();
+
// reset flag
m_started = false;
diff --git a/src/daemon/Greeter.h b/src/daemon/Greeter.h
index 4c7ff4c..5bd4380 100644
--- a/src/daemon/Greeter.h
+++ b/src/daemon/Greeter.h
@@ -23,6 +23,7 @@
#include <QObject>
#include "Auth.h"
+#include "AmdgpuPerformance.h"
#include "entrance_theme_config.h"
#include "ChildExitWatcher.h"
@@ -44,6 +45,7 @@ namespace Entrance {
bool start();
void stop();
+ void restoreGpuPerformance();
private:
void finished();
@@ -65,6 +67,7 @@ namespace Entrance {
Auth *m_auth { nullptr };
pid_t m_process { 0 };
ChildExitWatcher m_exitWatcher;
+ AmdgpuPerformance m_gpuPerformance;
};
}
diff --git a/src/daemon/meson.build b/src/daemon/meson.build
index 569931d..bbef67a 100644
--- a/src/daemon/meson.build
+++ b/src/daemon/meson.build
@@ -7,6 +7,7 @@ daemon_sources = files([
'DaemonApp.cpp',
'SavedState.cpp',
'Greeter.cpp',
+ 'AmdgpuPerformance.cpp',
'Display.cpp',
'SocketServer.cpp',
'entrance_greeter_peer.c',
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.