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=-5.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,URIBL_DBL_ABUSE_MALW, USER_AGENT_SANE_1 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 54900C35247 for ; Mon, 3 Feb 2020 17:18:23 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 EA3A92080D for ; Mon, 3 Feb 2020 17:18:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uLjSwZdl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EA3A92080D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZBWR7OwaiSCoIxwGL1IGsbXK37uoINQQmdwWJfF6Gqc=; b=uLjSwZdlFC6HTiXycaIcYcDtk 9aXo2YJMtF+qh0XJdSfHhiqDM9zEO8FmX7w1hdEn30Kt+BiN2hOOydZjxxAenC1UuG6quSgUXeljz oUATsHCQiH8HsZjngVsw4rp1me8rfasrlUzV5Lh4QcT2HJ/wK3rYSLQolNUTPk4iC///oX45IZaay sfLeDy8SUeuBSmGOD75pgpbWR//9aj39zB9uG8KbE13B9RvPEN6GT8V+t8m9YRg7tdpSAUdDv/5h1 uXRtzsxp8oJ1V/TtYyl30LN46U2glRj//QoZSjioGFrHE0+U6lwCcluMB2rmFnQkSuyMZE4DlO67A SRX0wmWWw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iyfMX-0002iE-ML; Mon, 03 Feb 2020 17:18:17 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iyfMU-0002hK-1g for linux-arm-kernel@lists.infradead.org; Mon, 03 Feb 2020 17:18:15 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E65051045; Mon, 3 Feb 2020 09:18:10 -0800 (PST) Received: from [10.1.196.37] (e121345-lin.cambridge.arm.com [10.1.196.37]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D6BE63F52E; Mon, 3 Feb 2020 09:18:09 -0800 (PST) Subject: Re: [PATCH 4/4] arm64: Dereference CPU operations indirectly To: Gavin Shan , linux-arm-kernel@lists.infradead.org References: <20200202232437.7626-5-gshan@redhat.com> From: Robin Murphy Message-ID: <097551e7-fbbd-98c1-bd32-83cf1cc0278b@arm.com> Date: Mon, 3 Feb 2020 17:18:08 +0000 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20200202232437.7626-5-gshan@redhat.com> Content-Language: en-GB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200203_091814_177962_6FAE44CB X-CRM114-Status: GOOD ( 23.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, catalin.marinas@arm.com, lorenzo.pieralisi@arm.com, will@kernel.org, sudeep.holla@arm.com Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 02/02/2020 11:24 pm, Gavin Shan wrote: > One CPU operations is maintained through array @cpu_ops[NR_CPUS]. 2KB > memory is consumed when CONFIG_NR_CPUS is set to 256. It seems too > much memory has been used for this. > > This introduces another array (@cpu_ops_index[NR_CPUS]), of which the > index to CPU operations array is stored. With this, we just one byte > for each CPU, 256 bytes for 256 CPUs, to dereference the CPU operations > indirectly. By extension of the same argument, that's still four times as big as it *needs* to be ;) How important is the memory saving vs. the runtime overhead of more indirection? > Signed-off-by: Gavin Shan > --- > arch/arm64/kernel/cpu_ops.c | 44 +++++++++++++++++++++---------------- > 1 file changed, 25 insertions(+), 19 deletions(-) > > diff --git a/arch/arm64/kernel/cpu_ops.c b/arch/arm64/kernel/cpu_ops.c > index e133011f64b5..2a58222a2f24 100644 > --- a/arch/arm64/kernel/cpu_ops.c > +++ b/arch/arm64/kernel/cpu_ops.c > @@ -20,39 +20,33 @@ extern const struct cpu_operations acpi_parking_protocol_ops; > #endif > extern const struct cpu_operations cpu_psci_ops; > > -static const struct cpu_operations *cpu_ops[NR_CPUS] __ro_after_init; > - > -static const struct cpu_operations *const dt_supported_cpu_ops[] __initconst = { > +static const struct cpu_operations *const cpu_ops[] = { > &smp_spin_table_ops, > - &cpu_psci_ops, > - NULL, > -}; > - > -static const struct cpu_operations *const acpi_supported_cpu_ops[] __initconst = { > #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL > &acpi_parking_protocol_ops, > #endif > &cpu_psci_ops, > NULL, > }; > +static unsigned char cpu_ops_indexes[NR_CPUS] __ro_after_init; > > -static const struct cpu_operations * __init cpu_get_ops(const char *name) > +static unsigned char __init get_cpu_ops_index(const char *name) > { > - const struct cpu_operations *const *ops; > - > - ops = acpi_disabled ? dt_supported_cpu_ops : acpi_supported_cpu_ops; > + const struct cpu_operations *const *ops = cpu_ops; > + unsigned char index = 0; > > while (*ops) { For a statically-initialised array which isn't exported to other compilation units you don't really need the null-terminator dance; a simple for (index = 0; index < ARRAY_SIZE(cpu_ops); index++) should suffice. > if (!strcmp(name, (*ops)->name)) > - return *ops; > + return (index + 1); Also this magic +1 is a bit horrible - I don't see any need for the interface to expose the underlying storage format, so it could just as easily return the actual index as an int with a negative error case. Robin. > > ops++; > + index++; > } > > - return NULL; > + return 0; > } > > -static const char *__init cpu_read_enable_method(int cpu) > +static const char *__init get_cpu_method(int cpu) > { > const char *enable_method; > > @@ -98,21 +92,33 @@ static const char *__init cpu_read_enable_method(int cpu) > */ > int __init init_cpu_ops(int cpu) > { > - const char *enable_method = cpu_read_enable_method(cpu); > + const char *enable_method = get_cpu_method(cpu); > + unsigned char index; > > if (!enable_method) > return -ENODEV; > > - cpu_ops[cpu] = cpu_get_ops(enable_method); > - if (!cpu_ops[cpu]) { > + index = get_cpu_ops_index(enable_method); > + if (!index) { > pr_warn("Unsupported enable-method: %s\n", enable_method); > return -EOPNOTSUPP; > } > > + cpu_ops_indexes[cpu] = index; > + > return 0; > } > > const struct cpu_operations *get_cpu_ops(int cpu) > { > - return cpu_ops[cpu]; > + unsigned char index = cpu_ops_indexes[cpu]; > + > + /* > + * The corresponding CPU operation isn't set when the > + * index is equal to zero. > + */ > + if (!index) > + return NULL; > + > + return cpu_ops[index - 1]; > } > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel