From nobody Mon Feb 9 14:50:46 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552325914180379.8772381374389; Mon, 11 Mar 2019 10:38:34 -0700 (PDT) Received: from localhost ([127.0.0.1]:37430 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3Osg-0007nB-5w for importer@patchew.org; Mon, 11 Mar 2019 13:38:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3ODm-0007J5-PE for qemu-devel@nongnu.org; Mon, 11 Mar 2019 12:56:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3ODk-0003fr-Ri for qemu-devel@nongnu.org; Mon, 11 Mar 2019 12:56:14 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:35313) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3ODj-0003b5-5V for qemu-devel@nongnu.org; Mon, 11 Mar 2019 12:56:12 -0400 Received: by mail-wr1-x42d.google.com with SMTP id t18so5945364wrx.2 for ; Mon, 11 Mar 2019 09:56:10 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id e12sm6484836wrs.91.2019.03.11.09.56.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Mar 2019 09:56:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Vpe/Y0UWR5sWVoGFiXlnvAck+qUEuOl5CVYOZvpMGXU=; b=PGwzz/5MKtEMhDfUUkNrDZYkOzRakM2e0CH/cnt2Rp5cP/BvdEcxO+u3gMIYZgoZed 9bT+Rs5LyH4zXs13eRLws1NfTi9Wuk76PsPt5Bk+cmxpN5AA1lTcKzqlNjgvxRychp1V zLjCaDlvSei93pfwK2nw/Ls3QI5vp7DBOkgDUDyRQZt7IDg5s27Z0jZcy9WvVoF/+636 tiGrSqGsmSf1qc1i89sS+k9fedNLDLlRi991RtU4yUZnJnChKC8IzG9mpo2SQEezl9Y8 ackOAPqHyI/Ly9mAqb0aSmUzY9z0wMmYK9dMmJuuzXw/g1zae0U+eFchr/6bzCMYeR8P hPjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Vpe/Y0UWR5sWVoGFiXlnvAck+qUEuOl5CVYOZvpMGXU=; b=g7QGMX97PgHF250ohO5bx0vDY0Qt+uZbVZJeh6XOEiPCMFpCqTHy3a9E4vxpBSJBzQ qf0WKJZYcrIOyGvGrp0pGfH6jhhrNIXZrE9KYamR0aKnB2vtZK8hButNFCfDu4kPnEFp U8GuSudrE/Rh01PTGb52udOcq8bOSMdEBlxQ9YcPtKLQ4lmgzpwmjzgg0TJNqCKWez8X h5M6FGSIdwLYCABCSggw5tOfG9hqS/moB6j1iWoMvbbSN4oIIO5IALaTOgMAZ+Wfsou/ QQkWHa0J77K98j6bxznJDdg23jesIY9jxeEGkOyZVJ+Gh+AnPx/zACHQkdLeptG87OpU 1b+Q== X-Gm-Message-State: APjAAAV5nUEezWs/lswSxr6Dr9n9m4zOpWtTgRKcdzUTtYP6uY+kYm3j /Yw8E2GzZAdhHaQ6ISp50oD09Zep X-Google-Smtp-Source: APXvYqyiXHIXrknEDEBGbe7AKr3GvjKbri5raHxjFnK3N3FrVGk4A1ZcA9YReG0dvIL/zFJxedTQuQ== X-Received: by 2002:adf:dfc4:: with SMTP id q4mr21346459wrn.276.1552323368551; Mon, 11 Mar 2019 09:56:08 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 11 Mar 2019 17:55:32 +0100 Message-Id: <1552323335-46779-29-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1552323335-46779-1-git-send-email-pbonzini@redhat.com> References: <1552323335-46779-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42d Subject: [Qemu-devel] [PULL v2 28/31] exec.c: refactor function flatview_add_to_dispatch() 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: Wei Yang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Wei Yang flatview_add_to_dispatch() registers page based on the condition of *section*, which may looks like this: |s|PPPPPPP|s| where s stands for subpage and P for page. The procedure of this function could be described as: - register first subpage - register page - register last subpage This means the procedure could be simplified into these three steps instead of a loop iteration. This patch refactors the function into three corresponding steps and adds some comment to clarify it. Signed-off-by: Wei Yang Message-Id: <20190311054252.6094-1-richardw.yang@linux.intel.com> [Paolo: move exit before adjustment of remain.offset_within_*, otherwise int128_get64 fails when a region is 2^64 bytes long] Signed-off-by: Paolo Bonzini --- exec.c | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/exec.c b/exec.c index 1d4f378..86a38d3 100644 --- a/exec.c +++ b/exec.c @@ -1599,35 +1599,49 @@ static void register_multipage(FlatView *fv, phys_page_set(d, start_addr >> TARGET_PAGE_BITS, num_pages, section_in= dex); } =20 +/* + * The range in *section* may look like this: + * + * |s|PPPPPPP|s| + * + * where s stands for subpage and P for page. + */ void flatview_add_to_dispatch(FlatView *fv, MemoryRegionSection *section) { - MemoryRegionSection now =3D *section, remain =3D *section; + MemoryRegionSection remain =3D *section; Int128 page_size =3D int128_make64(TARGET_PAGE_SIZE); =20 - if (now.offset_within_address_space & ~TARGET_PAGE_MASK) { - uint64_t left =3D TARGET_PAGE_ALIGN(now.offset_within_address_spac= e) - - now.offset_within_address_space; + /* register first subpage */ + if (remain.offset_within_address_space & ~TARGET_PAGE_MASK) { + uint64_t left =3D TARGET_PAGE_ALIGN(remain.offset_within_address_s= pace) + - remain.offset_within_address_space; =20 + MemoryRegionSection now =3D remain; now.size =3D int128_min(int128_make64(left), now.size); register_subpage(fv, &now); - } else { - now.size =3D int128_zero(); - } - while (int128_ne(remain.size, now.size)) { + if (int128_eq(remain.size, now.size)) { + return; + } remain.size =3D int128_sub(remain.size, now.size); remain.offset_within_address_space +=3D int128_get64(now.size); remain.offset_within_region +=3D int128_get64(now.size); - now =3D remain; - if (int128_lt(remain.size, page_size)) { - register_subpage(fv, &now); - } else if (remain.offset_within_address_space & ~TARGET_PAGE_MASK)= { - now.size =3D page_size; - register_subpage(fv, &now); - } else { - now.size =3D int128_and(now.size, int128_neg(page_size)); - register_multipage(fv, &now); + } + + /* register whole pages */ + if (int128_ge(remain.size, page_size)) { + MemoryRegionSection now =3D remain; + now.size =3D int128_and(now.size, int128_neg(page_size)); + register_multipage(fv, &now); + if (int128_eq(remain.size, now.size)) { + return; } + remain.size =3D int128_sub(remain.size, now.size); + remain.offset_within_address_space +=3D int128_get64(now.size); + remain.offset_within_region +=3D int128_get64(now.size); } + + /* register last subpage */ + register_subpage(fv, &remain); } =20 void qemu_flush_coalesced_mmio_buffer(void) --=20 1.8.3.1