From nobody Tue May 14 22:08:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1693275892; cv=none; d=zohomail.com; s=zohoarc; b=lX83T8XJcnubihGjH3WFJ06vN4JcQQs3gt/Tn7Q4mtgPnYzDpsQsz/ppIKY1VbGIfaFYfRKD6dRCVSzwjSyADZRPu9qPrfd71BYKfnK3DOVa1H/FuB+YejSi3ZqHUHlGXMLUmMJtfVbG5r3IzT65jTzkovFvnAA29HDTrCwn1ic= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693275892; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=broNGonemM+rDaH5unXMoBs7zFx3WjEl12fq4zi9yeU=; b=kL0Vsd7qSIOri+d4y4AC3vt/wtwC28szy2FPl8CKVLof6HOQxx6il+fMC5frM8LUUhrwgYizafSygJX+X8UfwN3zFmhqCh8MdIqExWiJF3ZgrehTTU/zrb3N4XVbUPn8bKBCa1Z0F+954szMIq9O9Fv0jJW+CPmICWwVzy2nmjg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693275892498475.7123211808828; Mon, 28 Aug 2023 19:24:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qaoOs-0002OT-T6; Mon, 28 Aug 2023 22:24:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qaoOp-0002OI-Rk for qemu-devel@nongnu.org; Mon, 28 Aug 2023 22:24:11 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qaoOn-0002A6-7W for qemu-devel@nongnu.org; Mon, 28 Aug 2023 22:24:11 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1bf078d5f33so30857565ad.3 for ; Mon, 28 Aug 2023 19:24:03 -0700 (PDT) Received: from D491Q0MXRG.bytedance.net ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id ci24-20020a17090afc9800b00265a7145fe5sm9612706pjb.41.2023.08.28.19.23.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 28 Aug 2023 19:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1693275842; x=1693880642; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=broNGonemM+rDaH5unXMoBs7zFx3WjEl12fq4zi9yeU=; b=G2+ss+io9qffsslWYu5d0fuVAP9eYS61Y/AwEY0YJdYMv2oIy/FOWYReCb9q1bhueI Wnmm5KsF/pD6bK/i4xnmdiwKHnPrVHcGOeLTVQlNCx2vHiQ85F1HVhmVHt9/35Lk1aDT +otSvtPQQJyWz7qIKM4Zlx3yWsLE6F1QoK6FJTUPiMptk7SV0UFrJR/xvjmc1e67Xh9M ezIZ8JMi0yGlOB/1tZ/LHIiP0xSYJ+7L/vJi2GOrnFzua6R95cDcQtAPUw82skqLFHjT M8jKLUFceevTFR+TGxclq+0jiKEPZN95u+iyWVDrPyk6XC13tPOmaOMmPjqfc+ApxMpE Iz/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693275842; x=1693880642; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=broNGonemM+rDaH5unXMoBs7zFx3WjEl12fq4zi9yeU=; b=VPWxa27UdiKBBXA2WSMxXzEoZAQjPaLveJcfHtmcdvtiTgFY4HGsAzKYoXfQFYK1au SUZ9/VTmgUA9AKaVPqohm+Hq3x0HKHPSSD4q/iEhSF5GzJpc4mxZt+dhym+el4L3Fam+ /TLvM9ANGOjj2H1a3kYenq743ZpmJBznvaD3ReXKtZDotoOxkDJxVUJCLNenF++6Toio SfujMqvpZyHkrwQLSoLaxbwTNGdhfJL2IJzgrLbADTX6avrFFMIR4Auunoe2v25NXc+F DPc89cBZxfd/smjnnKrMM/uqi4fbIS76RHNZ+JeBU/FDqwFYBGDYB6g14UpJiHMvIEwz Tb/g== X-Gm-Message-State: AOJu0Yztr+Iq8huOAgvQd0DiNh1OW5Cv9J+S9S5aWrsvrqzXdhyN3QTe 8k91yRVSsZUrjF/Hg4wz8f8DbQ1fBWdPK2CPdRo= X-Google-Smtp-Source: AGHT+IFfH7vZ8UusHI0IxYj975/YKyvq6pTTHtrb7u+boXlebelOX+8058rSYu23rYexcVc917jHJQ== X-Received: by 2002:a17:90a:df95:b0:26f:e9fd:8287 with SMTP id p21-20020a17090adf9500b0026fe9fd8287mr10714877pjv.20.1693275841636; Mon, 28 Aug 2023 19:24:01 -0700 (PDT) From: hongmianquan To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, david@redhat.com, philmd@linaro.org, peterx@redhat.com, hongmianquan Subject: [RESEND] memory: avoid updating ioeventfds for some address_space Date: Tue, 29 Aug 2023 10:23:54 +0800 Message-Id: <20230829022354.94149-1-hongmianquan@bytedance.com> X-Mailer: git-send-email 2.32.1 (Apple Git-133) MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=hongmianquan@bytedance.com; helo=mail-pl1-x630.google.com 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, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1693275893338100003 Content-Type: text/plain; charset="utf-8" When updating ioeventfds, we need to iterate all address spaces, but some address spaces do not register eventfd_add|del call when memory_listener_register() and they do nothing when updating ioeventfds. So we can skip these AS in address_space_update_ioeventfds(). The overhead of memory_region_transaction_commit() can be significantly reduced. For example, a VM with 8 vhost net devices and each one has 64 vectors, can reduce the time spent on memory_region_transaction_commit b= y 20%. Signed-off-by: hongmianquan --- include/exec/memory.h | 1 + softmmu/memory.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 7f5c11a0cc..556f4f1871 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1089,6 +1089,7 @@ struct AddressSpace { struct FlatView *current_map; =20 int ioeventfd_nb; + int ioeventfd_notifiers; struct MemoryRegionIoeventfd *ioeventfds; QTAILQ_HEAD(, MemoryListener) listeners; QTAILQ_ENTRY(AddressSpace) address_spaces_link; diff --git a/softmmu/memory.c b/softmmu/memory.c index 7d9494ce70..178816c845 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -842,6 +842,10 @@ static void address_space_update_ioeventfds(AddressSpa= ce *as) AddrRange tmp; unsigned i; =20 + if (!as->ioeventfd_notifiers) { + return; + } + /* * It is likely that the number of ioeventfds hasn't changed much, so = use * the previous size as the starting value, with some headroom to avoid @@ -3075,6 +3079,10 @@ void memory_listener_register(MemoryListener *listen= er, AddressSpace *as) } =20 listener_add_address_space(listener, as); + + if (listener->eventfd_add || listener->eventfd_del) { + as->ioeventfd_notifiers++; + } } =20 void memory_listener_unregister(MemoryListener *listener) @@ -3083,6 +3091,10 @@ void memory_listener_unregister(MemoryListener *list= ener) return; } =20 + if (listener->eventfd_add || listener->eventfd_del) { + listener->address_space->ioeventfd_notifiers--; + } + listener_del_address_space(listener, listener->address_space); QTAILQ_REMOVE(&memory_listeners, listener, link); QTAILQ_REMOVE(&listener->address_space->listeners, listener, link_as); --=20 2.11.0