From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933174AbdKPAYl (ORCPT ); Wed, 15 Nov 2017 19:24:41 -0500 Received: from cloudserver094114.home.net.pl ([79.96.170.134]:46826 "EHLO cloudserver094114.home.net.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753083AbdKPAYb (ORCPT ); Wed, 15 Nov 2017 19:24:31 -0500 From: "Rafael J. Wysocki" To: WANG Chao Cc: Linux Kernel Mailing List , Linus Torvalds , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Vikas Shivappa , Kate Stewart , Len Brown , Greg Kroah-Hartman , Philippe Ombredanne , Mathias Krause , the arch/x86 maintainers , Linux PM , "Rafael J. Wysocki" Subject: Re: [PATCH] x86 / CPU: Always show current CPU frequency in /proc/cpuinfo Date: Thu, 16 Nov 2017 01:24:16 +0100 Message-ID: <8646127.yoBvgp8gpO@aspire.rjw.lan> In-Reply-To: <20171115093347.GA28750@WANG-Chaos-MacBook-Pro.local> References: <20171109103814.70688-1-chao.wang@ucloud.cn> <50366815.86mgx8Isne@aspire.rjw.lan> <20171115093347.GA28750@WANG-Chaos-MacBook-Pro.local> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday, November 15, 2017 10:33:47 AM CET WANG Chao wrote: > On 11/15/17 at 02:13P, Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki > > > > After commit 890da9cf0983 (Revert "x86: do not use cpufreq_quick_get() > > for /proc/cpuinfo "cpu MHz"") the "cpu MHz" number in /proc/cpuinfo > > on x86 can be either the nominal CPU frequency (which is constant) > > or the frequency most recently requested by a scaling governor in > > cpufreq, depending on the cpufreq configuration. That is somewhat > > inconsistent and is different from what it was before 4.13, so in > > order to restore the previous behavior, make it report the current > > CPU frequency like the scaling_cur_freq sysfs file in cpufreq. > > > > To that end, modify the /proc/cpuinfo implementation on x86 to use > > aperfmperf_snapshot_khz() to snapshot the APERF and MPERF feedback > > registers, if available, and use their values to compute the CPU > > frequency to be reported as "cpu MHz". > > > > However, do that carefully enough to avoid accumulating delays that > > lead to unacceptable access times for /proc/cpuinfo on systems with > > many CPUs. Run aperfmperf_snapshot_khz() once on all CPUs > > asynchronously at the /proc/cpuinfo open time, add a single delay > > upfront (if necessary) at that point and simply compute the current > > frequency while running show_cpuinfo() for each individual CPU. > > Hi, Rafael > > I tested your patch. It's much faster. > > But from what I got, calling aperfmperf_snapshot_khz() asynchronously > with 10ms sleep takes much longer than calling aperfmperf_snapshot_khz() > synchronously. > > Here's my result on 64 CPUs: > > - async aperfmperf_snapshot_khz() w/ 10ms sleep: > > # time cat /proc/cpuinfo > /dev/null > real 0m0.014s > user 0m0.000s > sys 0m0.002s > > - sync aperfmperf_snapshot_khz() w/o any sleep: > > # time cat /proc/cpuinfo > /dev/null > real 0m0.002s > user 0m0.000s > sys 0m0.002s Sure, but the delay is there, because without it the computed frequency may be way off for at least one of the CPUs. Thanks, Rafael