From nobody Fri Nov 14 00:46:48 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583428311; cv=none; d=zohomail.com; s=zohoarc; b=S0W8MJ3nLjSfYYg6Mcn9ZagRidp9KSOriu+lqV3KWtjedM8iKTQNG5sw22DW4Zr5dO6sshyqpM70L9DyXMQvFz/tHZX5/pddXULA/DicStFsbzDg2WuQGyF8mbSC2tcdU2bzFu6+4DIuqlNzjU7ecb9s769zHh/WWwhGjk22pYw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583428311; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SLh97FKAtkQVrPTIRRGRfMOyXgffESfmfCUhzdaV6WI=; b=L1AvCRM+gQ2QbjuiKLG+pLGSIFbJTovZQfs61HMaD8oPpdhi6U2y184C6IUUhWk52+MjR6X41CWcIQ27eQrdTr68/42rrhl6qvijQrwmCWdNoiVAMu0rPOXsjrQmYm7zOGfYmjyaA4UNura4CWsUFFk7Tdqp4ql5qcQL4DstbAU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1583428311643834.8584937844519; Thu, 5 Mar 2020 09:11:51 -0800 (PST) Received: from localhost ([::1]:53630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j9u2I-00056m-HK for importer@patchew.org; Thu, 05 Mar 2020 12:11:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37966) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j9tz1-00008B-0B for qemu-devel@nongnu.org; Thu, 05 Mar 2020 12:08:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j9tyy-0003Gb-Qm for qemu-devel@nongnu.org; Thu, 05 Mar 2020 12:08:26 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:30735 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j9tyy-0003Fp-E3 for qemu-devel@nongnu.org; Thu, 05 Mar 2020 12:08:24 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-53-i6IrNr6kP_yzyan2glhuyg-1; Thu, 05 Mar 2020 12:08:21 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1C928800D53; Thu, 5 Mar 2020 17:08:20 +0000 (UTC) Received: from localhost (ovpn-117-104.ams2.redhat.com [10.36.117.104]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02F1690538; Thu, 5 Mar 2020 17:08:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583428103; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SLh97FKAtkQVrPTIRRGRfMOyXgffESfmfCUhzdaV6WI=; b=TSe+yGnEQQv/hnnGuFtmhkkiz/wd/hkj/VEFLAVW9ZfWMiXGgXhYOQnPocY4Fg8prjDH4m DQl46GBxaJX4RLow2c0hrZaBT8T+2zUPzFscyYFoeHcLDmBgq6F5zJLhPp27McgheHtmUT yEIOz7dCljcVdvURgDpEby/jUz+sAhY= X-MC-Unique: i6IrNr6kP_yzyan2glhuyg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 2/7] aio-posix: move RCU_READ_LOCK() into run_poll_handlers() Date: Thu, 5 Mar 2020 17:08:01 +0000 Message-Id: <20200305170806.1313245-3-stefanha@redhat.com> In-Reply-To: <20200305170806.1313245-1-stefanha@redhat.com> References: <20200305170806.1313245-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Now that run_poll_handlers_once() is only called by run_poll_handlers() we can improve the CPU time profile by moving the expensive RCU_READ_LOCK() out of the polling loop. This reduces the run_poll_handlers() from 40% CPU to 10% CPU in perf's sampling profiler output. Signed-off-by: Stefan Hajnoczi --- util/aio-posix.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/util/aio-posix.c b/util/aio-posix.c index 029f146455..38c51f5d8f 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -583,16 +583,6 @@ static bool run_poll_handlers_once(AioContext *ctx, in= t64_t *timeout) bool progress =3D false; AioHandler *node; =20 - /* - * Optimization: ->io_poll() handlers often contain RCU read critical - * sections and we therefore see many rcu_read_lock() -> rcu_read_unlo= ck() - * -> rcu_read_lock() -> ... sequences with expensive memory - * synchronization primitives. Make the entire polling loop an RCU - * critical section because nested rcu_read_lock()/rcu_read_unlock() c= alls - * are cheap. - */ - RCU_READ_LOCK_GUARD(); - QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) { if (!QLIST_IS_INSERTED(node, node_deleted) && node->io_poll && aio_node_check(ctx, node->is_external) && @@ -636,6 +626,16 @@ static bool run_poll_handlers(AioContext *ctx, int64_t= max_ns, int64_t *timeout) =20 trace_run_poll_handlers_begin(ctx, max_ns, *timeout); =20 + /* + * Optimization: ->io_poll() handlers often contain RCU read critical + * sections and we therefore see many rcu_read_lock() -> rcu_read_unlo= ck() + * -> rcu_read_lock() -> ... sequences with expensive memory + * synchronization primitives. Make the entire polling loop an RCU + * critical section because nested rcu_read_lock()/rcu_read_unlock() c= alls + * are cheap. + */ + RCU_READ_LOCK_GUARD(); + start_time =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); do { progress =3D run_poll_handlers_once(ctx, timeout); --=20 2.24.1