mirror of
https://github.com/ilyakooo0/xmrig-bash-scripts.git
synced 2024-11-22 12:31:57 +03:00
Move some variables to functions
This commit is contained in:
parent
cef04fdc61
commit
065c2e6138
54
functions.sh
54
functions.sh
@ -37,3 +37,57 @@ start_xmrig () {
|
|||||||
stop_xmrig () {
|
stop_xmrig () {
|
||||||
screen -S $_XMRIG_SCREEN -X kill
|
screen -S $_XMRIG_SCREEN -X kill
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_cpu () {
|
||||||
|
# Check if CPU supports AES-NI
|
||||||
|
cpuid | grep -i aes > hw-aes.txt
|
||||||
|
if grep -q true "hw-aes.txt"; then
|
||||||
|
_AES_NI=true
|
||||||
|
else
|
||||||
|
_AES_NI=false
|
||||||
|
fi
|
||||||
|
rm hw-aes.txt
|
||||||
|
|
||||||
|
# Get number of available CPU Cores
|
||||||
|
_ENV_CORE=$(nproc --all)
|
||||||
|
echo -e "CPU Cores: $_ENV_CORE\n"
|
||||||
|
|
||||||
|
# Get CPU L3 cache value
|
||||||
|
_ENV_CORE_L3=$(getconf LEVEL3_CACHE_SIZE)
|
||||||
|
echo -e "L3 Cache in byte: $_ENV_CORE_L3\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
calc_threads () {
|
||||||
|
|
||||||
|
# Affine number of threads for _CPU_CN
|
||||||
|
_COUNTER="$(($_ENV_CORE_THREADS - 1))"
|
||||||
|
_ENV_CPU_THREADS=()
|
||||||
|
|
||||||
|
for i in `seq 0 $_COUNTER`; do
|
||||||
|
_ENV_CPU_THREADS+=("$i")
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Thread CPU Affinity: ${_ENV_CPU_THREADS[@]}"
|
||||||
|
_ENV_CPU_THREAD_AFFINITY="${_ENV_CPU_THREADS[@]}"
|
||||||
|
|
||||||
|
# Setting according to cpu cores but xmrig will not use all
|
||||||
|
# change to make value use _ENV_CORE_THREADS
|
||||||
|
# Check that hugepages set in /etc/sysctl.conf
|
||||||
|
_ENV_CHECK="nr_hugepages"
|
||||||
|
|
||||||
|
if sudo grep -q $_ENV_CHECK /etc/sysctl.conf; then
|
||||||
|
echo "Found nr_hugepages in /etc/sysctl.conf. All good!!"
|
||||||
|
echo -e "Refreshing sysctl configuration just to be sure.\n"
|
||||||
|
sudo sysctl -p
|
||||||
|
else
|
||||||
|
# Set value in current env
|
||||||
|
echo -e "Did not find nr_hugepages in /etc/sysctl.conf. Fixing that!!\n"
|
||||||
|
sudo sysctl -w vm.nr_hugepages="$_ENV_CORE"
|
||||||
|
sudo sysctl -p
|
||||||
|
|
||||||
|
# Add value to sysctl
|
||||||
|
echo "vm.nr_hugepages=$_ENV_CORE" | sudo tee -a /etc/sysctl.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ fi
|
|||||||
|
|
||||||
# Get settings
|
# Get settings
|
||||||
. settings.sh
|
. settings.sh
|
||||||
. functions.sh
|
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|
||||||
# Stop running instance
|
# Stop running instance
|
||||||
|
63
settings.sh
63
settings.sh
@ -17,6 +17,9 @@ _POOL_SERVER_PORT="3333"
|
|||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
|
# Load functions
|
||||||
|
. functions.sh
|
||||||
|
|
||||||
# Set working directory
|
# Set working directory
|
||||||
_WORK_DIR="$(pwd)"
|
_WORK_DIR="$(pwd)"
|
||||||
cd $_WORK_DIR
|
cd $_WORK_DIR
|
||||||
@ -70,63 +73,11 @@ echo -e "Cron on days: $_USER_CRONDAYS\n"
|
|||||||
_XMRIG_SCREEN="xmrig-cpu"
|
_XMRIG_SCREEN="xmrig-cpu"
|
||||||
echo -e "Screen session name: $_XMRIG_SCREEN\n"
|
echo -e "Screen session name: $_XMRIG_SCREEN\n"
|
||||||
|
|
||||||
# Check if CPU supports AES-NI
|
# call check_cpu
|
||||||
cpuid | grep -i aes > hw-aes.txt
|
check_cpu
|
||||||
if grep -q true "hw-aes.txt"; then
|
|
||||||
_AES_NI=true
|
|
||||||
else
|
|
||||||
_AES_NI=false
|
|
||||||
fi
|
|
||||||
rm hw-aes.txt
|
|
||||||
|
|
||||||
# Get number of available CPU Cores
|
# call calc_threads
|
||||||
_ENV_CORE=$(nproc --all)
|
calc_threads
|
||||||
echo -e "CPU Cores: $_ENV_CORE\n"
|
|
||||||
|
|
||||||
# Get CPU L3 cache value
|
|
||||||
_ENV_CORE_L3=$(getconf LEVEL3_CACHE_SIZE)
|
|
||||||
echo -e "L3 Cache in byte: $_ENV_CORE_L3\n"
|
|
||||||
|
|
||||||
# Determine number of threads possible
|
|
||||||
_ENV_CORE_L3_MB="$(($_ENV_CORE_L3 / 1000000))"
|
|
||||||
echo -e "L3 cache in Megabyte: $_ENV_CORE_L3_MB\n"
|
|
||||||
|
|
||||||
# Determine number of threads possible
|
|
||||||
_ENV_CORE_THREADS="$(($_ENV_CORE_L3_MB / 2))"
|
|
||||||
echo "Each thread requires 2 MB of cache"
|
|
||||||
echo -e "Number of threads possible is: $_ENV_CORE_THREADS\n"
|
|
||||||
|
|
||||||
# Affine number of threads for _CPU_CN
|
|
||||||
_COUNTER="$(($_ENV_CORE_THREADS - 1))"
|
|
||||||
_ENV_CPU_THREADS=()
|
|
||||||
|
|
||||||
for i in `seq 0 $_COUNTER`; do
|
|
||||||
_ENV_CPU_THREADS+=("$i")
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "Thread CPU Affinity: ${_ENV_CPU_THREADS[@]}"
|
|
||||||
|
|
||||||
_ENV_CPU_THREAD_AFFINITY="${_ENV_CPU_THREADS[@]}"
|
|
||||||
|
|
||||||
|
|
||||||
# Setting according to cpu cores but xmrig will not use all
|
|
||||||
# change to make value use _ENV_CORE_THREADS
|
|
||||||
# Check that hugepages set in /etc/sysctl.conf
|
|
||||||
_ENV_CHECK="nr_hugepages"
|
|
||||||
|
|
||||||
if sudo grep -q $_ENV_CHECK /etc/sysctl.conf; then
|
|
||||||
echo "Found nr_hugepages in /etc/sysctl.conf. All good!!"
|
|
||||||
echo -e "Refreshing sysctl configuration just to be sure.\n"
|
|
||||||
sudo sysctl -p
|
|
||||||
else
|
|
||||||
# Set value in current env
|
|
||||||
echo -e "Did not find nr_hugepages in /etc/sysctl.conf. Fixing that!!\n"
|
|
||||||
sudo sysctl -w vm.nr_hugepages="$_ENV_CORE"
|
|
||||||
sudo sysctl -p
|
|
||||||
|
|
||||||
# Add value to sysctl
|
|
||||||
echo "vm.nr_hugepages=$_ENV_CORE" | sudo tee -a /etc/sysctl.conf
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Run apt maintenance
|
# Run apt maintenance
|
||||||
# 1 = yes 0 = no
|
# 1 = yes 0 = no
|
||||||
|
Loading…
Reference in New Issue
Block a user