From patchwork Tue Nov 10 11:07:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 321012 Delivered-To: patch@linaro.org Received: by 2002:a17:906:d156:0:0:0:0 with SMTP id br22csp3446348ejb; Tue, 10 Nov 2020 03:07:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJzL5DB8rn1o35yPi1Hvq8bzKys1ADP0S3pCXwz8vgVWycDgU8i3zwMqP/AyIADFRr+B9jWc X-Received: by 2002:aa7:c358:: with SMTP id j24mr20604550edr.265.1605006464987; Tue, 10 Nov 2020 03:07:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605006464; cv=none; d=google.com; s=arc-20160816; b=nYr6JJROh8fyKPyHTSMk7Tv7to2VnHgs3C/y+h39iX3PzSYXE+JSGPUR5XkywTOG62 HxggqiH4sTlxsuhJNgiJUnZm8uDJTAJwCKdfJRyFKDdQzAUHgThaXkjaolV6igG/25zh NiMR8ksSBoNGsozvXPn3qC+yzIJDFghnIHOIPou92rZRPHIVGl3FVVt4e3LCEOCWsE74 jjHr7bwH9Fhuhx+3iCO46SwzCVBkw5YEP8j35XI9sOi7w4wQJK5ndxi2z5Nk765H6BxA JMaoMOE0H7HgOBDo4o5K3dNq+ccpJuNwDNgv4py5syF8684vqQklWRKo6o32Y+AaP4Gk dy3A== 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=dgVR97xnbI641O429UzQiQukqBRxePiUVthaX9ps4Qa+dTiChukuUw98xgTrqErJnM xQGuKW+dKUXTiN8q12UZBLfHvnW9UHjkVTRr29Wj03Gdg9rGMdfC3JIHGM/ISa4gkTO9 79Of2asZA6TG0XR8u6hhZ3VoceEzFbr8WGlkSNJTLz/5UqYMbDxNHJKbZke9EhL9u9he mCzDQjB8ZpEauha/ATtsUlzYIFS41ykA0Rk1/6/4FTua8M6U85bgUcsqfQOxJlN8jdwa BJlEZMNZ9no8y9GDbnFdKBxbRIvWLcyvUJD9n/rvAlZeSGalePxg06WM9xa6lHFCgRGR yWig== 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-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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 y10si8796229ejf.165.2020.11.10.03.07.44; Tue, 10 Nov 2020 03:07:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-pm-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-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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 S1729183AbgKJLHn (ORCPT + 9 others); Tue, 10 Nov 2020 06:07:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726861AbgKJLHn (ORCPT ); Tue, 10 Nov 2020 06:07:43 -0500 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 707C1C0613D1 for ; Tue, 10 Nov 2020 03:07:43 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id r186so9872825pgr.0 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=remGU7eSrJQcvkpt0RlgdYo3pJBu9yHBmk1xlak+AKWE2TZqH5nHBDHKt3HoZOhGeK 5Mhzh2Iph1Xd6QzGyQiuI3hlPzaVB7AnOJN3SDhx8AFCpqvAexprKX54Xu0bfC4KZ459 lemJMCuS3KYTfK38YMGQ6s3Xb4F5oKOjdboi8mJdGmuATi5oJEEBWX2URMRYAzI2kqw/ wfehG9tYvOCfU1rXBy7eiC8KxbXPt5BCpyTK5KrwDzKEVlkGZRaSjkKkavIhA6srNOXm OE8KeSe6Q/kh6BOj3xJFV41UikFWXQLtQw3jCbGC9OMXNHRKpUhhByECXnx5v3MrzU+K uDFw== X-Gm-Message-State: AOAM530oN8CgV1/qdidMuvDSWt4BhyNq84UTgkbz0iyoT0f6pGS5SqG2 2YuiP5ylSsaXKmg8OQC+umwOHA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-pm@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(-) -- 2.25.0.rc1.19.g042ed3e048af 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 "