跳至內容
出自 Arch Linux 中文维基

scx-scheds 是 scheds-ext 的程序實現,scheds-ext(Scheduler Extensions)是 Linux 的一個可拓展調度器框架,允許在不修改內核代碼的情況下通過 BPF(Berkeley Packet Filter)或 eBPF 來實現自定義調度策略。

安裝

需要先檢查內核是否支持 bpf,使用 root 權限執行指令:

# zcat /proc/config.gz | grep -i BPF

通常情況下會輸出這些內容:

# zcat /proc/config.gz | grep -i BPF
CONFIG_BPF=y
CONFIG_HAVE_EBPF_JIT=y
CONFIG_ARCH_WANT_DEFAULT_BPF_JIT=y
.....

如果得到如上結果,代表內核支持 BPF。 安裝 scx-schedsbpf

部署

scx-scheds 安裝後會提供兩個 systemd 服務 scx_loader.servicescx.servicescx.service 是 scx 調度程序,scx_loader.service 則是通過 D-Bus 來實現 scheds-ext 框架加載器和管理器的實用程序。

警告:現在不再推薦使用 scx.service,推薦使用 scx_loader.service ,且不要同時運行,否則它們不會執行任何東西。
警告:在使用 scheds-ext 框架的任何一個調度器時強烈建議禁用停止使用 ananicy-cpp-gitAUR 等相關的包,因為 anaicy-cpp-gitAUR 等相關的包會干擾系統優先級導致 scheds-ext watchdog 超時,使調度程序被「殺死」。

啟用 scx_loader 服務。

scx-scheds 在安裝後會生成一個默認配置文件位於 /etc/default/scx ,用於 scx.service

注意:scx_loader.service 不會使用 /etc/default/scx 配置文件。

配置 scx服務

scx.service 中分為兩個部分: SCX_SCHEDULERSCX_FLAGS

/etc/default/scx
# List of scx_schedulers: scx_bpfland scx_central scx_flash scx_lavd scx_layered scx_nest scx_qmap scx_rlfifo scx_rustland scx_rusty scx_simple scx_userland scx_p2dq scx_tickless
SCX_SCHEDULER=scx_bpfland

# Set custom flags for each scheduler, below is an example of how to use
#SCX_FLAGS='-p -m performance'

SCX_SCHEDULER 為 scx 調度器,總共14個調度器,主要調度器有4個: scx_bpflandscx_rustyscx_flashscx_lavd

SCX_FLAGS 是調度器的啟動參數,例如:

SCX_FLAGS='-p -m performance'

-p 參數表示 啟用每顆CPU的任務優先級劃分-m 表示使用模式, performance 代表 gaming 或 lowlatency (低延遲)。

配置 scx_loader服務

注意: scx_loader 服務的配置文件是不會自動生成的,需要用戶手動配置。

scx_loader 的配置文件有兩個: /etc/scx_loader.toml/etc/scx_loader/config.toml

文件結構為:

/etc/scx_loader/config.toml 
default_sched = "scx_bpfland"
default_mode = "Auto"

[scheds.scx_bpfland]
auto_mode = ["-m","performance"]

default_sched 意思是默認使用的調度器,scxscx_loader 的默認調度器都是 scx_bpfland ,如果欄位為空則什麼都不啟用。 default_mode 指默認啟動模式,主要參數有: "Auto""LowLatency""PowerSave""Gaming""Server" 。如果沒有參數則為默認模式,即 "Auto"[scheds.scx_name] 指對調度器的自定義標誌,把 scx_name 修改為實際的調度程序。參數標誌有: auto_mode , gaming_mode , lowlatency_mode , powersave_modeserver_mode ;每個欄位是一個字符串且每個字符串表示一個參數標誌。如果沒有參數標誌則使用默認。

參考樣本:

/etc/scx_loader.toml 
default_sched = "scx_bpfland"
default_mode = "LowLatency"

[scheds.scx_bpfland]
auto_mode = []
gaming_mode = ["-m", "performance"]
lowlatency_mode = ["-k", "-s", "5000", "-l", "5000"]
powersave_mode = ["-m", "powersave"]

參數標籤

scx_bpfland

  • Gaming Mode : -m performance
  • Low Latency Mode : -s 5000 -S 500 -l 5000
  • PowerSave Mode : -m powersave

scx_rusty

沒有自定義參數標誌,使用默認參數標誌。

scx_lavd

  • Gaming Mode : --performance
  • Low Latency Mode : --performance
  • AutoPower Mode : --autopower
  • PowerSave Mode : --powersave

scx_flash

沒有自定義參數標籤,使用默認參數標籤。

啟動和檢查

通過systemd啟動後,使用root權限進行檢查。通過命令檢查是否啟用以及查看調度器:

# cat /sys/kernel/sched_ext/state /sys/kernel/sched_ext/*/ops 2>/dev/null

回退模式

如果配置文件中未定義特定參數標誌, scx_loader 會自動使用默認的參數標誌。

參見