关于android:Android-系统实时调度优先级

49次阅读

共计 2086 个字符,预计需要花费 6 分钟才能阅读完成。

之前在 Android 过程调度中介绍过 Android 应用的调度策略。Android 对调度策略和优先级的治理是很审慎的,个别状况下不须要利用和服务调整本人的优先级。然而,一些有零碎开发能力的厂商有时会对优先级进行批改。如果没有通过充分考虑,可能会对系统运行产生不良影响,尤其是批改实时调度策略。

Linux kernel RT priority

目前,Linux 对实时调度的优先级治理是比拟宽泛的,能够在 0~99 间调整优先级。然而,这样也同样带来了优先级治理问题。社区大神就有埋怨这个问题(Controlling realtime priorities in kernel threads),提交了补丁来勾销实时调度优先级调整的大部分能力。先看一下以后内核中对 SCHED_FIFO 优先级的治理。

SubsystemPriorityDescription
Arm bL switcher1The Arm big.LITTLE switcher thread
crypto50Crypto engine worker thread
ACPI1ACPI processor aggregator driver
drbd2Distributed, replicated block device request handling
PSCI checker99PSCI firmware hotplug/suspend functionality checker
msm16MSM GPU driver
DRM1Direct rendering request scheduler
ivtv99Conexant cx23416/cx23415 MPEG encoder/decoder driver
mmc1MultiMediaCard drivers
cros_ec_spi50ChromeOS embedded controller SPI driver
powercap50“Powercap” idle-injection driver
powerclamp50Intel powerclamp thermal management subsystem
sc16is7xx50NXP SC16IS7xx serial port driver
watchdog99Watchdog timer driver subsystem
irq50Threaded interrupt handling
locktorture99Locking torture-testing module
rcuperf1Read-copy-update performance tester
rcutorture1Read-copy-update torture tester
sched/psi1Pressure-stall information data gathering

从上表能够看出,Kernel 中实时调度的优先级次要集中在三个地位:高优先级(99)、失常优先级(50)、低优先级(1)。所以,其实并不需要太多优先级的阶层,过多只会带来凌乱。

Android RT priority

Android 对于实时调度优先级的设置是通过三思而行的,要保障实时性又不能烦扰内核运行。其中,Sensor 设置了很高的优先级,因为其对实时性非常敏感。其余的实时调度线程都维持在低优先级上,同样因为音频对工夫敏感,而赋予了绝对高的优先级,但还是维持在低优先级上。下表列出 Android 零碎 (9.0) 中实时调度优先级的配置,

SubsystemPriorityDescription
SensorManager EventQueue98SensorManager EventQueue thread
SensorManager10SensorManager looper
FastMixer/FastCapture3AudioFlinger fast mixer and fast capture
AudioApp2AudioFlinger playback or record threads
Audio HAL3/2Flow AudioFlinger
AAudioService2Aaudio threads
SurfaceFlinger2SurfaceFlinger Main, DispSync and Event threads.
CameraService1When “camera.fifo.disable” isn’t 1.
SurfaceFlinger handleMessage1SCHED_FIFO when the display is turned on, SCHED_OTHER when turned off.
UI and RenderThreads1ActivityManagerService use SCHED_FIFO for UI and RenderThreads if “sys.use_fifo_ui” isn’t 0.

下面的两个表格总结了 Linux kernel 和 Android 零碎中实时调度策略优先级的配置,零碎开发人员能够做为参考。当开发人员须要批改或配置本人的实时调度策略是,须要充沛了解以后优先级的状态,以及应用实时调度策略的目标,从而抉择一个适合的优先级。

正文完
 0