Skip to content

Commit bca8a24

Browse files
authored
[202012] [Fastboot] Delay LLDP service for better fastboot performance (#10568) (#10744)
This PR is to backport a fix #10568 This PR is dependent on PR: #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, LLDP is delayed in 90 seconds until the system finish the init flow after fastboot. - How I did it Add a timer for LLDP service. 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.
1 parent 4f326e8 commit bca8a24

File tree

7 files changed

+68
-7
lines changed

7 files changed

+68
-7
lines changed

files/build_templates/init_cfg.json.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{%- set features = [("bgp", "enabled", false, "enabled"),
2222
("database", "always_enabled", false, "always_enabled"),
2323
("dhcp_relay", "enabled", false, "enabled"),
24-
("lldp", "enabled", false, "enabled"),
24+
("lldp", "enabled", true, "enabled"),
2525
("pmon", "enabled", false, "enabled"),
2626
("radv", "enabled", false, "enabled"),
2727
("snmp", "enabled", true, "enabled"),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
per_namespace/lldp.timer.j2

files/build_templates/per_namespace/lldp.service.j2

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,3 @@ ExecStart=/usr/bin/{{docker_container_name}}.sh wait{% if multi_instance == 'tru
2121
ExecStop=/usr/bin/{{docker_container_name}}.sh stop{% if multi_instance == 'true' %} %i{% endif %}
2222
Restart=always
2323
RestartSec=30
24-
25-
[Install]
26-
WantedBy=sonic.target
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
# This delay is for fast/warm reboot performance
3+
Description=Delays LLDP docker until SONiC has started
4+
PartOf=lldp{% if multi_instance == 'true' %}@%i{% endif %}.service
5+
6+
[Timer]
7+
OnUnitActiveSec=0 sec
8+
OnBootSec=1min 30 sec
9+
Unit=lldp{% if multi_instance == 'true' %}@%i{% endif %}.service
10+
11+
[Install]
12+
WantedBy=timers.target sonic.target sonic-delayed.target

files/build_templates/sonic_debian_extension.j2

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,19 @@ if [ -f {{service}} ]; then
700700
echo "{{service}}" | sudo tee -a $GENERATED_SERVICE_FILE
701701
fi
702702
{% endfor %}
703+
{% for timer in installer_timers.split(' ') -%}
704+
if [ -f {{timer}} ]; then
705+
sudo cp {{timer}} $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
706+
707+
{% if "@" in timer %}
708+
MULTI_INSTANCE="{{timer}}"
709+
SINGLE_INSTANCE=${MULTI_INSTANCE/"@"}
710+
sudo cp $SINGLE_INSTANCE $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
711+
{% endif %}
712+
713+
echo "{{timer}}" | sudo tee -a $GENERATED_SERVICE_FILE
714+
fi
715+
{% endfor %}
703716
if [ -f iccpd.service ]; then
704717
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl disable iccpd.service
705718
fi

files/scripts/syncd.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,19 @@ function startplatform() {
3636
}
3737

3838
function waitplatform() {
39-
39+
4040
if [[ x"$sonic_asic_platform" == x"mellanox" ]]; then
4141
debug "Starting pmon service..."
4242
/bin/systemctl start pmon
4343
debug "Started pmon service"
4444
fi
45+
if [[ x"$BOOT_TYPE" = @(x"fast"|x"warm"|x"fastfast") ]]; then
46+
debug "LLDP service is delayed by a timer for better fast/warm boot performance"
47+
else
48+
debug "Starting lldp service..."
49+
/bin/systemctl start lldp
50+
debug "Started lldp service"
51+
fi
4552
}
4653

4754
function stopplatform1() {
@@ -56,7 +63,7 @@ function stopplatform1() {
5663
debug "${TYPE} shutdown syncd process ..."
5764
/usr/bin/docker exec -i syncd$DEV /usr/bin/syncd_request_shutdown --${TYPE}
5865

59-
# wait until syncd quits gracefully or force syncd to exit after
66+
# wait until syncd quits gracefully or force syncd to exit after
6067
# waiting for 20 seconds
6168
start_in_secs=${SECONDS}
6269
end_in_secs=${SECONDS}
@@ -68,7 +75,7 @@ function stopplatform1() {
6875
done
6976

7077
if [[ $((end_in_secs - start_in_secs)) -gt $timer_threshold ]]; then
71-
debug "syncd process in container syncd$DEV did not exit gracefully"
78+
debug "syncd process in container syncd$DEV did not exit gracefully"
7279
fi
7380

7481
/usr/bin/docker exec -i syncd$DEV /bin/sync

slave.mk

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,14 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
975975
$(eval $(docker:-dbg.gz=.gz)_GLOBAL = yes)
976976
)
977977
fi
978+
if [ -f files/build_templates/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 ]; then
979+
j2 files/build_templates/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer
980+
981+
# Set the flag GLOBAL_TIMER for all the global system-wide dockers timers.
982+
$(if $(shell ls files/build_templates/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 2>/dev/null),\
983+
$(eval $(docker:-dbg.gz=.gz)_GLOBAL_TIMER = yes)
984+
)
985+
fi
978986
# Any service template, inside instance directory, will be used to generate .service and @.service file.
979987
if [ -f files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 ]; then
980988
export multi_instance="true"
@@ -985,6 +993,16 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
985993
export multi_instance="false"
986994
j2 files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service
987995
fi
996+
# Any timer template, inside instance directory, will be used to generate .timer and @.timer file.
997+
if [ -f files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 ]; then
998+
export multi_instance="true"
999+
j2 files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME)@.timer
1000+
$(if $(shell ls files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 2>/dev/null),\
1001+
$(eval $(docker:-dbg.gz=.gz)_TEMPLATE_TIMER = yes)
1002+
)
1003+
export multi_instance="false"
1004+
j2 files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer
1005+
fi
9881006
# Any service template, inside share_image directory, will be used to generate -chassis.service file.
9891007
# TODO: need better way to name the image-shared service
9901008
if [ -f files/build_templates/share_image/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 ]; then
@@ -1017,7 +1035,20 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
10171035
$(eval SERVICES += "$(addsuffix -chassis.service, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))")
10181036
)
10191037
)
1038+
# Marks template timers with an "@" according to systemd convention
1039+
# If the $($docker)_TEMPLATE_TIMER) variable is set, the timer will be treated as a template
1040+
# If the $($docker)_GLOBAL_TIMER) and $($docker)_TEMPLATE_TIMER) variables are set the timer will be added both as a global and template timer.
1041+
$(foreach docker, $($*_DOCKERS),\
1042+
$(if $($(docker:-dbg.gz=.gz)_TEMPLATE_TIMER),\
1043+
$(if $($(docker:-dbg.gz=.gz)_GLOBAL_TIMER),\
1044+
$(eval TIMERS += "$(addsuffix .timer, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))")\
1045+
)\
1046+
$(eval TIMERS += "$(addsuffix @.timer, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))"),\
1047+
$(eval TIMERS += "$(addsuffix .timer, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))")
1048+
)
1049+
)
10201050
export installer_services="$(SERVICES)"
1051+
export installer_timers="$(TIMERS)"
10211052

10221053
export installer_extra_files="$(foreach docker, $($*_DOCKERS), $(foreach file, $($(docker:-dbg.gz=.gz)_BASE_IMAGE_FILES), $($(docker:-dbg.gz=.gz)_PATH)/base_image_files/$(file)))"
10231054

0 commit comments

Comments
 (0)