From nobody Wed Apr 16 03:53:25 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=1583930649; cv=none; d=zohomail.com; s=zohoarc; b=oAWF/ZUvaSHIY8husrBhZsqPIihr7RlpxO892U4rtj0BXv5sLDoGPPytkyYiH4X32r2xSPGIXYKqKOJrsVa1HCSdi6Y+nQxiYmZoD8Xy/gHR3uqHHfJbsesNBY2AacQmN7dWoyCbw0iL9rtp7bgbcTPyXKo8xceey+gAFPYPN88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583930649; 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=5vEhsnHdkrdmlhhoxg4gu84Vi1CeoTvkMYk4LdIuEGI=; b=TozJ6ehaTCg2s/uP/OM0+Wz4SwNL+SIOcuLvBXaNkz+TuwUWqyRUbjt/HQ2AxYAM8AEOorSwD80AfSKS/5itRYqdDkkov6+Jq8rbNiMH30BI1WJBCQjmdv2cwzvagQF8ljRn7bnUq/MaeTBai6IAaa6qqn3ZHTYIjbtyHnHJiNY= 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 1583930649357261.01511377824033; Wed, 11 Mar 2020 05:44:09 -0700 (PDT) Received: from localhost ([::1]:51168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0iW-0003FI-Aw for importer@patchew.org; Wed, 11 Mar 2020 08:44:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46960) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0fm-0006nP-KL for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:41:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jC0fl-0000He-FN for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:41:18 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:41122 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 1jC0fl-0000HG-B5 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:41:17 -0400 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-263-HZF3W29oPL6OHaIlFysOwA-1; Wed, 11 Mar 2020 08:41:10 -0400 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 9BC498024CF; Wed, 11 Mar 2020 12:41:09 +0000 (UTC) Received: from localhost (unknown [10.36.118.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F8E392D27; Wed, 11 Mar 2020 12:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583930477; 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=5vEhsnHdkrdmlhhoxg4gu84Vi1CeoTvkMYk4LdIuEGI=; b=OTahsydW2jtjd5emneYS8G8U7hyoHXmp3d/12Fe6Y6vzPdjpoNLP7DZ8Kt9GB6AfsqWWdD CJihxOzmqBBvpgeUdCLP7shyHtK3prpivfXxVG+lhxd07uD+3sOMssUCqsbbZl1KFbQCbj BoLDi6KgLSiDekbmb8gtLP77F9K+dEU= X-MC-Unique: HZF3W29oPL6OHaIlFysOwA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PULL 4/9] aio-posix: move RCU_READ_LOCK() into run_poll_handlers() Date: Wed, 11 Mar 2020 12:40:40 +0000 Message-Id: <20200311124045.277969-5-stefanha@redhat.com> In-Reply-To: <20200311124045.277969-1-stefanha@redhat.com> References: <20200311124045.277969-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 , Peter Maydell , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf 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 Link: https://lore.kernel.org/r/20200305170806.1313245-3-stefanha@redhat.com Message-Id: <20200305170806.1313245-3-stefanha@redhat.com> --- 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 65964a2597..11a4971955 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