From patchwork Tue Jan 16 09:52:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 124650 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp955640lje; Tue, 16 Jan 2018 01:52:58 -0800 (PST) X-Google-Smtp-Source: ACJfBos1U+zuuAeqwyRKkDY5ct5P7B9dtVO2Pe123LezzwcOcwJow8DVaWF5q5fwtIU35cJiZvA+ X-Received: by 10.84.132.36 with SMTP id 33mr6674733ple.57.1516096378354; Tue, 16 Jan 2018 01:52:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516096378; cv=none; d=google.com; s=arc-20160816; b=fB4FCQLt9XKYN97VSBBNyUSHju1wXuuHED0x42/5MtIV6xCSfNWb/EL8Or0j7NTQV7 aM/3pCnE4QVbkUFcPJ7LpsWkDSub9B+GdLGzmn0NlZixuRFgXsK8/kS+A8Honqj50EZn Q9g1dt7pVTAI6ZJ3gZV6bx2KcVG1SE6lm6CVchOU7kmgtkUv1S1O5tQukS33F0Li67rN N61tSBbxZKHiHakwme+NscFzUspPlOT/CBo80/gcIyPZLLrKWDKXsbVY2Vgjdbia1QU1 nM8fkXD4EkNunfwqK6LOxKTzRdIO2qKBf+1hSDQjwkYyGVK8sB6zPa3VisiPuvtlY3yC 4yPA== 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=CcVlb8d/s76JyMYmSXN4Bld9Y8l+tnfSrhtEUAfvpYY=; b=Ypf8aGkoUFHRrN1NO1aBZB+0FDk7Rssz1ml+Ef09lA8gXyZ2r81AYyr1bXRg4OLwfs IKp4DluBN1nwTJMdKsSwwG+C97v1ipYzxJ0X5XWlJWgSHGk6SbcCD/qsDmethJDMxorM T2Qx1Kt2nldWJ+4srUU3Z8hs7Lc7NP1txsebZ4C4CmJJaMi8EeNGA/a3spGbfOETD6ew Qig9zCfPgza48gkoLXo5gPuT2v7pSFUqx4nr7gdtl+zx8BRlyqD7b3c97szTyC3ietgr toXwUyU0M8UgTApUKBA4WItZthNzdlazHk2dGhky3sEKoaxsGrg13oOeF128+accXR1q OlTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UUZLDKQz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id l33si1560013pld.178.2018.01.16.01.52.58; Tue, 16 Jan 2018 01:52:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=UUZLDKQz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1751449AbeAPJw4 (ORCPT + 28 others); Tue, 16 Jan 2018 04:52:56 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:45443 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751406AbeAPJww (ORCPT ); Tue, 16 Jan 2018 04:52:52 -0500 Received: by mail-pf0-f196.google.com with SMTP id a88so7887911pfe.12 for ; Tue, 16 Jan 2018 01:52:51 -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; bh=CcVlb8d/s76JyMYmSXN4Bld9Y8l+tnfSrhtEUAfvpYY=; b=UUZLDKQz8jR5yWZ5kGPlsloJLdmRghDbxHIfeh2S7xoSazFTj3Gr/DR15Eiqm473fi 0WPF5UzOR7TZj/XSn9H9Wppje3hrw4ciCo2d34qWHPEfhzKpjwWDLTrSDNppoOxRjgpm ps5MKi/VxNtnmeSMO6EEfP9BH/ou2Urw6ore0= 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=CcVlb8d/s76JyMYmSXN4Bld9Y8l+tnfSrhtEUAfvpYY=; b=MAenGGXIKbLnMby000RMwvnxrAsk/DlmwVhZQ3k3ZQf5Xrq286X8wyMEPhTBfCbaRV D3iiXY9sDackaPsFD83T1qFyVCW4L/fFzvE0XnUFcFVMeXDJm3W9MTGyzOI+MP8HH9rq 74OfkeNYVlzLAxhLcgO4dfbv6KJIKZxsibtG+oAKFP1UVEo4R687SxPnGk3U8xyaT88J nUWhVca6Sbd+dwEdTOud3o1kwUJmF6VkPF136jZGiOo+pp0ezrjyQ/aeorzrHiTemD4B 4G2snqCPZI53I9itnbrodwllbEiiPNrFK0EH2lQgnwqLAg8YFkbmaIbhusAqaNxUZdSW fVMA== X-Gm-Message-State: AKwxytfsqvPhIHMAIqFWzCmVFTzI9j6YgOqJzuju9dqwGHn6q8B5SnPH sXyvWZzz87i8ufXoeOEb8efXIg== X-Received: by 10.98.108.130 with SMTP id h124mr17846909pfc.33.1516096371109; Tue, 16 Jan 2018 01:52:51 -0800 (PST) Received: from localhost ([122.172.95.205]) by smtp.gmail.com with ESMTPSA id e3sm3133941pfb.143.2018.01.16.01.52.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jan 2018 01:52:50 -0800 (PST) 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 V4] thermal: Add cooling device's statistics in sysfs Date: Tue, 16 Jan 2018 15:22:44 +0530 Message-Id: <6e557b90950723065d49c9a545146ce31d7dc6e1.1516096153.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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" file shows the clock_t time 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 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 --- 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 | 32 +++++ 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 | 227 ++++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 1 + 7 files changed, 283 insertions(+), 2 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/Documentation/thermal/sysfs-api.txt b/Documentation/thermal/sysfs-api.txt index bb9a0a53e76b..5a71f8152dff 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: Time (clock_t) 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,32 @@ 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: + The amount of time spent by the cooling device in various cooling + states. The output will have "