@@ -2852,6 +2852,8 @@ def main():
28522852 }
28532853
28542854 ssh_passthrough = []
2855+ cpu_specified = False
2856+
28552857
28562858 script_home = os .path .dirname (os .path .abspath (__file__ ))
28572859 working_dir = os .path .join (script_home , "output" )
@@ -2888,6 +2890,7 @@ def main():
28882890 i += 1
28892891 elif arg == "--cpu" :
28902892 config ['cpu' ] = args [i + 1 ]
2893+ cpu_specified = True
28912894 i += 1
28922895 elif arg == "--cpu-type" :
28932896 config ['cputype' ] = args [i + 1 ]
@@ -3437,6 +3440,41 @@ def find_image_link(releases, target_zst, target_xz):
34373440 serial_arg = "tcp:{}:{},server,nowait" .format (serial_bind_addr , config ['serialport' ])
34383441 debuglog (config ['debug' ], "Switched serial to TCP for VNC Console: " + serial_arg )
34393442
3443+ # Acceleration determination
3444+ accel = "tcg"
3445+ if config ['arch' ] == "aarch64" :
3446+ if host_arch == "aarch64" :
3447+ if os .path .exists ("/dev/kvm" ):
3448+ if os .access ("/dev/kvm" , os .R_OK | os .W_OK ):
3449+ accel = "kvm"
3450+ else :
3451+ log ("Warning: /dev/kvm exists but is not writable. Falling back to TCG." )
3452+ elif platform .system () == "Darwin" and hvf_supported ():
3453+ accel = "hvf"
3454+ elif config ['arch' ] == "riscv64" :
3455+ accel = "tcg"
3456+ else : # x86_64
3457+ if host_arch in ["x86_64" , "amd64" ]:
3458+ if IS_WINDOWS :
3459+ if config ['whpx' ]:
3460+ accel = "whpx"
3461+ elif os .path .exists ("/dev/kvm" ):
3462+ if os .access ("/dev/kvm" , os .R_OK | os .W_OK ):
3463+ accel = "kvm"
3464+ else :
3465+ log ("Warning: /dev/kvm exists but is not writable. Falling back to TCG." )
3466+ elif platform .system () == "Darwin" :
3467+ accel = "hvf"
3468+
3469+ # CPU optimization for TCG
3470+ if not cpu_specified and accel == "tcg" :
3471+ try :
3472+ if int (config ['cpu' ]) > 2 :
3473+ debuglog (config ['debug' ], "TCG mode detected and no CPU count specified, limiting to 2 cores for performance optimization." )
3474+ config ['cpu' ] = "2"
3475+ except (ValueError , TypeError ):
3476+ pass
3477+
34403478 # Disk type selection
34413479 if config ['disktype' ]:
34423480 disk_if = config ['disktype' ]
@@ -3536,21 +3574,6 @@ def find_image_link(releases, target_zst, target_xz):
35363574 if not os .path .exists (vars_path ):
35373575 create_sized_file (vars_path , 64 )
35383576
3539- accel = "tcg"
3540- if host_arch == "aarch64" :
3541- if os .path .exists ("/dev/kvm" ):
3542- if os .access ("/dev/kvm" , os .R_OK | os .W_OK ):
3543- accel = "kvm"
3544- else :
3545- log ("Warning: /dev/kvm exists but is not writable. Falling back to TCG." )
3546- elif platform .system () == "Darwin" :
3547- # On Apple Silicon, HVF is available if we're on aarch64 host AND the system supports it
3548- if host_arch == "aarch64" and hvf_supported ():
3549- accel = "hvf"
3550- else :
3551- # Intel Mac trying to run aarch64 -> TCG, or HVF not supported
3552- accel = "tcg"
3553-
35543577 if config ['cputype' ]:
35553578 cpu = config ['cputype' ]
35563579 else :
@@ -3605,19 +3628,6 @@ def find_image_link(releases, target_zst, target_xz):
36053628 ])
36063629 else :
36073630 # x86_64
3608- accel = "tcg"
3609- if host_arch in ["x86_64" , "amd64" ]:
3610- if IS_WINDOWS :
3611- if config ['whpx' ]:
3612- accel = "whpx"
3613- elif os .path .exists ("/dev/kvm" ):
3614- if os .access ("/dev/kvm" , os .R_OK | os .W_OK ):
3615- accel = "kvm"
3616- else :
3617- log ("Warning: /dev/kvm exists but is not writable. Falling back to TCG." )
3618- elif platform .system () == "Darwin" :
3619- accel = "hvf"
3620-
36213631 machine_opts = "pc,accel={},hpet=off,smm=off,graphics=on,vmport=off,usb=on" .format (accel )
36223632
36233633 if accel in ["kvm" , "whpx" , "hvf" ]:
0 commit comments