From 4613e8dec384c651620b309348190d09bf8d76f7 Mon Sep 17 00:00:00 2001 From: Charis Poag Date: Thu, 20 Jul 2023 15:20:36 -0500 Subject: [PATCH] Update logging and README for other project usage Updates: * [rocm-smi] Logging now can update files on per-project-basis for install/remove * [rocm-smi] README now has latest build instructions, including test builds * [rocm-smi] Updated README to include revision dates Change-Id: Ifb19a6f32ccf6938f47225db53fef88021909264 Signed-off-by: Charis Poag --- .gitignore | 3 +++ DEBIAN/postinst.in | 43 +++++++++++++++++++++------------------ DEBIAN/prerm.in | 14 +++++++++---- README.md | 15 +++++++------- RPM/post.in | 50 +++++++++++++++++++++++++++++----------------- RPM/preun.in | 12 ++++++++--- 6 files changed, 85 insertions(+), 52 deletions(-) diff --git a/.gitignore b/.gitignore index 55abee102c..91cbeef563 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ build/ # CMake cache .cache/ + +# Simulated SYSFS - for early development or debug +device/ \ No newline at end of file diff --git a/DEBIAN/postinst.in b/DEBIAN/postinst.in index eaccaa938b..a62d7e9eea 100755 --- a/DEBIAN/postinst.in +++ b/DEBIAN/postinst.in @@ -1,32 +1,37 @@ #!/bin/bash - #set -x +packageName="rocm-smi-lib" +logPath=/var/log/rocm_smi_lib +logName=ROCm-SMI-lib.log +logFile="${logPath}/${logName}" +logrotateConfFile=/etc/logrotate.d/rocm_smi.conf + do_addLogFolder() { - sudo mkdir -p /var/log/rocm_smi_lib - sudo touch /var/log/rocm_smi_lib/ROCm-SMI-lib.log - sudo chmod -R a+rw /var/log/rocm_smi_lib - sudo chmod a+rw /var/log/rocm_smi_lib/ROCm-SMI-lib.log + sudo mkdir -p "${logPath}" + sudo touch "${logFile}" + sudo chmod -R a+rw "${logPath}" + sudo chmod a+rw "${logFile}" } do_configureLogrotate() { logrotate --version &>/dev/null if [ $? -ne 0 ]; then echo "[WARNING] Detected logrotate is not installed."\ - "ROCm-smi logs (when turned on) will not rotate properly." + "$packageName logs (when turned on) will not rotate properly." return fi - if [ ! -f /etc/logrotate.d/rocm_smi.conf ]; then - sudo touch /etc/logrotate.d/rocm_smi.conf - sudo chmod 644 /etc/logrotate.d/rocm_smi.conf # root r/w, all others read + if [ ! -f $logrotateConfFile ]; then + sudo touch "${logrotateConfFile}" + sudo chmod 644 "${logrotateConfFile}" # root r/w, all others read # ROCm SMI logging rotation, rotates files using root user/group # Hourly logrotation check # Only rotates if size grew larger than 1MB # Max of 4 rotation files, oldest will be removed # Rotated files use date extention of ex. ROCm-SMI-lib.log.2023-05-09_16:51:42 - cat <<'EOF' | sudo tee /etc/logrotate.d/rocm_smi.conf >/dev/null -/var/log/rocm_smi_lib/ROCm-SMI-lib.log { + cat << EOF | sudo tee "${logrotateConfFile}" >/dev/null +${logFile} { su root root hourly missingok @@ -42,12 +47,12 @@ EOF # issue was RPM build thought we were using macros # https://gitlab.kitware.com/cmake/cmake/-/issues/22965 # https://rpm-software-management.github.io/rpm/manual/spec.html - sudo sed -i s/%%/%/g /etc/logrotate.d/rocm_smi.conf + sudo sed -i s/%%/%/g "${logrotateConfFile}" # workaround: remove extra 'OURCE' text # from rocm_smi.conf. Unsure if CMAKE, # bash, or here document # issue (only seen on RHEL 8.7) - sudo sed -i s/OURCE//g /etc/logrotate.d/rocm_smi.conf + sudo sed -i s/OURCE//g "${logrotateConfFile}" fi # check if logrotate uses system timers, Ubuntu/modern OS's do # Several older OS's like RHEL 8.7, do not. Instead defaults @@ -60,16 +65,16 @@ EOF if [ -f /etc/cron.hourly/logrotate ]; then sudo mv /etc/cron.daily/logrotate /etc/cron.hourly/logrotate else - echo "[WARNING] Could find and configure hourly cron for ROCm-smi's"\ - " logrotate. ROCm-smi logs (when turned on) will not rotate properly." + echo "[WARNING] Could find and configure hourly cron for $packageName's"\ + " logrotate. $packageName logs (when turned on) will not rotate properly." return fi else # confirm that it's already been moved to hourly sudo find /etc/cron.* -iname logrotate -print -quit |grep -iq hourly if [ $? -ne 0 ]; then - echo "[WARNING] Could not configure an hourly cron for ROCm-smi's logrotate."\ - "ROCm-smi logs (when turned on) may not rotate properly." + echo "[WARNING] Could not configure an hourly cron for $packageName's logrotate."\ + "$packageName logs (when turned on) may not rotate properly." fi fi else @@ -94,8 +99,8 @@ WantedBy=timers.target EOF sudo systemctl reenable --now logrotate.timer else - echo "[WARNING] Could not configure systemd timer for ROCm's logrotate."\ - "ROCm-smi logs (when turned on) will not rotate properly." + echo "[WARNING] Could not configure systemd timer for $packageName's logrotate."\ + "$packageName logs (when turned on) will not rotate properly." fi fi } diff --git a/DEBIAN/prerm.in b/DEBIAN/prerm.in index 7c23e8e990..9b4efa9899 100755 --- a/DEBIAN/prerm.in +++ b/DEBIAN/prerm.in @@ -1,14 +1,19 @@ #!/bin/bash - set -e +packageName="rocm-smi-lib" +logPath=/var/log/rocm_smi_lib +logName=ROCm-SMI-lib.log +logFile="${logPath}/${logName}" +logrotateConfFile=/etc/logrotate.d/rocm_smi.conf + rm_logFolder() { - sudo rm -rf /var/log/rocm_smi_lib + sudo rm -rf "$logPath" } return_logrotateToOrigConfig() { - if [ -f /etc/logrotate.d/rocm_smi.conf ]; then - sudo rm -rf /etc/logrotate.d/rocm_smi.conf + if [ -f $logrotateConfFile ]; then + sudo rm -rf "${logrotateConfFile}" fi if [ -f /etc/cron.hourly/logrotate ]; then sudo mv /etc/cron.hourly/logrotate /etc/cron.daily/logrotate @@ -33,6 +38,7 @@ rm_pyc() { rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/rocm_smi/__pycache__ } + case "$1" in ( remove | upgrade) rm_ldconfig diff --git a/README.md b/README.md index c36f81f705..948ef14988 100755 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The ROCm System Management Interface Library, or ROCm SMI library, is part of th The information contained herein is for informational purposes only, and is subject to change without notice. In addition, any stated support is planned and is also subject to change. While every precaution has been taken in the preparation of this document, it may contain technical inaccuracies, omissions and typographical errors, and AMD is under no obligation to update or otherwise correct this information. Advanced Micro Devices, Inc. makes no representations or warranties with respect to the accuracy or completeness of the contents of this document, and assumes no liability of any kind, including the implied warranties of noninfringement, merchantability or fitness for particular purposes, with respect to the operation or use of AMD hardware, software or other products described herein. -© 2022 Advanced Micro Devices, Inc. All Rights Reserved. +© 2022-2023 Advanced Micro Devices, Inc. All Rights Reserved. # Building ROCm SMI @@ -28,8 +28,8 @@ After the ROCm SMI library git repository has been cloned to a local Linux machi ```shell mkdir -p build cd build -cmake -make +cmake .. +make -j $(nproc) # Install library file and header; default location is /opt/rocm $ make install ``` @@ -57,11 +57,10 @@ In order to verify the build and capability of ROCm SMI on your system and to se ```shell # Set environment variables used in CMakeLists.txt file -ROCM_DIR= -mkdir -cd -cmake -DROCM_DIR=$ROCM_DIR /tests/rocm_smi_test -make +mkdir build +cd build +cmake -DBUILD_TESTS=ON .. +make -j $(nproc) ``` To run the test, execute the program `rsmitst` that is built from the steps above. diff --git a/RPM/post.in b/RPM/post.in index 29787d660f..379dcd7152 100755 --- a/RPM/post.in +++ b/RPM/post.in @@ -1,31 +1,37 @@ #!/bin/bash #set -x +packageName="rocm-smi-lib" +logPath=/var/log/rocm_smi_lib +logName=ROCm-SMI-lib.log +logFile="${logPath}/${logName}" +logrotateConfFile=/etc/logrotate.d/rocm_smi.conf + do_addLogFolder() { - sudo mkdir -p /var/log/rocm_smi_lib - sudo touch /var/log/rocm_smi_lib/ROCm-SMI-lib.log - sudo chmod -R a+rw /var/log/rocm_smi_lib - sudo chmod a+rw /var/log/rocm_smi_lib/ROCm-SMI-lib.log + sudo mkdir -p "${logPath}" + sudo touch "${logFile}" + sudo chmod -R a+rw "${logPath}" + sudo chmod a+rw "${logFile}" } do_configureLogrotate() { logrotate --version &>/dev/null if [ $? -ne 0 ]; then echo "[WARNING] Detected logrotate is not installed."\ - "ROCm-smi logs (when turned on) will not rotate properly." + "$packageName logs (when turned on) will not rotate properly." return fi - if [ ! -f /etc/logrotate.d/rocm_smi.conf ]; then - sudo touch /etc/logrotate.d/rocm_smi.conf - sudo chmod 644 /etc/logrotate.d/rocm_smi.conf # root r/w, all others read + if [ ! -f $logrotateConfFile ]; then + sudo touch "${logrotateConfFile}" + sudo chmod 644 "${logrotateConfFile}" # root r/w, all others read # ROCm SMI logging rotation, rotates files using root user/group # Hourly logrotation check # Only rotates if size grew larger than 1MB # Max of 4 rotation files, oldest will be removed # Rotated files use date extention of ex. ROCm-SMI-lib.log.2023-05-09_16:51:42 - cat <<'EOF' | sudo tee /etc/logrotate.d/rocm_smi.conf >/dev/null -/var/log/rocm_smi_lib/ROCm-SMI-lib.log { + cat << EOF | sudo tee "${logrotateConfFile}" >/dev/null +${logFile} { su root root hourly missingok @@ -41,12 +47,12 @@ EOF # issue was RPM build thought we were using macros # https://gitlab.kitware.com/cmake/cmake/-/issues/22965 # https://rpm-software-management.github.io/rpm/manual/spec.html - sudo sed -i s/%%/%/g /etc/logrotate.d/rocm_smi.conf + sudo sed -i s/%%/%/g "${logrotateConfFile}" # workaround: remove extra 'OURCE' text # from rocm_smi.conf. Unsure if CMAKE, # bash, or here document # issue (only seen on RHEL 8.7) - sudo sed -i s/OURCE//g /etc/logrotate.d/rocm_smi.conf + sudo sed -i s/OURCE//g "${logrotateConfFile}" fi # check if logrotate uses system timers, Ubuntu/modern OS's do # Several older OS's like RHEL 8.7, do not. Instead defaults @@ -59,16 +65,16 @@ EOF if [ -f /etc/cron.hourly/logrotate ]; then sudo mv /etc/cron.daily/logrotate /etc/cron.hourly/logrotate else - echo "[WARNING] Could find and configure hourly cron for ROCm-smi's"\ - " logrotate. ROCm-smi logs (when turned on) will not rotate properly." + echo "[WARNING] Could find and configure hourly cron for $packageName's"\ + " logrotate. $packageName logs (when turned on) will not rotate properly." return fi else # confirm that it's already been moved to hourly sudo find /etc/cron.* -iname logrotate -print -quit |grep -iq hourly if [ $? -ne 0 ]; then - echo "[WARNING] Could not configure an hourly cron for ROCm-smi's logrotate."\ - "ROCm-smi logs (when turned on) may not rotate properly." + echo "[WARNING] Could not configure an hourly cron for $packageName's logrotate."\ + "$packageName logs (when turned on) may not rotate properly." fi fi else @@ -93,12 +99,20 @@ WantedBy=timers.target EOF sudo systemctl reenable --now logrotate.timer else - echo "[WARNING] Could not configure systemd timer for ROCm's logrotate."\ - "ROCm-smi logs (when turned on) will not rotate properly." + echo "[WARNING] Could not configure systemd timer for $packageName's logrotate."\ + "$packageName logs (when turned on) will not rotate properly." fi fi } +do_ldconfig() { + # left-hand term originates from ENABLE_LDCONFIG = ON/OFF at package build + if [ "@ENABLE_LDCONFIG@" == "ON" ]; then + echo @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ > /etc/ld.so.conf.d/x86_64-librocm_smi_lib.conf + ldconfig + fi +} + # left-hand term originates from ENABLE_LDCONFIG = ON/OFF at package build if [ "@ENABLE_LDCONFIG@" == "ON" ]; then echo -e "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@" > /etc/ld.so.conf.d/x86_64-librocm_smi_lib.conf diff --git a/RPM/preun.in b/RPM/preun.in index 612504c3f2..b9c2eda6b3 100755 --- a/RPM/preun.in +++ b/RPM/preun.in @@ -1,13 +1,19 @@ #!/bin/bash #set -x +packageName="rocm-smi-lib" +logPath=/var/log/rocm_smi_lib +logName=ROCm-SMI-lib.log +logFile="${logPath}/${logName}" +logrotateConfFile=/etc/logrotate.d/rocm_smi.conf + rm_logFolder() { - sudo rm -rf /var/log/rocm_smi_lib + sudo rm -rf "$logPath" } return_logrotateToOrigConfig() { - if [ -f /etc/logrotate.d/rocm_smi.conf ]; then - sudo rm -rf /etc/logrotate.d/rocm_smi.conf + if [ -f $logrotateConfFile ]; then + sudo rm -rf "${logrotateConfFile}" fi if [ -f /etc/cron.hourly/logrotate ]; then sudo mv /etc/cron.hourly/logrotate /etc/cron.daily/logrotate