如何在没有220v插座的图书馆优雅的用Surface Go 3码字

封面

话说旧事

两年前的今天,在同学的安利下我开箱了一台Surface Go 3,但是出厂预装的Win11家庭版22000实在难用,主要就是一个字:。在i3-10100Y这个TDP-up有7瓦CPU上运行臃肿的Win11,再加上那128G寸土寸金的SSD属实是有点小才大用了,尤其是装了WSA之后。
不插电源用Win11两个小时就没电了!!
于是我给它装回了Win10 Iot LTSC 2021系统。在获得流畅体验的同时,开始追求更加极客的玩法。
网上说装黑苹果可以提升Windows笔电的续航,但我装了Big Sur之后续航不仅没有变好,撞温度墙的次数也不比Win11少。后续的VenturaSonoma系统也是如此,尽管台前调度确实好用。
离谱的是,Surface Go 3这东西开机的时候不会给SD卡卡槽上电,也就意味着我无法在SD卡安装系统。
于是我从Windows划了32G出来试了试ChromeOS,一个基于Gentoo浏览器系统。在获得更好的安卓体验的同时,电脑也能更加凉快。但是ChromeOS还是限制太多,比如想要享受纯净的Linux体验,就得开个Debian容器,要不然就是装chromebrew,不爽。在多次尝试将ChromeOS 装到SD卡中,均以失败告终,因为无法认到在SD卡内的rootfs

甚至FydeOS官方对我的评价是…

Chromium OS跟一般的Linux不一样,不建议这么骚操作,我们官方不会出教程,你只能自己去尝试一下

更要命的是,经历过我几次在SSD内折腾黑苹果之后,内置硬盘的寿命仅在一年就消耗了3%!!!
但是面对着捉襟见肘的空间,我打算放手搏一搏,死马当活马医,直接把ArchLinux装到SD卡里。

前情提要

开机,进Arch Live CD,把SD卡挂载到/mnt,把ESP挂到/mnt/boot下,直接pacstrap开跑。没想到啊,还成功了。查阅相关资料才知道,Surface会在加载initramfs之后给SD卡卡槽上电。先不管ChromeOS 了,先把Arch整好再说。

⚠警告
请不要把swap放到SD卡内,否则你的卡寿命会掉的很快。别说你买了延保就使劲造,回头丢数据了有你好哭的
所以我直接把swap关了

既然是个x86机器,那就想办法榨干它。vscode, Obsidian, syncthing, Chrome, Waydroid, Android Studio, Intellij Idea啥的全怼进去。
然后AS在跑编译的时候就爆内存了,淦,下次不碰8G的电脑了

在跑Waydroid的时候,最开始还挺流畅的,但后来越来越卡,然后又流畅一会儿,又卡一会儿。

这让我突然想到了之前Win11的时候,电脑老撞温度墙,一撞墙CPU就强制锁到399MHz频率运行到降温为止。让我十分头大。

试着解决

突然想起来我在Windows上简单粗暴的调教温度墙的经历:直接用ThrottleStop禁用牙膏厂的Turbo Boost,然后电脑撑死就60度,上不去了。于是直接到Arch照搬这个操作。

一开始就是简单的关闭Turbo Boost,将/sys/devices/system/cpu/intel_pstate/no_turbo文件内容写为1,以此关闭Intel的p-state下的睿频功能。

1
2
sudo su
echo 1 >> /sys/devices/system/cpu/intel_pstate/no_turbo && exit

效果显著!Waydroid中运行12306这个网页套壳的卖票软件(真不是星穹铁道)飞常准看飞机,苏菲就没撞过温度墙,一直50度很乖。就算我再开一个日益臃肿的最新版酷安,也是这个温度。

但是随之而来的问题是,两万毫安的充电宝只能撑大半天因为苏菲吸得是在太快了。就算平时开个Okular看书,Obsidian记笔记,再开个syncthing同步,也只能勉强将温度维持到40度,一直降不下来。问题是我平时也用不到那么高的性能,为了防止性能过剩,怎么办呢?

