Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1515317 > unrolled thread

[PATCH v2 0/2] cpufreq: stats: clear statistics

Started byMarkus Mayer <code@mmayer.net>
First post2016-11-04 18:00 +0100
Last post2016-11-07 05:40 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v2 0/2] cpufreq: stats: clear statistics Markus Mayer <code@mmayer.net> - 2016-11-04 18:00 +0100
    [PATCH v2 2/2] cpufreq: stats: clear statistics Markus Mayer <code@mmayer.net> - 2016-11-04 18:00 +0100
      Re: [PATCH v2 2/2] cpufreq: stats: clear statistics Viresh Kumar <viresh.kumar@linaro.org> - 2016-11-07 05:40 +0100

#1515317 — [PATCH v2 0/2] cpufreq: stats: clear statistics

FromMarkus Mayer <code@mmayer.net>
Date2016-11-04 18:00 +0100
Subject[PATCH v2 0/2] cpufreq: stats: clear statistics
Message-ID<szQ0q-4l3-3@gated-at.bofh.it>
From: Markus Mayer <mmayer@broadcom.com>

This series lets the user clear the CPUfreq stats by writing to a new
sysfs attribute.

Changes since v1:
    - add new cpufreq_freq_attr_wr_perm() macro for write-only
      attributes (because this is a separate commit, this patch has
      turned into a series)
    - remove the Kconfig option, compiling the code unconditionally
    - remove show_reset()
    - cpufreq_stats_clear_table() takes a struct cpufreq_stats * as
      argument rather than a struct cpufreq_policy *

For v1, see https://lkml.org/lkml/2016/11/3/581.

Markus Mayer (2):
  cpufreq: add new attribute type cpufreq_freq_attr_wr_perm()
  cpufreq: stats: clear statistics

 Documentation/cpu-freq/cpufreq-stats.txt |  6 ++++++
 drivers/cpufreq/cpufreq_stats.c          | 22 ++++++++++++++++++++++
 include/linux/cpufreq.h                  |  4 ++++
 3 files changed, 32 insertions(+)

-- 
2.7.4

[toc] | [next] | [standalone]


#1515322 — [PATCH v2 2/2] cpufreq: stats: clear statistics

FromMarkus Mayer <code@mmayer.net>
Date2016-11-04 18:00 +0100
Subject[PATCH v2 2/2] cpufreq: stats: clear statistics
Message-ID<szQ0q-4l3-25@gated-at.bofh.it>
In reply to#1515317
From: Markus Mayer <mmayer@broadcom.com>

Allow CPUfreq statistics to be cleared by writing anything to
/sys/.../cpufreq/stats/reset.

Signed-off-by: Markus Mayer <mmayer@broadcom.com>
---
 Documentation/cpu-freq/cpufreq-stats.txt |  6 ++++++
 drivers/cpufreq/cpufreq_stats.c          | 22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/Documentation/cpu-freq/cpufreq-stats.txt b/Documentation/cpu-freq/cpufreq-stats.txt
index 8d9773f..3c355f6 100644
--- a/Documentation/cpu-freq/cpufreq-stats.txt
+++ b/Documentation/cpu-freq/cpufreq-stats.txt
@@ -44,11 +44,17 @@ the stats driver insertion.
 total 0
 drwxr-xr-x  2 root root    0 May 14 16:06 .
 drwxr-xr-x  3 root root    0 May 14 15:58 ..
+--w-------  1 root root 4096 May 14 16:06 reset
 -r--r--r--  1 root root 4096 May 14 16:06 time_in_state
 -r--r--r--  1 root root 4096 May 14 16:06 total_trans
 -r--r--r--  1 root root 4096 May 14 16:06 trans_table
 --------------------------------------------------------------------------------
 
+-  reset
+Write-only attribute that can be used to reset the stat counters. This can be
+useful for evaluating system behaviour under different governors without the
+need for a reboot.
+
 -  time_in_state
 This gives the amount of time spent in each of the frequencies supported by
 this CPU. The cat output will have "<frequency> <time>" pair in each line, which
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index 06d3abd..66419e6 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -41,6 +41,18 @@ static int cpufreq_stats_update(struct cpufreq_stats *stats)
 	return 0;
 }
 
+static void cpufreq_stats_clear_table(struct cpufreq_stats *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_total_trans(struct cpufreq_policy *policy, char *buf)
 {
 	return sprintf(buf, "%d\n", policy->stats->total_trans);
@@ -64,6 +76,14 @@ static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf)
 	return len;
 }
 
