From patchwork Tue Jan 23 08:54:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pavel Dovgalyuk X-Patchwork-Id: 125487 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp1633796ljf; Tue, 23 Jan 2018 01:05:30 -0800 (PST) X-Google-Smtp-Source: AH8x2251TyhmogtUjv02bBHajrtmGwA/Di82Ec2r79HjFnR+GKnCTR5xd9VdxXb9axpODtmpaYCl X-Received: by 10.37.13.129 with SMTP id 123mr1712799ybn.156.1516698330441; Tue, 23 Jan 2018 01:05:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516698330; cv=none; d=google.com; s=arc-20160816; b=wueK7mBv+FtbW0AV/MWzUkNa/7QE87kgtrf1tmaDOZaRr+64Of9HLNQsn0AxAj34LL tD9D46mNWYXMjvlklscsecw7apltAt82JP/2EbZPf7a3ZmNV3w1WVYnHXT7lgvSvAPzN vfEJxrZB91RMJtqGgOINcxc/lGwax4YhKldRhkHGDk2Hdg9UBJt4huGxrH35XT1KquSu iNe3+lfs1xnA6R9shiHtpszFgpXsulcR5HzTsqY7Rs5O4W62t2kDk8QkVWMFnKcROlg3 3uNKVQ+m6TosYV2ubbl3ipUEKrdsQaeON4pbaNTA6t0Gwop1yvKiKlrV1SxuKKwuO14h YEHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:to:from:arc-authentication-results; bh=KzpNJiMEg8uyfEWj1jsl3leIXmlNYLnok6xi9ReuC1E=; b=I/uz1yBv4GZgDUwC14GO+oaOTXNDONTWS0IZCpXSSFHmL8e9CMSnIheUoVABpELI3/ SqovBM4slT3doxhLvZEj/haoSY6dD1pk/Zn9PbguA/bWZVDAXODjLIHGAVXIEVkmhyXK BPgU/nSDi+EOqV4+RdqF3Jc6NtWqXU1OEgfvbGqai3tf4dn+i6/UsAqACdLqupLCXoQ9 fXEw20vrPBIFI3VyuDzW0WuOV6Qi8PjPghBvEn0L88Ul1V0icolgmMPeQheJJcVfJKFz KleKHVnhqb8je2NjzaY1xYnkq8eQThRjrXW1mAzxR/mc7JBFx/Wy+R8O/+3o3jJ+e7r6 Oitw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id u29si2351273ybd.664.2018.01.23.01.05.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 23 Jan 2018 01:05:30 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:45996 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eduWH-0002zZ-Ou for patch@linaro.org; Tue, 23 Jan 2018 04:05:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40826) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eduM1-0002AM-CH for qemu-devel@nongnu.org; Tue, 23 Jan 2018 03:54:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eduLx-0000Jt-AJ for qemu-devel@nongnu.org; Tue, 23 Jan 2018 03:54:53 -0500 Received: from mail.ispras.ru ([83.149.199.45]:57324) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eduLw-0000JX-Ts for qemu-devel@nongnu.org; Tue, 23 Jan 2018 03:54:49 -0500 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 00B2B54006A; Tue, 23 Jan 2018 11:54:47 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 23 Jan 2018 11:54:49 +0300 Message-ID: <20180123085449.3419.11778.stgit@pasha-VirtualBox> In-Reply-To: <20180123085319.3419.97865.stgit@pasha-VirtualBox> References: <20180123085319.3419.97865.stgit@pasha-VirtualBox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v5 16/24] replay: make locking visible outside replay code 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: kwolf@redhat.com, peter.maydell@linaro.org, pavel.dovgaluk@ispras.ru, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, zuban32s@gmail.com, maria.klimushenkova@ispras.ru, dovgaluk@ispras.ru, kraxel@redhat.com, boost.lists@gmail.com, pbonzini@redhat.com, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée The replay_mutex_lock/unlock/locked functions are now going to be used for ensuring lock-step behaviour between the two threads. Make them public API functions and also provide stubs for non-QEMU builds on common paths. Signed-off-by: Alex Bennée Tested-by: Pavel Dovgalyuk --- include/sysemu/replay.h | 14 ++++++++++++++ replay/replay-internal.c | 9 ++++----- replay/replay-internal.h | 5 ++--- stubs/replay.c | 15 +++++++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index b86d6bb..9973849 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -47,6 +47,20 @@ extern ReplayMode replay_mode; /* Name of the initial VM snapshot */ extern char *replay_snapshot; +/* Replay locking + * + * The locks are needed to protect the shared structures and log file + * when doing record/replay. They also are the main sync-point between + * the main-loop thread and the vCPU thread. This was a role + * previously filled by the BQL which has been busy trying to reduce + * its impact across the code. This ensures blocks of events stay + * sequential and reproducible. + */ + +void replay_mutex_lock(void); +void replay_mutex_unlock(void); +bool replay_mutex_locked(void); + /* Replay process control functions */ /*! Enables recording or saving event log with specified parameters */ diff --git a/replay/replay-internal.c b/replay/replay-internal.c index 157c863..a9a6a64 100644 --- a/replay/replay-internal.c +++ b/replay/replay-internal.c @@ -169,6 +169,8 @@ void replay_finish_event(void) replay_fetch_data_kind(); } +static __thread bool replay_locked; + void replay_mutex_init(void) { qemu_mutex_init(&lock); @@ -179,9 +181,7 @@ void replay_mutex_destroy(void) qemu_mutex_destroy(&lock); } -static __thread bool replay_locked; - -static bool replay_mutex_locked(void) +bool replay_mutex_locked(void) { return replay_locked; } @@ -204,7 +204,7 @@ void replay_mutex_unlock(void) void replay_save_instructions(void) { if (replay_file && replay_mode == REPLAY_MODE_RECORD) { - replay_mutex_lock(); + g_assert(replay_mutex_locked()); int diff = (int)(replay_get_current_step() - replay_state.current_step); /* Time can only go forward */ @@ -215,6 +215,5 @@ void replay_save_instructions(void) replay_put_dword(diff); replay_state.current_step += diff; } - replay_mutex_unlock(); } } diff --git a/replay/replay-internal.h b/replay/replay-internal.h index 8e4c701..f5f8e96 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -100,12 +100,11 @@ int64_t replay_get_qword(void); void replay_get_array(uint8_t *buf, size_t *size); void replay_get_array_alloc(uint8_t **buf, size_t *size); -/* Mutex functions for protecting replay log file */ +/* Mutex functions for protecting replay log file and ensuring + * synchronisation between vCPU and main-loop threads. */ void replay_mutex_init(void); void replay_mutex_destroy(void); -void replay_mutex_lock(void); -void replay_mutex_unlock(void); /*! Checks error status of the file. */ void replay_check_error(void); diff --git a/stubs/replay.c b/stubs/replay.c index 9991ee5..cb050ef 100644 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -73,3 +73,18 @@ uint64_t blkreplay_next_id(void) { return 0; } + +void replay_mutex_lock(void) +{ + abort(); +} + +void replay_mutex_unlock(void) +{ + abort(); +} + +bool replay_mutex_locked(void) +{ + return false; +}