Merge "[bugfix][T106][bug-view-1890] Delay the fota backup process by 10 minutes and reduce the cpu usage to 20%" into INTEST_PM_SDK6.1_2WIFI
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
index 0ff4c1a..c7ed9ed 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
+++ b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
@@ -95,6 +95,8 @@
#dm-verity for squashfs
DISTRO_FEATURES += " dm-verity "
+#support cgroup
+DISTRO_FEATURES += " cgroup "
#CUSTOM_MACRO在各个产品不变的宏放到cpe-base.inc文件,变化的宏放在产品发布文件。
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-core/images/files/zx297520v3/vehicle_dc_ref/fs/normal/rootfs/etc/init.d/first.sh b/cap/zx297520v3/sources/meta-zxic-custom/recipes-core/images/files/zx297520v3/vehicle_dc_ref/fs/normal/rootfs/etc/init.d/first.sh
index 285cdd5..b01f11b 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/recipes-core/images/files/zx297520v3/vehicle_dc_ref/fs/normal/rootfs/etc/init.d/first.sh
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-core/images/files/zx297520v3/vehicle_dc_ref/fs/normal/rootfs/etc/init.d/first.sh
@@ -46,6 +46,22 @@
mount -t devpts devpts /dev/pts
mkdir -p /tmp/run
+#support cgroup
+if [ -e /sys/fs/cgroup ]; then
+ mount -t tmpfs cgroup /sys/fs/cgroup
+ #mkdir -p /sys/fs/cgroup/cpuset
+ #mount -t cgroup -o cpuset cpuset /sys/fs/cgroup/cpuset
+ mkdir -p /sys/fs/cgroup/cpu,cpuacct
+ mount -t cgroup -o cpu,cpuacct cgroup /sys/fs/cgroup/cpu,cpuacct
+ mkdir -p /sys/fs/cgroup/memory
+ mount -t cgroup -o memory cgroup /sys/fs/cgroup/memory
+ cd /sys/fs/cgroup
+ ln -s /sys/fs/cgroup/cpu,cpuacct cpu
+ ln -s /sys/fs/cgroup/cpu,cpuacct cpuacct
+fi
+
+
+
#软锁panic
#echo 1 > /proc/sys/kernel/softlockup_panic
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-kernel/linux/files/zx297520v3/cgroup.cfg b/cap/zx297520v3/sources/meta-zxic-custom/recipes-kernel/linux/files/zx297520v3/cgroup.cfg
new file mode 100644
index 0000000..d72754a
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-kernel/linux/files/zx297520v3/cgroup.cfg
@@ -0,0 +1,7 @@
+CONFIG_CGROUP_SCHED=y
+CONFIG_CGROUP_PIDS=y
+CONFIG_CGROUP_CPUACCT=y
+CONFIG_FAIR_GROUP_SCHED=y
+CONFIG_CFS_BANDWIDTH=y
+CONFIG_CGROUPS=y
+
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-kernel/linux/linux-zxic_5.10.bbappend b/cap/zx297520v3/sources/meta-zxic-custom/recipes-kernel/linux/linux-zxic_5.10.bbappend
index 3d328f4..ac8c86c 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/recipes-kernel/linux/linux-zxic_5.10.bbappend
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-kernel/linux/linux-zxic_5.10.bbappend
@@ -4,4 +4,5 @@
file://${LINUX_CONFIG} \
${@bb.utils.contains('DISTRO_FEATURES', 'OPTEE', 'file://optee.cfg', '', d)} \
${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity', 'file://dm-verity.cfg', '', d)} \
-"
\ No newline at end of file
+ ${@bb.utils.contains('DISTRO_FEATURES', 'cgroup', 'file://cgroup.cfg', '', d)} \
+"
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-fota-backup/lynq-fota-backup.sh b/cap/zx297520v3/src/lynq/framework/lynq-fota-backup/lynq-fota-backup.sh
index 53eb20f..8013112 100644
--- a/cap/zx297520v3/src/lynq/framework/lynq-fota-backup/lynq-fota-backup.sh
+++ b/cap/zx297520v3/src/lynq/framework/lynq-fota-backup/lynq-fota-backup.sh
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# Run the daemon
+# Run the daemon with CPU cgroup limitation
#
DAEMON="lynq-fota-backup-service"
@@ -8,11 +8,52 @@
EXEC="/usr/bin/lynq-fota-backup"
EXEC_ARGS=""
+# Cgroup配置
+CGROUP_NAME="fota_backup"
+CGROUP_PATH="/sys/fs/cgroup/cpu/$CGROUP_NAME"
+CPU_LIMIT="20000" # 20% CPU (100000 = 100%)
+
+# 创建Cgroup并设置CPU限制
+setup_cgroup() {
+ if [ ! -d "$CGROUP_PATH" ]; then
+ mkdir -p "$CGROUP_PATH"
+ echo "$CPU_LIMIT" > "$CGROUP_PATH/cpu.cfs_quota_us"
+ echo "100000" > "$CGROUP_PATH/cpu.cfs_period_us"
+ echo "Cgroup $CGROUP_NAME created with 20% CPU limit"
+ else
+ echo "Cgroup $CGROUP_NAME already exists, updating limit"
+ echo "$CPU_LIMIT" > "$CGROUP_PATH/cpu.cfs_quota_us"
+ fi
+}
+
+# 将进程添加到Cgroup
+add_to_cgroup() {
+ PID=$1
+ if [ -d "$CGROUP_PATH" ]; then
+ echo "$PID" > "$CGROUP_PATH/tasks"
+ echo -n "Process $PID added to Cgroup $CGROUP_NAME"
+ else
+ echo -n "ERROR: Cgroup $CGROUP_PATH does not exist!"
+ fi
+}
start() {
- echo -n "Starting $DAEMON... "
- start-stop-daemon --no-close -S -b -m -p $PIDFILE -x $EXEC -- $EXEC_ARGS
- [ $? -eq 0 ] && echo "OK" || echo "ERROR"
+ sleep 600
+ echo "Starting $DAEMON with 20% CPU limit... "
+ setup_cgroup
+ start-stop-daemon --no-close -S -b -m -p $PIDFILE -x $EXEC -- $EXEC_ARGS
+ RETVAL=$?
+ if [ $RETVAL -eq 0 ]; then
+ PID=$(cat $PIDFILE 2>/dev/null)
+ if [ -n "$PID" ]; then
+ add_to_cgroup "$PID"
+ else
+ echo "WARNING: Failed to read PID from $PIDFILE"
+ fi
+ echo "OK"
+ else
+ echo "ERROR"
+ fi
}
stop() {
@@ -22,18 +63,22 @@
}
restart() {
- stop
- start
+ stop
+ start &
}
case "$1" in
- start|stop|restart)
+ start)
+ start &
+ ;;
+ stop|restart)
"$1"
;;
- *)
+ *)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
+