From 6dcd7981704d1f9cf8693c66591cd314a6438502 Mon Sep 17 00:00:00 2001 From: funnyfunny <1360681597@qq.com> Date: Wed, 28 Jun 2023 18:18:58 +0800 Subject: [PATCH] =?UTF-8?q?310b=20=E9=80=82=E9=85=8Ddavinci=5Fmanager=5Fdo?= =?UTF-8?q?cker=E6=94=B9=E5=90=8D=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=8C=82?= =?UTF-8?q?=E8=BD=BDso=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/scripts/base.list_A500A2 | 4 +- build/scripts/run_main.sh | 43 ++++++++--------- cli/src/main.c | 5 +- hook/main.go | 6 +-- runtime/main.go | 88 ++++++++++++++++++---------------- runtime/main_test.go | 11 +++-- 6 files changed, 81 insertions(+), 76 deletions(-) diff --git a/build/scripts/base.list_A500A2 b/build/scripts/base.list_A500A2 index 50ff608..ace6cd0 100644 --- a/build/scripts/base.list_A500A2 +++ b/build/scripts/base.list_A500A2 @@ -7,7 +7,6 @@ /var/slogd /usr/lib64/libsemanage.so.2 /usr/lib64/libmmpa.so -/usr/lib64/libcrypto.so.1.1 /usr/lib64/libdrvdsmi.so /usr/lib64/libdcmi.so /usr/lib64/libstackcore.so @@ -18,5 +17,4 @@ /usr/lib64/libaicpu_sharder.so /usr/lib64/libadump.so /usr/lib64/libtsd_eventclient.so -/usr/lib64/aicpu_kernels -/usr/lib64/libyaml-0.so.2 \ No newline at end of file +/usr/lib64/aicpu_kernels \ No newline at end of file diff --git a/build/scripts/run_main.sh b/build/scripts/run_main.sh index c3b9d14..ae9d061 100644 --- a/build/scripts/run_main.sh +++ b/build/scripts/run_main.sh @@ -40,6 +40,21 @@ function save_install_args() { } >> "${INSTALL_PATH}"/ascend_docker_runtime_install.info } +function add_so() { + if grep -qi "ubuntu" "/etc/os-release"; then + echo "[info]: os is Ubuntu" + echo -e "\n/usr/lib/aarch64-linux-gnu/libcrypto.so.1.1" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list + echo "/usr/lib/aarch64-linux-gnu/libyaml-0.so.2" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list + elif grep -qi "euler" "/etc/os-release"; then + echo "[info]: os is Euler/OpenEuler" + echo -e "\n/usr/lib64/libcrypto.so.1.1" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list + echo "/usr/lib64/libyaml-0.so.2" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list + else + echo "ERROR: not support this os" + exit + fi +} + function install() { echo 'installing ascend docker runtime' @@ -89,20 +104,10 @@ function install() cp -f ./base.list_A200ISoC ${ASCEND_RUNTIME_CONFIG_DIR}/base.list elif [ "${a500a2}" == "y" ]; then cp -f ./base.list_A500A2 ${ASCEND_RUNTIME_CONFIG_DIR}/base.list + add_so elif [ "${a200ia2}" == "y" ]; then cp -f ./base.list_A200IA2 ${ASCEND_RUNTIME_CONFIG_DIR}/base.list - if grep -qi "ubuntu" "/etc/os-release"; then - echo "[info]: A200IA2 os is Ubuntu" - echo -e "\n/usr/lib/aarch64-linux-gnu/libcrypto.so.1.1" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list - echo "/usr/lib/aarch64-linux-gnu/libyaml-0.so.2.0.6" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list - elif grep -qi "euler" "/etc/os-release"; then - echo "[info]: A200IA2 os is Euler/OpenEuler" - echo -e "\n/usr/lib64/libcrypto.so.1.1.1m" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list - echo "/usr/lib64/libyaml-0.so.2.0.9" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list - else - echo "ERROR: not support this os" - exit - fi + add_so else cp -f ./base.list ${ASCEND_RUNTIME_CONFIG_DIR}/base.list fi @@ -185,6 +190,7 @@ function upgrade() elif [ "$(grep "a500a2=y" "${INSTALL_PATH}"/ascend_docker_runtime_install.info)" == "a500a2=y" ]; then a500a2=y cp -f ./base.list_A500A2 ${ASCEND_RUNTIME_CONFIG_DIR}/base.list + add_so elif [ "$(grep "a200=y" "${INSTALL_PATH}"/ascend_docker_runtime_install.info)" == "a200=y" ]; then a200=y cp -f ./base.list_A200 ${ASCEND_RUNTIME_CONFIG_DIR}/base.list @@ -194,18 +200,7 @@ function upgrade() elif [ "x$(grep "a200ia2=y" "${INSTALL_PATH}"/ascend_docker_runtime_install.info)" == "xa200ia2=y" ]; then a200ia2=y cp -f ./base.list_A200IA2 ${ASCEND_RUNTIME_CONFIG_DIR}/base.list - if grep -qi "ubuntu" "/etc/os-release"; then - echo "[info]: A200IA2 os is Ubuntu" - echo -e "\n/usr/lib/aarch64-linux-gnu/libcrypto.so.1.1" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list - echo -e "/usr/lib/aarch64-linux-gnu/libyaml-0.so.2.0.6" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list - elif grep -qi "euler" "/etc/os-release"; then - echo "[info]: A200IA2 os is Euler/OpenEuler" - echo -e "\n/usr/lib64/libcrypto.so.1.1.1m" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list - echo -e "/usr/lib64/libyaml-0.so.2.0.9" >> ${ASCEND_RUNTIME_CONFIG_DIR}/base.list - else - echo "ERROR: not support this os" - exit - fi + add_so else cp -f ./base.list ${ASCEND_RUNTIME_CONFIG_DIR}/base.list fi diff --git a/cli/src/main.c b/cli/src/main.c index f629d18..e30513e 100644 --- a/cli/src/main.c +++ b/cli/src/main.c @@ -194,9 +194,8 @@ static bool CheckWhiteList(const char* fileName) {"/usr/lib64/libmpi_dvpp_adapter.so"}, {"/usr/lib64/libaicpu_scheduler.so"}, {"/usr/lib64/libaicpu_processer.so"}, {"/usr/lib64/libaicpu_prof.so"}, {"/usr/lib64/libaicpu_sharder.so"}, {"/usr/lib64/libadump.so"}, {"/usr/lib64/libtsd_eventclient.so"}, - {"/usr/lib64/aicpu_kernels"}, {"/usr/lib64/libyaml-0.so.2"}, {"/usr/lib64/libcrypto.so.1.1.1m"}, - {"/usr/lib64/libyaml-0.so.2.0.9"}, {"/usr/lib/aarch64-linux-gnu/libyaml-0.so.2.0.6"}, - {"/usr/lib/aarch64-linux-gnu/libcrypto.so.1.1"} + {"/usr/lib64/aicpu_kernels"}, {"/usr/lib64/libyaml-0.so.2"}, + {"/usr/lib/aarch64-linux-gnu/libyaml-0.so.2"}, {"/usr/lib/aarch64-linux-gnu/libcrypto.so.1.1"} }; for (size_t iLoop = 0; iLoop < WHITE_LIST_NUM; iLoop++) { diff --git a/hook/main.go b/hook/main.go index 60423df..c794dad 100644 --- a/hook/main.go +++ b/hook/main.go @@ -415,8 +415,8 @@ func main() { log.Fatal("command error") } if err := doPrestartHook(); err != nil { - hwlog.RunLog.Errorf("ascend docker hook failed") - hwlog.OpLog.Errorf("%v ascend docker hook failed", logPrefixWords) - log.Fatal(fmt.Errorf("failed in runtime.doProcess ")) + hwlog.RunLog.Errorf("ascend docker hook failed: %#v", err) + hwlog.OpLog.Errorf("%v ascend docker hook failed: %#v", logPrefixWords, err) + log.Fatal(fmt.Errorf("failed in runtime.doProcess: %#v", err)) } } diff --git a/runtime/main.go b/runtime/main.go index 70a7ab5..0059168 100644 --- a/runtime/main.go +++ b/runtime/main.go @@ -81,21 +81,24 @@ const ( // Ascend910 ascend 910 chip Ascend910 = "Ascend910" - devicePath = "/dev/" - davinciName = "davinci" - davinciManager = "davinci_manager" - devmmSvm = "devmm_svm" - hisiHdc = "hisi_hdc" - svm0 = "svm0" - tsAisle = "ts_aisle" - upgrade = "upgrade" - sys = "sys" - vdec = "vdec" - vpc = "vpc" - pngd = "pngd" - venc = "venc" - dvppCmdList = "dvpp_cmdlist" - logDrv = "log_drv" + devicePath = "/dev/" + davinciName = "davinci" + virtualDavinciName = "vdavinci" + davinciManager = "davinci_manager" + davinciManagerDocker = "davinci_manager_docker" + notRenameDeviceType = "" + devmmSvm = "devmm_svm" + hisiHdc = "hisi_hdc" + svm0 = "svm0" + tsAisle = "ts_aisle" + upgrade = "upgrade" + sys = "sys" + vdec = "vdec" + vpc = "vpc" + pngd = "pngd" + venc = "venc" + dvppCmdList = "dvpp_cmdlist" + logDrv = "log_drv" ) type args struct { @@ -346,20 +349,23 @@ func getValueByKey(data []string, name string) string { return "" } -func addDeviceToSpec(spec *specs.Spec, dPath string, vdevice bool) error { +func addDeviceToSpec(spec *specs.Spec, dPath string, deviceType string) error { device, err := oci.DeviceFromPath(dPath) if err != nil { return fmt.Errorf("failed to get %s info : %#v", dPath, err) } - if vdevice { - re := regexp.MustCompile("[0-9]+") - vDeviceNumber := re.FindAllString(dPath, -1) + switch deviceType { + case virtualDavinciName: + vDeviceNumber := regexp.MustCompile("[0-9]+").FindAllString(dPath, -1) if len(vDeviceNumber) != 1 { - return fmt.Errorf("error vdevice : %s", dPath) + return fmt.Errorf("invalid vdavinci path: %s", dPath) } - vPath := devicePath + davinciName + vDeviceNumber[0] - device.Path = vPath + device.Path = devicePath + davinciName + vDeviceNumber[0] + case davinciManagerDocker: + device.Path = devicePath + davinciManager + default: + // do nothing } spec.Linux.Devices = append(spec.Linux.Devices, *device) @@ -390,12 +396,20 @@ func addAscend310BManagerDevice(spec *specs.Spec) error { for _, device := range Ascend310BManageDevices { dPath := devicePath + device - if err := addDeviceToSpec(spec, dPath, false); err != nil { + if err := addDeviceToSpec(spec, dPath, notRenameDeviceType); err != nil { hwlog.RunLog.Warnf("failed to add %s to spec : %#v", dPath, err) } } - return nil + davinciManagerPath := devicePath + davinciManagerDocker + if _, err := os.Stat(davinciManagerPath); err != nil { + hwlog.RunLog.Warnf("failed to get davinci manager docker, err: %#v", err) + davinciManagerPath = devicePath + davinciManager + if _, err := os.Stat(davinciManagerPath); err != nil { + return fmt.Errorf("failed to get davinci manager, err: %#v", err) + } + } + return addDeviceToSpec(spec, davinciManagerPath, davinciManagerDocker) } func addCommonManagerDevice(spec *specs.Spec) error { @@ -406,7 +420,7 @@ func addCommonManagerDevice(spec *specs.Spec) error { for _, device := range commonManagerDevices { dPath := devicePath + device - if err := addDeviceToSpec(spec, dPath, false); err != nil { + if err := addDeviceToSpec(spec, dPath, notRenameDeviceType); err != nil { return fmt.Errorf("failed to add common manage device to spec : %#v", err) } } @@ -415,11 +429,6 @@ func addCommonManagerDevice(spec *specs.Spec) error { } func addManagerDevice(spec *specs.Spec) error { - managerPath := devicePath + davinciManager - if err := addDeviceToSpec(spec, managerPath, false); err != nil { - return fmt.Errorf("add davinci_manager to spec error: %#v", err) - } - chipName, err := dcmi.GetChipName() if err != nil { return fmt.Errorf("get chip name error: %#v", err) @@ -427,10 +436,11 @@ func addManagerDevice(spec *specs.Spec) error { devType := GetDeviceTypeByChipName(chipName) hwlog.RunLog.Infof("device type is: %s", devType) if devType == Ascend310B { - if err = addAscend310BManagerDevice(spec); err != nil { - return fmt.Errorf("add 310B manage device error: %#v", err) - } - return nil + return addAscend310BManagerDevice(spec) + } + + if err := addDeviceToSpec(spec, devicePath+davinciManager, notRenameDeviceType); err != nil { + return fmt.Errorf("add davinci_manager to spec error: %#v", err) } productType, err := dcmi.GetProductType(&dcmi.NpuWorker{}) @@ -462,16 +472,14 @@ func addDevice(spec *specs.Spec) error { return fmt.Errorf("failed to parse device : %#v", err) } hwlog.RunLog.Infof("devices is: %#v", devices) - devciename := davinciName - vdevice := false + deviceName := davinciName virtual := getValueByKey(spec.Process.Env, ascendRuntimeOptions) if strings.Contains(virtual, "VIRTUAL") { - devciename = "v" + devciename - vdevice = true + deviceName = virtualDavinciName } for _, deviceId := range devices { - dPath := devicePath + devciename + strconv.Itoa(deviceId) - if err = addDeviceToSpec(spec, dPath, vdevice); err != nil { + dPath := devicePath + deviceName + strconv.Itoa(deviceId) + if err = addDeviceToSpec(spec, dPath, deviceName); err != nil { return fmt.Errorf("failed to add davinci device to spec: %v", err) } } diff --git a/runtime/main_test.go b/runtime/main_test.go index 5e5c23a..c540f8b 100644 --- a/runtime/main_test.go +++ b/runtime/main_test.go @@ -397,17 +397,22 @@ func TestAddDeviceToSpec0(t *testing.T) { }, } - err := addDeviceToSpec(&spec, devPath, false) + err := addDeviceToSpec(&spec, devPath, notRenameDeviceType) assert.Nil(t, err) assert.Contains(t, spec.Linux.Devices[0].Path, devPath) } func TestAddAscend310BManagerDevice(t *testing.T) { - statStub := gomonkey.ApplyFunc(addDeviceToSpec, func(spec *specs.Spec, dPath string, vdevice bool) error { + statStub := gomonkey.ApplyFunc(addDeviceToSpec, func(spec *specs.Spec, dPath string, deviceType string) error { return nil }) defer statStub.Reset() + pathStub := gomonkey.ApplyFunc(os.Stat, func(name string) (os.FileInfo, error) { + return nil, nil + }) + defer pathStub.Reset() + spec := specs.Spec{ Linux: &specs.Linux{ Devices: []specs.LinuxDevice{}, @@ -422,7 +427,7 @@ func TestAddAscend310BManagerDevice(t *testing.T) { } func TestAddCommonManagerDevice(t *testing.T) { - statStub := gomonkey.ApplyFunc(addDeviceToSpec, func(spec *specs.Spec, dPath string, vdevice bool) error { + statStub := gomonkey.ApplyFunc(addDeviceToSpec, func(spec *specs.Spec, dPath string, deviceType string) error { return nil }) defer statStub.Reset()