Skip to content

Commit

Permalink
Replace straightforward sonic-cfggen calls with sonic-db-cli (#20232)
Browse files Browse the repository at this point in the history
### Why I did it

Fix #20048

It is explained in ticket above, how sonic-cfggen calls in the hostname.sh, pcie-check.sh and banner-config and hogging the CPU and slightly delaying the start of swss

**pcie-check.sh**
redis-cli call is also replaced with sonic-db-cli since redis-cli is a wrapper around the actual redis-cli under database container
<img width="1113" alt="image" src="https://github.com/user-attachments/assets/bed9d055-3b9f-4f75-aabd-1e0335716396">

**swss start**
If the SKU has create_only_config_db_buffers.json set to true, the only config that's updated today is. 
```
{
    "DEVICE_METADATA": {
        "localhost": {
            "create_only_config_db_buffers": "true"
        }
    }
}
```
We use sonic-cfggen which cause 1.5 sec delay in the start of swss container. Thus replace with sonic-db-cli. If a complex use case arises in future, this can be updated.
<img width="1483" alt="Screenshot 2024-09-16 at 12 45 05 PM" src="https://github.com/user-attachments/assets/ee3248b5-7623-42c4-9b50-81b114c71ae7">


### How I did it

#### How to verify it

**Note: Everything was tested on MSN2700 device, Intel Celeron CPU with 2 cores**

- 1.5 sec saved in the swss container start
<img width="1298" alt="image" src="https://github.com/user-attachments/assets/817739f1-26a2-41ad-89e4-1e76e31532ac">

- 1.6 sec saved in the start of swss service. Previously, it took almost 1.8 sec after config-setup is finished for the swss to start. After replacing the calls, it start almost 0.2 sec after config-setup is finished

In total, anywhere between 2.5 - 3.5 sec is saved
  • Loading branch information
vivekrnv authored Oct 4, 2024
1 parent e18cecb commit 81f1bf4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion files/build_templates/docker_image_ctl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ start() {
if [ -d "$HWSKU_FOLDER" ]; then
CREATE_ONLY_CONFIG_DB_BUFFERS_JSON="$HWSKU_FOLDER/create_only_config_db_buffers.json"
if [ -f "$CREATE_ONLY_CONFIG_DB_BUFFERS_JSON" ]; then
$SONIC_CFGGEN -j $CREATE_ONLY_CONFIG_DB_BUFFERS_JSON --write-to-db
$SONIC_DB_CLI CONFIG_DB HSET 'DEVICE_METADATA|localhost' create_only_config_db_buffers true
fi
fi
{%- endif %}
Expand Down
8 changes: 4 additions & 4 deletions files/image_config/bannerconfig/banner-config.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash -e

STATE=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["state"]')
STATE=$(sonic-db-cli CONFIG_DB HGET 'BANNER_MESSAGE|global' state)
LOGIN=
MOTD=
LOGOUT=

if [[ $STATE == "enabled" ]]; then
LOGIN=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["login"]')
MOTD=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["motd"]')
LOGOUT=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["logout"]')
LOGIN=$(sonic-db-cli CONFIG_DB HGET 'BANNER_MESSAGE|global' login)
MOTD=$(sonic-db-cli CONFIG_DB HGET 'BANNER_MESSAGE|global' motd)
LOGOUT=$(sonic-db-cli CONFIG_DB HGET 'BANNER_MESSAGE|global' logout)

echo -e "$LOGIN" > /etc/issue.net
echo -e "$LOGIN" > /etc/issue
Expand Down
4 changes: 2 additions & 2 deletions files/image_config/hostname/hostname-config.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -e

CURRENT_HOSTNAME=`hostname`
HOSTNAME=`sonic-cfggen -d -v DEVICE_METADATA[\'localhost\'][\'hostname\']`
CURRENT_HOSTNAME=$(hostname)
HOSTNAME=$(sonic-db-cli CONFIG_DB HGET 'DEVICE_METADATA|localhost' hostname)

if [ -z "$HOSTNAME" ] ; then
echo "Missing hostname in the config file, setting to default 'sonic'"
Expand Down
6 changes: 3 additions & 3 deletions files/image_config/pcie-check/pcie-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function debug()
function check_and_rescan_pcie_devices()
{
PCIE_CHK_CMD='sudo pcieutil check | grep "$RESULTS"'
PLATFORM=$(sonic-cfggen -H -v DEVICE_METADATA.localhost.platform)
PLATFORM=$(sonic-db-cli CONFIG_DB HGET 'DEVICE_METADATA|localhost' platform)

if [ ! -f /usr/share/sonic/device/$PLATFORM/pcie*.yaml ]; then
debug "pcie.yaml does not exist! Can't check PCIe status!"
Expand All @@ -38,7 +38,7 @@ function check_and_rescan_pcie_devices()
fi

if [ "$(eval $PCIE_CHK_CMD)" = "$EXPECTED" ]; then
redis-cli -n 6 HSET $PCIE_STATUS_TABLE "status" "PASSED"
sonic-db-cli STATE_DB HSET $PCIE_STATUS_TABLE "status" "PASSED"
debug "PCIe check passed"
exit
else
Expand All @@ -54,7 +54,7 @@ function check_and_rescan_pcie_devices()

done
debug "PCIe check failed"
redis-cli -n 6 HSET $PCIE_STATUS_TABLE "status" "FAILED"
sonic-db-cli STATE_DB HSET $PCIE_STATUS_TABLE "status" "FAILED"
}

check_and_rescan_pcie_devices
2 changes: 1 addition & 1 deletion files/image_config/rsyslog/rsyslog-config.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
PLATFORM=$(sonic-db-cli CONFIG_DB HGET 'DEVICE_METADATA|localhost' platform)

# Parse the device specific asic conf file, if it exists
ASIC_CONF=/usr/share/sonic/device/$PLATFORM/asic.conf
Expand Down

0 comments on commit 81f1bf4

Please sign in to comment.