From patchwork Thu Mar 11 00:21:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 397385 Delivered-To: patch@linaro.org Received: by 2002:a17:906:a383:0:0:0:0 with SMTP id k3csp2149ejz; Wed, 10 Mar 2021 16:29:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1D4QhtAtvtQqGn2yRb/C26Affdk/3CfbCtJ7oESnnyFdLz6xWd6DDpH0mN8hZEniQWv4a X-Received: by 2002:a02:ca50:: with SMTP id i16mr1101358jal.5.1615422566418; Wed, 10 Mar 2021 16:29:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615422566; cv=none; d=google.com; s=arc-20160816; b=NvRv7+7HSKbBSrhGrhS5RFMUyAYYLYErHzZgwA06ETlOOfVdW8ZUTa8FqqwEB+ZT9C 08EUR3WXYJSrk8vQO2AmLLVlM9XNqBfQD5yg+0khZMjDHwMfRHFkS2MinfKbhDo6f42y TaFa19wXpjGQxeKiPCSy6uxbsCn3sbBdrOsM5PJ3KhYIjijb2vhTdVpvVBwaH/nK0wfI OgdFY0Lw/8q/t7MoSjmIOj8b1ofSfbKMU6vXel3z7Mn9XfTlN/jdizrxLKLINdKOSuj5 UHd0c265sBqtexpW7qYSq4sLM+22Ii0VwHIlusPfYLxuv23lmdamPKHD8T20yURtHjWr cq7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=7xeEhlQtM0fbvE7NxUGTdI3mS6R4AAuovhR3QGDZMN4=; b=KiTVBWKy4oaBHP9mjcfIGpwg6XJtS2ocz74ya/LXOcqu3wVk3QaWeXlXTS9y3Ir8QN +zsyHWr6kTiksD34O5AYQVsIUg8a/NStDe31vjHgXQYmbVNsUNuXu1GOds/Hqi8H+STq 0NThtY3eoE1T+n1GMCF2EmecAqnsgwdrQHbGR9i6yFb7QMf10e711wsDBsh9MsG+4L9T oVC7Bi3uF91loAuON4x0Ztff67pPkQZQpRNI9TFcahh28nN6miSGaNx5MG422mxOF7vS B/lilDsPdBDjSD60Np/H45l6MSZRBOYmb0NqisOANKJMaaXyBPMPJGbF5Bb0QWdy6Rwf 9i5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="uL/a9BNy"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k18si976658jam.96.2021.03.10.16.29.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Mar 2021 16:29:26 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="uL/a9BNy"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lK9Cf-0006hP-PW for patch@linaro.org; Wed, 10 Mar 2021 19:29:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lK95v-0004t7-UU for qemu-devel@nongnu.org; Wed, 10 Mar 2021 19:22:27 -0500 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]:35430) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lK95r-0001Nr-Gr for qemu-devel@nongnu.org; Wed, 10 Mar 2021 19:22:27 -0500 Received: by mail-oi1-x22e.google.com with SMTP id u6so13898665oic.2 for ; Wed, 10 Mar 2021 16:22:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7xeEhlQtM0fbvE7NxUGTdI3mS6R4AAuovhR3QGDZMN4=; b=uL/a9BNyQm+QVs8rWZXRm9BwYV7955RXkq+3CXJimlHaGiWXbZ263PEJbO/O8tgJy1 ftaA6jDmzWFLNTQLFDcdGGD3LJbtoAtwl0jh98ocD2qpuldbaPTvQm7Wef7WU6IhvVDW 9Shq/sRuK7gisLeV0xSxutHT39jw84RXsY/Q/VD+32cqbqa9Gt+tE1sZMYT6nP/CNT54 eP3yO/M6IbKd2/X7RkZElbcvjq5LXDpRUlqKwZOPBkWGBQVx1bnrt4D3x7M6yGTuQMLC FxORtW1PwgVeB5ytd4RDS7ZFwVj1K1Ulupe04Pl5GrUDq+8tiYq0RjUpoGmzqwyjITIo b0dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7xeEhlQtM0fbvE7NxUGTdI3mS6R4AAuovhR3QGDZMN4=; b=OOnkKK83nuXir2YYYHxhmIHL7SLK0sM5zSAk2i8Hcx7hDvgkx0N+5IHIz15F3eFAK/ 2ZzSQPeQHT+hNrecSRlpMzkQ1FP8p9DcQ0IS9QMd3SEt2Cp2U24O7VWVRpsu5eKyw02/ MSzrS8CtAAndHhYPfjL3CWhn57V8zd1u052Yp8GjaWrY5DGb77DZVnWAPRPOlEKqtfJ1 j2n6px/BM/1i7rR1CeLUYpRKqsx2OQ9CRKRzDF6muP5xZZbyrM6esNgFWRuH3ZwXACMs PFfGddqxqAI90eBokm0wOCpUVIc+JtYeS5i/6LX2ejBO703P/EpFlloQtw5Tb02FKa+x RwAw== X-Gm-Message-State: AOAM530eizTawcqdUw0m+ZZ7OaIOpbuj1E9tPC6a+3JtrNHWF2hNw0gL PGMIfh4J7akcjmTdxnqsyevdfVJ9+XQL1dWm X-Received: by 2002:aca:6084:: with SMTP id u126mr4250486oib.45.1615422141304; Wed, 10 Mar 2021 16:22:21 -0800 (PST) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id a6sm300962otq.79.2021.03.10.16.22.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 16:22:20 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 18/26] tcg: Tidy tcg_n_regions Date: Wed, 10 Mar 2021 18:21:48 -0600 Message-Id: <20210311002156.253711-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210311002156.253711-1-richard.henderson@linaro.org> References: <20210311002156.253711-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22e; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22e.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: r.bolshakov@yadro.com, j@getutm.app Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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(-) -- 2.25.1 diff --git a/tcg/region.c b/tcg/region.c index 7fb24f6b60..57017c1e80 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -363,38 +363,33 @@ void tcg_region_reset_all(void) tcg_region_tree_reset_all(); } -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 regions * being of reasonable size. If that's not possible we make do by evenly * 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 == 1 || !qemu_tcg_mttcg_enabled()) { return 1; } - /* Try to have more regions than max_cpus, with each region being >= 2 MB */ - for (i = 8; i > 0; i--) { - size_t regions_per_thread = i; - size_t region_size; - - region_size = tcg_init_ctx.code_gen_buffer_size; - region_size /= max_cpus * regions_per_thread; - - if (region_size >= 2 * 1024u * 1024) { - return max_cpus * regions_per_thread; - } + /* + * Try to have more regions than max_cpus, with each region being >= 2 MB. + * If we can't, then just allocate one region per vCPU thread. + */ + n_regions = tb_size / (2 * MiB); + if (n_regions <= 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 } @@ -826,7 +821,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_cpus) buf = tcg_init_ctx.code_gen_buffer; total_size = tcg_init_ctx.code_gen_buffer_size; page_size = qemu_real_host_page_size; - n_regions = tcg_n_regions(max_cpus); + n_regions = tcg_n_regions(total_size, max_cpus); /* The first region will be 'aligned - buf' bytes larger than the others */ aligned = QEMU_ALIGN_PTR_UP(buf, page_size);