mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
Log the GPU ceiling and mid-session clock hold changes (#2893)
* Log the GPU ceiling, steps and mid-session clock hold changes The clock log now records the GPU frequency steps and floor once in its header, probes each limit file as readable or refused, and adds the allowed GPU maximum to every sample in the CPU cur/max(of top) style, so a vendor or thermal cap on the GPU ceiling shows up and changes during a session are visible. Samples are unchanged when no limit file is readable. The limit reading is shared with the device info GPU clock range. Turning the GPU clock hold on or off during a session now logs the same line the session start logs. * Ignore a zero GPU ceiling and log hold changes in order A ceiling file that reads zero is no longer printed as a limit and is listed as refused, matching how the step list is read. The hold state line is logged under the same lock as the state change, so overlapping toggles cannot log out of order. * Find a GPU ceiling that turns readable later and probe step tables as tables A ceiling file that read zero at session start is looked for again on each sample until one is found, and the log notes where it came from. Step and floor sources are probed with the same parser that reads them, so a table with a leading zero is listed as readable.
This commit is contained in:
1 parent
de73e429cc
commit
cc93ab51c5
7 files changed
+192
-34
No files matched your search
@@ -1471,7 +1471,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
SessionPrefs.setGpuClockPin(this@SessionActivity, on)
|
||||
gpuClockPin = on
|
||||
Thread {
|
||||
GpuClockPin.sync(applicationContext)
|
||||
synchronized(GpuClockPin) { GpuClockPin.sync(applicationContext)?.let { Log.i(TAG, it) } }
|
||||
runOnUiThread { gpuClockPin = gpuClockHeld() }
|
||||
}.start()
|
||||
},
|
||||
|
||||
@@ -37,22 +37,22 @@ class ClockLogComponent(private val logFile: File) : SessionPart() {
|
||||
?.sortedBy { it.name.removePrefix("policy").toIntOrNull() ?: 0 } ?: emptyList()
|
||||
val gpuCandidates = gpuSources()
|
||||
val gpu = gpuCandidates.firstOrNull { !it.startsWith("/proc/") && firstNumber(it) != null }
|
||||
val stepSources = GpuLimits.stepSources()
|
||||
val maxSources = GpuLimits.maxSources()
|
||||
val minSources = GpuLimits.minSources()
|
||||
val steps = GpuLimits.first(stepSources)
|
||||
var ceiling = ceilingSource(maxSources)
|
||||
val power = app().getSystemService(Context.POWER_SERVICE) as? PowerManager
|
||||
val time = SimpleDateFormat("HH:mm:ss", Locale.US)
|
||||
try {
|
||||
FileWriter(logFile, true).use { w ->
|
||||
w.write("== clocks: ${Build.MANUFACTURER} ${Build.MODEL} (${Build.HARDWARE}), every ${PERIOD_MS / 1000}s\n")
|
||||
w.write("cpu policies: ${policies.joinToString { p -> p.name + " " + (File(p, "related_cpus").readTextOrNull()?.trim() ?: "?") }}\n")
|
||||
for (source in gpuCandidates) {
|
||||
val f = File(source)
|
||||
val state = when {
|
||||
!f.exists() -> continue
|
||||
firstNumber(source) != null -> "readable"
|
||||
else -> "refused"
|
||||
}
|
||||
w.write("gpu source $source: $state\n")
|
||||
}
|
||||
probeLines("gpu source", gpuCandidates).forEach { w.write(it + "\n") }
|
||||
w.write("gpu clock from: ${gpu ?: "nothing readable"}\n")
|
||||
(probeLines("gpu limit", stepSources, ::firstStep) + probeLines("gpu limit", maxSources, ::limit) +
|
||||
probeLines("gpu limit", minSources, ::firstStep)).distinct().forEach { w.write(it + "\n") }
|
||||
limitLines(steps, ceiling, GpuLimits.first(minSources)).forEach { w.write(it + "\n") }
|
||||
w.flush()
|
||||
while (running && logFile.length() < MAX_BYTES) {
|
||||
val line = StringBuilder(time.format(Date()))
|
||||
@@ -63,7 +63,8 @@ class ClockLogComponent(private val logFile: File) : SessionPart() {
|
||||
line.append(" ${p.name.removePrefix("policy").let { "p$it" }} ${mhz(cur)}/${mhz(max)}")
|
||||
if (hw != null && max != null && max < hw) line.append("(of ${mhz(hw)})")
|
||||
}
|
||||
gpu?.let { line.append(" | gpu ${mhz(firstNumber(it))} MHz") }
|
||||
if (ceiling == null) ceiling = ceilingSource(maxSources)?.also { w.write("gpu ceiling from: $it\n") }
|
||||
line.append(gpuField(gpu, ceiling, steps?.mhz?.last()))
|
||||
if (power != null && Build.VERSION.SDK_INT >= 29) {
|
||||
line.append(" | thermal ${power.currentThermalStatus}")
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
@@ -109,16 +110,41 @@ class ClockLogComponent(private val logFile: File) : SessionPart() {
|
||||
return list.distinct()
|
||||
}
|
||||
|
||||
internal fun probeLines(label: String, sources: List<String>, read: (String) -> Long? = ::firstNumber): List<String> = sources.mapNotNull { source ->
|
||||
when {
|
||||
!File(source).exists() -> null
|
||||
read(source) != null -> "$label $source: readable"
|
||||
else -> "$label $source: refused"
|
||||
}
|
||||
}
|
||||
|
||||
internal fun limitLines(steps: GpuLimits.Found?, ceiling: String?, floor: GpuLimits.Found?): List<String> = listOf(
|
||||
"gpu steps: " + (steps?.let { "${it.mhz.joinToString(" ")} MHz from ${it.path}" } ?: "nothing readable"),
|
||||
"gpu ceiling from: " + (ceiling ?: "nothing readable"),
|
||||
"gpu floor: " + (floor?.let { "${it.mhz.first()} MHz from ${it.path}" } ?: "nothing readable"),
|
||||
)
|
||||
|
||||
internal fun gpuField(clock: String?, ceiling: String?, top: Long?): String {
|
||||
if (clock == null && ceiling == null) return ""
|
||||
val field = StringBuilder(" | gpu ").append(mhz(clock?.let(::firstNumber)))
|
||||
ceiling?.let(::limit)?.let { max ->
|
||||
field.append('/').append(mhz(max))
|
||||
if (top != null && GpuLimits.mhz(max) < top) field.append("(of $top)")
|
||||
}
|
||||
return field.append(" MHz").toString()
|
||||
}
|
||||
|
||||
private fun File.readTextOrNull(): String? = runCatching { readText() }.getOrNull()
|
||||
|
||||
private fun firstNumber(path: String): Long? =
|
||||
runCatching { Regex("\\d+").find(File(path).readText())?.value?.toLong() }.getOrNull()
|
||||
|
||||
private fun mhz(raw: Long?): String = when {
|
||||
raw == null -> "?"
|
||||
raw > 10_000_000 -> (raw / 1_000_000).toString()
|
||||
raw > 10_000 -> (raw / 1_000).toString()
|
||||
else -> raw.toString()
|
||||
}
|
||||
internal fun limit(path: String): Long? = firstNumber(path)?.takeIf { it > 0 }
|
||||
|
||||
internal fun firstStep(path: String): Long? = GpuLimits.read(path).firstOrNull()
|
||||
|
||||
internal fun ceilingSource(sources: List<String>): String? = sources.firstOrNull { limit(it) != null }
|
||||
|
||||
private fun mhz(raw: Long?): String = raw?.let { GpuLimits.mhz(it).toString() } ?: "?"
|
||||
}
|
||||
}
|
||||
@@ -87,20 +87,10 @@ object DeviceInfo {
|
||||
private fun ghz(khz: Long) = String.format(Locale.US, "%.2f GHz", khz / 1e6)
|
||||
|
||||
private fun gpuRange(): String? {
|
||||
fun mhz(hz: Long) = "${hz / 1_000_000} MHz"
|
||||
val kgsl = read("/sys/class/kgsl/kgsl-3d0/gpu_available_frequencies")
|
||||
?.split(Regex("\\s+"))?.mapNotNull { it.toLongOrNull() }?.filter { it > 0 }.orEmpty()
|
||||
if (kgsl.isNotEmpty()) return "${mhz(kgsl.min())}–${mhz(kgsl.max())} (${kgsl.size} steps)"
|
||||
read("/sys/class/kgsl/kgsl-3d0/max_gpuclk")?.toLongOrNull()?.let { return "up to ${mhz(it)}" }
|
||||
val node = File("/sys/class/devfreq").listFiles()?.firstOrNull { f ->
|
||||
val n = f.name.lowercase()
|
||||
(n.contains("gpu") || n.contains("mali") || n.contains("kgsl-3d")) && listOf("bus", "bw", "memlat").none { n.contains(it) }
|
||||
} ?: return null
|
||||
val steps = read("${node.path}/available_frequencies")?.split(Regex("\\s+"))?.mapNotNull { it.toLongOrNull() }?.filter { it > 0 }.orEmpty()
|
||||
if (steps.isNotEmpty()) return "${mhz(steps.min())}–${mhz(steps.max())} (${steps.size} steps)"
|
||||
val min = read("${node.path}/min_freq")?.toLongOrNull()
|
||||
val max = read("${node.path}/max_freq")?.toLongOrNull() ?: return null
|
||||
return (if (min != null) "${mhz(min)}–" else "up to ") + mhz(max)
|
||||
GpuLimits.first(GpuLimits.stepSources())?.mhz?.let { return "${it.first()} MHz–${it.last()} MHz (${it.size} steps)" }
|
||||
val max = GpuLimits.first(GpuLimits.maxSources())?.mhz?.last() ?: return null
|
||||
val min = GpuLimits.first(GpuLimits.minSources())?.mhz?.first()
|
||||
return (if (min != null) "$min MHz–" else "up to ") + "$max MHz"
|
||||
}
|
||||
|
||||
private fun memory(context: Context) = Section("Memory", buildList<Pair<String, String>> {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.droiddeck.launcher.gpu
|
||||
|
||||
import java.io.File
|
||||
|
||||
object GpuLimits {
|
||||
class Found(val path: String, val mhz: List<Long>)
|
||||
|
||||
private const val KGSL = "/sys/class/kgsl/kgsl-3d0"
|
||||
private const val QCOM_GPU = "/sys/kernel/gpu"
|
||||
|
||||
fun stepSources(): List<String> = listOf(
|
||||
"$KGSL/gpu_available_frequencies", "$KGSL/freq_table_mhz", "$KGSL/devfreq/available_frequencies", "$QCOM_GPU/gpu_freq_table",
|
||||
) + devfreq("available_frequencies")
|
||||
|
||||
fun maxSources(): List<String> = listOf(
|
||||
"$KGSL/max_gpuclk", "$KGSL/max_clock_mhz", "$KGSL/devfreq/max_freq", "$QCOM_GPU/gpu_max_clock",
|
||||
) + devfreq("max_freq")
|
||||
|
||||
fun minSources(): List<String> = listOf(
|
||||
"$KGSL/min_clock_mhz", "$KGSL/devfreq/min_freq", "$QCOM_GPU/gpu_min_clock",
|
||||
) + devfreq("min_freq")
|
||||
|
||||
fun first(sources: List<String>): Found? =
|
||||
sources.firstNotNullOfOrNull { path -> read(path).takeIf { it.isNotEmpty() }?.let { Found(path, it) } }
|
||||
|
||||
fun read(path: String): List<Long> = runCatching {
|
||||
Regex("\\d+").findAll(File(path).readText()).map { mhz(it.value.toLong()) }.filter { it > 0 }.distinct().sorted().toList()
|
||||
}.getOrDefault(emptyList())
|
||||
|
||||
fun mhz(raw: Long): Long = when {
|
||||
raw > 10_000_000 -> raw / 1_000_000
|
||||
raw > 10_000 -> raw / 1_000
|
||||
else -> raw
|
||||
}
|
||||
|
||||
private fun devfreq(file: String): List<String> =
|
||||
File("/sys/class/devfreq").listFiles()?.filter { f ->
|
||||
val n = f.name.lowercase()
|
||||
(n.contains("gpu") || n.contains("mali") || n.contains("kgsl-3d")) && listOf("bus", "bw", "memlat").none { n.contains(it) }
|
||||
}?.sortedBy { it.name }?.map { "${it.path}/$file" }.orEmpty()
|
||||
}
|
||||
@@ -46,9 +46,10 @@ object GpuClockPin {
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun sync(context: Context) {
|
||||
if (!live) return
|
||||
if (SessionPrefs.gpuClockPin(context)) hold(context) else if (pinned) clear(context)
|
||||
fun sync(context: Context): String? {
|
||||
if (!live) return null
|
||||
if (!SessionPrefs.gpuClockPin(context) && pinned) clear(context)
|
||||
return hold(context)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
|
||||
Reference in new issue
Block a user