Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp597960lql; Mon, 11 Mar 2024 11:27:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXM79G0pzr/PrzTj3L1jrd1q9CvMAwFgcFk2BzuK4BkbQT2b/NoKzHNL4+dlbQG1bXgxms3KDz+U8Eq0pXbLB4qcsq32DQ57K3q8IH8jA== X-Google-Smtp-Source: AGHT+IHRnWmZxt5G2jPpgD7Ch62D7qwlcSr1LQQjdMVhcLBdN2d59GCVcZjkYE7e3sCMJXvjI0aS X-Received: by 2002:a2e:6a19:0:b0:2d4:292a:7a44 with SMTP id f25-20020a2e6a19000000b002d4292a7a44mr3700093ljc.36.1710181668873; Mon, 11 Mar 2024 11:27:48 -0700 (PDT) Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ek13-20020a056402370d00b0056830c31dbbsi2652929edb.96.2024.03.11.11.27.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 11:27:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99358-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=nt4+uhAb; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-99358-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99358-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6DD8B1F21615 for ; Mon, 11 Mar 2024 18:27:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 863CD5465B; Mon, 11 Mar 2024 18:27:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=os.amperecomputing.com header.i=@os.amperecomputing.com header.b="nt4+uhAb" Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2134.outbound.protection.outlook.com [40.107.243.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DF711EB5C; Mon, 11 Mar 2024 18:27:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.134 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710181657; cv=fail; b=jDrT18xT78i1WWFGHdwe4j+aJTRIq/Jj6zAN3dsaGXks7vxIm0BiUPABtT98Y/noF+GGpGpym7BXl0Jqya9uI/vEll684LPAVFecPoeeswhmof3uLEdCel/KgbDiycYn9u5P5aOuA123mSMJjm43VMaN0K21UFoRa6iNZfpJBDc= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710181657; c=relaxed/simple; bh=Ot6pVFSH5TS/bnJcBT14hcjswRnvk7N7khEiqdMNjWM=; h=Date:From:To:Cc:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=U3Ubi/JHrwwFeMZ3Xaj7rZVdcyFw96U0L4JqDMgI8OSI9HQ0goN/IUPOGhfHiTIWoOn53a12BtJ9Hpl5BpWN2JZasDfjJn5VDQhfOoyH/BEMzD00Dw17UDcWmlyKRE8oKrhXH9/CAjEoQ105+fZdZsrG34iaOF2A1Yuu6wCE/mI= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=os.amperecomputing.com; spf=pass smtp.mailfrom=os.amperecomputing.com; dkim=pass (1024-bit key) header.d=os.amperecomputing.com header.i=@os.amperecomputing.com header.b=nt4+uhAb; arc=fail smtp.client-ip=40.107.243.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=os.amperecomputing.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=os.amperecomputing.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bXEbGMU5ulcnM+VH07MyVseol+wLSyviAmJicv+FntnCj6WfoyyGtvj4wPb6RYvuIijbiDFFC4Ze1UfvmTnluF4uFk969zTuDRVg7IvIYv8dMt8fZch+ndDl059SQNcVE1L6R+0MheEgGOvahgzoE66SMrbqEUnfg+t2P4cxzciC53gmO3KiqlJof3BW+IlCHL5uZjqD+MuaMWg2PxIGUgztSlmVpT/gvUn/zHV/x9dFrdcMK5QJqrPug+/hHJyxWc/OqLvA6rHa1NMhS73Ea4t6NvUopQRJLuBJTOiTz574xRbn44EYLNpadQ4Fh9z9w8bwvMsa4McZfue1gt3dbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dRnjKnY2q5rQXL7eh+CZne7CByUhHPVSfBKLKlJLxEE=; b=BjzZelFt0cj7z+nARgUbm+ky/a1kQKwZTROpHJUogkb+BUnxP/gSBI9FAzQFZGk5f4J50rTerobrOpZDWfVZOwN1r3reLvNPEFXUm7rZnTlNhL40lPwx2T2ic1hsP0bVVbDk6MPx3YBpiGmkKjBL6+19GrBxCR8Hum4D1TZWMYG0cuhMfgSg28ymvqtB0AxRzlWTY08GSDHMG6JmAAyhZoTiTQFeSiMzfuom9Bf+hJeJTIhlSKMC8TtHe+w8MUnic0d3qyf60gPXasQCHrRvfPjq2IjsAL83QN07nz6xy8ev1vqEuLR6WHF7rIDCpyAM00Irif92D7GKkUJq8RR3Tg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dRnjKnY2q5rQXL7eh+CZne7CByUhHPVSfBKLKlJLxEE=; b=nt4+uhAbX4t34axyGlnM5yyyUTTmKFM7QSGbkgsbVNjNZMCoN7Abi7NI4VLwlP3RJKhH4ublx63kmF7vREz0p9YJk/7vbQE4/HFzwXRu+tpcDOJ0gAGSbq0R2Q/o72QtQFiO5vvdBqXN1tNY5MCSdJ99ubEFdOMEhnwCk3PJ/Gg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from MW4PR01MB6498.prod.exchangelabs.com (2603:10b6:303:79::19) by BN0PR01MB7183.prod.exchangelabs.com (2603:10b6:408:15a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.35; Mon, 11 Mar 2024 18:27:32 +0000 Received: from MW4PR01MB6498.prod.exchangelabs.com ([fe80::4fc3:132:87ac:c13b]) by MW4PR01MB6498.prod.exchangelabs.com ([fe80::4fc3:132:87ac:c13b%5]) with mapi id 15.20.7362.035; Mon, 11 Mar 2024 18:27:32 +0000 Date: Mon, 11 Mar 2024 11:27:27 -0700 From: Vanshidhar Konda To: "lihuisong (C)" Cc: Beata Michalska , Ionela Voinescu , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rafael@kernel.org, sumitg@nvidia.com, zengheng4@huawei.com, yang@os.amperecomputing.com, will@kernel.org, sudeep.holla@arm.com, liuyonglong@huawei.com, zhanjie9@hisilicon.com, linux-acpi@vger.kernel.org Subject: Re: Re: [PATCH v1 2/3] arm64: idle: Cache AMU counters before entering idle Message-ID: References: <20240229162520.970986-1-vanshikonda@os.amperecomputing.com> <20240229162520.970986-3-vanshikonda@os.amperecomputing.com> <3ed907bf-9526-3a46-41b9-8a0c747122f1@huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3ed907bf-9526-3a46-41b9-8a0c747122f1@huawei.com> X-ClientProxiedBy: CH2PR15CA0008.namprd15.prod.outlook.com (2603:10b6:610:51::18) To MW4PR01MB6498.prod.exchangelabs.com (2603:10b6:303:79::19) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW4PR01MB6498:EE_|BN0PR01MB7183:EE_ X-MS-Office365-Filtering-Correlation-Id: a7bab395-c94f-446f-f49a-08dc41f8eaa9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: quTbU0yTOzc8JxZsbjYJcmUX2epyH4EyiUVcu96+yfsSHTYZG1NrzpVo1ibxsicJANBBYnd4Dxc0BI9BznpkMcoLXdXMdnWl/0o3IqubmvxudxhP3Vx/j29H+/GWAdmxvhUOCGRULEltAMrSUR/LE6pgoHKKzrDtdNEO3CHu+qwVWligmmsQjFgqq5Gvf4yPdkmOAHbBrc6YMIrp+qIFYzURBefsGar4kuoJwljqrwt15Ah7VtBtt+SHdfPQ68KL9pHf19HeYR7AFkJ2BlyrjiPhp8atF5Y1nbEPr7quAj7T46We2Im7JyVwjsWEaKXE7BYa05ZtvT1G31/LHbVAzSeKeOUAf35cL6DA47JaTGdi0u51Fro/GF1LIYsozDqrs+PFUhXXY+hoGFGfaeBeX5M1TEpYWb6BQ/wvuK80aTc+GZr+lcVMpt3tFl3v3zadd/ygrlKHXm6YlA93JovpCvJpM62tpFSt6ogTErdzlNuf2Ee2zeVzV7ynp9v/VPoJXu7T/Ii5paG0MSd0Z83xSdDEZ2j3p+aIQnudO0NBmKoCaLH78c8JpHu98X06muTFrS6vE/k+1G+EjBdTbnb1PeKJX76ssUqzyj6wNxKnJK8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR01MB6498.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(1800799015)(376005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?M2FzVnM5S0lIejE0cTJpTFl2M2FQMFFvbFI2WkN0OURUV1E0UkdBMGNEWHZu?= =?utf-8?B?U1BncUlxd1I4NkUwaDRPSXJnQUxWYk9vUm5hZ2I1TEJIUVl2TWFmM0xjWEk2?= =?utf-8?B?ck92SHlYNEMvc3NDVnVndFJEdjd4Z3RoWldkVWVyK0NJM1FDSnUyL3J1WFQ4?= =?utf-8?B?MFRKbElmNUErbzFvQjRvZURVSWJTdHhqVHIvRk9odWd6OGRjZUdnbEptYm8r?= =?utf-8?B?eDcvTjQxajBQQzk2K1FZaHVBdnJFWW45Ym1ma3o1ckFnR3JwcHJIcUZKU1JO?= =?utf-8?B?OTBNTmp5ckw3YWtCUm83alZsQjRJcktvcUYvYXpFc0hONmowUGFzYWZCbFRz?= =?utf-8?B?dGJLcmZSdEdZemo2RkgxbUp1UE0vUEc3blBoZWpUNkpLZmo4ZUdGaHFCNGlu?= =?utf-8?B?R0tXUlhmTFB3L3g0MzVaV0h0cFlOcW9RVlFNSjdQNU81YWp3bVA4ZFpvNXo4?=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446f-f49a-08dc41f8eaa9 X-MS-Exchange-CrossTenant-AuthSource: MW4PR01MB6498.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2024 18:27:32.6058 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: glaj+rLrlNVxIA8VrpqSEqS0JUgG6QhFaTgD7RU9IOUTPlfUi4HqEXZVenC0uyQcovwE1Kek9deiqbqdb+gjRQsHBJ+9RD/3KOeuyeTL1S2w0lxEVOKSIfk0SONckW+O X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR01MB7183 On Thu, Mar 07, 2024 at 11:17:26AM +0800, lihuisong (C) wrote: > >在 2024/3/1 0:25, Vanshidhar Konda 写道: >>AMU counters do not increment while a CPU is in idle. Saving the value >>of the core and constant counters prior to invoking WFI allows FIE to >>compute the frequency of a CPU that is idle. >> >>Signed-off-by: Vanshidhar Konda >>--- >> arch/arm64/kernel/idle.c | 10 ++++++++++ >> arch/arm64/kernel/topology.c | 14 ++++++++------ >> 2 files changed, 18 insertions(+), 6 deletions(-) >> >>diff --git a/arch/arm64/kernel/idle.c b/arch/arm64/kernel/idle.c >>index 05cfb347ec26..5ed2e57188a8 100644 >>--- a/arch/arm64/kernel/idle.c >>+++ b/arch/arm64/kernel/idle.c >>@@ -26,6 +26,16 @@ void __cpuidle cpu_do_idle(void) >> arm_cpuidle_save_irq_context(&context); >>+#ifdef CONFIG_ARM64_AMU_EXTN >>+ /* Update the AMU counters before entering WFI. The cached AMU counter >>+ * value is used to determine CPU frequency while the CPU is idle >>+ * without needing to wake up the CPU. >>+ */ >>+ >>+ if (cpu_has_amu_feat(smp_processor_id())) >>+ update_freq_counters_refs(); >>+#endif >The below point I has mentioned in [1]. >This is just for the WFI state. >What about other deeper idle states, like retention and power down? >The path to enter idle state is different for them. We should do this >for all idle states. > Yes. That makes sense. I'll account for them in the next version of the patch. I'll work on the next version of the patch based on the updated patch from @Beata. Thanks, Vanshi >>+ >> dsb(sy); >> wfi(); >>diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c >>index db8d14525cf4..8905eb0c681f 100644 >>--- a/arch/arm64/kernel/topology.c >>+++ b/arch/arm64/kernel/topology.c >>@@ -240,13 +240,15 @@ unsigned int arch_freq_get_on_cpu(int cpu) >> } while (read_seqcount_retry(&cpu_sample->seq, seq)); >> /* >>- * Bail on invalid count and when the last update was too long ago, >>- * which covers idle and NOHZ full CPUs. >>+ * Bail on invalid count and when the last update was too long ago. >>+ * This covers idle, NOHZ full and isolated CPUs. >>+ * >>+ * Idle CPUs don't need to be measured because AMU counters stop >>+ * incrementing during WFI/WFE. >> */ >>- if (!delta_const_cnt || ((jiffies - last) > MAX_SAMPLE_AGE)) { >>- if (!(housekeeping_cpu(cpu, HK_TYPE_TICK) && idle_cpu(cpu))) >>- goto fallback; >>- } >>+ if (!delta_const_cnt || >>+ ((jiffies - last) > MAX_SAMPLE_AGE && !idle_cpu(cpu))) >>+ goto fallback; >> /* >> * CPU frequency = reference perf (in Hz) * (/\ delivered) / (/\ reference) >[1] https://lore.kernel.org/linux-arm-kernel/20231212072617.14756-1-lihuisong@huawei.com/ >