共计 2086 个字符,预计需要花费 6 分钟才能阅读完成。
之前在 Android 过程调度中介绍过 Android 应用的调度策略。Android 对调度策略和优先级的治理是很审慎的,个别状况下不须要利用和服务调整本人的优先级。然而,一些有零碎开发能力的厂商有时会对优先级进行批改。如果没有通过充分考虑,可能会对系统运行产生不良影响,尤其是批改实时调度策略。
Linux kernel RT priority
目前,Linux 对实时调度的优先级治理是比拟宽泛的,能够在 0~99 间调整优先级。然而,这样也同样带来了优先级治理问题。社区大神就有埋怨这个问题(Controlling realtime priorities in kernel threads),提交了补丁来勾销实时调度优先级调整的大部分能力。先看一下以后内核中对 SCHED_FIFO 优先级的治理。
Subsystem | Priority | Description |
---|---|---|
Arm bL switcher | 1 | The Arm big.LITTLE switcher thread |
crypto | 50 | Crypto engine worker thread |
ACPI | 1 | ACPI processor aggregator driver |
drbd | 2 | Distributed, replicated block device request handling |
PSCI checker | 99 | PSCI firmware hotplug/suspend functionality checker |
msm | 16 | MSM GPU driver |
DRM | 1 | Direct rendering request scheduler |
ivtv | 99 | Conexant cx23416/cx23415 MPEG encoder/decoder driver |
mmc | 1 | MultiMediaCard drivers |
cros_ec_spi | 50 | ChromeOS embedded controller SPI driver |
powercap | 50 | “Powercap” idle-injection driver |
powerclamp | 50 | Intel powerclamp thermal management subsystem |
sc16is7xx | 50 | NXP SC16IS7xx serial port driver |
watchdog | 99 | Watchdog timer driver subsystem |
irq | 50 | Threaded interrupt handling |
locktorture | 99 | Locking torture-testing module |
rcuperf | 1 | Read-copy-update performance tester |
rcutorture | 1 | Read-copy-update torture tester |
sched/psi | 1 | Pressure-stall information data gathering |
从上表能够看出,Kernel 中实时调度的优先级次要集中在三个地位:高优先级(99)、失常优先级(50)、低优先级(1)。所以,其实并不需要太多优先级的阶层,过多只会带来凌乱。
Android RT priority
Android 对于实时调度优先级的设置是通过三思而行的,要保障实时性又不能烦扰内核运行。其中,Sensor 设置了很高的优先级,因为其对实时性非常敏感。其余的实时调度线程都维持在低优先级上,同样因为音频对工夫敏感,而赋予了绝对高的优先级,但还是维持在低优先级上。下表列出 Android 零碎 (9.0) 中实时调度优先级的配置,
Subsystem | Priority | Description |
---|---|---|
SensorManager EventQueue | 98 | SensorManager EventQueue thread |
SensorManager | 10 | SensorManager looper |
FastMixer/FastCapture | 3 | AudioFlinger fast mixer and fast capture |
AudioApp | 2 | AudioFlinger playback or record threads |
Audio HAL | 3/2 | Flow AudioFlinger |
AAudioService | 2 | Aaudio threads |
SurfaceFlinger | 2 | SurfaceFlinger Main, DispSync and Event threads. |
CameraService | 1 | When “camera.fifo.disable” isn’t 1. |
SurfaceFlinger handleMessage | 1 | SCHED_FIFO when the display is turned on, SCHED_OTHER when turned off. |
UI and RenderThreads | 1 | ActivityManagerService use SCHED_FIFO for UI and RenderThreads if “sys.use_fifo_ui” isn’t 0. |
下面的两个表格总结了 Linux kernel 和 Android 零碎中实时调度策略优先级的配置,零碎开发人员能够做为参考。当开发人员须要批改或配置本人的实时调度策略是,须要充沛了解以后优先级的状态,以及应用实时调度策略的目标,从而抉择一个适合的优先级。
正文完