|
25 | 25 | #include "qemu/osdep.h"
|
26 | 26 | #include "qemu-common.h"
|
27 | 27 | #include "qemu/config-file.h"
|
| 28 | +#include "qemu/cutils.h" |
28 | 29 | #include "migration/vmstate.h"
|
29 | 30 | #include "monitor/monitor.h"
|
30 | 31 | #include "qapi/error.h"
|
@@ -797,40 +798,47 @@ void cpu_ticks_init(void)
|
797 | 798 |
|
798 | 799 | void configure_icount(QemuOpts *opts, Error **errp)
|
799 | 800 | {
|
800 |
| - const char *option; |
801 |
| - char *rem_str = NULL; |
| 801 | + const char *option = qemu_opt_get(opts, "shift"); |
| 802 | + bool sleep = qemu_opt_get_bool(opts, "sleep", true); |
| 803 | + bool align = qemu_opt_get_bool(opts, "align", false); |
| 804 | + long time_shift = -1; |
802 | 805 |
|
803 |
| - option = qemu_opt_get(opts, "shift"); |
804 |
| - if (!option) { |
805 |
| - if (qemu_opt_get(opts, "align") != NULL) { |
806 |
| - error_setg(errp, "Please specify shift option when using align"); |
807 |
| - } |
| 806 | + if (!option && qemu_opt_get(opts, "align")) { |
| 807 | + error_setg(errp, "Please specify shift option when using align"); |
808 | 808 | return;
|
809 | 809 | }
|
810 | 810 |
|
811 |
| - icount_sleep = qemu_opt_get_bool(opts, "sleep", true); |
812 |
| - if (icount_sleep) { |
813 |
| - timers_state.icount_warp_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL_RT, |
814 |
| - icount_timer_cb, NULL); |
815 |
| - } |
816 |
| - |
817 |
| - icount_align_option = qemu_opt_get_bool(opts, "align", false); |
818 |
| - |
819 |
| - if (icount_align_option && !icount_sleep) { |
| 811 | + if (align && !sleep) { |
820 | 812 | error_setg(errp, "align=on and sleep=off are incompatible");
|
| 813 | + return; |
821 | 814 | }
|
| 815 | + |
822 | 816 | if (strcmp(option, "auto") != 0) {
|
823 |
| - errno = 0; |
824 |
| - timers_state.icount_time_shift = strtol(option, &rem_str, 0); |
825 |
| - if (errno != 0 || *rem_str != '\0' || !strlen(option)) { |
| 817 | + if (qemu_strtol(option, NULL, 0, &time_shift) < 0 |
| 818 | + || time_shift < 0 || time_shift > MAX_ICOUNT_SHIFT) { |
826 | 819 | error_setg(errp, "icount: Invalid shift value");
|
| 820 | + return; |
827 | 821 | }
|
828 |
| - use_icount = 1; |
829 |
| - return; |
830 | 822 | } else if (icount_align_option) {
|
831 | 823 | error_setg(errp, "shift=auto and align=on are incompatible");
|
| 824 | + return; |
832 | 825 | } else if (!icount_sleep) {
|
833 | 826 | error_setg(errp, "shift=auto and sleep=off are incompatible");
|
| 827 | + return; |
| 828 | + } |
| 829 | + |
| 830 | + icount_sleep = sleep; |
| 831 | + if (icount_sleep) { |
| 832 | + timers_state.icount_warp_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL_RT, |
| 833 | + icount_timer_cb, NULL); |
| 834 | + } |
| 835 | + |
| 836 | + icount_align_option = align; |
| 837 | + |
| 838 | + if (time_shift >= 0) { |
| 839 | + timers_state.icount_time_shift = time_shift; |
| 840 | + use_icount = 1; |
| 841 | + return; |
834 | 842 | }
|
835 | 843 |
|
836 | 844 | use_icount = 2;
|
|
0 commit comments