Skip to content

Commit 484f186

Browse files
authored
Update bitaxe_hashrate_benchmark.py
Couple of changes: - color not working in windows terminal - suffix in filename in case of voltage/frequency argument - limited (1 successive) retries in case of overheat (previously any chip overheat reached ended the benchmark)
1 parent 52bd49a commit 484f186

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

bitaxe_hashrate_benchmark.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import sys
66
import argparse
77

8+
import os
9+
os.system("") # enables ansi escape characters in terminal - colors were not working in Windows terminal
10+
811
# ANSI Color Codes
912
GREEN = "\033[92m"
1013
YELLOW = "\033[93m"
@@ -72,6 +75,13 @@ def parse_arguments():
7275
if benchmark_time / sample_interval < 7:
7376
raise ValueError(RED + f"Error: Benchmark time is too short. Please increase the benchmark time or decrease the sample interval. At least 7 samples are required." + RESET)
7477

78+
# Add suffix to filename in case of manual initial voltage/frequency
79+
file_suffix = ""
80+
if initial_voltage != 1150:
81+
file_suffix = file_suffix + " v" + str(initial_voltage)
82+
if initial_frequency != 500:
83+
file_suffix = file_suffix + " f" + str(initial_frequency)
84+
7585
# Results storage
7686
results = []
7787

@@ -307,7 +317,7 @@ def save_results():
307317
try:
308318
# Extract IP from bitaxe_ip global variable and remove 'http://'
309319
ip_address = bitaxe_ip.replace('http://', '')
310-
filename = f"bitaxe_benchmark_results_{ip_address}.json"
320+
filename = f"bitaxe_benchmark_results_{ip_address}{file_suffix}.json"
311321
with open(filename, "w") as f:
312322
json.dump(results, f, indent=4)
313323
print(GREEN + f"Results saved to {filename}" + RESET)
@@ -346,12 +356,14 @@ def reset_to_best_setting():
346356

347357
current_voltage = initial_voltage
348358
current_frequency = initial_frequency
359+
retry_upon_overheat = 0
349360

350361
while current_voltage <= max_allowed_voltage and current_frequency <= max_allowed_frequency:
351362
set_system_settings(current_voltage, current_frequency)
352363
avg_hashrate, avg_temp, efficiency_jth, hashrate_ok, avg_vr_temp, error_reason = benchmark_iteration(current_voltage, current_frequency)
353364

354365
if avg_hashrate is not None and avg_temp is not None and efficiency_jth is not None:
366+
retry_upon_overheat = 0
355367
result = {
356368
"coreVoltage": current_voltage,
357369
"frequency": current_frequency,
@@ -370,20 +382,37 @@ def reset_to_best_setting():
370382
# If hashrate is good, try increasing frequency
371383
if current_frequency + frequency_increment <= max_allowed_frequency:
372384
current_frequency += frequency_increment
385+
print(GREEN + "Hashrate is good. Increasing frequency for next try." + RESET)
373386
else:
387+
print(GREEN + "Reached max frequency with good results. Stopping further testing." + RESET)
374388
break # We've reached max frequency with good results
375389
else:
376390
# If hashrate is not good, go back one frequency step and increase voltage
377391
if current_voltage + voltage_increment <= max_allowed_voltage:
378392
current_voltage += voltage_increment
379393
current_frequency -= frequency_increment # Go back to one frequency step and retry
380-
print(YELLOW + f"Hashrate to low compared to expected. Decreasing frequency to {current_frequency}MHz and increasing voltage to {current_voltage}mV" + RESET)
394+
print(YELLOW + f"Hashrate too low compared to expected. Decreasing frequency to {current_frequency}MHz and increasing voltage to {current_voltage}mV" + RESET)
381395
else:
396+
print(YELLOW + "Reached max voltage without good results. Stopping further testing." + RESET)
382397
break # We've reached max voltage without good results
383398
else:
384399
# If we hit thermal limits or other issues, we've found the highest safe settings
385-
print(GREEN + "Reached thermal or stability limits. Stopping further testing." + RESET)
386-
break # Stop testing higher values
400+
# In case of max Chip Temperature reached, continue loop to next voltage with decreased frequency
401+
# Condition added to avoid successive overheat tries and reset to high initial frequency
402+
if avg_hashrate is None and avg_temp is None and efficiency_jth is None and hashrate_ok is False and avg_vr_temp is None and error_reason == 'CHIP_TEMP_EXCEEDED' and initial_frequency <= current_frequency + frequency_increment and retry_upon_overheat < 1:
403+
# If overheat, return to initial frequency while increasing voltage (considering max_allowed_voltage)
404+
#and current_frequency + frequency_increment <= max_allowed_frequency and current_voltage + voltage_increment <= max_allowed_voltage
405+
retry_upon_overheat += 1
406+
if current_voltage + voltage_increment <= max_allowed_voltage:
407+
current_frequency = initial_frequency
408+
current_voltage += voltage_increment
409+
print(GREEN + "Reached thermal limit for the current voltage/frequency. Switching to next voltage increment." + RESET)
410+
else:
411+
print(GREEN + "Reached thermal limit for the current voltage/frequency. Next voltage increment out of voltage limit. Stopping further testing." + RESET)
412+
break # We've reached max voltage, can't increase voltage anymore
413+
else:
414+
print(GREEN + "Reached thermal or stability limits. Stopping further testing." + RESET)
415+
break # Stop testing higher values
387416

388417
save_results()
389418

@@ -445,7 +474,7 @@ def reset_to_best_setting():
445474

446475
# Save the final data to JSON
447476
ip_address = bitaxe_ip.replace('http://', '')
448-
filename = f"bitaxe_benchmark_results_{ip_address}.json"
477+
filename = f"bitaxe_benchmark_results_{ip_address}{file_suffix}.json"
449478
with open(filename, "w") as f:
450479
json.dump(final_data, f, indent=4)
451480

@@ -495,3 +524,4 @@ def cleanup_and_exit(reason=None):
495524
print(RED + f"Benchmarking stopped: {reason}" + RESET)
496525
print(GREEN + "Benchmarking completed." + RESET)
497526
sys.exit(0)
527+

0 commit comments

Comments
 (0)