Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp301146ybg; Wed, 3 Jun 2020 00:54:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysodJYhpt4X3UM86CR8xjvKWuRXHVUF1Q1khbVEe0k1U4wObUyVruSFz5tkMCpbNQxKUSm X-Received: by 2002:a17:906:fcd4:: with SMTP id qx20mr2261926ejb.496.1591170877665; Wed, 03 Jun 2020 00:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591170877; cv=none; d=google.com; s=arc-20160816; b=ZmqSjRuIhbzCcMcwQ54S+sSJL1+gXsUXFMHyImq7yk0E2wC3t8tKuH05RcuM4bTPHs plU4Ajlsn4HBXnB+yjVHN8kzFeXF9zihY7AJaephHviDtHjbWmE/PHR62vNOJfVv+Fel LFH8S9oLvPASY+jgAd+3NQsw9WmHLs5TaOAiaXzafLtLU3eLyNTpGrYdSNYwLNa4ol1O YIr5lgON1Ahc6nfAOfdbnwJKd4r9bpxweKlT3WzTaUVJCZrRdZxB5EBfWQWHQP2jqbJx SqPG5LlORp1WN30tvuoemTWTFiyf8Br5hRT5PAfsG1cgImIL3io6IUWxErtCTxidW0Dd yL/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=r/WSOOgzKah1n7hh2oJZG/JFgX3kZ1eyc3n37SqQbvQ=; b=nEb3V5THEZWLLWwD9PkgLMllRHdRHrUgJ/8B6mP/SHZnji7RiveMdqtkIP340yGy+W zIyqh4REnLizDY9Qff5vTzK6UDOWUQ6cjuGwzn1Y2aNDcAm0TkX1QGDONLi6FMKyVYre Ndt01013rY7YyZrNHctzjknZDHkCM3NXvdipaOAyK/hyVG2wDI91Aqv5U01f19Kwbjiy +D5IbW3yc2eTV2EGclkpSAUdNyABN8vuQE62k3SssV8j5jnoBki3gndc1vMy7pEALOjL vOfcXFQFfo8+++WVgEpzZYwUApIWbpNLra3w4n4PjvbVeL23i5QuSzAtBoJEot6NMGOJ fr5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FnKoWR7R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p22si662498edy.126.2020.06.03.00.54.14; Wed, 03 Jun 2020 00:54:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FnKoWR7R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725943AbgFCHwE (ORCPT + 99 others); Wed, 3 Jun 2020 03:52:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725828AbgFCHwE (ORCPT ); Wed, 3 Jun 2020 03:52:04 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 125FCC05BD1E for ; Wed, 3 Jun 2020 00:52:04 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id x22so1081034pfn.3 for ; Wed, 03 Jun 2020 00:52:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=r/WSOOgzKah1n7hh2oJZG/JFgX3kZ1eyc3n37SqQbvQ=; b=FnKoWR7RT8zK6PByUgH0+LGhcQmKt1grg2AvPgaaga/WlmpLgGnhAUb2SiK8pAq34n fVUqKqAXp2fimwkYQ4Bz9FN4F0MPN8jqiwJiim4n+PAfy/qX+SCeAvcGk0vHvdoeqtMp TgyP45XWLuCiDOigaq+k80TeuklEgj5PEb8f1ChyNTB7sMY6UI+Kj3nHUcW0P77mDum2 bWoDmtW8iQhFgCOgRdXJoixndB2OaRjsuLl9TThhsUuXmHQr9VTEcsjatQPxV91bOw8i Rk5DFYMufWU2v8h0M+JUdDHbPIUwU+htVbEVgl8k8l7iq57Bqzl2Jrjx5Fxd/Il6nH9+ tKzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=r/WSOOgzKah1n7hh2oJZG/JFgX3kZ1eyc3n37SqQbvQ=; b=Nz+lFt1tdXQI5DflTJJSb6pQkfwzCKgMIvKKFtguXEyElNTUqU5Z3pM+2r2KBdx+qL Nk6PMIexYNiiErc5xopxtvFG19gJQDau0ZFRe3GQnkEDndXGdQhMAhe7VhRWFiGTan8c n4QVl+6+sWX1I0WQyRHd3CIrxZl3Rrjp+WHKiXW1WIVBRU71xP1METofjLy1QTsGo7lw z4QzA47gBRT8O3xId9NeTtgjW2TX4GApv0AFHDjmbMsximjCghv5+5Cjv0qrzZXkKk+2 41m5N5v8LWCRVBv1xZOze5tX9mOPbOhH/XpUS3iFwuyHZtl9tsd3CkJE4IvaytiRlJqx +g6g== X-Gm-Message-State: AOAM532rC/f/ph/AFlBYBavUJG0xLYfDLrwEj5yw9TVsdLWEfpo6AGex 4SpgYGEHzo3uEod17xWc68CP2w== X-Received: by 2002:a17:90b:78b:: with SMTP id l11mr3995244pjz.97.1591170723258; Wed, 03 Jun 2020 00:52:03 -0700 (PDT) Received: from localhost ([122.172.62.209]) by smtp.gmail.com with ESMTPSA id j26sm1159884pfr.215.2020.06.03.00.52.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jun 2020 00:52:02 -0700 (PDT) Date: Wed, 3 Jun 2020 13:22:00 +0530 From: Viresh Kumar To: Xiongfeng Wang Cc: rjw@rjwysocki.net, guohanjun@huawei.com, Sudeep.Holla@arm.com, ionela.voinescu@arm.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [Question]: about 'cpuinfo_cur_freq' shown in sysfs when the CPU is in idle state Message-ID: <20200603075200.hbyofgcyiwocl565@vireshk-i7> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716-391-311a52 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02-06-20, 11:34, Xiongfeng Wang wrote: > Hi Viresh, > > Sorry to disturb you about another problem as follows. > > CPPC use the increment of Desired Performance counter and Reference Performance > counter to get the CPU frequency and show it in sysfs through > 'cpuinfo_cur_freq'. But ACPI CPPC doesn't specifically define the behavior of > these two counters when the CPU is in idle state, such as stop incrementing when > the CPU is in idle state. > > ARMv8.4 Extension inctroduced support for the Activity Monitors Unit (AMU). The > processor frequency cycles and constant frequency cycles in AMU can be used as > Delivered Performance counter and Reference Performance counter. These two > counter in AMU does not increase when the PE is in WFI or WFE. So the increment > is zero when the PE is in WFI/WFE. This cause no issue because > 'cppc_get_rate_from_fbctrs()' in cppc_cpufreq driver will check the increment > and return the desired performance if the increment is zero. > > But when the CPU goes into power down idle state, accessing these two counters > in AMU by memory-mapped address will return zero. Such as CPU1 went into power > down idle state and CPU0 try to get the frequency of CPU1. In this situation, > will display a very big value for 'cpuinfo_cur_freq' in sysfs. Do you have some > advice about this problem ? > > I was thinking about an idea as follows. We can run 'cppc_cpufreq_get_rate()' on > the CPU to be measured, so that we can make sure the CPU is in C0 state when we > access the two counters. Also we can return the actual frequency rather than > desired performance when the CPU is in WFI/WFE. But this modification will > change the existing logical and I am not sure if this will cause some bad effect. > > > diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c > index 257d726..ded3bcc 100644 > --- a/drivers/cpufreq/cppc_cpufreq.c > +++ b/drivers/cpufreq/cppc_cpufreq.c > @@ -396,9 +396,10 @@ static int cppc_get_rate_from_fbctrs(struct cppc_cpudata *cpu, > return cppc_cpufreq_perf_to_khz(cpu, delivered_perf); > } > > -static unsigned int cppc_cpufreq_get_rate(unsigned int cpunum) > +static int cppc_cpufreq_get_rate_cpu(void *info) > { > struct cppc_perf_fb_ctrs fb_ctrs_t0 = {0}, fb_ctrs_t1 = {0}; > + unsigned int cpunum = *(unsigned int *)info; > struct cppc_cpudata *cpu = all_cpu_data[cpunum]; > int ret; > > @@ -418,6 +419,22 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpunum) > return cppc_get_rate_from_fbctrs(cpu, fb_ctrs_t0, fb_ctrs_t1); > } > > +static unsigned int cppc_cpufreq_get_rate(unsigned int cpunum) > +{ > + unsigned int ret; > + > + ret = smp_call_on_cpu(cpunum, cppc_cpufreq_get_rate_cpu, &cpunum, true); > + > + /* > + * convert negative error code to zero, otherwise we will display > + * an odd value for 'cpuinfo_cur_freq' in sysfs > + */ > + if (ret < 0) > + ret = 0; > + > + return ret; > +} > + > static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state) > { > struct cppc_cpudata *cpudata; I don't see any other sane solution, even if this brings the CPU back to normal state and waste power. We should be able to reliably provide value to userspace. Rafael / Sudeep: What you do say ? -- viresh