diff mbox series

[v2,2/3] devfreq: add clearing transitions stats

Message ID 20191204150018.5234-3-k.konieczny@samsung.com (mailing list archive)
State New, archived
Headers show
Series devfreq: improve devfreq statistics counting | expand

Commit Message

Kamil Konieczny Dec. 4, 2019, 3 p.m. UTC
Add clearing transition table and time in states devfreq statistics
by writing to trans_stat file in devfreq sysfs.

Signed-off-by: Kamil Konieczny <k.konieczny@samsung.com>
---
Changes in v2:
 instead of creating new sysfs file, add new functionality to trans_stat
 and clear stats when anything is writen to it

 drivers/devfreq/devfreq.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

Comments

Chanwoo Choi Dec. 5, 2019, 12:38 a.m. UTC | #1
On 12/5/19 12:00 AM, Kamil Konieczny wrote:
> Add clearing transition table and time in states devfreq statistics
> by writing to trans_stat file in devfreq sysfs.

Have to add command example how to reset the trans_stat via sysfs
on patch description.

And, have to add how to do it on documentation file as following:
On next version, please contain the following modification with this patch.

diff --git a/Documentation/ABI/testing/sysfs-class-devfreq b/Documentation/ABI/testing/sysfs-class-devfreq
index 75897e2fde43..c172ff838643 100644
--- a/Documentation/ABI/testing/sysfs-class-devfreq
+++ b/Documentation/ABI/testing/sysfs-class-devfreq
@@ -60,7 +60,10 @@ Description:
                the number of transitions between states.
                In order to activate this ABI, the devfreq target device
                driver should provide the list of available frequencies
-               with its profile.
+               with its profile. If need to reset the statistics of devfreq
+               behavior on a specific device, enter 0(zero) to 'trans_stat'
+               as following:
+                       echo 0 > /sys/class/devfreq/.../trans_stat
 
 What:          /sys/class/devfreq/.../userspace/set_freq
 Date:          September 2011


