From patchwork Sat Sep 12 22:44:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonggang Luo X-Patchwork-Id: 11772089 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 19219112E for ; Sat, 12 Sep 2020 22:46:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9744A214F1 for ; Sat, 12 Sep 2020 22:46:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MmtHkXkL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9744A214F1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHEHm-0004Ss-K7 for patchwork-qemu-devel@patchwork.kernel.org; Sat, 12 Sep 2020 18:46:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHEGP-0002b3-Oc; Sat, 12 Sep 2020 18:44:57 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:44721) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHEGO-0004D3-3A; Sat, 12 Sep 2020 18:44:57 -0400 Received: by mail-pl1-x641.google.com with SMTP id j7so2651966plk.11; Sat, 12 Sep 2020 15:44:55 -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 :mime-version:content-transfer-encoding; bh=hrJEqDkxFKpoRhRzMOgEeJejUGbXqPW0+cFjCJrQlA0=; b=MmtHkXkLKig+O2YtkgqHDZaPXeZc10YWkqpZUhUSqqlqyGWoFntsFAzo7dykpBcgim HT566YA1t7oiJwW96tFw/o5My2j5WVMxTf0XrljIYVR7lMehPDiqha+8sluoUKnauy5D M4hYX0lxkYHA65ya8U+obMtAzUo/f87tFgxMVfDFzRwgv/5TgQSqZOBLjEuhqtKdMzYc YRvWbRhn3nbdyIPghTxedjBl2I6Ky6049qcPszuI5JMOmAEOmsJMPTYA/BU5b4qNT7wu f3Fjv4cMDRSOI3qW3h9QF/czvlL/8gmTFsrpmV8N6qB4DCln5z/vqDCsox755F9MJei/ 5+ew== 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:mime-version:content-transfer-encoding; bh=hrJEqDkxFKpoRhRzMOgEeJejUGbXqPW0+cFjCJrQlA0=; b=TWjOg9QI4GctoJ5vR9aG3nB0Jlwx6gOLdR/qQR7wUPAtCoqoBiuRSzl2kIPcGdkPL2 evJLNtj5FB4/uZU9h12Bd3QhHHLY3flMWSrr3IyEQyIJtCIMzyBXz0Lso+HJXa5dptIF 8hpJg/ey/VE6G7HVh0oX3/xgltg3Q+Tm45DqNJlY2T7UtyBFDqB9qnfzkFViBllvn7mD dss/tc34+FszrfcIlzoUr1hfTFysg+Pf8oO7cXCChu+dMBQP1lK2DWvA/ql7k0yRKSh0 HHXjLaZtY+0PyMjatdSZOeMyd+hVOQuPCs3IBHSSz+UvcknrxdKoLOJt1NcisG3OqAHv ox0Q== X-Gm-Message-State: AOAM530STrWOQm2ui1m4OQgwHj2Ac3gShj/H8bdBZt2GKm4Qy4u2xIEy pvPAc6T4Ijm6Y3JxGTGWMMd5whYg5eQvb0s4z7w= X-Google-Smtp-Source: ABdhPJwoHcObldCAwI7YCoB6+jl63wLQ9+UBhj5Xp2pkGE/6mOvz7XHUcbuOYN9AxmYncBFlDPW0jg== X-Received: by 2002:a17:902:441:b029:d0:89f4:621f with SMTP id 59-20020a1709020441b02900d089f4621fmr8565413ple.7.1599950693927; Sat, 12 Sep 2020 15:44:53 -0700 (PDT) Received: from localhost.localdomain ([103.94.185.75]) by smtp.googlemail.com with ESMTPSA id t10sm4639266pgp.15.2020.09.12.15.44.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2020 15:44:53 -0700 (PDT) From: Yonggang Luo To: qemu-devel@nongnu.org Subject: [PATCH v8 01/27] rcu: Implement drain_call_rcu Date: Sun, 13 Sep 2020 06:44:05 +0800 Message-Id: <20200912224431.1428-2-luoyonggang@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20200912224431.1428-1-luoyonggang@gmail.com> References: <20200912224431.1428-1-luoyonggang@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::641; envelope-from=luoyonggang@gmail.com; helo=mail-pl1-x641.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: Kevin Wolf , Maxim Levitsky , Ed Maste , Michael Roth , qemu-block@nongnu.org, Stefan Hajnoczi , Stefan Weil , Xie Changlong , Peter Lieven , Markus Armbruster , Max Reitz , Gerd Hoffmann , Stefan Hajnoczi , Wen Congyang , Paolo Bonzini , Richard Henderson , Li-Wen Hsu Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Maxim Levitsky This will allow is to preserve the semantics of hmp_device_del, that the device is deleted immediatly which was changed by previos patch that delayed this to RCU callback Signed-off-by: Maxim Levitsky Suggested-by: Stefan Hajnoczi Reviewed-by: Stefan Hajnoczi --- include/qemu/rcu.h | 1 + util/rcu.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/include/qemu/rcu.h b/include/qemu/rcu.h index 570aa603eb..0e375ebe13 100644 --- a/include/qemu/rcu.h +++ b/include/qemu/rcu.h @@ -133,6 +133,7 @@ struct rcu_head { }; extern void call_rcu1(struct rcu_head *head, RCUCBFunc *func); +extern void drain_call_rcu(void); /* The operands of the minus operator must have the same type, * which must be the one that we specify in the cast. diff --git a/util/rcu.c b/util/rcu.c index 60a37f72c3..c4fefa9333 100644 --- a/util/rcu.c +++ b/util/rcu.c @@ -293,6 +293,61 @@ void call_rcu1(struct rcu_head *node, void (*func)(struct rcu_head *node)) qemu_event_set(&rcu_call_ready_event); } + +struct rcu_drain { + struct rcu_head rcu; + QemuEvent drain_complete_event; +}; + +static void drain_rcu_callback(struct rcu_head *node) +{ + struct rcu_drain *event = (struct rcu_drain *)node; + qemu_event_set(&event->drain_complete_event); +} + +/* + * This function ensures that all pending RCU callbacks + * on the current thread are done executing + + * drops big qemu lock during the wait to allow RCU thread + * to process the callbacks + * + */ + +void drain_call_rcu(void) +{ + struct rcu_drain rcu_drain; + bool locked = qemu_mutex_iothread_locked(); + + memset(&rcu_drain, 0, sizeof(struct rcu_drain)); + qemu_event_init(&rcu_drain.drain_complete_event, false); + + if (locked) { + qemu_mutex_unlock_iothread(); + } + + + /* + * RCU callbacks are invoked in the same order as in which they + * are registered, thus we can be sure that when 'drain_rcu_callback' + * is called, all RCU callbacks that were registered on this thread + * prior to calling this function are completed. + * + * Note that since we have only one global queue of the RCU callbacks, + * we also end up waiting for most of RCU callbacks that were registered + * on the other threads, but this is a side effect that shoudn't be + * assumed. + */ + + call_rcu1(&rcu_drain.rcu, drain_rcu_callback); + qemu_event_wait(&rcu_drain.drain_complete_event); + + if (locked) { + qemu_mutex_lock_iothread(); + } + +} + void rcu_register_thread(void) { assert(rcu_reader.ctr == 0);