Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp836560rwl; Wed, 5 Apr 2023 08:19:26 -0700 (PDT) X-Google-Smtp-Source: AKy350aqo7OOj4HOODT2iKr0RntjQgNpoBFGeIqig2uX4MSHRnfeFtUZ3GX+//b+nYnViRqph8RV X-Received: by 2002:a05:6a20:9307:b0:db:b13:8544 with SMTP id r7-20020a056a20930700b000db0b138544mr5459974pzh.53.1680707966221; Wed, 05 Apr 2023 08:19:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680707966; cv=none; d=google.com; s=arc-20160816; b=Q0mqTm01PSdsW4vwhTIjBa3Gm9zU6KJ7ZTAfnzAPCZUqTENPGHhrq++KY/Q4rygRrJ REYp1wy/Z2MNH8aTvAWc68bDvlMnr2murW6U7yYopwyVmqcobDoWJmbxjRx2Ex/Iw4nK jQDvcknWG5NDRM68Lsjaz6g4MrJKRaT6/jlpiGvb5K2wktxiNhV/71hL9rY+XbjGqOAo cZe79YFyAlVaqGiEgEsvuf8QfpYSCELluun/sZiYy+t7NdD0vJBFYTFOLSG/CG26eBqt 9YfkNZDItf5/GCQSDdaIB7pK0mFwZ0MzwN5iX+1YmL04D145zGURS2wYRFKLWd/3Us6h p5fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=sWW2wHNkorlWl7f1lW5XfddvHk1ze5o7vXdVcEMXG2g=; b=nzq8gjuYnN2bBMDvb0mQE3t0czIOl8q/z5hQlFpEk3ZEocoySLIXaBiWHH+7GVTy3c Zt4vweZitLFjXa+0quPpEJBDCsmM3kAeSTV8AWipNwOZCH0xHH52k9sgnKm0gZcjxQFe AA4EWl6FNCsHKJRPysZbXYpX3WMENwYDEDIpXceOYRxhrlVqqatUqeVQ97qR805jcU/n WxgWXD0UtaU8TRGSDFZRybU9fjCzWinMGzo77R50DEZB3z+/Ed8ILjI84HaM8Ug+4sbQ ywDWy8aq0CTHNnvYtoj8E9D3r95fCR8FzQ5DitG7qHZG/P9K3xvX33X9jHnwEq22fVEo qWsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=fvLLT0TK; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 79-20020a621852000000b0062a450c329dsi12641230pfy.93.2023.04.05.08.19.13; Wed, 05 Apr 2023 08:19:26 -0700 (PDT) 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=@ventanamicro.com header.s=google header.b=fvLLT0TK; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238964AbjDEPSr (ORCPT + 99 others); Wed, 5 Apr 2023 11:18:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238941AbjDEPSY (ORCPT ); Wed, 5 Apr 2023 11:18:24 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A036476B0 for ; Wed, 5 Apr 2023 08:17:51 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id j18-20020a05600c1c1200b003ee5157346cso23961885wms.1 for ; Wed, 05 Apr 2023 08:17:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1680707870; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=sWW2wHNkorlWl7f1lW5XfddvHk1ze5o7vXdVcEMXG2g=; b=fvLLT0TKm80nLpradZWDrOdneNGgfIOpZX+TQzvpBIusENmya0I/V5nt+WjUABWW2l mbre3ur0k5ApQtARUVrDy3VbtXfvBG2b7NMfG6XJ8EPQRdy0yGlt/iHDjYNYaPJKAxwS nrObDnZzuvvkNUHI8TqpDe3ysxRKjhCor5+ZP/jbtWgiQYJffTIsupTet7RzDwP4cgwG 1yF2Dnn1g8d3PHLErOvpIrgNydSF7neE+RkSkyTxU8r3sEyXnNZD0c4MSO0JFlMsPFFq 3TWf4LI5HL942nnh7CC19GskHTaB8TpfkIBM2/amfHSQmVa7FEiXeAqQ30llEJ4N00Ph +z2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680707870; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=sWW2wHNkorlWl7f1lW5XfddvHk1ze5o7vXdVcEMXG2g=; b=aDIqCQoAHuIJUPz5/z6+6Uh3/bsudxpTla66ycsrdgVHXn+oJalccoeGO80LWlTr6C WMKYkyI06kXC/NpjeSxdK2nFtM/RSYYHiiPEx13cwEQZyGNsGrwwjS9Q09r6VHdkEXWj hh+13d5V1D/kPSJRrS+QWrcjUPqo6Z3z6QMagLi1D+rNCcuewGvzzJ/cuEkEJVpg3v4q eEHNzYKEkoBmPWX7VGyn2/4zFufqvC2QXEjMCPjdcuMegJyz9DQMD1TtLPBVrCo3L2bl CsbdjvDZC2Ij+YIwRjxe+ENhdM6s1ef0TWHI5xHVIZBjTfYAKS3YpxQm+hLOkNTsWGEl evvQ== X-Gm-Message-State: AAQBX9cjPu83Dhm2Y164RZS6xxt8TobBcrAGqdSYqEiVHVBKfjDOvo3J I0ZGs8IGO75I0Ap5MErtiNIqtA== X-Received: by 2002:a05:600c:b42:b0:3ed:66e0:b6de with SMTP id k2-20020a05600c0b4200b003ed66e0b6demr5272095wmr.22.1680707869916; Wed, 05 Apr 2023 08:17:49 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id h18-20020a05600c315200b003ef6708bc1esm2573765wmo.43.2023.04.05.08.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 08:17:49 -0700 (PDT) Date: Wed, 5 Apr 2023 17:17:48 +0200 From: Andrew Jones To: Sunil V L Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, linux-crypto@vger.kernel.org, platform-driver-x86@vger.kernel.org, llvm@lists.linux.dev, Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Len Brown , Daniel Lezcano , Thomas Gleixner , Weili Qian , Zhou Wang , Herbert Xu , Marc Zyngier , Maximilian Luz , Hans de Goede , Mark Gross , Nathan Chancellor , Nick Desaulniers , Tom Rix , "Rafael J . Wysocki" , "David S . Miller" , "Rafael J . Wysocki" Subject: Re: [PATCH V4 08/23] RISC-V: ACPI: Cache and retrieve the RINTC structure Message-ID: References: <20230404182037.863533-1-sunilvl@ventanamicro.com> <20230404182037.863533-9-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230404182037.863533-9-sunilvl@ventanamicro.com> X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 On Tue, Apr 04, 2023 at 11:50:22PM +0530, Sunil V L wrote: > RINTC structures in the MADT provide mapping between the hartid > and the CPU. This is required many times even at run time like > cpuinfo. So, instead of parsing the ACPI table every time, cache > the RINTC structures and provide a function to get the correct > RINTC structure for a given cpu. > > Signed-off-by: Sunil V L > Acked-by: Rafael J. Wysocki > --- > arch/riscv/include/asm/acpi.h | 2 ++ > arch/riscv/kernel/acpi.c | 60 +++++++++++++++++++++++++++++++++++ > 2 files changed, 62 insertions(+) > > diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h > index 9be52b6ffae1..1606dce8992e 100644 > --- a/arch/riscv/include/asm/acpi.h > +++ b/arch/riscv/include/asm/acpi.h > @@ -59,6 +59,8 @@ static inline bool acpi_has_cpu_in_madt(void) > > static inline void arch_fix_phys_package_id(int num, u32 slot) { } > > +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu); > +u32 get_acpi_id_for_cpu(int cpu); > #endif /* CONFIG_ACPI */ > > #endif /*_ASM_ACPI_H*/ > diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c > index 81d448c41714..40ab55309c70 100644 > --- a/arch/riscv/kernel/acpi.c > +++ b/arch/riscv/kernel/acpi.c > @@ -24,6 +24,66 @@ EXPORT_SYMBOL(acpi_disabled); > int acpi_pci_disabled = 1; /* skip ACPI PCI scan and IRQ initialization */ > EXPORT_SYMBOL(acpi_pci_disabled); > > +static struct acpi_madt_rintc cpu_madt_rintc[NR_CPUS]; > + > +static int acpi_parse_madt_rintc(union acpi_subtable_headers *header, const unsigned long end) > +{ > + struct acpi_madt_rintc *rintc = (struct acpi_madt_rintc *)header; > + int cpuid; > + > + if (!(rintc->flags & ACPI_MADT_ENABLED)) > + return 0; > + > + cpuid = riscv_hartid_to_cpuid(rintc->hart_id); > + /* > + * When CONFIG_SMP is disabled, mapping won't be created for > + * all cpus. > + * CPUs more than NR_CPUS, will be ignored. > + */ > + if (cpuid >= 0 && cpuid < NR_CPUS) > + cpu_madt_rintc[cpuid] = *rintc; > + > + return 0; > +} > + > +static int acpi_init_rintc_array(void) > +{ > + if (acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_parse_madt_rintc, 0) > 0) > + return 0; > + > + return -ENODEV; As Conor pointed out, the errors could be propagated from acpi_table_parse_madt(), which could reduce this function to return acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_parse_madt_rintc, 0); where the '< 0' check would be in the caller below. That sounds good to me, but then I'd take that a step further and just drop this helper altogether. > +} > + > +/* > + * Instead of parsing (and freeing) the ACPI table, cache > + * the RINTC structures since they are frequently used > + * like in cpuinfo. ^ extra space > + */ > +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu) > +{ > + static bool rintc_init_done; > + > + if (!rintc_init_done) { > + if (acpi_init_rintc_array()) { > + pr_err("No valid RINTC entries exist\n"); > + return NULL; > + } > + > + rintc_init_done = true; > + } > + > + return &cpu_madt_rintc[cpu]; > +} > + > +u32 get_acpi_id_for_cpu(int cpu) > +{ > + struct acpi_madt_rintc *rintc = acpi_cpu_get_madt_rintc(cpu); > + > + BUG_ON(!rintc); > + > + return rintc->uid; > +} > + > /* > * __acpi_map_table() will be called before paging_init(), so early_ioremap() > * or early_memremap() should be called here to for ACPI table mapping. > -- > 2.34.1 > Otherwise, Reviewed-by: Andrew Jones Thanks, drew