Pick core for running t/one-core-peak.sh
authorByteHamster <info@bytehamster.com>
Wed, 22 Sep 2021 14:30:35 +0000 (16:30 +0200)
committerByteHamster <info@bytehamster.com>
Sun, 26 Sep 2021 19:28:08 +0000 (21:28 +0200)
t/one-core-peak.sh

index 7c8ca56aed1a485b998ec9a1b4f89221f6bc8737..c391dcd5eb60ada2bb7a0ebfe9d3b97cb7c01e8b 100755 (executable)
@@ -4,7 +4,7 @@ args=$*
 first_cores=""
 taskset_cores=""
 first_cores_count=0
-nb_threads=4 #default from the benchmark
+nb_threads=1
 drives=""
 
 # Default options
@@ -39,11 +39,22 @@ check_binary() {
   done
 }
 
-
 detect_first_core() {
+  cpu_to_search="0"
+  if [ "${#drives[@]}" -eq 1 ]; then
+    device_name=$(block_dev_name ${drives[0]})
+    device_dir="/sys/block/${device_name}/device/"
+    pci_addr=$(cat ${device_dir}/address)
+    pci_dir="/sys/bus/pci/devices/${pci_addr}/"
+    cpu_to_search=$(cat ${pci_dir}/local_cpulist | cut -d"," -f 1 | cut -d"-" -f 1)
+  else
+    hint 'Passed multiple devices. Running on the first core.'
+  fi
+  core_to_run=$(lscpu  --all -pSOCKET,CORE,CPU | grep ",$cpu_to_search\$" | cut -d"," -f1-2)
+
   # Detect which logical cpus belongs to the first physical core
   # If Hyperthreading is enabled, two cores are returned
-  cpus=$(lscpu  --all -pSOCKET,CORE,CPU |grep "0,0")
+  cpus=$(lscpu  --all -pSOCKET,CORE,CPU | grep "$core_to_run")
   for cpu in ${cpus}; do
     IFS=','
     # shellcheck disable=SC2206