From patchwork Mon Apr 2 10:56:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 132656 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp2434086ljb; Mon, 2 Apr 2018 03:56:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx49DGrdfAFuH/O5qUlV8goBQX1YDu7cbT5Sfp5mNabapOYYbKFTm/jsfxFQog8whUawi9iF+ X-Received: by 2002:a17:902:bf01:: with SMTP id bi1-v6mr7974720plb.249.1522666602409; Mon, 02 Apr 2018 03:56:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522666602; cv=none; d=google.com; s=arc-20160816; b=zYWgaNULNZTTv6QlN8bPL+ufY32EKlEoZ54PidYg+FRTmbzGwxWa4ja889CEPAYayK ajJgBQMz+HVqvtwTcw1POt8OzrIGHvjjwdIG+v8Hj020PWuXNorpgTbWKx7XHpuGCep6 aCQG2d5CDJVcueE+L5dvZbKe2Eb3SBdpkLcvbCr4Q9HAFMDKgI/X/eCpRdWfp1aMlVBd mkMlc+eJEe67uSZaYQLIH64+WpjU4cCID6hd5LXPeAEuZGSd9cG5X+kxzstsoqtp0bhQ d0cDGh0bnBp4HE/bMmDGQlBP8ndEFp/GYiEV4DOyadmRt0M3qEJuWrfvUxlXFHuTv8KG RJ4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=ReXDOWu1tgIg5s6/9ZM0KfEibPnbp5+0pJIFak947NA=; b=zKd2TeWcaQ1kUb5HzyA+oUSvi0d4QnQHMeqZBZNBjPzhr3l2vhvSr2cd0mfLVBQg5S WLexYNYGTKxs1bcaGFYdsGmZsZH3FU6evea56vNT2WFX9NMvPvJHdAc1+zq/A09T2V60 rtjnMT5zGyy4z4u7itubqLh2mnKpmOo88RAUTJvjNO734lJAgo1PX1A8woge43JyEa6Y X2r3jYDKrQwCkWyPENo7qWRs5Nbj8eUWvRHzLWbB/fQdjKTZEGcnoN2GPxeB8LX0U/7N Y8Zxq+MfMxyTM8qg5CuGMQN1Y/NB/ZIoLEVL1p7sD8kmSorZ4tu8VVbJTCDAkjJCVtbH ypYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZE46dglP; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id v8-v6si97607plg.68.2018.04.02.03.56.41; Mon, 02 Apr 2018 03:56:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZE46dglP; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 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 S1754326AbeDBK4k (ORCPT + 11 others); Mon, 2 Apr 2018 06:56:40 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:39471 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754256AbeDBK4i (ORCPT ); Mon, 2 Apr 2018 06:56:38 -0400 Received: by mail-pl0-f67.google.com with SMTP id s24-v6so3873678plq.6 for ; Mon, 02 Apr 2018 03:56:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=ReXDOWu1tgIg5s6/9ZM0KfEibPnbp5+0pJIFak947NA=; b=ZE46dglPKu0vwZaLaGfeXkmG1B79Qxt7IUCIgNl4uQ4exW6KXs3L2i0IfAE8U8STtJ 2uqhG+0DSeKyJf/0Y0K1Is8QtdPadxdBY+HgWx9s1RhiJ8IST8FBgq12lK/fXgkiLu7K 5ifFjIK8J1KWjjrEnSI5jG2IDFdchxeYpYsiE= 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; bh=ReXDOWu1tgIg5s6/9ZM0KfEibPnbp5+0pJIFak947NA=; b=uZUC3gUyP/Owbrvr0Sgn2/r8m51RxMC5CSu5iuTvHTQuaHqoahU03uJIKOdKbdmD/j w2au3N4BR3NJxQOHbNHz+xvc4qT7pqAKlyLyJ362qEagpSr6MDl1qunZcb18akRTKnCA 9hbG6wjZQzpI52OnD3u3esb7QFa/v9ge9Uc2Jfs4UxjY76VxsiprrJyVWTn52pn0iR9p lU83N4T7U3WiwlBHwB8uIpYG4KqIbo5jVVZkyoK0hMrASm3ojQD99lUNuOfr8uFIpVy5 HGKYGTP4U62OV8Rx7sSP7nBVXj1UM5X4mHbGaoYnXAwZd/9LhWr0SZs0xgSsGDqUKTYa Tdeg== X-Gm-Message-State: AElRT7GSanMaCn5goJcgoDEfTNkAdLOtO2kzPu7ae1ushecFzYqnRCti ZTyaPn3bF6AVs8Ky7OzlFT5iQg== X-Received: by 2002:a17:902:bb81:: with SMTP id m1-v6mr9200622pls.71.1522666597282; Mon, 02 Apr 2018 03:56:37 -0700 (PDT) Received: from localhost ([122.171.228.188]) by smtp.gmail.com with ESMTPSA id 73sm260943pgg.73.2018.04.02.03.56.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Apr 2018 03:56:36 -0700 (PDT) From: Viresh Kumar To: Zhang Rui , Eduardo Valentin Cc: Viresh Kumar , Vincent Guittot , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH V5] thermal: Add cooling device's statistics in sysfs Date: Mon, 2 Apr 2018 16:26:25 +0530 Message-Id: X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This extends the sysfs interface for thermal cooling devices and exposes some pretty useful statistics. These statistics have proven to be quite useful specially while doing benchmarks related to the task scheduler, where we want to make sure that nothing has disrupted the test, specially the cooling device which may have put constraints on the CPUs. The information exposed here tells us to what extent the CPUs were constrained by the thermal framework. The write-only "reset" file is used to reset the statistics. The read-only "time_in_state_ms" file shows the time (in msec) spent by the device in the respective cooling states, and it prints one line per cooling state. The read-only "total_trans" file shows single positive integer value showing the total number of cooling state transitions the device has gone through since the time the cooling device is registered or the time when statistics were reset last. The read-only "trans_table" file shows a two dimensional matrix, where an entry (row i, column j) represents the number of transitions from State_i to State_j. This is how the directory structure looks like for a single cooling device: $ ls -R /sys/class/thermal/cooling_device0/ /sys/class/thermal/cooling_device0/: cur_state max_state power stats subsystem type uevent /sys/class/thermal/cooling_device0/power: autosuspend_delay_ms runtime_active_time runtime_suspended_time control runtime_status /sys/class/thermal/cooling_device0/stats: reset time_in_state_ms total_trans trans_table This is tested on ARM 64-bit Hisilicon hikey620 board running Ubuntu and ARM 64-bit Hisilicon hikey960 board running Android. Signed-off-by: Viresh Kumar --- V4->V5: - time_in_state's unit is msec now instead of clock_t. - Remove double setting of ->stats pointer. V3->V4: - Added CONFIG_THERMAL_STATISTICS - Added transition table file in sysfs - Updated documentation for new sysfs files - The unit of time in time_in_state is clock_t now - Separate routines for cooling device stat setup/destroy V2->V3: - Total number of states is max_level + 1. The earlier version didn't take that into account and so the stats for the highest state were missing. V1->V2: - Move to sysfs from debugfs Documentation/thermal/sysfs-api.txt | 31 +++++ drivers/thermal/Kconfig | 7 ++ drivers/thermal/thermal_core.c | 3 +- drivers/thermal/thermal_core.h | 10 ++ drivers/thermal/thermal_helpers.c | 5 +- drivers/thermal/thermal_sysfs.c | 225 ++++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 1 + 7 files changed, 280 insertions(+), 2 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/Documentation/thermal/sysfs-api.txt b/Documentation/thermal/sysfs-api.txt index bb9a0a53e76b..911399730c1c 100644 --- a/Documentation/thermal/sysfs-api.txt +++ b/Documentation/thermal/sysfs-api.txt @@ -255,6 +255,7 @@ temperature) and throttle appropriate devices. 2. sysfs attributes structure RO read only value +WO write only value RW read/write value Thermal sysfs attributes will be represented under /sys/class/thermal. @@ -286,6 +287,11 @@ if hwmon is compiled in or built as a module. |---type: Type of the cooling device(processor/fan/...) |---max_state: Maximum cooling state of the cooling device |---cur_state: Current cooling state of the cooling device + |---stats: Directory containing cooling device's statistics + |---stats/reset: Writing any value resets the statistics + |---stats/time_in_state_ms: Time (msec) spent in various cooling states + |---stats/total_trans: Total number of times cooling state is changed + |---stats/trans_table: Cooing state transition table Then next two dynamic attributes are created/removed in pairs. They represent @@ -490,6 +496,31 @@ cur_state - cur_state == max_state means the maximum cooling. RW, Required +stats/reset + Writing any value resets the cooling device's statistics. + WO, Required + +stats/time_in_state_ms: + The amount of time spent by the cooling device in various cooling + states. The output will have "