Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RX] randomx linux booster script #2637

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions doc/tuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Content Overview
* [Fast Startup](#fast-startup)
* [Booster Script](#booster-script)
* [Huge Page Support](#huge-page-support)
* [Benchmark](#benchmark)
* [Windows](#windows)
Expand All @@ -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
Expand Down
112 changes: 112 additions & 0 deletions scripts/randomx_booster.sh
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non blocking comment - those numbers are correct only for gen1 zen cores. Some testing is needed as they will set collateral bits with unknown function on gen2.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Numbers for C001_1020 and C001_1021 registers were taken from R7 3700X (Geekbench performance bias option in BIOS). Funny to see how you copy my work without any clue of what it does or how it was obtained :D AMD doesn't change MSR registers (at least these ones) within same family CPUs, and all Zen, Zen+ and Zen2 CPUs so far are family 17h.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Numbers for C001_1020 and C001_1021 registers were taken from R7 3700X (Geekbench performance bias option in BIOS).
AMD doesn't change MSR registers (at least these ones) within same family CPUs, and all Zen, Zen+ and Zen2 CPUs so far are family 17h.

+1, for the info

Funny to see how you copy my work without any clue of what it does or how it was obtained :D

please stop craying

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny to see how you copy my work without any clue of what it does or how it was obtained :D

Of course I know - you copied it from RagerX. That's why you have 2 gen2 MSRs and 2 gen1 MSRs. If you don't stop rocking your arse off, we will ban you from this repo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG lol. I figured the last two values myself, and the first two were sent to me by xnbya who tested prefetcher options in BIOS on some other AM4 board (that I didn't have). Your RagerX is a joke. Have you even implemented MSR mod there yet?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this is the screenshot of #monero-pools IRC from December 11th (everyone with IRC logs can check it): https://imgur.com/a/cE5XqHE
This where I got the info about the first 2 MSR registers and then I figured out the other two on my own, testing my BIOS.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RagerX came out on the 9th -> see, it only works on people who are dumb enough not to fact-check you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it came out on the 9th and it didn't have MSR mod back then because I tested it and I didn't see anything faster than I already had with xmrig on windows (without the mod). Maybe It has MSR mod now (of course), but I don't really care.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's very convenient to claim you had something before XMRig without proof when everything RagerX is closed source and people have no way of checking it. You're a pathological liar.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have been hanging out with pathological liars a bit too much.

https://medium.com/@crypto_ryo/senior-nasa-engineer-calls-out-howard-chu-hyc-symas-monero-developer-on-being-a-fraud-db0b46688041

But, hey, if "Look! I got this magic undocumented number of some guy on IRC. I totally don't know where it came from!!" is your story, that's your story.

Follow up question - do you think we would be dumb enough to put all our improvements at once :P. You will need to start looking harder for dodgy guys on IRC to find stuff for you =]

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