mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-02 11:05:39 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94c2d811c7 |
No files matched your search
@@ -108,7 +108,11 @@ public class HudMetrics {
|
||||
}
|
||||
|
||||
private List<String> discoverGpuUsagePaths() {
|
||||
if (gpuUsagePathsCache != null) return gpuUsagePathsCache;
|
||||
if (gpuUsagePathsCache == null) gpuUsagePathsCache = gpuUsagePaths();
|
||||
return gpuUsagePathsCache;
|
||||
}
|
||||
|
||||
public static List<String> gpuUsagePaths() {
|
||||
LinkedHashSet<String> candidates = new LinkedHashSet<>();
|
||||
|
||||
for (String p : GPU_USAGE_STATIC_PATHS) {
|
||||
@@ -157,8 +161,7 @@ public class HudMetrics {
|
||||
}
|
||||
}
|
||||
|
||||
gpuUsagePathsCache = new ArrayList<>(candidates);
|
||||
return gpuUsagePathsCache;
|
||||
return new ArrayList<>(candidates);
|
||||
}
|
||||
|
||||
private static final String[] GPU_USAGE_STATIC_PATHS = {
|
||||
|
||||
@@ -3,11 +3,18 @@ package com.droiddeck.launcher.session
|
||||
import android.os.SystemClock
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.core.SessionPart
|
||||
import com.droiddeck.launcher.hud.HudMetrics
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import java.io.File
|
||||
import java.io.RandomAccessFile
|
||||
|
||||
class GpuStatsComponent(val dir: File, private val root: File) : SessionPart() {
|
||||
class GpuStatsComponent(
|
||||
val dir: File,
|
||||
private val root: File,
|
||||
private val metrics: HudMetrics? = null,
|
||||
private val kgsl: Boolean = File(KGSL).exists(),
|
||||
private val loadNodes: () -> List<String> = HudMetrics::gpuUsagePaths,
|
||||
) : SessionPart() {
|
||||
@Volatile private var running = false
|
||||
private var thread: Thread? = null
|
||||
private val feeds = ArrayList<Feed>()
|
||||
@@ -23,6 +30,7 @@ class GpuStatsComponent(val dir: File, private val root: File) : SessionPart() {
|
||||
)
|
||||
|
||||
fun binds(): List<String> {
|
||||
if (!kgsl) return emptyList()
|
||||
val list = mutableListOf(dir.path + ":" + KGSL)
|
||||
if (File(dir, "perf_now").exists()) list.add(File(dir, "perf_now").path + ":" + MSM_LOAD)
|
||||
if (File(dir, "cur_freq").exists()) list.add(File(dir, "cur_freq").path + ":" + MSM_CLOCK)
|
||||
@@ -33,10 +41,9 @@ class GpuStatsComponent(val dir: File, private val root: File) : SessionPart() {
|
||||
sources = ""
|
||||
KgslBusy.status = "not tried"
|
||||
KgslClock.status = "not tried"
|
||||
if (!File(KGSL).exists()) return false
|
||||
val unreadable = MANGOHUD_FILES.any { File(KGSL, it).let { f -> f.exists() && !f.canRead() } }
|
||||
// Where SELinux hides the kgsl nodes completely (exists() is false too), the layer and cycle-counter feeds stand in.
|
||||
if (!unreadable && !File(GPUBUSY).canRead() && !loadBlocked()) return false
|
||||
if (kgsl && !unreadable && !File(GPUBUSY).canRead() && !loadBlocked()) return false
|
||||
return try {
|
||||
dir.mkdirs()
|
||||
dir.listFiles()?.forEach { java.nio.file.Files.deleteIfExists(it.toPath()) }
|
||||
@@ -44,19 +51,20 @@ class GpuStatsComponent(val dir: File, private val root: File) : SessionPart() {
|
||||
PASSTHROUGH_FILES.forEach { name ->
|
||||
runCatching { File(dir, name).writeText(File(KGSL, name).readText()) }
|
||||
}
|
||||
(loadFeed() ?: blockedLoadFeed())?.let { load ->
|
||||
((if (kgsl) loadFeed() else nodeLoadFeed()) ?: blockedLoadFeed())?.let { load ->
|
||||
feeds.add(load)
|
||||
feeds.add(Feed(File(dir, "perf_now"), load.source, load.read, "%-6s\n", percent = true))
|
||||
}
|
||||
(pick("clock_mhz", clockSources(), "%5d\n") { mhz(it) } ?: cycleClockFeed())?.let { clock ->
|
||||
(pick("clock_mhz", clockSources(), "%5d\n") { mhz(it) } ?: (if (kgsl) cycleClockFeed() else null))?.let { clock ->
|
||||
feeds.add(clock)
|
||||
feeds.add(Feed(File(dir, "cur_freq"), clock.source, { clock.read()?.times(1_000_000) }, "%-10d\n"))
|
||||
}
|
||||
pick("temp", tempSources(), "%6d\n") { milliCelsius(it) }?.let { feeds.add(it) }
|
||||
if (kgsl) pick("temp", tempSources(), "%6d\n") { milliCelsius(it) }?.let { feeds.add(it) }
|
||||
if (!kgsl && feeds.isEmpty()) return false
|
||||
refresh()
|
||||
createMissing(feeds.map { it.file })
|
||||
describeSources()
|
||||
Log.i(TAG, "hud: kgsl stats from the session's own: $sources")
|
||||
Log.i(TAG, "hud: GPU stats from the session's own: $sources")
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "hud: could not stand in for kgsl stats: $e")
|
||||
@@ -146,10 +154,10 @@ class GpuStatsComponent(val dir: File, private val root: File) : SessionPart() {
|
||||
// Vulkan layer and the compositor time their own GPU work until the memstore timestamps are seen moving, and
|
||||
// for the whole session where they never move.
|
||||
private fun blockedLoadFeed(): Feed? {
|
||||
if (!loadBlocked()) return null
|
||||
if (!noLoadNode(kgsl, loadNodes)) return null
|
||||
val load = LayerLoad(guestLoadDir(root), extra = ::compositorBusyNs, onWanted = ::compositorTiming)
|
||||
.also { it.clear(); layerLoad = it }
|
||||
val sampled = KgslBusy.open()?.let { reader ->
|
||||
val sampled = if (!kgsl) null else KgslBusy.open()?.let { reader ->
|
||||
memstore = reader
|
||||
MemstoreLoad(reader::counts).also { memstoreLoad = it }
|
||||
}
|
||||
@@ -289,6 +297,12 @@ class GpuStatsComponent(val dir: File, private val root: File) : SessionPart() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun nodeLoadFeed(): Feed? {
|
||||
val metrics = metrics ?: return null
|
||||
val node = loadNodes().firstOrNull() ?: return null
|
||||
return Feed(File(dir, "gpu_busy_percentage"), node, { metrics.gpuUsagePercent?.toLong() }, "%3d %%\n")
|
||||
}
|
||||
|
||||
private fun loadFeed(): Feed? {
|
||||
latchedBusyFeed()?.let { return it }
|
||||
return pick("gpu_busy_percentage", LOAD_SOURCES, "%3d %%\n") { it.coerceIn(0, 100) }
|
||||
@@ -362,9 +376,14 @@ class GpuStatsComponent(val dir: File, private val root: File) : SessionPart() {
|
||||
/** True when this app can see kgsl but none of its GPU load nodes (SELinux-blocked, e.g. the Retroid Pocket Duo). */
|
||||
fun loadBlocked(): Boolean = File(KGSL).exists() && !File(GPUBUSY).canRead() && LOAD_SOURCES.none { File(it).canRead() }
|
||||
|
||||
private fun noLoadNode(): Boolean = noLoadNode(File(KGSL).exists(), HudMetrics::gpuUsagePaths)
|
||||
|
||||
internal fun noLoadNode(kgsl: Boolean, loadNodes: () -> List<String>): Boolean =
|
||||
if (kgsl) loadBlocked() else loadNodes().isEmpty()
|
||||
|
||||
/** Turns on the in-game layer (tools/gpuload) where the load is blocked; empty elsewhere. */
|
||||
fun guestEnv(root: File): List<String> {
|
||||
if (!loadBlocked()) return emptyList()
|
||||
if (!noLoadNode()) return emptyList()
|
||||
guestLoadDir(root).mkdirs()
|
||||
return listOf("DROIDDECK_GPU_LOAD=1", "DROIDDECK_GPU_LOAD_DIR=$GUEST_LOAD_DIR")
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.droiddeck.launcher.core.AddonPack
|
||||
import com.droiddeck.launcher.gpu.LinuxVulkanDriver
|
||||
import com.droiddeck.launcher.gpu.LinuxVulkanDriverManager
|
||||
import com.droiddeck.launcher.gpu.SystemVulkanDriver
|
||||
import com.droiddeck.launcher.hud.HudMetrics
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.NotificationChannel
|
||||
@@ -1293,7 +1294,7 @@ class SessionService : Service() {
|
||||
gpuMem.attach(this)
|
||||
components.add(gpuMem)
|
||||
}
|
||||
val gpuStats = GpuStatsComponent(File(filesDir, "session/sys/kgsl-3d0"), LinuxRuntime.rootDir(this))
|
||||
val gpuStats = GpuStatsComponent(File(filesDir, "session/sys/kgsl-3d0"), LinuxRuntime.rootDir(this), HudMetrics(this))
|
||||
if (gpuStats.prepare()) {
|
||||
gpuStats.attach(this)
|
||||
components.add(gpuStats)
|
||||
|
||||
@@ -13,7 +13,7 @@ class GpuStatsBindsTest {
|
||||
@Test fun feedsWithNoValueYetAreStillBound() {
|
||||
val dir = tmp.newFolder("kgsl-3d0")
|
||||
GpuStatsComponent.createMissing(listOf(File(dir, "perf_now"), File(dir, "cur_freq")))
|
||||
val binds = GpuStatsComponent(dir, tmp.root).binds()
|
||||
val binds = GpuStatsComponent(dir, tmp.root, kgsl = true).binds()
|
||||
assertTrue(binds.contains(File(dir, "perf_now").path + ":" + GpuStatsComponent.MSM_LOAD))
|
||||
assertTrue(binds.contains(File(dir, "cur_freq").path + ":" + GpuStatsComponent.MSM_CLOCK))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import com.droiddeck.launcher.hud.HudMetrics
|
||||
import java.io.File
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
class GpuStatsComponentWithoutKgslTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
private val parts = ArrayList<GpuStatsComponent>()
|
||||
|
||||
private fun component(nodes: List<String>, metrics: HudMetrics? = null) =
|
||||
GpuStatsComponent(tmp.newFolder("kgsl-3d0"), tmp.root, metrics, kgsl = false, loadNodes = { nodes }).also { parts += it }
|
||||
|
||||
@After fun reset() {
|
||||
parts.forEach { it.stop() }
|
||||
KgslBusy.status = "not tried"
|
||||
KgslClock.status = "not tried"
|
||||
}
|
||||
|
||||
@Test fun noReadableLoadNodeWithoutKgslTurnsTheTimingFeedOn() {
|
||||
assertTrue(GpuStatsComponent.noLoadNode(false) { emptyList() })
|
||||
assertFalse(GpuStatsComponent.noLoadNode(false) { listOf(MALI_NODE) })
|
||||
}
|
||||
|
||||
@Test fun kgslDevicesIgnoreOtherGpusNodes() {
|
||||
val decided = GpuStatsComponent.noLoadNode(true) { throw AssertionError("kgsl devices read other GPUs' nodes") }
|
||||
assertEquals(GpuStatsComponent.loadBlocked(), decided)
|
||||
}
|
||||
|
||||
@Test fun withoutAnyLoadNodeTheHudLoadComesFromVulkanTiming() {
|
||||
val gpu = component(emptyList())
|
||||
assertTrue(gpu.prepare())
|
||||
assertTrue(GpuStatsComponent.sources, GpuStatsComponent.sources.startsWith("gpu_busy_percentage Vulkan timing"))
|
||||
assertTrue(File(gpu.dir, "perf_now").isFile)
|
||||
assertEquals(emptyList<String>(), gpu.binds())
|
||||
assertEquals("", GpuStatsComponent.readerStatus())
|
||||
}
|
||||
|
||||
@Test fun aReadableLoadNodeFeedsTheHudInsteadOfTheLayer() {
|
||||
val gpu = component(listOf(MALI_NODE), HudMetrics(null))
|
||||
assertTrue(gpu.prepare())
|
||||
assertTrue(GpuStatsComponent.sources, GpuStatsComponent.sources.startsWith("gpu_busy_percentage $MALI_NODE"))
|
||||
assertTrue(File(gpu.dir, "perf_now").isFile)
|
||||
assertFalse(File(GpuStatsComponent.guestLoadDir(tmp.root), "on").exists())
|
||||
assertEquals("", GpuStatsComponent.readerStatus())
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val MALI_NODE = "/sys/class/misc/mali0/device/utilisation"
|
||||
}
|
||||
}
|
||||
@@ -984,15 +984,10 @@ def valve_picks(steam_root):
|
||||
return sorted(picks, key=int)
|
||||
|
||||
|
||||
def launch_platforms(entry):
|
||||
return {part.strip() for option in entry.get("launch_options", ())
|
||||
for part in option["oslist"].split(",") if part.strip()}
|
||||
|
||||
|
||||
def tool_platforms(steam_root):
|
||||
entries = appinfo_entries(os.path.join(steam_root, "appcache", "appinfo.vdf"))
|
||||
platforms = {app: entry["oslist"] | launch_platforms(entry) for app, entry in entries.items() if entry["type"] == "tool"}
|
||||
return {app: found for app, found in platforms.items() if found & {"linux", "windows"}}
|
||||
return {app: entry["oslist"] for app, entry in entries.items()
|
||||
if entry["type"] == "tool" and entry["oslist"] & {"linux", "windows"}}
|
||||
|
||||
|
||||
def native_targets(steam_root, apps):
|
||||
@@ -1232,16 +1227,8 @@ def plan_mapping(current, installed, runnable, default, auto, native=None, picks
|
||||
changes["0"] = default
|
||||
for app in sorted((set(current) | installed | picks | set(auto) | set(overrides) | native_choices | set(tools)) - {"0"}, key=app_order):
|
||||
name = current.get(app, "")
|
||||
if app in tools and "linux" in tools[app]:
|
||||
if "windows" not in tools[app]:
|
||||
if name and (name.lower() in runnable or "proton" in name.lower()):
|
||||
changes[app] = None
|
||||
continue
|
||||
if app in overrides:
|
||||
target = overrides[app]
|
||||
if target is not DEFERRED_GAME_TOOL and (target or None) != (name or None):
|
||||
changes[app] = target or None
|
||||
elif name and (name == auto.get(app) or unrunnable(name, runnable) or name.lower() in removed):
|
||||
if app in tools and "linux" in tools[app] and "windows" not in tools[app]:
|
||||
if name and (name.lower() in runnable or "proton" in name.lower()):
|
||||
changes[app] = None
|
||||
continue
|
||||
if app in overrides:
|
||||
|
||||
@@ -73,56 +73,6 @@ class ToolPlatformsTest(unittest.TestCase):
|
||||
self.assertEqual(auto["900001"], TOOL)
|
||||
self.assertEqual(auto["976730"], TOOL)
|
||||
|
||||
def add_launch_only_linux_tool(self):
|
||||
self.entries[900007] = {"common": {"type": "Tool", "oslist": "windows"}, "config": {"launch": {
|
||||
"0": {"executable": "bin\\win64\\start.exe", "config": {"oslist": "windows"}},
|
||||
"1": {"executable": "bin\\start.sh", "config": {"oslist": "linux", "osarch": "64"}},
|
||||
}}}
|
||||
self.write_appinfo()
|
||||
|
||||
def test_linux_launch_entry_counts_as_a_linux_platform(self):
|
||||
self.add_launch_only_linux_tool()
|
||||
self.assertEqual(self.platforms()["900007"], {"windows", "linux"})
|
||||
self.assertEqual(self.platforms()["900001"], {"windows"})
|
||||
|
||||
def test_tool_with_a_linux_build_is_not_given_proton_before_install(self):
|
||||
self.add_launch_only_linux_tool()
|
||||
changes, auto = self.plan({"0": TOOL})
|
||||
self.assertNotIn("900007", changes)
|
||||
self.assertNotIn("900007", auto)
|
||||
self.assertEqual(changes["900001"], TOOL)
|
||||
|
||||
def test_own_proton_mapping_on_a_tool_with_a_linux_build_is_cleared(self):
|
||||
self.add_launch_only_linux_tool()
|
||||
changes, auto = self.plan({"0": TOOL, "900007": TOOL}, {"900007": TOOL})
|
||||
self.assertIsNone(changes["900007"])
|
||||
self.assertNotIn("900007", auto)
|
||||
|
||||
def test_user_selection_on_a_tool_with_a_linux_build_survives(self):
|
||||
self.add_launch_only_linux_tool()
|
||||
for name in (TOOL, "custom-windows"):
|
||||
with self.subTest(name=name):
|
||||
changes, auto = self.plan({"0": TOOL, "900007": name}, {"976730": TOOL})
|
||||
self.assertNotIn("900007", changes)
|
||||
|
||||
def test_stale_tool_on_a_tool_with_a_linux_build_is_cleared(self):
|
||||
self.add_launch_only_linux_tool()
|
||||
for name, removed in (("GE-Proton11-7", ("GE-Proton11-7",)), ("proton_9", ())):
|
||||
with self.subTest(name=name):
|
||||
changes, auto = self.plan({"0": TOOL, "900007": name}, removed=removed)
|
||||
self.assertIsNone(changes["900007"])
|
||||
self.assertNotIn("900007", auto)
|
||||
|
||||
def test_explicit_request_on_a_tool_with_a_linux_build_is_applied(self):
|
||||
self.add_launch_only_linux_tool()
|
||||
changes, auto = self.plan({"0": TOOL}, overrides={"900007": TOOL})
|
||||
self.assertEqual(changes["900007"], TOOL)
|
||||
changes, auto = self.plan({"0": TOOL, "900007": TOOL}, overrides={"900007": None})
|
||||
self.assertIsNone(changes["900007"])
|
||||
changes, auto = self.plan({"0": TOOL, "900007": TOOL}, overrides={"900007": TOOL})
|
||||
self.assertNotIn("900007", changes)
|
||||
self.assertNotIn("900007", auto)
|
||||
|
||||
def test_removed_ge_proton_is_cleared_with_or_without_saved_ownership(self):
|
||||
for saved in ({}, {"1826330": "GE-Proton11-7"}):
|
||||
with self.subTest(saved=saved):
|
||||
|
||||
Reference in new issue
Block a user