> 
> Signed-off-by: Kamil Konieczny <k.konieczny@samsung.com>
> ---
> Changes in v2:
>  instead of creating new sysfs file, add new functionality to trans_stat
>  and clear stats when anything is writen to it
> 
>  drivers/devfreq/devfreq.c | 22 +++++++++++++++++++++-
>  1 file changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index 0e2030403e4a..901af3b66a76 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -1478,7 +1478,27 @@ static ssize_t trans_stat_show(struct device *dev,
>  					devfreq->total_trans);
>  	return len;
>  }
> -static DEVICE_ATTR_RO(trans_stat);
> +
> +static ssize_t trans_stat_store(struct device *dev,
> +				struct device_attribute *attr,
> +				const char *buf, size_t count)
> +{
> +	struct devfreq *df = to_devfreq(dev);
> +	unsigned int cnt = df->profile->max_state;
> +

Why don't you check the input value is whether value is 0(zero) or not?
If user enter the any value to 'trans_stat', devfreq core
reset the statistics data. I want to decide the fixed value
for the reset as following:

	echo 0 > /sys/class/devfreq/devfreqX/trans_stat

> +	if (cnt == 0)
> +		return count;
> +
> +	mutex_lock(&df->lock);
> +	memset(df->time_in_state, 0, cnt * sizeof(u64));
> +	memset(df->trans_table, 0, cnt * cnt * sizeof(int));
> +	df->last_stat_updated = get_jiffies_64();
> +	df->total_trans = 0;
> +	mutex_unlock(&df->lock);
> +
> +	return count;
> +}
> +static DEVICE_ATTR_RW(trans_stat);
>  
>  static struct attribute *devfreq_attrs[] = {
>  	&dev_attr_name.attr,
>
Kamil Konieczny Dec. 5, 2019, 10:33 a.m. UTC | #2
Hi Chanwoo,

On 05.12.2019 01:38, Chanwoo Choi wrote:
> On 12/5/19 12:00 AM, Kamil Konieczny wrote:
>> Add clearing transition table and time in states devfreq statistics
>> by writing to trans_stat file in devfreq sysfs.
> 
> Have to add command example how to reset the trans_stat via sysfs
> on patch description.
> 
> And, have to add how to do it on documentation file as following:
> On next version, please contain the following modification with this patch.
> 
> diff --git a/Documentation/ABI/testing/sysfs-class-devfreq b/Documentation/ABI/testing/sysfs-class-devfreq
> index 75897e2fde43..c172ff838643 100644
> --- a/Documentation/ABI/testing/sysfs-class-devfreq
> +++ b/Documentation/ABI/testing/sysfs-class-devfreq
> @@ -60,7 +60,10 @@ Description:
>                 the number of transitions between states.
>                 In order to activate this ABI, the devfreq target device
>                 driver should provide the list of available frequencies
> -               with its profile.
> +               with its profile. If need to reset the statistics of devfreq
> +               behavior on a specific device, enter 0(zero) to 'trans_stat'
> +               as following:
> +                       echo 0 > /sys/class/devfreq/.../trans_stat
>  
>  What:          /sys/class/devfreq/.../userspace/set_freq
>  Date:          September 2011

Thank you for spotting this and giving patch, I will include it with v3.

>>
>> Signed-off-by: Kamil Konieczny <k.konieczny@samsung.com>
>> ---
>> Changes in v2:
>>  instead of creating new sysfs file, add new functionality to trans_stat
>>  and clear stats when anything is writen to it
>>
>>  drivers/devfreq/devfreq.c | 22 +++++++++++++++++++++-
>>  1 file changed, 21 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
>> index 0e2030403e4a..901af3b66a76 100644
>> --- a/drivers/devfreq/devfreq.c
>> +++ b/drivers/devfreq/devfreq.c
>> @@ -1478,7 +1478,27 @@ static ssize_t trans_stat_show(struct device *dev,
>>  					devfreq->total_trans);
>>  	return len;
>>  }
>> -static DEVICE_ATTR_RO(trans_stat);
>> +
>> +static ssize_t trans_stat_store(struct device *dev,
>> +				struct device_attribute *attr,
>> +				const char *buf, size_t count)
>> +{
>> +	struct devfreq *df = to_devfreq(dev);
>> +	unsigned int cnt = df->profile->max_state;
>> +
 
> Why don't you check the input value is whether value is 0(zero) or not?

I will follow your suggestion as this will help to avoid misuse

> If user enter the any value to 'trans_stat', devfreq core
> reset the statistics data. I want to decide the fixed value
> for the reset as following:
> 
> 	echo 0 > /sys/class/devfreq/devfreqX/trans_stat
> 

Thank you, I will add it to commit description.

>> +	if (cnt == 0)
>> +		return count;
>> +
>> +	mutex_lock(&df->lock);
>> +	memset(df->time_in_state, 0, cnt * sizeof(u64));
>> +	memset(df->trans_table, 0, cnt * cnt * sizeof(int));
>> +	df->last_stat_updated = get_jiffies_64();
>> +	df->total_trans = 0;
>> +	mutex_unlock(&df->lock);
>> +
>> +	return count;
>> +}
>> +static DEVICE_ATTR_RW(trans_stat);
>>  
>>  static struct attribute *devfreq_attrs[] = {
>>  	&dev_attr_name.attr,
diff mbox series

Patch

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 0e2030403e4a..901af3b66a76 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -1478,7 +1478,27 @@  static ssize_t trans_stat_show(struct device *dev,
 					devfreq->total_trans);
 	return len;
 }
-static DEVICE_ATTR_RO(trans_stat);
+
+static ssize_t trans_stat_store(struct device *dev,
+				struct device_attribute *attr,
+				const char *buf, size_t count)
+{
+	struct devfreq *df = to_devfreq(dev);
+	unsigned int cnt = df->profile->max_state;
+
+	if (cnt == 0)
+		return count;
+
+	mutex_lock(&df->lock);
+	memset(df->time_in_state, 0, cnt * sizeof(u64));
+	memset(df->trans_table, 0, cnt * cnt * sizeof(int));
+	df->last_stat_updated = get_jiffies_64();
+	df->total_trans = 0;
+	mutex_unlock(&df->lock);
+
+	return count;
+}
+static DEVICE_ATTR_RW(trans_stat);
 
 static struct attribute *devfreq_attrs[] = {
 	&dev_attr_name.attr,