对调度策略下手

之前查过很多资料,有更加精细粒度管理性能的(直接人工硬核介入CPU的时间片轮转),也有简单粗暴限制CPU最大占用率的。在目前看来,我的需求更倾向于限制最大运行频率。

初识cpupower工具

cpupower is a set of userspace utilities designed to assist with CPU frequency scaling. The package is not required to use scaling, but is highly recommended because it provides useful command-line utilities and a systemd service to change the governor at boot.
The configuration file for cpupower is located in /etc/default/cpupower. This configuration file is read by a bash script in /usr/lib/systemd/scripts/cpupower which is activated by systemd with cpupower.service. You may want to enable cpupower.service to start at boot.

-- 来自 Arch Wiki

香啊,很香啊!这东西太符合我的要求了!直接对CPU性能一顿限制,防止性能过剩

先把这软件装好:

1
sudo pacman -S cpupower

然后就可以通过cpupower frequency-info命令来查看当前CPU支持的模式信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
analyzing CPU 1:  
 driver: intel_pstate
 CPUs which run at the same hardware frequency: 1
 CPUs which need to have their frequency coordinated by software: 1
 maximum transition latency:  Cannot determine or is not supported.
 hardware limits: 400 MHz - 3.90 GHz
 available cpufreq governors: performance powersave
 current policy: frequency should be within 400 MHz and 1.30 GHz.
                 The governor "powersave" may decide which speed to use
                 within this range.
 current CPU frequency: Unable to call hardware
 current CPU frequency: 700 MHz (asserted by call to kernel)
 boost state support:
   Supported: yes
   Active: yes

好啊,很好啊!可以在400 MHz - 3.90 GHz之间变频,支持performancepowersave两个策略。

但是我测了一下,powersave策略似乎并没有什么效果,所以不如直接限频。

然后我们请那个男人来看一看它限频的用法:

1
man cpupower-frequency-set

嗯~~很好,用法和参数都给的很清楚。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
OPTIONS  
      -d --min <FREQ>
             new minimum CPU frequency the governor may select.
    -u --max <FREQ>
             new maximum CPU frequency the governor may select.
      -g --governor <GOV>
             new cpufreq governor.
      -f --freq <FREQ>
             specific frequency to be set. Requires userspace governor to be available and loaded.
      -r --related
             modify all hardware-related CPUs at the same time
      REMARKS
      By default values are applied on all cores. How to modify single core configurations is described in the cpupower(1) manpage in the --cpu  option  section.
      The -f FREQ, --freq FREQ parameter cannot be combined with any other parameter.
    FREQuencies can be passed in Hz, kHz (default), MHz, GHz, or THz by postfixing the value with the wanted unit name, without any space (frequency in kHz =^ Hz * 0.001 =^ MHz * 1000 =^ GHz * 1000000).
      On Linux kernels up to 2.6.29, the -r or --related parameter is ignored.

那,我们直接开限:

1
sudo cpupower frequency-set -u 700MHZ

很快啊,桌面上的KDE小组件显示的频率就超不过700MHz了。
如果要恢复,先记住上面cpupower frequency-info输出的提示第六行,就是CPU最高支持的频率,我这里是3.9GHz。那就把最大频率重新设置到3.9就行:

1
sudo cpupower frequency-set -u 3.9GHz

注意
这里的修改都是仅对本次开机有效,重启需要重新设置。

如何在开机的时候自动限频呢?
回忆一下上面Arch Wiki说的,默认配置文件在/etc/default/cpupower下,当启用服务cpupower之后开机就会去读配置限频。
这个是默认配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Define CPUs governor  
# valid governors: ondemand, performance, powersave, conservative, userspace.
#governor='ondemand'

# Limit frequency range
# Valid suffixes: Hz, kHz (default), MHz, GHz, THz
#min_freq="2.25GHz"
#max_freq="3GHz"

# Specific frequency to be set.
# Requires userspace governor to be available.
# Do not set governor field if you use this one.
#freq=

