From c71c91e2b0ab4aaef4a9b6ebec60da887912dd4d Mon Sep 17 00:00:00 2001 From: shlomibitton <60430976+shlomibitton@users.noreply.github.com> Date: Mon, 16 May 2022 09:31:32 +0300 Subject: [PATCH] [202012] [Fastboot] Delay PMON service for better fastboot performance (#10745) #### Why I did it Profiling the system state on init after fast-reboot during create_switch function execution, it is possible to see few python scripts running at the same time. This parallel execution consume CPU time and the duration of create_switch is longer than it should be. Following this finding, and the motivation to ensure these services will not interfere in the future, PMON is delayed in 90 seconds until the system finish the init flow after fastboot. #### How I did it Add a timer for PMON service. Exclude for MLNX platform the start trigger of PMON when SYNCD starts in case of fastboot. Copy the timer file to the host bin image. #### How to verify it Run fast-reboot on MLNX platform and observe faster create_switch execution time. --- files/build_templates/init_cfg.json.j2 | 2 +- files/build_templates/pmon.service.j2 | 3 --- files/build_templates/pmon.timer | 12 ++++++++++++ files/build_templates/sonic_debian_extension.j2 | 3 +++ files/scripts/syncd.sh | 11 ++++++++--- 5 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 files/build_templates/pmon.timer diff --git a/files/build_templates/init_cfg.json.j2 b/files/build_templates/init_cfg.json.j2 index b0e6307711..08ae19ef2e 100644 --- a/files/build_templates/init_cfg.json.j2 +++ b/files/build_templates/init_cfg.json.j2 @@ -22,7 +22,7 @@ ("database", "always_enabled", false, "always_enabled"), ("dhcp_relay", "enabled", false, "enabled"), ("lldp", "enabled", true, "enabled"), - ("pmon", "enabled", false, "enabled"), + ("pmon", "enabled", true, "enabled"), ("radv", "enabled", false, "enabled"), ("snmp", "enabled", true, "enabled"), ("swss", "enabled", false, "enabled"), diff --git a/files/build_templates/pmon.service.j2 b/files/build_templates/pmon.service.j2 index 59d9e6c331..a36324fdfe 100644 --- a/files/build_templates/pmon.service.j2 +++ b/files/build_templates/pmon.service.j2 @@ -18,6 +18,3 @@ ExecStart=/usr/bin/{{docker_container_name}}.sh wait ExecStop=/usr/bin/{{docker_container_name}}.sh stop Restart=always RestartSec=30 - -[Install] -WantedBy=sonic.target diff --git a/files/build_templates/pmon.timer b/files/build_templates/pmon.timer new file mode 100644 index 0000000000..2993051607 --- /dev/null +++ b/files/build_templates/pmon.timer @@ -0,0 +1,12 @@ +[Unit] +# This delay is for fast/warm reboot performance +Description=Delays pmon docker until SONiC has started +PartOf=pmon.service + +[Timer] +OnUnitActiveSec=0 sec +OnBootSec=1min 30 sec +Unit=pmon.service + +[Install] +WantedBy=timers.target sonic.target sonic-delayed.target diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 95fcf4e24c..92eac7d890 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -757,6 +757,9 @@ sudo cp $BUILD_TEMPLATES/mgmt-framework.timer $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_S echo "mgmt-framework.timer" | sudo tee -a $GENERATED_SERVICE_FILE {% endif %} +sudo cp $BUILD_TEMPLATES/pmon.timer $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM +echo "pmon.timer" | sudo tee -a $GENERATED_SERVICE_FILE + sudo cp $BUILD_TEMPLATES/sonic.target $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable sonic.target diff --git a/files/scripts/syncd.sh b/files/scripts/syncd.sh index 9f7418bbed..6d26eebf04 100755 --- a/files/scripts/syncd.sh +++ b/files/scripts/syncd.sh @@ -37,10 +37,15 @@ function startplatform() { function waitplatform() { + BOOT_TYPE=`getBootType` if [[ x"$sonic_asic_platform" == x"mellanox" ]]; then - debug "Starting pmon service..." - /bin/systemctl start pmon - debug "Started pmon service" + if [[ x"$BOOT_TYPE" = @(x"fast"|x"warm"|x"fastfast") ]]; then + debug "PMON service is delayed by a timer for better fast/warm boot performance" + else + debug "Starting pmon service..." + /bin/systemctl start pmon + debug "Started pmon service" + fi fi if [[ x"$BOOT_TYPE" = @(x"fast"|x"warm"|x"fastfast") ]]; then debug "LLDP service is delayed by a timer for better fast/warm boot performance"