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=-19.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_ALL,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 4022AC433E0 for ; Wed, 20 Jan 2021 16:48:38 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 F2E41233E2 for ; Wed, 20 Jan 2021 16:48:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2E41233E2 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+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=merlin.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=GjDrBJHXOTnL/OgAUfe2xYbyIuqk4vNghmsb1PEplgo=; b=yk5+e9VOaZ/SpakevXkcHfrxu aq8LE2eBWhvCgmjTxWyReN5wDn7geW3KBy5h2c8CjsFc7Jivo5/wpSFnmF9yrS24Tq4xKWc7FReuU ei5VAEZ0KqmvuSSGGVmi+1BDBAJCapTBt5R/g97TkRgn9n2grKqk9eHUcZX6FaBhl/eG3UG36HAYf PZ0LPgoCG9Rz+h6J0TVyVmN6AxSihb3KpShFFwPjPFmZjtEpg2YMScIutX0GnkpS8jfyL4AYg5W2n AQZliYlTkm/4eXF/qPq+QC8G3p0YEL8D5zEcN/OWn1uneg3rpXwIquFaRVDVqJwOvp9GP8bgVYoA6 pn0+Q6M5g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2Gd5-0005Dl-Q6; Wed, 20 Jan 2021 16:46:47 +0000 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2Gd2-0005D6-Ss for linux-arm-kernel@lists.infradead.org; Wed, 20 Jan 2021 16:46:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1611161205; x=1642697205; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=f/6B+U88WSe2xMQeGzdeR6lOL8Z3BXjNUSDfIqFQAeE=; b=sZY/wdFiT40rIFh+NKkhg6zeDfSxJvntxuu5LgphrdJkAaYsBPDb/anx zgywYHG9I4YBVIsSioZcDLc9Yv5rv3nkfhO5b/D7YYTAWZAsJrA+j+NKd Km6tV2FsedZmaZwRiRUI7yIPi+mzcfYl6n8imLAvZODjVeowy1HKC7Wrg k=; X-IronPort-AV: E=Sophos;i="5.79,361,1602547200"; d="scan'208";a="112233310" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1d-474bcd9f.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 20 Jan 2021 16:46:34 +0000 Received: from EX13MTAUWC002.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1d-474bcd9f.us-east-1.amazon.com (Postfix) with ESMTPS id 98CBFA18DB; Wed, 20 Jan 2021 16:46:33 +0000 (UTC) Received: from EX13D20UWC001.ant.amazon.com (10.43.162.244) by EX13MTAUWC002.ant.amazon.com (10.43.162.240) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 20 Jan 2021 16:46:33 +0000 Received: from edge-m1-r3-201.e-iad16.amazon.com (10.43.162.94) by EX13D20UWC001.ant.amazon.com (10.43.162.244) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 20 Jan 2021 16:46:31 +0000 Subject: Re: [RFC PATCH 2/7] arm64: kernel: Add a WFI hook. To: Mohamed Mediouni , References: <20210120132717.395873-1-mohamed.mediouni@caramail.com> <20210120132717.395873-3-mohamed.mediouni@caramail.com> From: Alexander Graf Message-ID: Date: Wed, 20 Jan 2021 17:46:28 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20210120132717.395873-3-mohamed.mediouni@caramail.com> Content-Language: en-US X-Originating-IP: [10.43.162.94] X-ClientProxiedBy: EX13D16UWB004.ant.amazon.com (10.43.161.170) To EX13D20UWC001.ant.amazon.com (10.43.162.244) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210120_114645_201189_FA7A85E5 X-CRM114-Status: GOOD ( 23.47 ) 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 , Catalin Marinas , Hector Martin , linux-kernel@vger.kernel.org, Marc Zyngier , Will Deacon , Stan Skowronek Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 20.01.21 14:27, Mohamed Mediouni wrote: > From: Stan Skowronek > > WFI drops register state on Apple Silicon for SMP systems. It probably drops the register because it loses power on WFI, right? Have you tried to set the ARM64_REG_CYC_OVRD_ok2pwrdn_force_up bit in ARM64_REG_CYC_OVRD yet? XNU has a call for that[1]. Maybe that's enough to convince the core to preserve its register state for now. For real power savings, we will probably want much more sophisticated deep sleep capabilities later that would reach beyond just register saving on WFI (different wakeup mechanisms, IRQ balancing, etc). Alex [1] https://github.com/opensource-apple/xnu/blob/master/osfmk/arm64/machine_routines_asm.s#L797 > > This hook will be used for a hardware workaround in the > Apple CPU start driver. > > Signed-off-by: Stan Skowronek > Signed-off-by: Mohamed Mediouni > --- > arch/arm64/include/asm/cpu_ops.h | 2 ++ > arch/arm64/kernel/cpu_ops.c | 6 ++++++ > arch/arm64/kernel/process.c | 11 +++++++++-- > 3 files changed, 17 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/cpu_ops.h b/arch/arm64/include/asm/cpu_ops.h > index e95c4df83911..4be0fc5bcaf9 100644 > --- a/arch/arm64/include/asm/cpu_ops.h > +++ b/arch/arm64/include/asm/cpu_ops.h > @@ -23,6 +23,7 @@ > * @cpu_boot: Boots a cpu into the kernel. > * @cpu_postboot: Optionally, perform any post-boot cleanup or necessary > * synchronisation. Called from the cpu being booted. > + * @cpu_wfi: Optionally, replace calls to WFI in default idle with this. > * @cpu_can_disable: Determines whether a CPU can be disabled based on > * mechanism-specific information. > * @cpu_disable: Prepares a cpu to die. May fail for some mechanism-specific > @@ -43,6 +44,7 @@ struct cpu_operations { > int (*cpu_prepare)(unsigned int); > int (*cpu_boot)(unsigned int); > void (*cpu_postboot)(void); > + void (*cpu_wfi)(void); > #ifdef CONFIG_HOTPLUG_CPU > bool (*cpu_can_disable)(unsigned int cpu); > int (*cpu_disable)(unsigned int cpu); > diff --git a/arch/arm64/kernel/cpu_ops.c b/arch/arm64/kernel/cpu_ops.c > index e133011f64b5..6979fc4490b2 100644 > --- a/arch/arm64/kernel/cpu_ops.c > +++ b/arch/arm64/kernel/cpu_ops.c > @@ -19,12 +19,18 @@ extern const struct cpu_operations smp_spin_table_ops; > extern const struct cpu_operations acpi_parking_protocol_ops; > #endif > extern const struct cpu_operations cpu_psci_ops; > +#ifdef CONFIG_ARCH_APPLE > +extern const struct cpu_operations cpu_apple_start_ops; > +#endif > > static const struct cpu_operations *cpu_ops[NR_CPUS] __ro_after_init; > > static const struct cpu_operations *const dt_supported_cpu_ops[] __initconst = { > &smp_spin_table_ops, > &cpu_psci_ops, > +#ifdef CONFIG_ARCH_APPLE > + &cpu_apple_start_ops, > +#endif > NULL, > }; > > diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c > index 34ec400288d0..611c639e20be 100644 > --- a/arch/arm64/kernel/process.c > +++ b/arch/arm64/kernel/process.c > @@ -57,6 +57,7 @@ > #include > #include > #include > +#include > > #if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_STACKPROTECTOR_PER_TASK) > #include > @@ -74,8 +75,14 @@ void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd); > > static void noinstr __cpu_do_idle(void) > { > - dsb(sy); > - wfi(); > + const struct cpu_operations *ops = get_cpu_ops(task_cpu(current)); > + > + if (ops->cpu_wfi) { > + ops->cpu_wfi(); > + } else { > + dsb(sy); > + wfi(); > + } > } > > static void noinstr __cpu_do_idle_irqprio(void) > -- > 2.29.2 > Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel