* [PATCH v3] cpufreq: stats: clear statistics
@ 2016-11-07 18:02 Markus Mayer
2016-11-08 4:09 ` Viresh Kumar
0 siblings, 1 reply; 3+ messages in thread
From: Markus Mayer @ 2016-11-07 18:02 UTC (permalink / raw)
To: Viresh Kumar, Rafael J . Wysocki
Cc: Power Management List, Broadcom Kernel List,
Linux Kernel Mailing List, Markus Mayer
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>
---
Changes since v2:
- changed name of write-only macro to cpufreq_freq_attr_wo()
- removed "perm" parameter from write-only macro
- squashed the two separate commits into a single one
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 *
Documentation/cpu-freq/cpufreq-stats.txt | 6 ++++++
drivers/cpufreq/cpufreq_stats.c | 22 ++++++++++++++++++++++
include/linux/cpufreq.h | 4 ++++
3 files changed, 32 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..ac284e6 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_wo(reset);
static struct attribute *default_attrs[] = {
&total_trans.attr,
&time_in_state.attr,
+ &reset.attr,
#ifdef CONFIG_CPU_FREQ_STAT_DETAILS
&trans_table.attr,
#endif
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 5fa55fc..490573e 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -234,6 +234,10 @@ __ATTR(_name, _perm, show_##_name, NULL)
static struct freq_attr _name = \
__ATTR(_name, 0644, show_##_name, store_##_name)
+#define cpufreq_freq_attr_wo(_name) \
+static struct freq_attr _name = \
+__ATTR(_name, 0200, NULL, store_##_name)
+
struct global_attr {
struct attribute attr;
ssize_t (*show)(struct kobject *kobj,
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v3] cpufreq: stats: clear statistics
2016-11-07 18:02 [PATCH v3] cpufreq: stats: clear statistics Markus Mayer
@ 2016-11-08 4:09 ` Viresh Kumar
2016-11-14 0:31 ` Rafael J. Wysocki
0 siblings, 1 reply; 3+ messages in thread
From: Viresh Kumar @ 2016-11-08 4:09 UTC (permalink / raw)
To: Markus Mayer
Cc: Rafael J . Wysocki, Power Management List, Broadcom Kernel List,
Linux Kernel Mailing List, Markus Mayer
On 07-11-16, 10:02, 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>
> ---
>
> Changes since v2:
> - changed name of write-only macro to cpufreq_freq_attr_wo()
> - removed "perm" parameter from write-only macro
> - squashed the two separate commits into a single one
>
> 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 *
>
> Documentation/cpu-freq/cpufreq-stats.txt | 6 ++++++
> drivers/cpufreq/cpufreq_stats.c | 22 ++++++++++++++++++++++
> include/linux/cpufreq.h | 4 ++++
> 3 files changed, 32 insertions(+)
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
viresh
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] cpufreq: stats: clear statistics
2016-11-08 4:09 ` Viresh Kumar
@ 2016-11-14 0:31 ` Rafael J. Wysocki
0 siblings, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2016-11-14 0:31 UTC (permalink / raw)
To: Viresh Kumar, Markus Mayer
Cc: Power Management List, Broadcom Kernel List,
Linux Kernel Mailing List, Markus Mayer
On Tuesday, November 08, 2016 09:39:40 AM Viresh Kumar wrote:
> On 07-11-16, 10:02, 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>
> > ---
> >
> > Changes since v2:
> > - changed name of write-only macro to cpufreq_freq_attr_wo()
> > - removed "perm" parameter from write-only macro
> > - squashed the two separate commits into a single one
> >
> > 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 *
> >
> > Documentation/cpu-freq/cpufreq-stats.txt | 6 ++++++
> > drivers/cpufreq/cpufreq_stats.c | 22 ++++++++++++++++++++++
> > include/linux/cpufreq.h | 4 ++++
> > 3 files changed, 32 insertions(+)
>
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Applied.
Thanks,
Rafael
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-11-14 0:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-07 18:02 [PATCH v3] cpufreq: stats: clear statistics Markus Mayer
2016-11-08 4:09 ` Viresh Kumar
2016-11-14 0:31 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).