From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WRHl7-0002dh-V0 for qemu-devel@nongnu.org; Sat, 22 Mar 2014 04:58:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WRHl2-0001uH-OI for qemu-devel@nongnu.org; Sat, 22 Mar 2014 04:58:29 -0400 Received: from mail-ee0-x236.google.com ([2a00:1450:4013:c00::236]:55812) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WRHl2-0001ty-DK for qemu-devel@nongnu.org; Sat, 22 Mar 2014 04:58:24 -0400 Received: by mail-ee0-f54.google.com with SMTP id d49so2564081eek.41 for ; Sat, 22 Mar 2014 01:58:23 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <532D50A7.8000403@redhat.com> Date: Sat, 22 Mar 2014 09:58:15 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1395429454-24690-1-git-send-email-fred.konrad@greensocs.com> <1395429454-24690-2-git-send-email-fred.konrad@greensocs.com> In-Reply-To: <1395429454-24690-2-git-send-email-fred.konrad@greensocs.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC PATCH 01/12] icount: put icount variables into TimerState. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: fred.konrad@greensocs.com, qemu-devel@nongnu.org Cc: mark.burton@greensocs.com Il 21/03/2014 20:17, fred.konrad@greensocs.com ha scritto: > From: KONRAD Frederic > > This puts qemu_icount and qemu_icount_bias into TimerState structure to allow > them to be migrated. > > Signed-off-by: KONRAD Frederic > --- > cpus.c | 29 ++++++++++++++++------------- > 1 file changed, 16 insertions(+), 13 deletions(-) > > diff --git a/cpus.c b/cpus.c > index 1104d61..687717f 100644 > --- a/cpus.c > +++ b/cpus.c > @@ -100,17 +100,12 @@ static bool all_cpu_threads_idle(void) > > /* Protected by TimersState seqlock */ > > -/* Compensate for varying guest execution speed. */ > -static int64_t qemu_icount_bias; > static int64_t vm_clock_warp_start; > /* Conversion factor from emulated instructions to virtual clock ticks. */ > static int icount_time_shift; > /* Arbitrarily pick 1MIPS as the minimum allowable speed. */ > #define MAX_ICOUNT_SHIFT 10 > > -/* Only written by TCG thread */ > -static int64_t qemu_icount; > - > static QEMUTimer *icount_rt_timer; > static QEMUTimer *icount_vm_timer; > static QEMUTimer *icount_warp_timer; > @@ -127,6 +122,11 @@ typedef struct TimersState { > int64_t cpu_clock_offset; > int32_t cpu_ticks_enabled; > int64_t dummy; > + > + /* Compensate for varying guest execution speed. */ > + int64_t qemu_icount_bias; > + /* Only written by TCG thread */ > + int64_t qemu_icount; > } TimersState; > > static TimersState timers_state; > @@ -137,14 +137,14 @@ static int64_t cpu_get_icount_locked(void) > int64_t icount; > CPUState *cpu = current_cpu; > > - icount = qemu_icount; > + icount = timers_state.qemu_icount; > if (cpu) { > if (!cpu_can_do_io(cpu)) { > fprintf(stderr, "Bad clock read\n"); > } > icount -= (cpu->icount_decr.u16.low + cpu->icount_extra); > } > - return qemu_icount_bias + (icount << icount_time_shift); > + return timers_state.qemu_icount_bias + (icount << icount_time_shift); > } > > int64_t cpu_get_icount(void) > @@ -282,7 +282,8 @@ static void icount_adjust(void) > icount_time_shift++; > } > last_delta = delta; > - qemu_icount_bias = cur_icount - (qemu_icount << icount_time_shift); > + timers_state.qemu_icount_bias = cur_icount > + - (timers_state.qemu_icount << icount_time_shift); > seqlock_write_unlock(&timers_state.vm_clock_seqlock); > } > > @@ -331,7 +332,7 @@ static void icount_warp_rt(void *opaque) > int64_t delta = cur_time - cur_icount; > warp_delta = MIN(warp_delta, delta); > } > - qemu_icount_bias += warp_delta; > + timers_state.qemu_icount_bias += warp_delta; > } > vm_clock_warp_start = -1; > seqlock_write_unlock(&timers_state.vm_clock_seqlock); > @@ -349,7 +350,7 @@ void qtest_clock_warp(int64_t dest) > int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL); > int64_t warp = MIN(dest - clock, deadline); > seqlock_write_lock(&timers_state.vm_clock_seqlock); > - qemu_icount_bias += warp; > + timers_state.qemu_icount_bias += warp; > seqlock_write_unlock(&timers_state.vm_clock_seqlock); > > qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); > @@ -1248,7 +1249,8 @@ static int tcg_cpu_exec(CPUArchState *env) > int64_t count; > int64_t deadline; > int decr; > - qemu_icount -= (cpu->icount_decr.u16.low + cpu->icount_extra); > + timers_state.qemu_icount -= (cpu->icount_decr.u16.low > + + cpu->icount_extra); > cpu->icount_decr.u16.low = 0; > cpu->icount_extra = 0; > deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL); > @@ -1263,7 +1265,7 @@ static int tcg_cpu_exec(CPUArchState *env) > } > > count = qemu_icount_round(deadline); > - qemu_icount += count; > + timers_state.qemu_icount += count; > decr = (count > 0xffff) ? 0xffff : count; > count -= decr; > cpu->icount_decr.u16.low = decr; > @@ -1276,7 +1278,8 @@ static int tcg_cpu_exec(CPUArchState *env) > if (use_icount) { > /* Fold pending instructions back into the > instruction counter, and clear the interrupt flag. */ > - qemu_icount -= (cpu->icount_decr.u16.low + cpu->icount_extra); > + timers_state.qemu_icount -= (cpu->icount_decr.u16.low > + + cpu->icount_extra); > cpu->icount_decr.u32 = 0; > cpu->icount_extra = 0; > } > Reviewed-by: Paolo Bonzini