Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp511984ybg; Wed, 3 Jun 2020 06:42:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxizTUks+VlRt+G4nTD8g9jUUN+5RYPGAm7Ee09Pn3xgJ5FIm6gOpa7KyEFcFSz6GYIlevz X-Received: by 2002:a17:906:b7cd:: with SMTP id fy13mr2367960ejb.443.1591191766457; Wed, 03 Jun 2020 06:42:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591191766; cv=none; d=google.com; s=arc-20160816; b=Ajn4oOaX64Veqf+l1otDOJ7xn+2ynlMqu3sI38dhLA9DzS0qB8mDdpJ429F6QTsE8Y Lr8FMaFm1tT/O7zHUhA7SDc0pDTDJYa+roNhNjNJOHsYQrvRrIPVPV5WKM7ywOjzVnVP U1Y9/Nh1w42aiX0S8QVJ+Dzh2mERIQ9TiZKiespTu/zoqKMfG9UMjhHkKgJOwi+yam8b I9SmCheAtaYJyAQUgvQF9mE9VZ1vDtiAeKtNX4PZFdVW+tF3mI0kJWoRHwq0iDC21KjI n2xwdkY4QOT/c6fBAkPsFwvE+3hNzJLQqIZCayyTJYiAxt0eAwJ7/gFShxgKdiCMy9fm tgWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=QtRjhLaAAXrKs3rcG85ERI4DR22fXXuoilSjsbEiHeg=; b=i4desPNquXIFbT3sjKdN9PPZGJQ+fxNCVh5W8vkqRi5k3n82FRSqvi65V1sV/JCzhW FW4QPUfPpJOFd2Hp32yI4mGjGodiF7u34pyHwN0G8ju2NSIEi9uoiDUnqMxL05jJGjJ6 MVBMk1rnblvjOC5uAHucq22Nr/clXhi2EF8/b92UTmoiNRncSF56kNR+RKx3lcQfp56q Sl7Ls4aOyluO5Or4FAJ8+sTufhEUVY4FMiD1kGRpJ6EFpjm4beAMHqEI4/+wPaWuI4iV 8iv9g4hC+a35V6zu9X/V2jpnDhkRNdoNEGkd5lXBj93D8+4RJvfLFT9PErBsoZqQmdRt Bj8g== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a20si1024321edv.497.2020.06.03.06.42.23; Wed, 03 Jun 2020 06:42:46 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725992AbgFCNkC (ORCPT + 99 others); Wed, 3 Jun 2020 09:40:02 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:46329 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725834AbgFCNkC (ORCPT ); Wed, 3 Jun 2020 09:40:02 -0400 Received: by mail-oi1-f195.google.com with SMTP id 25so899009oiy.13; Wed, 03 Jun 2020 06:40:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QtRjhLaAAXrKs3rcG85ERI4DR22fXXuoilSjsbEiHeg=; b=fxH11YFr76LFMpYXBHGs8JZ6LozbXxhqQ8niywQHPznjnQQ3gyDWyoeQ5WlkJdVOBT ZuNmeafBTSvXH3Lg3BmmzdpCAL3aAQLCfKe5Hbwyi4BJ+14mBhPZUZO/0HhvxGzbnk3X HLv36Miuat40mkksoJt+tXQ0CW6r/7Qf3Etrwj1a/3tp32nGbCw/+CWlfrRL+xEwSesS eQkgdMPEGCltntto848scIqS7xlT+HlFobfodSaz6e8hXd4ywQXgCi3Zgx5quwVivQ6j 6S/za8z90qUtJKdl8d5I7v8UxvgkO2/XRDqYCuKC+zXd7mhua61o9grIrJPDpjyfjG1z m7wA== X-Gm-Message-State: AOAM532Hz6jsBOJd67DpZTKQ6ttlauHd5CCUy1Mi4FrjhQUZoYRuSx4h AhEfckdjibiQ1goQ31jerlSE+3XrgGmmoOA3naY= X-Received: by 2002:aca:ad88:: with SMTP id w130mr6530787oie.103.1591191601127; Wed, 03 Jun 2020 06:40:01 -0700 (PDT) MIME-Version: 1.0 References: <20200603075200.hbyofgcyiwocl565@vireshk-i7> In-Reply-To: <20200603075200.hbyofgcyiwocl565@vireshk-i7> From: "Rafael J. Wysocki" Date: Wed, 3 Jun 2020 15:39:46 +0200 Message-ID: Subject: Re: [Question]: about 'cpuinfo_cur_freq' shown in sysfs when the CPU is in idle state To: Viresh Kumar Cc: Xiongfeng Wang , "Rafael J. Wysocki" , Hanjun Guo , Sudeep Holla , Ionela Voinescu , Linux PM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 3, 2020 at 9:52 AM Viresh Kumar wrote: > > 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 ? The frequency value obtained by kicking the CPU out of idle artificially is bogus, though. You may as well return a random number instead. The frequency of a CPU in an idle state is in fact unknown in the case at hand, so returning 0 looks like the cleanest option to me. Thanks!