From patchwork Wed Oct 17 08:24:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Pisarenko X-Patchwork-Id: 10644999 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 807311057 for ; Wed, 17 Oct 2018 08:29:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DAB629879 for ; Wed, 17 Oct 2018 08:29:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FD232A980; Wed, 17 Oct 2018 08:29:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D395329879 for ; Wed, 17 Oct 2018 08:29:57 +0000 (UTC) Received: from localhost ([::1]:34503 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gChDJ-0001Ib-62 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 17 Oct 2018 04:29:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCh9J-00075R-Ms for qemu-devel@nongnu.org; Wed, 17 Oct 2018 04:25:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCh9I-0008Jc-Oa for qemu-devel@nongnu.org; Wed, 17 Oct 2018 04:25:49 -0400 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]:41688) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gCh9I-0008Ic-Ed for qemu-devel@nongnu.org; Wed, 17 Oct 2018 04:25:48 -0400 Received: by mail-lj1-x242.google.com with SMTP id u21-v6so23469859lja.8 for ; Wed, 17 Oct 2018 01:25:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ZYjn/vYGFuPfM/3O21pjNuxhUP/+Csm9i9XUyBvxbN0=; b=AfLJpK7hJsyHoTx2/B8lLK3+aWfikRv4k/rhzKPerbkjh6O/gpOoXmHwcB9bcUvPw4 /6up8klxDJDRxaDCVqa/TFHqJjOZBeCNFI1trPexDFEqtmZ0DTykfFsVlP9Y+kljbCnG fMAPC+h02KwSTeAnCqh3ibz9Kf1Dv4NsetsBJb8izzc7Q28f6ZPvydlHGAmsvsFENkV6 gavGhqDxWKpCZDoCtg+FLPtjMH5TT6oEHil0l5jKXnmp2foQ+5Y1IuonGZZL+j9rA18U +XXtg1hWsyyCY05bBTuWEJoDFipgVPRV0raIvQRh/auA8alXczU5qkJcG1egLSno3Y6i iTqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ZYjn/vYGFuPfM/3O21pjNuxhUP/+Csm9i9XUyBvxbN0=; b=FHOsKnAjXKSTPu8d/I0aO4zwGPuUFSwYpPdr1hG8/JJSBIi/QDfii3KMkmsh5Nlf77 CYs+igXyH/NBD8YTPc4PYdL+XDAjCble2kZjey0XejFVenAHMysFS56lNQpP9IZw7jjH dXmIehaS2Jj/yW7r26FqOVBNXzqItI8tyCapX1QW2DvqRX6L2mdWq85h8LKyZmDgERoI XutE95PL4FsCtc7kGYds2Odt+InpXorTgZLUX5yFcVLCzha/ycjU+xsp7rlGQXQhmy0C BKnQFqIiy+0zb43gM6xbTyIuCk6Of2StX3NYJew4Xs+CpcdhpVSKtLUzCsDEY8MAzayr V7kQ== X-Gm-Message-State: ABuFfoiTNZkoYCluRtwTg6rbAYMdOq+DcQw0edsGvYgshWOVSK46Sffs a7DMi2IZrfex86U3wzId5uLfZWR2VDo= X-Google-Smtp-Source: ACcGV62TSvwe6z4gzJyzwhz97mqxMRwRin4co0Y42JjEx2MYiE6UAt9z9iiiX3cdejut23tYc4IkVA== X-Received: by 2002:a2e:8457:: with SMTP id u23-v6mr14311515ljh.154.1539764746553; Wed, 17 Oct 2018 01:25:46 -0700 (PDT) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id h77-v6sm3897735ljf.59.2018.10.17.01.25.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Oct 2018 01:25:45 -0700 (PDT) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 14:24:21 +0600 Message-Id: <549dbf4ebfa4c82051d01a264c27f88929fc277b.1539764043.git.artem.k.pisarenko@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::242 Subject: [Qemu-devel] [PATCH v2 4/4] Optimize record/replay checkpointing for all clocks it applies to X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Artem Pisarenko , Pavel Dovgalyuk Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Removes redundant checkpoints in replay log when there are no expired timers in timers list, associated with corresponding clock (i.e. no rr events associated with current clock value). This also improves performance in rr mode. Signed-off-by: Artem Pisarenko --- include/qemu/timer.h | 2 +- util/qemu-timer.c | 62 +++++++++++++++++++++++++--------------------------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 8e3f236..bd627dc 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -70,7 +70,7 @@ typedef enum { * QEMU_TIMER_ATTR_EXTERNAL: drives external subsystem * * Timers with this attribute do not recorded in rr mode, therefore it could be - * used for the subsystems that operate outside the guest core. Applicable only + * used for the subsystems that operate outside the guest core. Relevant only * with virtual clock type. */ diff --git a/util/qemu-timer.c b/util/qemu-timer.c index e9a0f00..7315ca1 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -495,6 +495,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) QEMUTimerCB *cb; void *opaque; bool need_replay_checkpoint = false; + ReplayCheckpoint replay_checkpoint_id; if (!atomic_read(&timer_list->active_timers)) { return false; @@ -505,43 +506,40 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) goto out; } - switch (timer_list->clock->type) { - case QEMU_CLOCK_REALTIME: - break; - default: - case QEMU_CLOCK_VIRTUAL: - if (replay_mode != REPLAY_MODE_NONE) { - /* Checkpoint for virtual clock is redundant in cases where - * it's being triggered with only non-EXTERNAL timers, because - * these timers don't change guest state directly. - * Since it has conditional dependence on specific timers, it is - * subject to race conditions and requires special handling. - * See below. - */ + if (replay_mode != REPLAY_MODE_NONE) { + /* Postpone actual checkpointing to timer list processing + * to properly check if we actually need it. + */ + switch (timer_list->clock->type) { + case QEMU_CLOCK_VIRTUAL: need_replay_checkpoint = true; + replay_checkpoint_id = CHECKPOINT_CLOCK_VIRTUAL; + break; + case QEMU_CLOCK_HOST: + need_replay_checkpoint = true; + replay_checkpoint_id = CHECKPOINT_CLOCK_HOST; + break; + case QEMU_CLOCK_VIRTUAL_RT: + need_replay_checkpoint = true; + replay_checkpoint_id = CHECKPOINT_CLOCK_VIRTUAL_RT; + break; + default: + break; } - break; - case QEMU_CLOCK_HOST: - if (!replay_checkpoint(CHECKPOINT_CLOCK_HOST)) { - goto out; - } - break; - case QEMU_CLOCK_VIRTUAL_RT: - if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL_RT)) { - goto out; - } - break; } /* - * Extract expired timers from active timers list and and process them. + * Extract expired timers from active timers list and and process them, + * taking into account checkpointing required in rr mode. * - * In rr mode we need "filtered" checkpointing for virtual clock. - * Checkpoint must be replayed before any non-EXTERNAL timer has been - * processed and only one time (virtual clock value stays same). But these - * timers may appear in the timers list while it being processed, so this - * must be checked until we finally decide that "no timers left - we are - * done". + * Checkpoint must be replayed before any timer has been processed + * and only one time. But new timers may appear in the timers list while + * it's being processed, so this must be checked until we finally decide + * that "no timers left - we are done" (to avoid skipping checkpoint due to + * possible races). + * Also checkpoint for virtual clock is redundant in cases where it's being + * triggered with only non-EXTERNAL timers, because these timers don't + * change guest state directly. */ current_time = qemu_clock_get_ns(timer_list->clock->type); qemu_mutex_lock(&timer_list->active_timers_lock); @@ -557,7 +555,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) /* once we got here, checkpoint clock only once */ need_replay_checkpoint = false; qemu_mutex_unlock(&timer_list->active_timers_lock); - if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL)) { + if (!replay_checkpoint(replay_checkpoint_id)) { goto out; } qemu_mutex_lock(&timer_list->active_timers_lock);