@@ -49,21 +49,19 @@ static bool icount_sleep = true;
4949/* Arbitrarily pick 1MIPS as the minimum allowable speed. */
5050#define MAX_ICOUNT_SHIFT 10
5151
52- /*
53- * 0 = Do not count executed instructions.
54- * 1 = Fixed conversion of insn to ns via "shift" option
55- * 2 = Runtime adaptive algorithm to compute shift
56- */
57- int use_icount ;
52+ /* Do not count executed instructions */
53+ ICountMode use_icount = ICOUNT_DISABLED ;
5854
5955static void icount_enable_precise (void )
6056{
61- use_icount = 1 ;
57+ /* Fixed conversion of insn to ns via "shift" option */
58+ use_icount = ICOUNT_PRECISE ;
6259}
6360
6461static void icount_enable_adaptive (void )
6562{
66- use_icount = 2 ;
63+ /* Runtime adaptive algorithm to compute shift */
64+ use_icount = ICOUNT_ADAPTATIVE ;
6765}
6866
6967/*
@@ -256,7 +254,7 @@ static void icount_warp_rt(void)
256254 int64_t warp_delta ;
257255
258256 warp_delta = clock - timers_state .vm_clock_warp_start ;
259- if (icount_enabled () == 2 ) {
257+ if (icount_enabled () == ICOUNT_ADAPTATIVE ) {
260258 /*
261259 * In adaptive mode, do not let QEMU_CLOCK_VIRTUAL run too far
262260 * ahead of real time (it might already be ahead so careful not
@@ -419,7 +417,7 @@ void icount_account_warp_timer(void)
419417 icount_warp_rt ();
420418}
421419
422- void icount_configure (QemuOpts * opts , Error * * errp )
420+ bool icount_configure (QemuOpts * opts , Error * * errp )
423421{
424422 const char * option = qemu_opt_get (opts , "shift" );
425423 bool sleep = qemu_opt_get_bool (opts , "sleep" , true);
@@ -429,27 +427,28 @@ void icount_configure(QemuOpts *opts, Error **errp)
429427 if (!option ) {
430428 if (qemu_opt_get (opts , "align" ) != NULL ) {
431429 error_setg (errp , "Please specify shift option when using align" );
430+ return false;
432431 }
433- return ;
432+ return true ;
434433 }
435434
436435 if (align && !sleep ) {
437436 error_setg (errp , "align=on and sleep=off are incompatible" );
438- return ;
437+ return false ;
439438 }
440439
441440 if (strcmp (option , "auto" ) != 0 ) {
442441 if (qemu_strtol (option , NULL , 0 , & time_shift ) < 0
443442 || time_shift < 0 || time_shift > MAX_ICOUNT_SHIFT ) {
444443 error_setg (errp , "icount: Invalid shift value" );
445- return ;
444+ return false ;
446445 }
447446 } else if (icount_align_option ) {
448447 error_setg (errp , "shift=auto and align=on are incompatible" );
449- return ;
448+ return false ;
450449 } else if (!icount_sleep ) {
451450 error_setg (errp , "shift=auto and sleep=off are incompatible" );
452- return ;
451+ return false ;
453452 }
454453
455454 icount_sleep = sleep ;
@@ -463,7 +462,7 @@ void icount_configure(QemuOpts *opts, Error **errp)
463462 if (time_shift >= 0 ) {
464463 timers_state .icount_time_shift = time_shift ;
465464 icount_enable_precise ();
466- return ;
465+ return true ;
467466 }
468467
469468 icount_enable_adaptive ();
@@ -491,11 +490,14 @@ void icount_configure(QemuOpts *opts, Error **errp)
491490 timer_mod (timers_state .icount_vm_timer ,
492491 qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) +
493492 NANOSECONDS_PER_SECOND / 10 );
493+ return true;
494494}
495495
496496void icount_notify_exit (void )
497497{
498- if (icount_enabled () && current_cpu ) {
498+ assert (icount_enabled ());
499+
500+ if (current_cpu ) {
499501 qemu_cpu_kick (current_cpu );
500502 qemu_clock_notify (QEMU_CLOCK_VIRTUAL );
501503 }
0 commit comments