Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.d/290-qos-hybrid.change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
模拟器开机后要求 Windows 不对它做后台降速,大小核处理器上更不容易被排到小核 (ModAVD/ModAVD#290)
The emulator now opts out of Windows background throttling, making efficiency-core placement less likely on hybrid CPUs
28 changes: 28 additions & 0 deletions internal/emu/affinity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"slices"
"testing"

"modavd/internal/errs"
"modavd/internal/host"
"modavd/internal/root"
)
Expand Down Expand Up @@ -236,3 +237,30 @@ func TestQemuCoresCommandLine(t *testing.T) {
}
}
}

// The QoS boost (ModAVD/ModAVD#290): MODAVD_QOS_BOOST=off skips the call; a Windows without the switch is a skip,
// not a failure; any other error is named.
func TestQoSBoostNote(t *testing.T) {
cases := []struct {
name, env string
err error
called bool
want string
}{
{"default", "", nil, true, "已关进程节流"},
{"on", "on", nil, true, "已关进程节流"},
{"off", "off", nil, false, "按 MODAVD_QOS_BOOST=off 不关进程节流"},
{"OFF spaced", " OFF ", nil, false, "按 MODAVD_QOS_BOOST=off 不关进程节流"},
{"unsupported", "", errs.New(errs.Unsupported, "x"), true, "系统不支持关进程节流,跳过"},
{"wrapped unsupported", "", errs.Wrap(errs.Internal, errs.New(errs.Unsupported, "x"), "y"), true,
"系统不支持关进程节流,跳过"},
{"failed", "", errs.New(errs.Internal, "拒绝访问"), true, "关进程节流失败(拒绝访问)"},
}
for _, c := range cases {
called := false
got := qosBoostNote(c.env, func() error { called = true; return c.err })
if got != c.want || called != c.called {
t.Errorf("%s: %q called %v, want %q called %v", c.name, got, called, c.want, c.called)
}
}
}
27 changes: 27 additions & 0 deletions internal/emu/afterboot.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"modavd/internal/adb"
"modavd/internal/avd"
"modavd/internal/errs"
"modavd/internal/guest"
"modavd/internal/host"
"modavd/internal/jsonord"
Expand Down Expand Up @@ -140,6 +141,10 @@ func (m *Manager) afterBoot(ctx context.Context, inst *avd.Instance, mode bootSe
note, plan := m.tuneHostScheduling(p, cores)
spare = plan.Spare
m.Log.Infof("实例 %d 宿主调度: %s", i, note)
if root.CurrentPlatform().Windows() {
// hybrid cores or not (ModAVD/ModAVD#290): whether the line above matters on this host
m.Log.Infof("实例 %d 宿主处理器核: %s", i, host.CoreClassesText(host.CoreClasses()))
}
},
func() {
if !root.CurrentPlatform().Windows() {
Expand Down Expand Up @@ -295,6 +300,7 @@ func (m *Manager) tuneHostScheduling(p host.Process, cores int) (string, hostPla
} else {
notes = append(notes, "优先级高于正常")
}
notes = append(notes, qosBoostNote(os.Getenv(envQoSBoost), func() error { return host.DisableExecutionThrottling(p) }))
groups := host.L3Groups()
if hasBigL3(groups) {
lock, ok, err := host.Lock(affinityLockPath(), affinityLockWait)
Expand Down Expand Up @@ -323,6 +329,27 @@ func (m *Manager) tuneHostScheduling(p host.Process, cores int) (string, hostPla
return strings.Join(notes, ","), plan
}

// envQoSBoost set to "off" leaves the execution speed throttling of qemu to Windows (A/B runs, and the way back).
// By default it is turned off (ModAVD/ModAVD#290): a headless or background instance is otherwise an EcoQoS candidate,
// which on hybrid processors means the efficiency cores and lower clocks for the translated game's main thread.
const envQoSBoost = "MODAVD_QOS_BOOST"

// qosBoostNote runs disable (host.DisableExecutionThrottling) unless env (the value of envQoSBoost) is "off", and says
// what came of it for the scheduling line. A Windows without the switch is no failure.
func qosBoostNote(env string, disable func() error) string {
if strings.EqualFold(strings.TrimSpace(env), "off") {
return "按 " + envQoSBoost + "=off 不关进程节流"
}
switch err := disable(); {
case err == nil:
return "已关进程节流"
case errs.CodeOf(err) == errs.Unsupported:
return "系统不支持关进程节流,跳过"
default:
return fmt.Sprintf("关进程节流失败(%v)", err)
}
}

// hostCPUs is the logical processor count: those under an L3 group, at least runtime.NumCPU.
func hostCPUs(groups []host.L3Group) int {
var all uint64
Expand Down
23 changes: 23 additions & 0 deletions internal/host/coreclass.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package host

import (
"fmt"
"strings"
)

// CoreClassesText describes the host's cores by efficiency class for the boot log and the problem report (Chinese,
// as both of them): one class is a processor without hybrid cores; several are listed slowest first.
func CoreClassesText(classes []CoreClass) string {
switch len(classes) {
case 0:
return "读不到"
case 1:
return fmt.Sprintf("没有大小核(%d 核 %d 个逻辑处理器,效率等级都是 %d)", classes[0].Cores, classes[0].Logical,
classes[0].Class)
}
parts := make([]string, len(classes))
for k, c := range classes {
parts[k] = fmt.Sprintf("等级 %d:%d 核 %d 个逻辑处理器", c.Class, c.Cores, c.Logical)
}
return "有大小核(效率等级越高越快):" + strings.Join(parts, ";")
}
21 changes: 21 additions & 0 deletions internal/host/coreclass_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package host

import "testing"

func TestCoreClassesText(t *testing.T) {
cases := []struct {
name string
classes []CoreClass
want string
}{
{"unreadable", nil, "读不到"},
{"uniform", []CoreClass{{Class: 0, Cores: 16, Logical: 32}}, "没有大小核(16 核 32 个逻辑处理器,效率等级都是 0)"},
{"hybrid", []CoreClass{{Class: 0, Cores: 8, Logical: 8}, {Class: 1, Cores: 8, Logical: 16}},
"有大小核(效率等级越高越快):等级 0:8 核 8 个逻辑处理器;等级 1:8 核 16 个逻辑处理器"},
}
for _, c := range cases {
if got := CoreClassesText(c.classes); got != c.want {
t.Errorf("%s: %q, want %q", c.name, got, c.want)
}
}
}
13 changes: 13 additions & 0 deletions internal/host/unsupported_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ func GetSystemMemory() (SystemMemory, error) { return SystemMemory{}, errUnsuppo
// L3Groups lists the L3 caches of the host.
func L3Groups() []L3Group { return nil }

// CoreClass is one efficiency class of the host's cores (Windows EfficiencyClass).
type CoreClass struct {
Class uint8
Cores int
Logical int
}

// CoreClasses lists the efficiency classes of the host's cores on Windows.
func CoreClasses() []CoreClass { return nil }

// DisableExecutionThrottling calls SetProcessInformation(ProcessPowerThrottling) on Windows.
func DisableExecutionThrottling(Process) error { return errUnsupported }

// SharedMemoryExists calls OpenFileMappingW for the Windows named mapping.
func SharedMemoryExists(string) bool { return false }

Expand Down
7 changes: 7 additions & 0 deletions internal/host/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Listener = win.Listener
type StartOptions = win.StartOptions
type FileLock = win.FileLock
type L3Group = win.L3Group
type CoreClass = win.CoreClass

const SpawnHelperArg = win.SpawnHelperArg
const HideConsole = win.HideConsole
Expand Down Expand Up @@ -97,5 +98,11 @@ func FileChangeStamp(f *os.File) string { return win.FileChange

func TerminateRefused(p Process) bool { return win.TerminateRefused(p) }

// CoreClasses are the efficiency classes of the host's cores, nil when unreadable.
func CoreClasses() []CoreClass { return win.CoreClasses() }

// DisableExecutionThrottling turns EcoQoS off for p; errs.Unsupported on a Windows without the switch.
func DisableExecutionThrottling(p Process) error { return win.DisableExecutionThrottling(p) }

// InfoBox displays an informational message with the Windows backend.
func InfoBox(message string) error { return win.InfoBox(message) }
5 changes: 5 additions & 0 deletions internal/i18n/locales/en/emu.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
"关掉占用这些文件的程序后再运行一次 modavd delete %d --yes,会接着删": "Close the programs using these files, then run modavd delete %d --yes again; it will continue deleting",
"关掉应用后": "after closing the app",
"关机命令自己返回了,安卓没有开始关机: %s": "The shutdown command returned by itself and Android did not start shutting down: %s",
"关进程节流失败(%v)": "Turning off power throttling failed (%v)",
"其他": "Other",
"内测包 %s 低于 %s": "Beta package %s is lower than %s",
"内测包 %s(%s)": "Beta package %s (%s)",
Expand Down Expand Up @@ -321,6 +322,7 @@
"实例 %d 客体时钟源: %s(可选 %s,客体 %s)": "Instance %d guest clock source: %s (available %s, guest %s)",
"实例 %d 客体时钟源是 %s,不是 tsc(可选 %s,客体 %s):这次开机读时钟都要退出到模拟器,整体会慢,关机再开才恢复": "Instance %d: the guest clock source is %s, not tsc (available %s, guest %s): every clock read in this boot has to exit to the emulator, so everything is slower until you shut down and start again",
"实例 %d 客体重启后的开机后调优已补做(%.1f 秒,%d 条警告)": "Instance %d: post-boot tuning was redone after the guest restarted (%.1f s, %d warnings)",
"实例 %d 宿主处理器核: %s": "Instance %d host processor cores: %s",
"实例 %d 宿主调度: %s": "Instance %d host scheduling: %s",
"实例 %d 宿主输入法": "Instance %d host IME",
"实例 %d 宿主输入法: %s %s,默认 %s%s(%.1f 秒)": "Instance %d host IME: %s %s, default %s%s (%.1f s)",
Expand Down Expand Up @@ -539,6 +541,7 @@
"导入 %s 时跳过了 %d 个符号链接或特殊文件(例如 %s)": "Skipped %[2]d symbolic links or special files while importing %[1]s (for example %[3]s)",
"导入需要 %d MiB,请检查目标数据盘和电脑磁盘的剩余空间": "Import requires %d MiB. Check the available space on the target data disk and host drive",
"少建几台,或者先删掉不用的实例": "Create fewer, or delete instances you no longer use first",
"已关进程节流": "power throttling off",
"已写入 ModAVD 实例 %d 的设置: %s": "Wrote settings of ModAVD instance %d: %s",
"已写入实例 %d 的按应用走代理:%s": "Wrote per-app proxy of instance %d: %s",
"已删除 ModAVD 实例 %d": "Deleted ModAVD instance %d",
Expand Down Expand Up @@ -594,6 +597,7 @@
"拿着它的程序:%v": "Programs holding it: %v",
"挂补丁会重启安卓框架,装到一半会失败;等它挂完(start 返回)再装": "Mounting the patch restarts the Android framework and an install in progress would fail; wait until the mount is done (start returns), then install",
"挂这些补丁要重启 zygote,只在前台没有应用、也没有安装正在进行时才挂(不然就留到之后再启动一次,或下次开机)": "Mounting these patches needs a zygote restart, so it only happens when no app is in the foreground and no install is in progress (otherwise it waits for another start later, or the next start)",
"按 %v=off 不关进程节流": "power throttling left on by %v=off",
"探测超时(%.0f 秒)": "Probe timed out (%.0f s)",
"探测进程退出码 %d,没有结果": "The probe process exited with code %d and gave no result",
"接着做设置的期限 %v 已过": "The deadline %v for continuing the setup has passed",
Expand Down Expand Up @@ -742,6 +746,7 @@
"签名不同,卸载旧版 %d 失败(%s)": "Signature differs; uninstalling the old version %d failed (%s)",
"算不出 %v 的相对路径": "Cannot work out the relative path of %v",
"算不出已分配和可回收的大小:%v": "Cannot calculate the allocated and reclaimable sizes: %v",
"系统不支持关进程节流,跳过": "power throttling switch not supported by Windows, skipped",
"系统镜像 API 为 %s,当前平台需要 %s": "The system image API is %s; this platform needs %s",
"系统镜像架构为 %s,Apple Silicon 需要 %s": "The system image architecture is %s; Apple Silicon needs %s",
"组件": "Components",
Expand Down
6 changes: 5 additions & 1 deletion internal/i18n/locales/en/host.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"当前平台暂不支持此操作": "This operation is not supported on this platform yet",
"当前平台暂不支持消息框": "Message boxes are not supported on this platform yet"
"当前平台暂不支持消息框": "Message boxes are not supported on this platform yet",
"有大小核(效率等级越高越快):%v": "hybrid cores (a higher efficiency class is faster): %v",
"没有大小核(%d 核 %d 个逻辑处理器,效率等级都是 %d)": "no hybrid cores (%d cores, %d logical processors, all of efficiency class %d)",
"等级 %d:%d 核 %d 个逻辑处理器": "class %d: %d cores, %d logical processors",
"读不到": "unreadable"
}
1 change: 1 addition & 0 deletions internal/i18n/locales/en/report.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
"启动卡死线程转储(startup-*-hang-threads.txt):没有": null,
"命令行一直在变长": null,
"图形说明:宿主 Metal 支持不代表模拟器 Vulkan 或游戏兼容性已通过验证": null,
"处理器核的效率等级(大小核)": null,
"复制 %v 失败:%v": null,
"复制 mas-avd.json 失败:%v": null,
"复制到剪贴板": "Copying to the clipboard",
Expand Down
7 changes: 7 additions & 0 deletions internal/i18n/locales/en/win.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"中转进程的参数不是合法的 JSON: %v": "The relay process arguments are not valid JSON: %v",
"中转进程的参数里没有要启动的程序": "The relay process arguments do not name a program to start",
"中转进程要一个 JSON 参数,收到 %d 个": "The relay process needs one JSON argument, got %d",
"关闭%s的进程节流失败: %v": "Failed to turn off power throttling of %s: %v",
"关闭进程节流": "turn off power throttling",
"切换 Edge 窗口失败: %w": "Failed to switch the Edge window: %w",
"启动 %s 失败: %v": "Failed to start %s: %v",
"启动 %s 失败:中转进程 %.0f 秒内没有回报": "Failed to start %s: the relay process did not report back within %.0f seconds",
Expand Down Expand Up @@ -46,12 +48,17 @@
"读不到系统的 TCP(IPv6)监听表: %v": "Cannot read the system TCP (IPv6) listener table: %v",
"读不到进程列表: %v": "Cannot read the process list: %v",
"读取%s的绑核失败: %v": "Failed to read the CPU affinity of %s: %v",
"读取%s的进程节流失败: %v": "Failed to read power throttling of %s: %v",
"读取绑核": "read CPU affinity",
"读取进程节流": "read power throttling",
"读命令行": "read the command line",
"读程序路径": "read the program path",
"调整%s的优先级失败: %v": "Failed to change the priority of %s: %v",
"调整优先级": "change priority",
"路径 %s 不可用: %v": "Path %s is unavailable: %v",
"这个 Windows 版本不支持关闭进程节流: %v": "This Windows version cannot turn off power throttling: %v",
"这个 Windows 版本没有 GetProcessInformation": "This Windows version has no GetProcessInformation",
"这个 Windows 版本没有 SetProcessInformation": "This Windows version has no SetProcessInformation",
"这台电脑上用不了窗口操作: %v": "Window operations are not available on this computer: %v",
"进程 %d": "process %d",
"退出": "Exit",
Expand Down
1 change: 1 addition & 0 deletions internal/report/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ func collect(ctx context.Context, rootDir string, h Host, opt CollectOptions) (r
}
c.step("ModAVD 目录与版本", c.rootAndVersions)
c.step("Windows / CPU / 内存 / 显卡", c.computer)
c.extra(sectionCoreClasses, c.coreClasses)
c.step("虚拟化功能", c.features)
c.step("加速检查(emulator -accel-check)", c.accelCheck)
c.step("杀毒软件", c.antivirus)
Expand Down
16 changes: 15 additions & 1 deletion internal/report/extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ import (
"time"

"modavd/internal/adb"
"modavd/internal/host"
"modavd/internal/root"
)

// Sections collect-info.ps1 never had, so that whoever sends the problem package is not asked for these separately:
// what the manager and the boot watch logged, every adb.exe with the adb server's own log, and the TCP ports Windows
// keeps for itself. The parity tests leave these sections and their files out (goOnlySections, goOnlyEntry).
// keeps for itself, and whether the processor has hybrid cores (ModAVD/ModAVD#290). The parity tests leave these sections and their files out (goOnlySections, goOnlyEntry).
const (
sectionManagerLogs = "管理器日志"
sectionAdbProcesses = "adb.exe 进程与 adb server 日志"
sectionPortExcluded = "Windows 保留的 TCP 端口(netsh)"
sectionCoreClasses = "处理器核的效率等级(大小核)"
)

// hostCoreClasses reads the host's core efficiency classes (a variable so tests can give their own).
var hostCoreClasses = host.CoreClasses

var (
// managerLogTailBytes: modavd-ui.log starts over at 5 MB (one .1 backup), the boot watch's log at 4 MB.
managerLogTailBytes int64 = 5 << 20
Expand Down Expand Up @@ -227,3 +232,12 @@ func (c *collector) portExclusions() error {
}
return nil
}

// coreClasses says whether the host has cores of different efficiency classes (Intel's performance and efficiency
// cores) and how many logical processors each has: whether Windows may put a background emulator on the slow ones.
// The processor model is in the 本机 section.
func (c *collector) coreClasses() error {
c.section(sectionCoreClasses)
c.L(host.CoreClassesText(hostCoreClasses()))
return nil
}
34 changes: 34 additions & 0 deletions internal/report/extra_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"path/filepath"
"strings"
"testing"

"modavd/internal/host"
)

// setNetsh makes netsh.exe answer stdout, or fail to start with startErr.
Expand Down Expand Up @@ -118,3 +120,35 @@ func TestCollectPortExclusions(t *testing.T) {
t.Errorf("problems %q, summary:\n%s", res.Problems, s)
}
}

// Hybrid cores or not (ModAVD/ModAVD#290): a Go-only section right after 本机, from the host's core topology.
func TestCollectCoreClasses(t *testing.T) {
useGoldenZone(t, "full")
old := hostCoreClasses
t.Cleanup(func() { hostCoreClasses = old })
hostCoreClasses = func() []host.CoreClass {
return []host.CoreClass{{Class: 0, Cores: 8, Logical: 8}, {Class: 1, Cores: 8, Logical: 16}}
}
f := newFixture(t, "full", testTempDir(t), "")
guardDials(t, f.adbPort)
res, _, files := runCollect(t, f)
s := summaryOf(t, files)
want := "\r\n== 处理器核的效率等级(大小核) ==\r\n有大小核(效率等级越高越快):等级 0:8 核 8 个逻辑处理器;等级 1:8 核 16 个逻辑处理器\r\n"
if !strings.Contains(s, want) {
t.Errorf("want %q in:\n%s", want, s)
}
if strings.Index(s, "== 本机 ==") > strings.Index(s, "== 处理器核的效率等级(大小核) ==") {
t.Error("the section comes before 本机")
}
if strings.Contains(strings.Join(res.Problems, "\n"), sectionCoreClasses) {
t.Errorf("problems %q", res.Problems)
}

hostCoreClasses = func() []host.CoreClass { return nil }
f = newFixture(t, "full", testTempDir(t), "")
guardDials(t, f.adbPort)
_, _, files = runCollect(t, f)
if s := summaryOf(t, files); !strings.Contains(s, "\r\n== 处理器核的效率等级(大小核) ==\r\n读不到\r\n") {
t.Errorf("unreadable:\n%s", s)
}
}
2 changes: 1 addition & 1 deletion internal/report/parity_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func TestCollectMatchesScript(t *testing.T) {

// goOnlySections are the summary sections collect-info.ps1 does not have (extra.go).
var goOnlySections = map[string]bool{sectionManagerLogs: true, sectionAdbProcesses: true, sectionPortExcluded: true,
sectionFrameRate: true}
sectionFrameRate: true, sectionCoreClasses: true}

// withoutGoOnly drops goOnlySections from summary lines: each with the empty line before its header and its lines.
func withoutGoOnly(ls []string) []string {
Expand Down
Loading
Loading