# Utilizes cores in one processor package/socket first before processes are  
# scheduled to other processor packages/sockets.
# See man (1) CPUPOWER-SET for additional details.
#mc_scheduler=

# Utilizes thread siblings of one processor core first before processes are
# scheduled to other cores. See man (1) CPUPOWER-SET for additional details.
#smp_scheduler=

#  Sets a register on supported Intel processore which allows software to convey
# its policy for the relative importance of performance versus energy savings to
# the  processor. See man (1) CPUPOWER-SET for additional details.
#perf_bias=

# vim:set ts=2 sw=2 ft=sh et:

我们依葫芦画瓢,按文件的第七、第八行,填入max_freq="700MHz"后保存退出重启开机,频率就被默认限制到700Mhz了!

至此,这台苏菲总算变得轻快好使了,让它机如其名,正真的GO起来。

后话:死机了咋整

记不记得以前山寨机和电视机顶盒,总会有一个reset按钮,当机器死机的时候拿根牙签戳一下,设备就会强制重启?
对你没看错,Linux内核也给我们提供了这个功能!
对于表面走3这电子垃圾再合适不过了

根据Arch Wiki上的说法,我们只要启用sysrq这个调用,就可以实现一些用户主动触发的控制内核行为:

Kernel (SysRq)
There are several low level shortcuts that are implemented in the kernel via the SysRq key which can be used for debugging and recovering from an unresponsive system. Whenever possible, it is recommended that you use these shortcuts instead of doing a hard shutdown (holding down the power button to completely power off the system).


提示
SysRq键被映射到键盘上的Prt Scn功能键上了。注意使用的时候不要按下Fn否则(Surface Go 键盘上)触发的是F8而不是SysRq了。

启用它也很简单,只需要在终端运行sysctl kernel.sysrq=1 或者 echo "1" > /proc/sys/kernel/sysrq,然后就会自动启用这个功能。
但每次开机都得输一次,多麻烦!所以贴心的Linus先生给我们提供了一种传递内核参数的方式:将sysrq_always_enabled=1这段内核参数添加到grub里。最后你的grub启动脚本应该是这样的:

file
1
2
3
4
5
6
7
8
9
10
11
12
menuentry 'Arch Linux - linux-surface' --class arch --class gnu-linux --class gnu --class os {  
       load_video
       set gfxpayload=keep
       insmod gzio
       insmod part_gpt
       insmod fat
       search --no-floppy --fs-uuid --set=root 8848-8848
       echo    'Loading Linux linux-surface ...'
       linux   /vmlinuz-linux-surface root=UUID=11451419-8848-2333-8848-114514191981 rw loglevel=3 sysrq_always_enabled=1
       echo    'Loading initial ramdisk ...'
       initrd  /intel-ucode.img /initramfs-linux-surface.img
}

这样你每次开机之后都默认启用了SysRq。

那么问题来了,死机之后怎么调用它来强行重启呢?
继续看Arch Wiki给我们的一张表:

Keyboard Shortcut Description Code to Enable Other Functions Enabled
Alt+SysRq+r Unraw Take control of keyboard back from X. 4 Alt+SysRq+k SAK
Alt+SysRq+e Terminate Send SIGTERM to all processes, allowing them to terminate gracefully. 64 Alt+SysRq+f OOM kill
Alt+SysRq+j Thaw
Alt+SysRq+i Kill Send SIGKILL to all processes, forcing them to terminate immediately.
Alt+SysRq+s Sync Flush data to disk. 16 -
Alt+SysRq+u Unmount Unmount and remount all filesystems read-only. 32 -
Alt+SysRq+b Reboot Reboot 128 -

也就是说,强制重启只需要按组合键alt 截屏 b就行。
有没有找回一点当年山寨机顶盒的感觉2333


如何在没有220v插座的图书馆优雅的用Surface Go 3码字
http://blog.coolenoch.ink/2023/10/29/5如何在没有220v插座的图书馆优雅的用Surface Go 3码字-231029/
作者
CoolestEnoch
发布于
2023年10月29日
许可协议