From nobody Mon Apr 29 13:07:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=ispras.ru ARC-Seal: i=1; a=rsa-sha256; t=1617013423; cv=none; d=zohomail.com; s=zohoarc; b=T+kuiGAeeh5Qbyei4CgoaKZvb5cMSMcD5rxk/A1TWEIo+zC+uEze/Uf/W3Ejm6l88ARr8zfpWrm7dG7o/8iTGFYuPReWMXB53rhlF8I/IcE356s6f4vvUIKX8RtPXqxOtMf3pvSYQ1rl7olaqwJ12kzvzq1gMlTqmcDulPe6UMs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617013423; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=1U4efgJ+uTg3zyVauAVR4t6NynTL+w1PWLbNc1ECcBA=; b=DrY+kc0GrCq2t7Ho+ifMoQWWzIScLRlL0UYx6duT3GK4st9cN0F4q2sV1FY6m5i3aWqi1NsBBlNvw4FwOChsCOY5/MFJJMc6MFvpNI9REPIpYJZ31nbsaw2IummPFbzqR65BOmisGc1DAz1vEGhOKIBTpKEaplZ0tWGdEmbuz4I= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617013423480328.6695554056264; Mon, 29 Mar 2021 03:23:43 -0700 (PDT) Received: from localhost ([::1]:34256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lQp3d-0008NT-Ay for importer@patchew.org; Mon, 29 Mar 2021 06:23:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lQp2g-0007qy-D6 for qemu-devel@nongnu.org; Mon, 29 Mar 2021 06:22:42 -0400 Received: from mail.ispras.ru ([83.149.199.84]:52110) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lQp2d-0005cy-0K for qemu-devel@nongnu.org; Mon, 29 Mar 2021 06:22:42 -0400 Received: from [127.0.1.1] (unknown [62.118.151.149]) by mail.ispras.ru (Postfix) with ESMTPSA id ECF4B407624A; Mon, 29 Mar 2021 10:22:30 +0000 (UTC) Subject: [PATCH] icount: get rid of static variable From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Mon, 29 Mar 2021 13:22:30 +0300 Message-ID: <161701335066.1180180.7104085247702343395.stgit@pasha-ThinkPad-X280> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=83.149.199.84; envelope-from=pavel.dovgalyuk@ispras.ru; helo=mail.ispras.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alex.bennee@linaro.org, pbonzini@redhat.com, pavel.dovgalyuk@ispras.ru, cfontana@suse.de Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This patch moves static last_delta variable into timers_state structure to allow correct vmstate operations with icount shift=3Dauto enab= led. Signed-off-by: Pavel Dovgalyuk --- softmmu/cpu-timers.c | 5 +++-- softmmu/icount.c | 9 +++------ softmmu/timers-state.h | 2 ++ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/softmmu/cpu-timers.c b/softmmu/cpu-timers.c index cd38595245..34ddfa02f1 100644 --- a/softmmu/cpu-timers.c +++ b/softmmu/cpu-timers.c @@ -188,11 +188,12 @@ static const VMStateDescription icount_vmstate_adjust= _timers =3D { =20 static const VMStateDescription icount_vmstate_shift =3D { .name =3D "timer/icount/shift", - .version_id =3D 1, - .minimum_version_id =3D 1, + .version_id =3D 2, + .minimum_version_id =3D 2, .needed =3D icount_shift_state_needed, .fields =3D (VMStateField[]) { VMSTATE_INT16(icount_time_shift, TimersState), + VMSTATE_INT64(last_delta, TimersState), VMSTATE_END_OF_LIST() } }; diff --git a/softmmu/icount.c b/softmmu/icount.c index dbcd8c3594..21341a4ce4 100644 --- a/softmmu/icount.c +++ b/softmmu/icount.c @@ -176,9 +176,6 @@ static void icount_adjust(void) int64_t cur_icount; int64_t delta; =20 - /* Protected by TimersState mutex. */ - static int64_t last_delta; - /* If the VM is not running, then do nothing. */ if (!runstate_is_running()) { return; @@ -193,20 +190,20 @@ static void icount_adjust(void) delta =3D cur_icount - cur_time; /* FIXME: This is a very crude algorithm, somewhat prone to oscillatio= n. */ if (delta > 0 - && last_delta + ICOUNT_WOBBLE < delta * 2 + && timers_state.last_delta + ICOUNT_WOBBLE < delta * 2 && timers_state.icount_time_shift > 0) { /* The guest is getting too far ahead. Slow time down. */ qatomic_set(&timers_state.icount_time_shift, timers_state.icount_time_shift - 1); } if (delta < 0 - && last_delta - ICOUNT_WOBBLE > delta * 2 + && timers_state.last_delta - ICOUNT_WOBBLE > delta * 2 && timers_state.icount_time_shift < MAX_ICOUNT_SHIFT) { /* The guest is getting too far behind. Speed time up. */ qatomic_set(&timers_state.icount_time_shift, timers_state.icount_time_shift + 1); } - last_delta =3D delta; + timers_state.last_delta =3D delta; qatomic_set_i64(&timers_state.qemu_icount_bias, cur_icount - (timers_state.qemu_icount << timers_state.icount_time_shift)); diff --git a/softmmu/timers-state.h b/softmmu/timers-state.h index db4e60f18f..8c262ce139 100644 --- a/softmmu/timers-state.h +++ b/softmmu/timers-state.h @@ -43,6 +43,8 @@ typedef struct TimersState { =20 /* Conversion factor from emulated instructions to virtual clock ticks= . */ int16_t icount_time_shift; + /* Icount delta used for shift auto adjust. */ + int64_t last_delta; =20 /* Compensate for varying guest execution speed. */ int64_t qemu_icount_bias;