diff --git a/functions.sh b/functions.sh index dc6c85e..299e451 100755 --- a/functions.sh +++ b/functions.sh @@ -37,3 +37,57 @@ start_xmrig () { stop_xmrig () { 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 + +} + diff --git a/install.sh b/install.sh index 1267e66..f6fcad9 100755 --- a/install.sh +++ b/install.sh @@ -11,7 +11,6 @@ fi # Get settings . settings.sh -. functions.sh sleep 5 # Stop running instance diff --git a/settings.sh b/settings.sh index 60b49b2..474de2b 100755 --- a/settings.sh +++ b/settings.sh @@ -17,6 +17,9 @@ _POOL_SERVER_PORT="3333" ##################################################################### +# Load functions +. functions.sh + # Set working directory _WORK_DIR="$(pwd)" cd $_WORK_DIR @@ -70,63 +73,11 @@ echo -e "Cron on days: $_USER_CRONDAYS\n" _XMRIG_SCREEN="xmrig-cpu" echo -e "Screen session name: $_XMRIG_SCREEN\n" -# 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 +# call check_cpu +check_cpu -# 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" - -# 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 +# call calc_threads +calc_threads # Run apt maintenance # 1 = yes 0 = no