diff --git a/CMakeLists.txt b/CMakeLists.txt index f1fb146e5..79a0fab34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -542,10 +542,19 @@ target_link_libraries(xmr-stak-rx ${MHTD} ${LIBS} xmr-stak-rx-backend) # Install ################################################################################ +# install booster script +if(NOT WIN32) + install(DIRECTORY "${CMAKE_SOURCE_DIR}/scripts/" DESTINATION ${CMAKE_INSTALL_PREFIX}/${LIBRARY_OUTPUT_PATH} + FILES_MATCHING PATTERN "*.sh" + PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE GROUP_READ GROUP_EXECUTE + PATTERN .git EXCLUDE + ) +endif() + # do not install the binary if the project and install are equal if( NOT CMAKE_INSTALL_PREFIX STREQUAL PROJECT_BINARY_DIR ) install(TARGETS xmr-stak-rx - RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/${EXECUTABLE_OUTPUT_PATH}") + RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/${EXECUTABLE_OUTPUT_PATH}") if(CUDA_FOUND) if(WIN32) install(TARGETS xmrstakrx_cuda_backend diff --git a/doc/tuning.md b/doc/tuning.md index 19427b4b2..d7151a61f 100644 --- a/doc/tuning.md +++ b/doc/tuning.md @@ -2,6 +2,7 @@ ## Content Overview * [Fast Startup](#fast-startup) +* [Booster Script](#booster-script) * [Huge Page Support](#huge-page-support) * [Benchmark](#benchmark) * [Windows](#windows) @@ -24,9 +25,19 @@ ## Fast Startup You can disable the miner self test performed on each miner start by adding the command line option `--noTest` +## Booster Script + +The linux booster script manipulates the CPU caching behavior and activates huge pages. + +Call `sudo ./randomx_booster.sh`. + +The booster script will try to install all dependencies if need. +If the script can not install the dependencies (e.g. unknown systems) please install the tools `wrmsr` and `numactl`. + ## Huge Page Support In Linux you can enable 2 MiB huge pages with the following command. +In linux you can use our [booster script](#booster-script) to active huge pages ``` sudo sysctl -w vm.nr_hugepages=1300 diff --git a/scripts/randomx_booster.sh b/scripts/randomx_booster.sh new file mode 100755 index 000000000..f85c4c59c --- /dev/null +++ b/scripts/randomx_booster.sh @@ -0,0 +1,112 @@ +#!/usr/bin/env bash +# based on xmrig's randomx_boost.sh script +# lifted by psychocrypt + +function help() +{ + echo "$(basename $0) modifies caching behaviors of your CPU" + echo "and activates huge pages." + echo "Reboot your system to revert the changes." + echo "" + echo "must be called with administrative privileges e.g. 'sudo $(basename $0)'" +} + +if [ $# -ge 1 ] ; then + help + exit 1 +fi + +hasAptGet=$(which apt-get >/dev/null && { echo 1; } || { echo 0; }) +hasApt=$(which apt >/dev/null && { echo 1; } || { echo 0; }) +hasYum=$(which yum >/dev/null && { echo 1; } || { echo 0; }) + +tools=$(which wrmsr >/dev/null || { echo "msr-tools "; })$(which numactl >/dev/null || { echo " numactl"; }) + +if [ -n "$tools" ] ; then + echo "tool '$tools' not found, $(basename $0) is trying to install the dependency" + if [ $hasAptGet -eq 1 ] ; then + comm="apt-get --no-install-recommends --yes install $tools" + echo "execute: $comm" + $comm + elif [ $hasApt -eq 1 ] ; then + comm="apt-get --no-install-recommends --yes install $tools" + echo "execute: $comm" + $comm + elif [ $hasYum -eq 1 ] ; then + comm="yum install -y $tools" + echo "execute: $comm" + $comm + else + echo "package manager unknown, please install '$tools' by hand" >&2 + exit 1 + fi +fi + +hasWrmsr=$(which wrmsr >/dev/null && { echo 1; } || { echo 0; }) +if [ $hasWrmsr -eq 0 ] ; then + echo "dependency 'wrmsr' not found, tool failed" >&2 + exit 1 +fi + +hasNumactl=$(which numactl >/dev/null && { echo 1; } || { echo 0; }) +if [ $hasNumactl -eq 0 ] ; then + echo "dependency 'numactl' not found, tool failed" >&2 + exit 1 +fi + +echo "" +modprobe msr + +if cat /proc/cpuinfo | grep -q "AMD Ryzen" ; + then + echo "Detected Ryzen" + wrmsr -a 0xc0011022 0x510000 + wrmsr -a 0xc001102b 0x1808cc16 + wrmsr -a 0xc0011020 0 + wrmsr -a 0xc0011021 0x40 + echo "MSR register values for Ryzen applied" + echo "Reboot your system to revert the changes." +elif cat /proc/cpuinfo | grep -q "Intel" ; + then + echo "Detected Intel" + wrmsr -a 0x1a4 7 + echo "MSR register values for Intel applied" + echo "Reboot your system to revert the changes." +else + echo "No supported CPU detected" +fi + +echo "" + +### begin enable huge pages +required_num_huge_pages=1280 +num_huge_pages=$(cat /proc/meminfo | grep "HugePages_Free" | sed 's/ \{2,\}/ /g' | cut -d" " -f2) + +if [ $num_huge_pages -lt $required_num_huge_pages ] ; then + echo "active 2 MiB pages" + echo "execute: sysctl -w vm.nr_hugepages=$required_num_huge_pages" + sysctl -w vm.nr_hugepages="$required_num_huge_pages" +fi +# verify number of huge pages +num_huge_pages=$(cat /proc/meminfo | grep "HugePages_Free" | sed 's/ \{2,\}/ /g' | cut -d" " -f2) +num_memsets=$((num_huge_pages/required_num_huge_pages)) + +if [ $num_memsets -eq 0 ] ; then + echo "Error: not enough 2 MiB pages $num_huge_pages/$required_num_huge_pages" >&2 +fi + +# apply gigabyte pages last because 2MiB pages will give more performance +numNodes=$(numactl --hardware | grep available | cut -d" " -f2) +freeGigPages=$(cat /sys/kernel/mm/hugepages/hugepages-1048576kB/free_hugepages) +neededGigPages=$((numNodes * 3)) + +if [ $freeGigPages -lt $neededGigPages ] ; then + echo "" + echo "activate 1 GiB pages" + comm="echo $neededGigPages > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages" + echo "execute: $comm" + echo "$neededGigPages" > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages +fi +### end enable huge pages + +exit 0