Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6474064pxb; Tue, 15 Feb 2022 03:18:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYxbG6safy0Otfb6GA8WhCudkTxjWtmPChPJPVLwhXhxHZgqVxylmh16Pwtrq65H3+CukN X-Received: by 2002:a17:907:6088:: with SMTP id ht8mr2580292ejc.528.1644923925346; Tue, 15 Feb 2022 03:18:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644923925; cv=none; d=google.com; s=arc-20160816; b=M/TEJ6lvGYS/hEmSqpoBckCaz/Pc+GGDZPJOwrnGL8AZaCEPqG2Sffa/TsJlZujJYg /2siNTi3dKx21p0JKTc/H2LNKOCEu+XFMFWK6JszwpXAPU6fC8yD6XS54j+7FYJluciL XKWTckA9bTIwA4DxRoAumCSe7HypgNNVmQAPxJij/AnlO96tScyLxl/udlQpoV4he00C 5NCT9gkSWSsj4vIP6N3KFAaP4cu2AKBYTurgt/8SFhcmNRC95pW04DLxBI+RlW6sxK8s wGWLHMQqKoXOMJsbSm04lb5Nw7w6nX5OtJzMzzqFlgeHPDAhVaNgSMvv4/Rg94sT0oZQ opZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=DccZUZa+VfjP4PTVC3djkRTiSLU4tlCAGkiuzoH/sq8=; b=IJNXk6o00OONP54CyIuPViFbBzwvvEyQFbSzf+ETMctLhnAda0/zlfssxHkx3tpMm3 L+TNhhltYGfG9Ey6Nm0NMMK1MjNwsHfTv/ckRn4iGoiLxEjR29Cz5h613pw1bmuuEF4k 2daaFIGZLk4zW3abIWW7iuWwOpmDQidPm5SuZ916CFLLe3tBc6IXxpMoU2iCHb/5Ap3d gUvlRj3N4FN/5BqxXTt7xmZ3uA/aWA8V2fG5l384v7l4q/SdDPzozDqbdYeSlSioj2iw dJjJp5rOIv/nFaIlM45sCw+fkZuPM1h9jNB5RPrv6Jx2+V5DeC46OtxjTMD0p3LthoLu 3eEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=S7jfbAdb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp27si26416074ejc.727.2022.02.15.03.18.18; Tue, 15 Feb 2022 03:18:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=S7jfbAdb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235821AbiBOJYG (ORCPT + 99 others); Tue, 15 Feb 2022 04:24:06 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231675AbiBOJYE (ORCPT ); Tue, 15 Feb 2022 04:24:04 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 291586CA40 for ; Tue, 15 Feb 2022 01:23:55 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: kholk11) with ESMTPSA id 8D3931F43B3F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1644917034; bh=hcFgN+kiCWyV67UTRX3dStpLJO5sEXbV1LYXA+9D5z8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=S7jfbAdb/5nprt+0wj2VMT0eCmVD1a3pkyqXisfTHz2JX2wH/4aNjS9IJDrcXQxUk kn3fd++81y+RbTiEiKwetSJ9OsX0Kk2526HQL+baoenLf8wi+W2BuIzcSmUOCtPma/ zW4YKSeDZRrgtgFKk2TD9LFg0j6GCYuNwtQoE5i+q1zjFr8CRwa/jPdjVHqYMv9ilS z3q7rQnlaxfPrc1KFDjMi26kMNO9guQF9SEXSeFtIHrA3hinlZrIYQR14ur0dIxnS9 YdSEjLTqp6kdASK9c0K0SMK3a1SxQC9xx/gwt+zktVba1joLR3+yzs1U+w7mZ8wFgM h7dhyw/b1JrhA== Message-ID: <5119045c-3c30-3625-d7ba-3100eda3ccbd@collabora.com> Date: Tue, 15 Feb 2022 10:23:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 Subject: Re: [PATCH] drm/panfrost: Dynamically allocate pm_domains Content-Language: en-US To: Alyssa Rosenzweig , Alyssa Rosenzweig Cc: dri-devel@lists.freedesktop.org, Rob Herring , Tomeu Vizoso , Steven Price , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org References: <20220214203132.4722-1-alyssa.rosenzweig@collabora.com> From: AngeloGioacchino Del Regno In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Il 14/02/22 21:55, Alyssa Rosenzweig ha scritto: > mali_kbase hardcodes MAX_PM_DOMAINS (=5 for the mt8192 kernel). I have > no real objection to it but Angelo did. Maybe should've marked this RFC. Clarifying, the suggested patch was not a big objection, but I think that it would be a nice preventive cleanup that is useful for the power tree that has to be managed on MT8192 and possibly on other SoCs. I would expect to see a variable amount of PM domains to take care of as time goes by (with new SoCs, not necessarily only MediaTek) due to granular power optimizations but, at the same time, dynamically allocating the pm_domain_devs and links structures makes this driver to also be nice with older platforms, where memory is a little more constrained, allowing Linux to have a lighter footprint, even if not by much. Logic for this footprint saving is "a little here, a little there, becomes a bit more considerable" (of course, being aware of both upsides and downsides in dynamically allocating things, and avoiding to write gigabytes of text to explain common knowledge). P.S.: Thank you all! Regards, Angelo > > On Mon, Feb 14, 2022 at 03:31:32PM -0500, Alyssa Rosenzweig wrote: >> MT8192 requires 5 power domains. Rather than bump MAX_PM_DOMAINS and >> waste memory on every supported Panfrost chip, instead dynamically >> allocate pm_domain_devs and pm_domain_links. This adds some flexibility; >> it seems inevitable a new MediaTek device will require more than 5 >> domains. >> >> On non-MediaTek devices, this saves a small amount of memory. >> >> Suggested-by: AngeloGioacchino Del Regno >> Signed-off-by: Alyssa Rosenzweig >> --- >> drivers/gpu/drm/panfrost/panfrost_device.c | 14 ++++++++++---- >> drivers/gpu/drm/panfrost/panfrost_device.h | 5 ++--- >> 2 files changed, 12 insertions(+), 7 deletions(-) >> >> diff --git a/drivers/gpu/drm/panfrost/panfrost_device.c b/drivers/gpu/drm/panfrost/panfrost_device.c >> index ee612303f076..661cdec320af 100644 >> --- a/drivers/gpu/drm/panfrost/panfrost_device.c >> +++ b/drivers/gpu/drm/panfrost/panfrost_device.c >> @@ -127,7 +127,10 @@ static void panfrost_pm_domain_fini(struct panfrost_device *pfdev) >> { >> int i; >> >> - for (i = 0; i < ARRAY_SIZE(pfdev->pm_domain_devs); i++) { >> + if (!pfdev->pm_domain_devs || !pfdev->pm_domain_links) >> + return; >> + >> + for (i = 0; i < pfdev->comp->num_pm_domains; i++) { >> if (!pfdev->pm_domain_devs[i]) >> break; >> >> @@ -161,9 +164,12 @@ static int panfrost_pm_domain_init(struct panfrost_device *pfdev) >> return -EINVAL; >> } >> >> - if (WARN(num_domains > ARRAY_SIZE(pfdev->pm_domain_devs), >> - "Too many supplies in compatible structure.\n")) >> - return -EINVAL; >> + pfdev->pm_domain_devs = devm_kcalloc(pfdev->dev, num_domains, >> + sizeof(*pfdev->pm_domain_devs), >> + GFP_KERNEL); >> + pfdev->pm_domain_links = devm_kcalloc(pfdev->dev, num_domains, >> + sizeof(*pfdev->pm_domain_links), >> + GFP_KERNEL); >> >> for (i = 0; i < num_domains; i++) { >> pfdev->pm_domain_devs[i] = >> diff --git a/drivers/gpu/drm/panfrost/panfrost_device.h b/drivers/gpu/drm/panfrost/panfrost_device.h >> index 8b25278f34c8..98e3039696f9 100644 >> --- a/drivers/gpu/drm/panfrost/panfrost_device.h >> +++ b/drivers/gpu/drm/panfrost/panfrost_device.h >> @@ -22,7 +22,6 @@ struct panfrost_job; >> struct panfrost_perfcnt; >> >> #define NUM_JOB_SLOTS 3 >> -#define MAX_PM_DOMAINS 3 >> >> struct panfrost_features { >> u16 id; >> @@ -87,8 +86,8 @@ struct panfrost_device { >> struct regulator_bulk_data *regulators; >> struct reset_control *rstc; >> /* pm_domains for devices with more than one. */ >> - struct device *pm_domain_devs[MAX_PM_DOMAINS]; >> - struct device_link *pm_domain_links[MAX_PM_DOMAINS]; >> + struct device **pm_domain_devs; >> + struct device_link **pm_domain_links; >> bool coherent; >> >> struct panfrost_features features; >> -- >> 2.34.1 >>