什么使得’pulseaudio’过程能够获得-11的良好水平?

我注意到我的Gentoo Linux机器上的pulseaudio进程具有-11的良好级别.但我不知道它是如何获得如此高优先级的,无论是否由普通用户拥有.

我知道非root用户可以使用nice命令启动一个优先级低于0的程序,如果我们尝试给进程一个比0更高的优先级,则说“权限被拒绝”.

因为pulseaudio进程是由我(非root用户)拥有的,所以我认为没有任何特殊处理就无法获得如此高的优先级.

所以,我的问题是什么“治疗”确实使pulseaudio具有低的niceness值.

最佳答案
PulseAudio需要比其他桌面程序更高的优先级,主要是为了避免延迟问题并获得无跳过的音频播放.但允许PulseAudio具有更高优先级的过程相当复杂.

要获得此特殊优先级,它将使用RealtimeKit(rtkit-daemon)进程.此D-Bus服务允许某些用户程序使用实时调度并执行一些严格的策略以防止滥用:

  • Only clients with RLIMIT_RTTIME set will get RT scheduling.
    • 07001: Specifies a limit on the amount of CPU time that a process scheduled under a real-time scheduling policy may consume without making a blocking system call
  • RT scheduling will only be handed out to processes with SCHED_RESET_ON_FORK set to guarantee that the scheduling settings cannot ‘leak’ to child processes, thus making sure that ‘RT fork bombs’ cannot be used to bypass RLIMIT_RTTIME and take the system down.
    • 07002: If set this will make sure that when the process forks a) the scheduling priority is reset to DEFAULT_PRIO if it was higher and b) the scheduling policy is reset to SCHED_NORMAL if it was either SCHED_FIFO or SCHED_RR.
  • Limits are enforced on all user controllable resources, only a maximum number of users, processes, threads can request RT scheduling at the same time.
  • Only a limited number of threads may be made RT in a specific time frame.
  • Client authorization is verified with 07003.

[…] it includes a canary-based watchdog that automatically demotes
all real-time threads to SCHED_OTHER should the system overload despite the logic pointed out above. For more information regarding 07004 […]

更多相关信息:

> RealtimeKit and the audio problem
> RealtimeKit announcement on the LAD (Linux-Sound) list
> PulseAudio set_scheduler(int rtprio) function source that implements this

转载注明原文:什么使得’pulseaudio’过程能够获得-11的良好水平? - 代码日志