Skip to content

Commit 1d84e0d

Browse files
authored
[Fastboot] Delay LLDP service for better fastboot performance (#10568)
- 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. This PR is dependent on PR: #10567
1 parent bc30528 commit 1d84e0d

File tree

7 files changed

+70
-9
lines changed

7 files changed

+70
-9
lines changed

files/build_templates/init_cfg.json.j2

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
{%- set features = [("bgp", "enabled", false, "enabled"),
3131
("database", "always_enabled", false, "always_enabled"),
32-
("lldp", "enabled", false, "enabled"),
32+
("lldp", "enabled", true, "enabled"),
3333
("pmon", "enabled", false, "enabled"),
3434
("radv", "enabled", false, "enabled"),
3535
("snmp", "enabled", true, "enabled"),
@@ -83,6 +83,6 @@
8383
"state" : "disabled", {% endif %}
8484
"rate_limit_interval" : "600"
8585
}{%if not loop.last %},{% endif -%}
86-
{% endfor %}
86+
{% endfor %}
8787
}
8888
}

files/build_templates/lldp.timer.j2

+1
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

-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,3 @@ ExecStartPre=/usr/local/bin/{{docker_container_name}}.sh start{% if multi_instan
2020
ExecStart=/usr/local/bin/{{docker_container_name}}.sh wait{% if multi_instance == 'true' %} %i{% endif %}
2121
ExecStop=/usr/local/bin/{{docker_container_name}}.sh stop{% if multi_instance == 'true' %} %i{% endif %}
2222
RestartSec=30
23-
24-
[Install]
25-
WantedBy=sonic.target
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

+14-1
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ fi
655655
## ensure proc is mounted
656656
sudo mount proc /proc -t proc || true
657657
if [[ $CONFIGURED_ARCH == armhf ]]; then
658-
# A workaround to fix the armhf build hung issue, caused by sonic-platform-nokia-7215_1.0_armhf.deb post installation script
658+
# A workaround to fix the armhf build hung issue, caused by sonic-platform-nokia-7215_1.0_armhf.deb post installation script
659659
ps -eo pid,cmd | grep python | grep "/etc/entropy.py" | awk '{print $1}' | xargs sudo kill -9 2>/dev/null || true
660660
fi
661661

@@ -774,6 +774,19 @@ if [ -f {{service}} ]; then
774774
echo "{{service}}" | sudo tee -a $GENERATED_SERVICE_FILE
775775
fi
776776
{% endfor %}
777+
{% for timer in installer_timers.split(' ') -%}
778+
if [ -f {{timer}} ]; then
779+
sudo cp {{timer}} $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
780+
781+
{% if "@" in timer %}
782+
MULTI_INSTANCE="{{timer}}"
783+
SINGLE_INSTANCE=${MULTI_INSTANCE/"@"}
784+
sudo cp $SINGLE_INSTANCE $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
785+
{% endif %}
786+
787+
echo "{{timer}}" | sudo tee -a $GENERATED_SERVICE_FILE
788+
fi
789+
{% endfor %}
777790
if [ -f iccpd.service ]; then
778791
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl disable iccpd.service
779792
fi

files/scripts/syncd.sh

+10-3
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,19 @@ function startplatform() {
4444
}
4545

4646
function waitplatform() {
47-
47+
4848
if [[ x"$sonic_asic_platform" == x"mellanox" ]]; then
4949
debug "Starting pmon service..."
5050
/bin/systemctl start pmon
5151
debug "Started pmon service"
5252
fi
53+
if [[ x"$BOOT_TYPE" = @(x"fast"|x"warm"|x"fastfast") ]]; then
54+
debug "LLDP service is delayed by a timer for better fast/warm boot performance"
55+
else
56+
debug "Starting lldp service..."
57+
/bin/systemctl start lldp
58+
debug "Started lldp service"
59+
fi
5360
}
5461

5562
function stopplatform1() {
@@ -64,7 +71,7 @@ function stopplatform1() {
6471
debug "${TYPE} shutdown syncd process ..."
6572
/usr/bin/docker exec -i syncd$DEV /usr/bin/syncd_request_shutdown --${TYPE}
6673

67-
# wait until syncd quits gracefully or force syncd to exit after
74+
# wait until syncd quits gracefully or force syncd to exit after
6875
# waiting for 20 seconds
6976
start_in_secs=${SECONDS}
7077
end_in_secs=${SECONDS}
@@ -76,7 +83,7 @@ function stopplatform1() {
7683
done
7784

7885
if [[ $((end_in_secs - start_in_secs)) -gt $timer_threshold ]]; then
79-
debug "syncd process in container syncd$DEV did not exit gracefully"
86+
debug "syncd process in container syncd$DEV did not exit gracefully"
8087
fi
8188

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

slave.mk

+31
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,14 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
11621162
$(eval $(docker:-dbg.gz=.gz)_GLOBAL = yes)
11631163
)
11641164
fi
1165+
if [ -f files/build_templates/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 ]; then
1166+
j2 files/build_templates/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer
1167+
1168+
# Set the flag GLOBAL_TIMER for all the global system-wide dockers timers.
1169+
$(if $(shell ls files/build_templates/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 2>/dev/null),\
1170+
$(eval $(docker:-dbg.gz=.gz)_GLOBAL_TIMER = yes)
1171+
)
1172+
fi
11651173
# Any service template, inside instance directory, will be used to generate .service and @.service file.
11661174
if [ -f files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 ]; then
11671175
export multi_instance="true"
@@ -1172,6 +1180,16 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
11721180
export multi_instance="false"
11731181
j2 files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service
11741182
fi
1183+
# Any timer template, inside instance directory, will be used to generate .timer and @.timer file.
1184+
if [ -f files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 ]; then
1185+
export multi_instance="true"
1186+
j2 files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME)@.timer
1187+
$(if $(shell ls files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 2>/dev/null),\
1188+
$(eval $(docker:-dbg.gz=.gz)_TEMPLATE_TIMER = yes)
1189+
)
1190+
export multi_instance="false"
1191+
j2 files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer
1192+
fi
11751193
# Any service template, inside share_image directory, will be used to generate -chassis.service file.
11761194
# TODO: need better way to name the image-shared service
11771195
if [ -f files/build_templates/share_image/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 ]; then
@@ -1209,7 +1227,20 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
12091227
$(eval SERVICES += "$(addsuffix -chassis.service, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))")
12101228
)
12111229
)
1230+
# Marks template timers with an "@" according to systemd convention
1231+
# If the $($docker)_TEMPLATE_TIMER) variable is set, the timer will be treated as a template
1232+
# If the $($docker)_GLOBAL_TIMER) and $($docker)_TEMPLATE_TIMER) variables are set the timer will be added both as a global and template timer.
1233+
$(foreach docker, $($*_DOCKERS),\
1234+
$(if $($(docker:-dbg.gz=.gz)_TEMPLATE_TIMER),\
1235+
$(if $($(docker:-dbg.gz=.gz)_GLOBAL_TIMER),\
1236+
$(eval TIMERS += "$(addsuffix .timer, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))")\
1237+
)\
1238+
$(eval TIMERS += "$(addsuffix @.timer, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))"),\
1239+
$(eval TIMERS += "$(addsuffix .timer, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))")
1240+
)
1241+
)
12121242
export installer_services="$(SERVICES)"
1243+
export installer_timers="$(TIMERS)"
12131244

12141245
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)))"
12151246

0 commit comments

Comments
 (0)