From 4e8ee73e1400e1f14f715b65391308c309c3d773 Mon Sep 17 00:00:00 2001 From: Shantanu Shrivastava Date: Mon, 9 Oct 2023 12:40:11 +0000 Subject: [PATCH] Adding prebuilt dpu docker --- dockers/docker-orchagent/orchagent.sh | 2 +- .../build_templates/sonic_debian_extension.j2 | 6 --- files/scripts/docker-dpu-base.sh | 1 + platform/pensando/docker-dpu.dep | 7 ++++ platform/pensando/docker-dpu.mk | 40 +++++++++++++++++++ platform/pensando/docker-dpu/Dockerfile.j2 | 7 ++++ platform/pensando/dpu/debian/dpu.init | 38 ++++++++++++------ platform/pensando/dpu/debian/dpu.install | 1 - platform/pensando/rules.mk | 1 + rules/docker-dpu-base.dep | 4 ++ rules/docker-dpu-base.mk | 8 ++++ scripts/prepare_docker_buildinfo.sh | 25 ++++++++++-- slave.mk | 18 +++++++++ 13 files changed, 134 insertions(+), 24 deletions(-) create mode 100644 files/scripts/docker-dpu-base.sh create mode 100644 platform/pensando/docker-dpu.dep create mode 100644 platform/pensando/docker-dpu.mk create mode 100644 platform/pensando/docker-dpu/Dockerfile.j2 create mode 100644 rules/docker-dpu-base.dep create mode 100644 rules/docker-dpu-base.mk diff --git a/dockers/docker-orchagent/orchagent.sh b/dockers/docker-orchagent/orchagent.sh index 64c5c1a03d8e..883864dbd919 100755 --- a/dockers/docker-orchagent/orchagent.sh +++ b/dockers/docker-orchagent/orchagent.sh @@ -65,7 +65,7 @@ elif [ "$platform" == "mellanox" ]; then elif [ "$platform" == "innovium" ]; then ORCHAGENT_ARGS+="-m $MAC_ADDRESS" elif [ "$platform" == "pensando" ]; then - MAC_ADDRESS=$(ip link show oob_mnic0 | grep ether | awk '{print $2}') + MAC_ADDRESS=$(ip link property add dev oob_mnic0 altname eth0; ip link show oob_mnic0 | grep ether | awk '{print $2}') ORCHAGENT_ARGS+="-m $MAC_ADDRESS" else # Should we use the fallback MAC in case it is not found in Device.Metadata diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index fcab69933578..b9efe0a445fc 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -764,12 +764,6 @@ fi {% endfor %} if [[ $CONFIGURED_PLATFORM == pensando ]]; then -#we need to start pciemgrd process soon at the bootup for pci txn to be up. -#if we don't start pciemgrd early pcie timeout happens and server reboots. -#pciemgrd runs as part of dpu docker. So load this at build time itself. -sudo LANG=C DOCKER_HOST="$DOCKER_HOST" chroot $FILESYSTEM_ROOT docker load -i boot/dpu_sw.tar -sudo LANG=C chroot $FILESYSTEM_ROOT rm -f boot/dpu_sw.tar - #Disable rc.local sudo LANG=C chroot $FILESYSTEM_ROOT chmod -x /etc/rc.local fi diff --git a/files/scripts/docker-dpu-base.sh b/files/scripts/docker-dpu-base.sh new file mode 100644 index 000000000000..a9bf588e2f88 --- /dev/null +++ b/files/scripts/docker-dpu-base.sh @@ -0,0 +1 @@ +#!/bin/bash diff --git a/platform/pensando/docker-dpu.dep b/platform/pensando/docker-dpu.dep new file mode 100644 index 000000000000..7611a05cdf2f --- /dev/null +++ b/platform/pensando/docker-dpu.dep @@ -0,0 +1,7 @@ +DOCKER_DPU_STEM = docker-dpu +DOCKER_DPU = $(DOCKER_DPU_STEM).gz +DPATH := $($(DOCKER_DPU)_PATH) +DEP_FILES := platform/pensando/docker-dpu.dep platform/pensando/docker-dpu.mk + +$(DOCKER_DPU)_CACHE_MODE := none +$(DOCKER_DPU)_DEP_FILES := $(DEP_FILES) diff --git a/platform/pensando/docker-dpu.mk b/platform/pensando/docker-dpu.mk new file mode 100644 index 000000000000..f479a4e1a564 --- /dev/null +++ b/platform/pensando/docker-dpu.mk @@ -0,0 +1,40 @@ +# docker dpu image for load +DOCKER_DPU_STEM = docker-dpu + +DOCKER_DPU = $(DOCKER_DPU_STEM).gz + +$(DOCKER_DPU)_PATH = $(PLATFORM_PATH)/$(DOCKER_DPU_STEM) + +$(DOCKER_DPU)_LOAD_DOCKERS = $(DOCKER_DPU_BASE) + +$(DOCKER_DPU)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_BUSTER) + +$(DOCKER_DPU)_DBG_DEPENDS += $($(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_DEPENDS) + +$(DOCKER_DPU)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_IMAGE_PACKAGES) + +SONIC_DOCKER_IMAGES += $(DOCKER_DPU) + +$(DOCKER_DPU)_PACKAGE_NAME = dpu +$(DOCKER_DPU)_CONTAINER_NAME = dpu +$(DOCKER_DPU)_VERSION = 1.0.0 +$(DOCKER_DPU)_RUN_OPT += --privileged -t +$(DOCKER_DPU)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro + +#NIC_MOUNT="-v /dev/shm:/dev/shm -v /boot/nicA/nic_core:/nic -v /boot/nicA/shared/conf/gen:/nic/conf/gen" +$(DOCKER_DPU)_RUN_OPT += --privileged -t +$(DOCKER_DPU)_RUN_OPT += -v /host/dpu/update:/update +$(DOCKER_DPU)_RUN_OPT += -v /host/dpu/sysconfig/config0:/sysconfig/config0 +$(DOCKER_DPU)_RUN_OPT += -v /host/dpu/sysconfig/config1:/sysconfig/config1 +$(DOCKER_DPU)_RUN_OPT += -v /host/dpu/obfl:/obfl +$(DOCKER_DPU)_RUN_OPT += -v /host/dpu/data:/data +$(DOCKER_DPU)_RUN_OPT += -v /host/dpu/tmpfsshare:/tmp +$(DOCKER_DPU)_RUN_OPT += -v /host/dpu/runfs:/run +$(DOCKER_DPU)_RUN_OPT += -v /host/dpu/logfs:/var/log +$(DOCKER_DPU)_RUN_OPT += -v /sys:/sys +#$(DOCKER_DPU)_RUN_OPT += $NIC_MOUNT +$(DOCKER_DPU)_RUN_OPT += --net=host +$(DOCKER_DPU)_RUN_OPT += docker-dpu:v1 + +SONIC_BUSTER_DOCKERS += $(DOCKER_DPU) +SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_DPU) diff --git a/platform/pensando/docker-dpu/Dockerfile.j2 b/platform/pensando/docker-dpu/Dockerfile.j2 new file mode 100644 index 000000000000..1b380c8110e7 --- /dev/null +++ b/platform/pensando/docker-dpu/Dockerfile.j2 @@ -0,0 +1,7 @@ +# DOWNLOADED_DOCKER_IMAGES +FROM docker-dpu-base + +RUN echo "docker-dpu-base" + +ENTRYPOINT ["/nic/tools/sysinit.sh", "classic", "hw", "30"] + diff --git a/platform/pensando/dpu/debian/dpu.init b/platform/pensando/dpu/debian/dpu.init index c0be5f9e86e5..9f9f43feecca 100755 --- a/platform/pensando/dpu/debian/dpu.init +++ b/platform/pensando/dpu/debian/dpu.init @@ -1,6 +1,10 @@ #!/bin/bash + +# {C} Copyright 2023 AMD Systems Inc. All rights reserved + # This script starts/stops dpu sw + ### BEGIN INIT INFO # Provides: load-dpu # Required-Start: @@ -14,20 +18,26 @@ ACTIVE_FILE="/boot/active.txt" NIC_MOUNT="" LOG_FILE="/tmp/active_nic" +TAG="latest" +HOST_DIR=/host/dpu function start_dpu() { - mkdir -p /host/dpu/update - mkdir -p /host/dpu/sysconfig/config0 - mkdir -p /host/dpu/sysconfig/config1 - mkdir -p /host/dpu/obfl - mkdir -p /host/dpu/data - mkdir -p /host/dpu/tmpfsshare - mkdir -p /host/dpu/runfs - mkdir -p /host/dpu/logfs - mount -t tmpfs -o size=20M,mode=1777 tmpfs /host/dpu/tmpfsshare - mount -t tmpfs -o size=20M,mode=0755 runs /host/dpu/runfs - mount -t tmpfs -o size=20M,mode=0755 logfs /host/dpu/logfs + modprobe ionic_mnic + modprobe mnet_uio_pdrv_genirq + modprobe mdev + + mkdir -p $HOST_DIR/update + mkdir -p $HOST_DIR/sysconfig/config0 + mkdir -p $HOST_DIR/sysconfig/config1 + mkdir -p $HOST_DIR/obfl + mkdir -p $HOST_DIR/data + mkdir -p $HOST_DIR/tmpfsshare + mkdir -p $HOST_DIR/runfs + mkdir -p $HOST_DIR/logfs + mount -t tmpfs -o size=20M,mode=1777 tmpfs $HOST_DIR/tmpfsshare + mount -t tmpfs -o size=20M,mode=0755 runs $HOST_DIR/runfs + mount -t tmpfs -o size=20M,mode=0755 logfs $HOST_DIR/logfs if [ -f "$ACTIVE_FILE" ]; then ACTIVE_CONTENTS=$(cat "$ACTIVE_FILE") @@ -41,9 +51,11 @@ function start_dpu() echo "/boot/active.txt not present" > $LOG_FILE fi echo "Active Nic: $ACTIVE_NIC" >> $LOG_FILE - echo "NIC_MOUNT: $NIC_MOUNT" >> $LOG_FILE + echo "NIC_MOUNT: $NIC_MOUNT" >> $LOG_FILE + + docker ps -a --format "{{.ID}}\t{{.Image}}" | grep "docker-dpu:latest" | awk '{print $1}' | xargs -I {} docker rm {} - docker run -v /host/dpu/update:/update -v /host/dpu/sysconfig/config0:/sysconfig/config0 -v /host/dpu/sysconfig/config1:/sysconfig/config1 -v /host/dpu/obfl:/obfl -v /host/dpu/data:/data -v /host/dpu/tmpfsshare:/tmp -v /host/dpu/runfs:/run -v /host/dpu/logfs:/var/log -v /sys:/sys $NIC_MOUNT --net=host --privileged dpu:v1 + docker run -v $HOST_DIR/update:/update -v $HOST_DIR/sysconfig/config0:/sysconfig/config0 -v $HOST_DIR/sysconfig/config1:/sysconfig/config1 -v $HOST_DIR/obfl:/obfl -v $HOST_DIR/data:/data -v $HOST_DIR/tmpfsshare:/tmp -v $HOST_DIR/runfs:/run -v $HOST_DIR/logfs:/var/log -v /sys:/sys $NIC_MOUNT --net=host --name=docker-dpu --privileged docker-dpu:$TAG } case "$1" in diff --git a/platform/pensando/dpu/debian/dpu.install b/platform/pensando/dpu/debian/dpu.install index 795dd2db77e0..5aecbfa115fc 100644 --- a/platform/pensando/dpu/debian/dpu.install +++ b/platform/pensando/dpu/debian/dpu.install @@ -1,2 +1 @@ systemd/dpu.service lib/systemd/system -image/dpu_sw.tar /boot/ diff --git a/platform/pensando/rules.mk b/platform/pensando/rules.mk index 586ca0162eb1..2652ac65db75 100644 --- a/platform/pensando/rules.mk +++ b/platform/pensando/rules.mk @@ -1,4 +1,5 @@ include $(PLATFORM_PATH)/dpu.mk +include $(PLATFORM_PATH)/docker-dpu.mk include $(PLATFORM_PATH)/one-image.mk include $(PLATFORM_PATH)/sdk.mk include $(PLATFORM_PATH)/docker-syncd-pensando.mk diff --git a/rules/docker-dpu-base.dep b/rules/docker-dpu-base.dep new file mode 100644 index 000000000000..fbc438fd3b31 --- /dev/null +++ b/rules/docker-dpu-base.dep @@ -0,0 +1,4 @@ +DEP_FILES := rules/docker-dpu-base.dep rules/docker-dpu-base.mk + +$(DOCKER_DPU_BASE)_CACHE_MODE := none +$(DOCKER_DPU_BASE)_DEP_FILES := $(DEP_FILES) diff --git a/rules/docker-dpu-base.mk b/rules/docker-dpu-base.mk new file mode 100644 index 000000000000..fcceeb582bb2 --- /dev/null +++ b/rules/docker-dpu-base.mk @@ -0,0 +1,8 @@ +# docker dpu image for load + +DOCKER_DPU_BASE_STEM = docker-dpu-base + +DOCKER_DPU_BASE = $(DOCKER_DPU_BASE_STEM).gz + +DOWNLOADED_DOCKER_IMAGES += $(DOCKER_DPU_BASE) + diff --git a/scripts/prepare_docker_buildinfo.sh b/scripts/prepare_docker_buildinfo.sh index 0ee79c201f5b..15d9cfe2f301 100755 --- a/scripts/prepare_docker_buildinfo.sh +++ b/scripts/prepare_docker_buildinfo.sh @@ -55,14 +55,27 @@ ENV IMAGENAME='${IMAGENAME}' ENV DISTRO='${DISTRO}' RUN pre_run_buildinfo '${IMAGENAME}' ' +DOWNLOADED_DOCKER_IMAGES_DOCKERFILE_PRE_SCRIPT='# Auto-Generated for buildinfo +ARG SONIC_VERSION_CACHE +ARG SONIC_VERSION_CONTROL_COMPONENTS +COPY ["buildinfo", "/usr/local/share/buildinfo"] +COPY vcache/ /sonic/target/vcache/'${IMAGENAME}' +COPY ["tmp_extract", "/"] +ENV IMAGENAME='${IMAGENAME}' +ENV DISTRO='${DISTRO}' +RUN pre_run_buildinfo '${IMAGENAME}' +' # Add the auto-generate code if it is not added in the target Dockerfile if [ ! -f $DOCKERFILE_TARGET ] || ! grep -q "Auto-Generated for buildinfo" $DOCKERFILE_TARGET; then # Insert the docker build script before the RUN command LINE_NUMBER=$(grep -Fn -m 1 'RUN' $DOCKERFILE | cut -d: -f1) TEMP_FILE=$(mktemp) - awk -v text="${DOCKERFILE_PRE_SCRIPT}" -v linenumber=$LINE_NUMBER 'NR==linenumber{print text}1' $DOCKERFILE > $TEMP_FILE - + if ! grep -q "DOWNLOADED_DOCKER_IMAGES" $DOCKERFILE_TARGET; then + awk -v text="${DOCKERFILE_PRE_SCRIPT}" -v linenumber=$LINE_NUMBER 'NR==linenumber{print text}1' $DOCKERFILE > $TEMP_FILE + else + awk -v text="${DOWNLOADED_DOCKER_IMAGES_DOCKERFILE_PRE_SCRIPT}" -v linenumber=$LINE_NUMBER 'NR==linenumber{print text}1' $DOCKERFILE > $TEMP_FILE + fi # Append the docker build script at the end of the docker file echo -e "\nRUN post_run_buildinfo ${IMAGENAME} " >> $TEMP_FILE echo -e "\nRUN post_run_cleanup ${IMAGENAME} " >> $TEMP_FILE @@ -73,7 +86,13 @@ fi # Copy the build info config mkdir -p ${BUILDINFO_PATH} -cp -rf src/sonic-build-hooks/buildinfo/* $BUILDINFO_PATH +if ! grep -q "DOWNLOADED_DOCKER_IMAGES" $DOCKERFILE_TARGET; then + cp -rf src/sonic-build-hooks/buildinfo/* $BUILDINFO_PATH +else + cp -rf src/sonic-build-hooks/buildinfo/* $BUILDINFO_PATH + mkdir -p $DOCKERFILE_PATH/tmp_extract + dpkg --extract $BUILDINFO_PATH/sonic-build-hooks_1.0_all.deb $DOCKERFILE_PATH/tmp_extract +fi # Generate the version lock files scripts/versions_manager.py generate -t "$BUILDINFO_VERSION_PATH" -n "$IMAGENAME" -d "$DISTRO" -a "$ARCH" diff --git a/slave.mk b/slave.mk index 92103b5e2777..49aa807032fb 100644 --- a/slave.mk +++ b/slave.mk @@ -1086,6 +1086,24 @@ $(foreach IMAGE,$(DOCKER_IMAGES), $(eval $(IMAGE)_FILES_PATH := $(FILES_PATH))) $(foreach IMAGE,$(DOCKER_DBG_IMAGES), $(eval $(IMAGE)_DEBS_PATH := $(DEBS_PATH))) $(foreach IMAGE,$(DOCKER_DBG_IMAGES), $(eval $(IMAGE)_FILES_PATH := $(FILES_PATH))) +# Targets for downloaded docker images +$(addprefix $(TARGET_PATH)/,$(DOWNLOADED_DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .platform \ + $$(%.gz_DEP_FILES) + $(HEADER) + + cp files/$(DOWNLOADED_DOCKER_IMAGES) target/$(DOWNLOADED_DOCKER_IMAGES) + + $(FOOTER) + +DOCKER_LOAD_DOWNLOADED_TARGETS = $(addsuffix -load,$(addprefix $(TARGET_PATH)/, \ + $(DOWNLOADED_DOCKER_IMAGES))) + +$(DOCKER_LOAD_DOWNLOADED_TARGETS) : $(TARGET_PATH)/%.gz-load : .platform docker-start $$(TARGET_PATH)/$$*.gz + $(HEADER) + $(call docker-image-load,$*) + $(FOOTER) + + # Targets for building docker images $(addprefix $(TARGET_PATH)/, $(DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .platform docker-start \ $$(addprefix $$($$*.gz_DEBS_PATH)/,$$($$*.gz_DEPENDS)) \