+static ssize_t store_reset(struct cpufreq_policy *policy, const char *buf,
+			   size_t count)
+{
+	/* We don't care what is written to the attribute. */
+	cpufreq_stats_clear_table(policy->stats);
+	return count;
+}
+
 #ifdef CONFIG_CPU_FREQ_STAT_DETAILS
 static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
 {
@@ -113,10 +133,12 @@ cpufreq_freq_attr_ro(trans_table);
 
 cpufreq_freq_attr_ro(total_trans);
 cpufreq_freq_attr_ro(time_in_state);
+cpufreq_freq_attr_wr_perm(reset, 0200);
 
 static struct attribute *default_attrs[] = {
 	&total_trans.attr,
 	&time_in_state.attr,
+	&reset.attr,
 #ifdef CONFIG_CPU_FREQ_STAT_DETAILS
 	&trans_table.attr,
 #endif
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1515846 — Re: [PATCH v2 2/2] cpufreq: stats: clear statistics

FromViresh Kumar <viresh.kumar@linaro.org>
Date2016-11-07 05:40 +0100
SubjectRe: [PATCH v2 2/2] cpufreq: stats: clear statistics
Message-ID<sAJSW-6w9-5@gated-at.bofh.it>
In reply to#1515322
On 04-11-16, 09:55, Markus Mayer wrote:
> From: Markus Mayer <mmayer@broadcom.com>
> 
> Allow CPUfreq statistics to be cleared by writing anything to
> /sys/.../cpufreq/stats/reset.
> 
> Signed-off-by: Markus Mayer <mmayer@broadcom.com>
> ---
>  Documentation/cpu-freq/cpufreq-stats.txt |  6 ++++++
>  drivers/cpufreq/cpufreq_stats.c          | 22 ++++++++++++++++++++++
>  2 files changed, 28 insertions(+)
> 
> diff --git a/Documentation/cpu-freq/cpufreq-stats.txt b/Documentation/cpu-freq/cpufreq-stats.txt
> index 8d9773f..3c355f6 100644
> --- a/Documentation/cpu-freq/cpufreq-stats.txt
> +++ b/Documentation/cpu-freq/cpufreq-stats.txt
> @@ -44,11 +44,17 @@ the stats driver insertion.
>  total 0
>  drwxr-xr-x  2 root root    0 May 14 16:06 .
>  drwxr-xr-x  3 root root    0 May 14 15:58 ..
> +--w-------  1 root root 4096 May 14 16:06 reset
>  -r--r--r--  1 root root 4096 May 14 16:06 time_in_state
>  -r--r--r--  1 root root 4096 May 14 16:06 total_trans
>  -r--r--r--  1 root root 4096 May 14 16:06 trans_table
>  --------------------------------------------------------------------------------
>  
> +-  reset
> +Write-only attribute that can be used to reset the stat counters. This can be
> +useful for evaluating system behaviour under different governors without the
> +need for a reboot.
> +
>  -  time_in_state
>  This gives the amount of time spent in each of the frequencies supported by
>  this CPU. The cat output will have "<frequency> <time>" pair in each line, which
> diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
> index 06d3abd..66419e6 100644
> --- a/drivers/cpufreq/cpufreq_stats.c
> +++ b/drivers/cpufreq/cpufreq_stats.c
> @@ -41,6 +41,18 @@ static int cpufreq_stats_update(struct cpufreq_stats *stats)
>  	return 0;
>  }
>  
> +static void cpufreq_stats_clear_table(struct cpufreq_stats *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_total_trans(struct cpufreq_policy *policy, char *buf)
>  {
>  	return sprintf(buf, "%d\n", policy->stats->total_trans);
> @@ -64,6 +76,14 @@ static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf)
>  	return len;
>  }
>  
> +static ssize_t store_reset(struct cpufreq_policy *policy, const char *buf,
> +			   size_t count)
> +{
> +	/* We don't care what is written to the attribute. */
> +	cpufreq_stats_clear_table(policy->stats);
> +	return count;
> +}
> +
>  #ifdef CONFIG_CPU_FREQ_STAT_DETAILS
>  static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
>  {
> @@ -113,10 +133,12 @@ cpufreq_freq_attr_ro(trans_table);
>  
>  cpufreq_freq_attr_ro(total_trans);
>  cpufreq_freq_attr_ro(time_in_state);
> +cpufreq_freq_attr_wr_perm(reset, 0200);

Just drop the perm argument and this patch looks fine as well.

-- 
viresh

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web