Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3905315pxb; Tue, 10 Nov 2020 03:11:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLeCIZIUSyReK6SbuajyNz6FL8dLcYmJ7XGGiABNKm9Ngl9nAsLCjBplri1H08OESv8b/Q X-Received: by 2002:a17:906:90da:: with SMTP id v26mr20450303ejw.367.1605006703800; Tue, 10 Nov 2020 03:11:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605006703; cv=none; d=google.com; s=arc-20160816; b=RRnN03ja1FlxsatnUjhW3V6jdPNwIW4e10hbhTEcJbbydPuaYYB/3ckOXnX7edbYKD DS9IncRxgm92hHUNV9/QE4XyttcT45RYx7KbJD1UteHyDLOkCb+q0tC5HBsZPCPXMYw2 25ialue2tOiJkBu6DhoOdFmV4vbSldaekNDW5DWryYvBoFHe0fJhD8S3nynYHHNel5Wf h0yknhpFk8JNZPSvxHjG7StCxLzmeeTFH26fhESC6rDt2MU999BNVn47UlWMFFkZmm+p 402jhm7H6Sq4yyrcaptVdKYVJp9VZdKauJyANmNe5dGpZii47xu8FNQC1Tp0RLFpjXtn sL1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=dxnc/wj2TvGDBxmyx5Nf+xxtQWZ4ImyGwOdGSdt4B2U=; b=1FR4gQsh5sNMEEiju81x52eV/VCJo/3yYGW9iU/ODG2W8Cs9+seWnReAp3zmrHGcNs 6YeaQ+MwmGZlZ0hmBcKC16xOqD/GR08AGKRin4/S+N9RZUf58998/VrPVq5y7tDewiWv K12Dg4N9g1weeaFvw9RYHsv0OShwa62TSdI59NPSduGTnn9q0tNKkxXx49Ss0KvPgd/W F4UFzmupOrZyrxpwj+98Ox95Vpik05q9+FIzju7bkrmyRtqVmH33xrxBC07eHeZMdctG Ug40f9XrqxkzWEHonnJfp8TO2xA0C9eT76tj+EogPD+WcQZuvMViRkt4AXUmlyOuR43H XB7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eTzewguE; 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 bh4si11568757ejb.551.2020.11.10.03.11.19; Tue, 10 Nov 2020 03:11:43 -0800 (PST) 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=eTzewguE; 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 S1729359AbgKJLHo (ORCPT + 99 others); Tue, 10 Nov 2020 06:07:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727536AbgKJLHn (ORCPT ); Tue, 10 Nov 2020 06:07:43 -0500 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D45EC0613D3 for ; Tue, 10 Nov 2020 03:07:43 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id f27so6455697pgl.1 for ; Tue, 10 Nov 2020 03:07:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=dxnc/wj2TvGDBxmyx5Nf+xxtQWZ4ImyGwOdGSdt4B2U=; b=eTzewguEpa+CGdbUOfXmyzQCrTmpUuGJbRjlbYm85CVMLnUnbQ4bw9Pp22L8ZEMlD3 gt4Fo6Db47692OZi6grP2eicQfyl1TXeRBCa0UxOSX7FmDOmGvQfdtiG7rHfuQ/9W6Nx BQhLqDyNa/Zmyad5BXXGGZN/T932PHp2Yi4y9/yTlTsR4kVxpKXmfrSk8IWCjhcPAGug d+ESQJswqC9bsLIoZOqENQrC4kApXFRUT512haWhNFkt26d3RGQ3gorEBxOCCNClH395 p+ayBJDde87H3jszRWCat+eO71rYbqHJ1BbCoKseEKdu7rgbFzYGiuA2CNEJdIe4v22I fJuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=dxnc/wj2TvGDBxmyx5Nf+xxtQWZ4ImyGwOdGSdt4B2U=; b=G/bxfua6kJ8tCtpweZ0YVUwjzblfOfv8X4kHMdQcfXA6XkMlQsTQ7m9OI5hQl/LBpz HoowRSwaVxYP+yXbYnuiPF819gcEbj1H5sdoJCrHmabC98xjiav0UeyZT48/QC2zTdVm /wLpwnWGGkLfEjoKSpAOQocCB/rG5ZX6enDv28LBrM/6lcfS2XRuBUgfXbqOiC8B1TS3 dXsrkNX4+Vfu44LUHkeCqZv0d8+t8G291qTr4e3hBMnxtADxbGpP/AQ21V2KkFOZNOyl IxFFirqR/rZi4VhoNFobtbgPON7ckkA08U/+4vVYTk+W2MWyZfLZLNK+gmNh3sOKHwg/ ZMNw== X-Gm-Message-State: AOAM530CfybGD3dWghN9U3sYHUs38JCYeOOuqwYrMjXO0lkVNRhQEclE +7Tqy3ekT9NRMGmjgoWqCuxTt7TdupWXig== X-Received: by 2002:a17:90a:d590:: with SMTP id v16mr4517353pju.88.1605006462913; Tue, 10 Nov 2020 03:07:42 -0800 (PST) Received: from localhost ([122.172.12.172]) by smtp.gmail.com with ESMTPSA id b67sm14296322pfa.151.2020.11.10.03.07.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Nov 2020 03:07:41 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar , Jonathan Corbet Cc: linux-pm@vger.kernel.org, Vincent Guittot , Thomas Renninger , Shuah Khan , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] cpufreq: stats: Switch to ktime and msec instead of jiffies and usertime Date: Tue, 10 Nov 2020 16:37:37 +0530 Message-Id: <0e0fb542b6f6b26944cb2cf356041348aeac95f6.1605006378.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The cpufreq and thermal core, both provide sysfs statistics to help userspace learn about the behavior of frequencies and cooling states. This is how they look: /sys/devices/system/cpu/cpufreq/policy0/stats/time_in_state:208000 11 /sys/devices/system/cpu/cpufreq/policy0/stats/time_in_state:432000 147 /sys/devices/system/cpu/cpufreq/policy0/stats/time_in_state:729000 1600 /sys/devices/system/cpu/cpufreq/policy0/stats/time_in_state:960000 879 /sys/devices/system/cpu/cpufreq/policy0/stats/time_in_state:1200000 399 /sys/class/thermal/cooling_device0/stats/time_in_state_ms:state0 4097 /sys/class/thermal/cooling_device0/stats/time_in_state_ms:state1 8932 /sys/class/thermal/cooling_device0/stats/time_in_state_ms:state2 15868 /sys/class/thermal/cooling_device0/stats/time_in_state_ms:state3 1384 /sys/class/thermal/cooling_device0/stats/time_in_state_ms:state4 103 Here, state0 of thermal corresponds to the highest frequency of the CPU, i.e. 1200000 and state4 to the lowest one. While both of these try to show similar kind of data (which can still be very much different from each other), the values looked different (by a factor of 10, i.e. thermal's time_in_state is almost 10 times that of cpufreq time_in_state). This comes from the fact that cpufreq core displays the time in usertime units (10 ms). It would be better if both the frameworks displayed times in the same unit as the users may need to correlate between them and different scales just make it awkward. And the choice of thermal core for that (msec) seems to be a better choice as it is easier to read. The thermal core also does the stats calculations using ktime, which is much more accurate as compared to jiffies used by cpufreq core. This patch updates the cpufreq core to use ktime for the internal calculations and changes the units of time_in_state to msec. The results look like this after this commit: /sys/devices/system/cpu/cpufreq/policy0/stats/time_in_state:208000 13 /sys/devices/system/cpu/cpufreq/policy0/stats/time_in_state:432000 790 /sys/devices/system/cpu/cpufreq/policy0/stats/time_in_state:729000 12492 /sys/devices/system/cpu/cpufreq/policy0/stats/time_in_state:960000 13259 /sys/devices/system/cpu/cpufreq/policy0/stats/time_in_state:1200000 3830 /sys/class/thermal/cooling_device0/stats/time_in_state_ms:state0 3888 /sys/class/thermal/cooling_device0/stats/time_in_state_ms:state1 13432 /sys/class/thermal/cooling_device0/stats/time_in_state_ms:state2 12336 /sys/class/thermal/cooling_device0/stats/time_in_state_ms:state3 740 /sys/class/thermal/cooling_device0/stats/time_in_state_ms:state4 0 FWIW, tools/power/cpupower/ does consume the time_in_state values from the sysfs files but it is independent of the unit of the time and didn't require an update. Signed-off-by: Viresh Kumar --- Documentation/cpu-freq/cpufreq-stats.rst | 5 +-- drivers/cpufreq/cpufreq_stats.c | 47 +++++++++++++----------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/Documentation/cpu-freq/cpufreq-stats.rst b/Documentation/cpu-freq/cpufreq-stats.rst index 9ad695b1c7db..9f94012a882f 100644 --- a/Documentation/cpu-freq/cpufreq-stats.rst +++ b/Documentation/cpu-freq/cpufreq-stats.rst @@ -64,9 +64,8 @@ need for a reboot. This gives the amount of time spent in each of the frequencies supported by this CPU. The cat output will have "