Anolis开源plugsched 是 Linux 内核调度器子系统热升级的 SDK,它可以实现在不重启系统、应用的情况下动态替换调度器子系统。
龙蜥实验室中2核的机器1小时的时间不能完成内核的编译,需要阿里云ECS创建一台16核以上的按量计费机器,安装 Anolis OS 7.9 ANCK镜像,下载的kernel源码包是匹配这个版本的系统
因为需要编译内核,所以占用cpu较多,其他模块占用cpu较少
plugsched sdk在容器中可以找到
运行的脚本内容为以下内容,按 https://gitee.com/anolis/plugsched 说明整理,包括debuginfo包安装,容器启动,编译rpm包,安装rpm包,测试等过程,都在脚本中完成
# Anolis OS 7.9 ANCK 使用
echo "=====安装 debuginfo====="
yum install anolis-repos -y
yum install yum-utils podman kernel-debuginfo-$(uname -r) kernel-devel-$(uname -r) --enablerepo=Plus-debuginfo --enablerepo=Plus -y
# yum install 如果没有安装debuginfo包,这里下载后安装
wget -c https://mirrors.openanolis.cn/anolis/7.9/Plus/x86_64/debug/Packages/kernel-debuginfo-common-x86_64-$(uname -r).rpm
rpm -ivh kernel-debuginfo-common-x86_64-$(uname -r).rpm
wget -c https://mirrors.openanolis.cn/anolis/7.9/Plus/x86_64/debug/Packages/kernel-debuginfo-$(uname -r).rpm
rpm -ivh kernel-debuginfo-$(uname -r).rpm
mkdir /tmp/work && cd /tmp/work
yumdownloader --source kernel-$(uname -r) --enablerepo=Plus --enablerepo=Plus-debuginfo
wget -c https://mirrors.openanolis.cn/anolis/7.9/Plus/source/Packages/kernel-4.19.91-25.7.an7.src.rpm
# 启动容器
podman run -itd --name=plugsched -v /tmp/work:/tmp/work -v /usr/src/kernels:/usr/src/kernels -v /usr/lib/debug/lib/modules:/usr/lib/debug/lib/modules docker.io/plugsched/plugsched-sdk
echo "=====创建 rpm====="
cat >/tmp/work/core.diff <<EOF
diff --git a/scheduler/kernel/sched/mod/core.c b/scheduler/kernel/sched/mod/core.c
index 9f16b72..21262fd 100644
--- a/scheduler/kernel/sched/mod/core.c
+++ b/scheduler/kernel/sched/mod/core.c
@@ -3234,6 +3234,9 @@ static void __sched notrace __schedule(bool preempt)
struct rq *rq;
int cpu;
+ if (sched_feat(PLUGSCHED_TEST))
+ printk_once("I am the new scheduler: __schedule\n");
+
cpu = smp_processor_id();
rq = cpu_rq(cpu);
prev = rq->curr;
diff --git a/scheduler/kernel/sched/mod/features.h b/scheduler/kernel/sched/mod/features.h
index 4c40fac..8d1eafd 100644
--- a/scheduler/kernel/sched/mod/features.h
+++ b/scheduler/kernel/sched/mod/features.h
@@ -1,4 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
+SCHED_FEAT(PLUGSCHED_TEST, false)
+
/*
* Only give sleepers 50% of their service deficit. This allows
* them to run sooner, but does not allow tons of sleepers to
EOF
cat >/tmp/work/create_rpm.sh <<EOF
set -x
cd /tmp/work
uname_r=\$(uname -r)
plugsched-cli extract_src kernel-\${uname_r%.*}.src.rpm ./kernel
plugsched-cli init $(uname -r) ./kernel ./scheduler
patch -p1 <core.diff
plugsched-cli build /tmp/work/scheduler
cp /usr/local/lib/plugsched/rpmbuild/RPMS/x86_64/scheduler-xxx-\${uname_r%.*}.yyy.x86_64.rpm /tmp/work/scheduler-xxx.rpm
EOF
# 执行容器中命令
podman exec plugsched bash /tmp/work/create_rpm.sh
echo "=====安装 scheduler====="
cat /sys/kernel/debug/sched_features
rpm -ivh /tmp/work/scheduler-xxx.rpm
lsmod | grep scheduler
dmesg | tail -n 10
cat /sys/kernel/debug/sched_features
echo PLUGSCHED_TEST > /sys/kernel/debug/sched_features
dmesg | tail -n 5
echo "=====移除 scheduler====="
rpm -e scheduler-xxx
dmesg | tail -n 8
cat /sys/kernel/debug/sched_features