Skip to content

Commit 94f271c

Browse files
shlomibittonjudyjoseph
authored andcommitted
[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 f1ec710 commit 94f271c

File tree

7 files changed

+70
-9
lines changed

7 files changed

+70
-9
lines changed

files/build_templates/init_cfg.json.j2

Lines changed: 2 additions & 2 deletions
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

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

@@ -771,6 +771,19 @@ if [ -f {{service}} ]; then
771771
echo "{{service}}" | sudo tee -a $GENERATED_SERVICE_FILE
772772
fi
773773
{% endfor %}
774+
{% for timer in installer_timers.split(' ') -%}
775+
if [ -f {{timer}} ]; then
776+
sudo cp {{timer}} $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
777+
778+
{% if "@" in timer %}
779+
MULTI_INSTANCE="{{timer}}"
780+
SINGLE_INSTANCE=${MULTI_INSTANCE/"@"}
781+
sudo cp $SINGLE_INSTANCE $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
782+
{% endif %}
783+
784+
echo "{{timer}}" | sudo tee -a $GENERATED_SERVICE_FILE
785+
fi
786+
{% endfor %}
774787
if [ -f iccpd.service ]; then
775788
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl disable iccpd.service
776789
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
@@ -1092,6 +1092,14 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
10921092
$(eval $(docker:-dbg.gz=.gz)_GLOBAL = yes)
10931093
)
10941094
fi
1095+
if [ -f files/build_templates/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 ]; then
1096+
j2 files/build_templates/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer
1097+
1098+
# Set the flag GLOBAL_TIMER for all the global system-wide dockers timers.
1099+
$(if $(shell ls files/build_templates/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 2>/dev/null),\
1100+
$(eval $(docker:-dbg.gz=.gz)_GLOBAL_TIMER = yes)
1101+
)
1102+
fi
10951103
# Any service template, inside instance directory, will be used to generate .service and @.service file.
10961104
if [ -f files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 ]; then
10971105
export multi_instance="true"
@@ -1102,6 +1110,16 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
11021110
export multi_instance="false"
11031111
j2 files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service
11041112
fi
1113+
# Any timer template, inside instance directory, will be used to generate .timer and @.timer file.
1114+
if [ -f files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 ]; then
1115+
export multi_instance="true"
1116+
j2 files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME)@.timer
1117+
$(if $(shell ls files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 2>/dev/null),\
1118+
$(eval $(docker:-dbg.gz=.gz)_TEMPLATE_TIMER = yes)
1119+
)
1120+
export multi_instance="false"
1121+
j2 files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer
1122+
fi
11051123
# Any service template, inside share_image directory, will be used to generate -chassis.service file.
11061124
# TODO: need better way to name the image-shared service
11071125
if [ -f files/build_templates/share_image/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 ]; then
@@ -1139,7 +1157,20 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
11391157
$(eval SERVICES += "$(addsuffix -chassis.service, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))")
11401158
)
11411159
)
1160+
# Marks template timers with an "@" according to systemd convention
1161+
# If the $($docker)_TEMPLATE_TIMER) variable is set, the timer will be treated as a template
1162+
# If the $($docker)_GLOBAL_TIMER) and $($docker)_TEMPLATE_TIMER) variables are set the timer will be added both as a global and template timer.
1163+
$(foreach docker, $($*_DOCKERS),\
1164+
$(if $($(docker:-dbg.gz=.gz)_TEMPLATE_TIMER),\
1165+
$(if $($(docker:-dbg.gz=.gz)_GLOBAL_TIMER),\
1166+
$(eval TIMERS += "$(addsuffix .timer, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))")\
1167+
)\
1168+
$(eval TIMERS += "$(addsuffix @.timer, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))"),\
1169+
$(eval TIMERS += "$(addsuffix .timer, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))")
1170+
)
1171+
)
11421172
export installer_services="$(SERVICES)"
1173+
export installer_timers="$(TIMERS)"
11431174

11441175
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)))"
11451176

0 commit comments

Comments
 (0)