Commits

stqn committed e3498b0

mprime-phc-setup: add AMD support (inversed search); kill -9 mprime.

Comments (0)

Files changed (1)

 
 debug=0
 
+amd_max_vid=124
+
 # Tolerance for inaccurate frequencies during the test (in percent)
 # Added because of https://bbs.archlinux.org/viewtopic.php?pid=1301126#p1301126
 # NOTE: actually it seems that the problem is different: some CPUs have a bogus 1st
 	exit 1
 fi
 
+# Check if AMD processor, then need to reverse the search direction
+if lsmod | grep phc_k8 >/dev/null ; then
+	vid_delta=1
+	vid_limit=$amd_max_vid
+else
+	vid_delta=-1
+	vid_limit=0
+fi
+
 # Warn user about end of the world
 echo ""
 echo "Warning: this might crash your computer or applications."
 function kill_mprime
 {
 	(( mp_pid <= 1 )) && return
-	kill $mp_pid
+	kill -9 $mp_pid
 	wait $mp_pid &>/dev/null # needed to suppress the "killed" message by bash
 	mp_pid=-1
 }
 	read
 
 	# There was a crash at $cur_vid, so increase it and go directly to pass 2
-	cur_vid=$((cur_vid+2))
+	cur_vid=$((cur_vid-2*vid_delta))
 	pass2=1
 else
 	cur_vid=${vid[0]}
 
 	# Pass 1: lowering vid quickly until there is an error
 
-	if (( cur_vid > ${vid[f]} && pass2 == 0 )); then
+	if (( cur_vid*vid_delta < ${vid[f]}*vid_delta && pass2 == 0 )); then
 		#echo "forcing cur vid to max"
 		cur_vid=${vid[f]}
 	fi
 
-	((cur_vid--))
+	cur_vid=$((cur_vid+vid_delta))
 
-	for (( ; cur_vid > 0 && pass2 == 0; cur_vid-- )); do
+	for (( ; cur_vid != vid_limit && pass2 == 0; cur_vid+=vid_delta )); do
 		count=$short_test_length
 
 		echo "Trying vid $cur_vid for $count seconds"
 				kill_mprime
 				echo ""
 				echo "Hardware failure detected."
-				((cur_vid++))
+				((cur_vid-=vid_delta))
 				break 2
 			fi
 			cur_freq=$(cat $cpuf/scaling_cur_freq)
 
 	# Pass 2: stress testing for a longer time and going up in case of an error.
 
-	for (( ; cur_vid >= 0 && cur_vid < ${vid[f]}-safety_vid_delta; cur_vid++ )); do
+	for (( ; cur_vid*vid_delta <= vid_limit && cur_vid*vid_delta > (${vid[f]}+safety_vid_delta*vid_delta)*vid_delta; cur_vid-=vid_delta )); do
 		count=$long_test_length
 		echo "Trying vid $cur_vid for $count seconds"
 		save_state
 
 	echo ""
 	echo "Found working vid. Adding $safety_vid_delta for safety."
-	(( cur_vid < 0 )) && cur_vid=0
-	if (( cur_vid + safety_vid_delta > ${vid[f]} )); then
+	(( cur_vid*vid_delta > vid_limit*vid_delta )) && cur_vid=$vid_limit
+	if (( (cur_vid - safety_vid_delta*vid_delta)*vid_delta < ${vid[f]}*vid_delta )); then
 		final_vids=${final_vids}${vid[f]}
 	else
-		final_vids=${final_vids}$((cur_vid+safety_vid_delta))
+		final_vids=${final_vids}$((cur_vid-safety_vid_delta*vid_delta))
 	fi
 	(( f < nb_freqs-1 )) && final_vids="$final_vids "
 	echo "Current results: $final_vids"