From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2248FC4743D for ; Tue, 8 Jun 2021 16:09:12 +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 B8FFD61078 for ; Tue, 8 Jun 2021 16:09:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8FFD61078 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqeHu-00088j-Vg for qemu-devel@archiver.kernel.org; Tue, 08 Jun 2021 12:09:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqeFn-0005za-V4 for qemu-devel@nongnu.org; Tue, 08 Jun 2021 12:06:59 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:38513) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqeFj-0002wS-3Q for qemu-devel@nongnu.org; Tue, 08 Jun 2021 12:06:59 -0400 Received: by mail-wm1-x32b.google.com with SMTP id t4-20020a1c77040000b029019d22d84ebdso2333892wmi.3 for ; Tue, 08 Jun 2021 09:06:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:user-agent:from:to:cc:subject:date:in-reply-to :message-id:mime-version:content-transfer-encoding; bh=RQi1+5AAsXE+lTy97a6xx4GR4Rvf3m+LedvZPew6ZQM=; b=dtZQNRvl/wERROjP4dlZwNRdjR3ap06v+3w2iLQ42Ci/AUVYhu/x7z+MVQNACCg4R2 DoulqE6qFsoeDEH/Cqko/NyDPKEf63Ig3MjTdjsaiuC8YBpEV0mnBuSjFEfSNYmBc7Nz 6wgGCt/pbEuzsoKnISX9EiYgg9mCw7jbH3D1qUywpePyaa8WJZXSH4zM5D+HfO2uYVER f8Q2OMaI4F/m2nLDQ13p87AtNe7I1qhOQlfztRBBbkFCYVzmmYmCu/68uNQVZXCupvis ccM7z9N28kWJovku9Ch4A0uOJGc4SR60oEM985o/XE2xJdqTOQBfCWgvgChzEtzbzAbF QMXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject:date :in-reply-to:message-id:mime-version:content-transfer-encoding; bh=RQi1+5AAsXE+lTy97a6xx4GR4Rvf3m+LedvZPew6ZQM=; b=Cmt7wkJ2ZXQEKKPVVdXl2gOorEAS1hVHlMsvILrumwO52kyDE3xh3uK0F/vGgPFRyO RbqwqqZ6i2FmI7xkgWHfoNN/SDYW3Mxg9uL/V0XL5GJ96wmZ9pjHRfagqbTDTa0/iqMC UiXOJTjULEkYZy3kNjyGB0rS1875uyNE1Dl+z1SJyarZ9sXGPSnQwY+4NucaIjr//Bk1 8fHXYoc6EN8alZkz0NtKOPZCdzVVRfA1JZxoBkIdVxlTVMI2xHSvHscAVdDruTXFwzMH MnXHx1yDKy6b6ZTOQxRtOjJbH3Q8O1ub5URVsYFEM28Jqex99hEuxbFPM1ptYnV7y96O b4wA== X-Gm-Message-State: AOAM5303MxxNYvPBzR6M4Pztk8ofEsljApdQZWONNBZefaB6oIR3LCAQ khe2Pe65MY1Y5My/PiEEU0AMJA== X-Google-Smtp-Source: ABdhPJwsBJp1xDIyDsuVVx0GXTmizMTrY/35TCGuG6FCQGNz8kQ82ZKnQgZNdAF8xdL9w5SYxjQ24Q== X-Received: by 2002:a1c:6503:: with SMTP id z3mr22813582wmb.72.1623168413108; Tue, 08 Jun 2021 09:06:53 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id 32sm23056190wrs.5.2021.06.08.09.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 09:06:52 -0700 (PDT) Received: from zen (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id BD5531FF7E; Tue, 8 Jun 2021 17:06:51 +0100 (BST) References: <20210502231844.1977630-1-richard.henderson@linaro.org> <20210502231844.1977630-19-richard.henderson@linaro.org> User-agent: mu4e 1.5.13; emacs 28.0.50 From: Alex =?utf-8?Q?Benn=C3=A9e?= To: Richard Henderson Subject: Re: [PATCH v3 18/28] tcg: Tidy tcg_n_regions Date: Tue, 08 Jun 2021 17:06:32 +0100 In-reply-to: <20210502231844.1977630-19-richard.henderson@linaro.org> Message-ID: <87v96ojq78.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32b.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Richard Henderson writes: > Compute the value using straight division and bounds, > rather than a loop. Pass in tb_size rather than reading > from tcg_init_ctx.code_gen_buffer_size, > > Signed-off-by: Richard Henderson > --- > tcg/region.c | 29 ++++++++++++----------------- > 1 file changed, 12 insertions(+), 17 deletions(-) > > diff --git a/tcg/region.c b/tcg/region.c > index bd81b35359..b44246e1aa 100644 > --- a/tcg/region.c > +++ b/tcg/region.c > @@ -363,38 +363,33 @@ void tcg_region_reset_all(void) > tcg_region_tree_reset_all(); > } >=20=20 > -static size_t tcg_n_regions(unsigned max_cpus) > +static size_t tcg_n_regions(size_t tb_size, unsigned max_cpus) > { > #ifdef CONFIG_USER_ONLY > return 1; > #else > + size_t n_regions; > + > /* > * It is likely that some vCPUs will translate more code than others, > * so we first try to set more regions than max_cpus, with those reg= ions > * being of reasonable size. If that's not possible we make do by ev= enly > * dividing the code_gen_buffer among the vCPUs. > */ > - size_t i; > - > /* Use a single region if all we have is one vCPU thread */ > if (max_cpus =3D=3D 1 || !qemu_tcg_mttcg_enabled()) { > return 1; > } >=20=20 > - /* Try to have more regions than max_cpus, with each region being >= =3D 2 MB */ > - for (i =3D 8; i > 0; i--) { > - size_t regions_per_thread =3D i; > - size_t region_size; > - > - region_size =3D tcg_init_ctx.code_gen_buffer_size; > - region_size /=3D max_cpus * regions_per_thread; > - > - if (region_size >=3D 2 * 1024u * 1024) { > - return max_cpus * regions_per_thread; > - } > + /* > + * Try to have more regions than max_cpus, with each region being >= =3D 2 MB. > + * If we can't, then just allocate one region per vCPU thread. > + */ > + n_regions =3D tb_size / (2 * MiB); > + if (n_regions <=3D max_cpus) { > + return max_cpus; > } > - /* If we can't, then just allocate one region per vCPU thread */ > - return max_cpus; > + return MIN(n_regions, max_cpus * 8); > #endif > } This is so much easier to follow now ;-) Reviewed-by: Alex Benn=C3=A9e --=20 Alex Benn=C3=A9e