From patchwork Thu Nov 3 20:46:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Mayer X-Patchwork-Id: 9411455 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9613360585 for ; Thu, 3 Nov 2016 20:47:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 892EB2AEEB for ; Thu, 3 Nov 2016 20:47:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CB3C2AF46; Thu, 3 Nov 2016 20:47:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D897B2AEEB for ; Thu, 3 Nov 2016 20:47:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756871AbcKCUrQ (ORCPT ); Thu, 3 Nov 2016 16:47:16 -0400 Received: from smtp-out-no.shaw.ca ([64.59.134.12]:37390 "EHLO smtp-out-no.shaw.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756553AbcKCUrQ (ORCPT ); Thu, 3 Nov 2016 16:47:16 -0400 Received: from triton.mmayer.net ([70.71.160.251]) by shaw.ca with SMTP id 2Oumc23axr8m42OuncRejz; Thu, 03 Nov 2016 14:47:14 -0600 X-Authority-Analysis: v=2.2 cv=b8XC2pOx c=1 sm=1 tr=0 a=6xzog4CasRozao6qlzTIAw==:117 a=6xzog4CasRozao6qlzTIAw==:17 a=L24OOQBejmoA:10 a=Q-fNiiVtAAAA:8 a=MIsCFu7WsoRdjHj9DH8A:9 a=Fp8MccfUoT0GBdDC_Lng:22 Received: by triton.mmayer.net (Postfix, from userid 501) id 27C142ADA760; Thu, 3 Nov 2016 13:47:11 -0700 (PDT) From: Markus Mayer To: Viresh Kumar , "Rafael J . Wysocki" Cc: Power Management List , Broadcom Kernel List , Linux Kernel Mailing List , Markus Mayer Subject: [PATCH] cpufreq: stats: clear statistics Date: Thu, 3 Nov 2016 13:46:15 -0700 Message-Id: <20161103204615.85395-1-code@mmayer.net> X-Mailer: git-send-email 2.9.2 X-CMAE-Envelope: MS4wfEacVTonEgV9CV1mqZlWaXVutfPJcz7lrXyVRDarDr7ygW0muLcfX2yvyy/Y4aSX8x/Y1+35ZsO+uZc9T9E0h6K/Ys8cNZVj3ivpEZ6fIHuebzTkXu+c 01DZhDSE/hThYWD16iMs8EXjYER+5QFRpgfOBf013q8li4VVxFDniH1fKrcUB1FUBY7K1CYGvzCa6B1SPFw96rHKZl1vcgthnl+XndTJKyg9KFfY1YegF25g PvKUzTeFYaZyj1wwFIij6xJPA38R63Xy6SbgK7NnwrQxbE1Qkn2R0QWDD6pq/ks5L/O+dOZb8NBn+6uCF63u+jbe4Jzospbp+sZY+Sg4DcLH/+W3dEW4k4rl hE3+xv+wGrct0ImYCn2yKvfi3tOP6g== Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Mayer Allow cpufreq statistics to be cleared by writing anything to /sys/.../cpufreq/stats/reset. Reading this new sysfs entry returns nothing. Resetting the statistics can be useful in a test environment (test governor, retrieve stats, reset stats, test other governor, etc.). This feature is not meant for production use. Signed-off-by: Markus Mayer --- drivers/cpufreq/Kconfig | 10 ++++++++++ drivers/cpufreq/cpufreq_stats.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/cpufreq/Kconfig b/drivers/cpufreq/Kconfig index d8b164a..97a458e 100644 --- a/drivers/cpufreq/Kconfig +++ b/drivers/cpufreq/Kconfig @@ -45,6 +45,16 @@ config CPU_FREQ_STAT_DETAILS If in doubt, say N. +config CPU_FREQ_STAT_RESET + bool "Allow reset of CPU frequency transition statistics" + depends on CPU_FREQ_STAT + help + If enabled, writing to /sys/[...]/cpufreq/stats/reset will reset the + current CPUfreq statistics. This is primarily meant for testing. It + should not be enabled on a production system. + + If in doubt, say N. + choice prompt "Default CPUFreq governor" default CPU_FREQ_DEFAULT_GOV_USERSPACE if ARM_SA1100_CPUFREQ || ARM_SA1110_CPUFREQ diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 06d3abd..e4e1e3e 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -111,6 +111,35 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf) cpufreq_freq_attr_ro(trans_table); #endif +#ifdef CONFIG_CPU_FREQ_STAT_RESET +static void cpufreq_stats_clear_table(struct cpufreq_policy *policy) +{ + struct cpufreq_stats *stats = policy->stats; + unsigned int count = stats->max_state; + + memset(stats->time_in_state, 0, count * sizeof(u64)); +#ifdef CONFIG_CPU_FREQ_STAT_DETAILS + memset(stats->trans_table, 0, count * count * sizeof(int)); +#endif + stats->last_time = get_jiffies_64(); + stats->total_trans = 0; +} + +static ssize_t show_reset(struct cpufreq_policy *policy, char *buf) +{ + buf[0] = '\0'; + return 0; +} + +static ssize_t store_reset(struct cpufreq_policy *policy, const char *buf, + size_t count) +{ + cpufreq_stats_clear_table(policy); + return count; +} +cpufreq_freq_attr_rw(reset); +#endif + cpufreq_freq_attr_ro(total_trans); cpufreq_freq_attr_ro(time_in_state); @@ -120,6 +149,9 @@ static struct attribute *default_attrs[] = { #ifdef CONFIG_CPU_FREQ_STAT_DETAILS &trans_table.attr, #endif +#ifdef CONFIG_CPU_FREQ_STAT_RESET + &reset.attr, +#endif NULL }; static struct attribute_group stats_attr_group = {