2019-11-13 09:16:11

by Kamil Konieczny

[permalink] [raw]
Subject: [PATCH 1/7] devfreq: change time stats to 64-bit

Change time stats counting to bigger type by using 64-bit jiffies.
This will make devfreq stats code look similar to cpufreq stats and
prevents overflow (for HZ = 1000 after 49.7 days).

Signed-off-by: Kamil Konieczny <[email protected]>
---
drivers/devfreq/devfreq.c | 14 +++++++-------
include/linux/devfreq.h | 4 ++--
2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index ab22bf8a12d6..1602cca20fc4 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -158,9 +158,9 @@ static int set_freq_table(struct devfreq *devfreq)
int devfreq_update_status(struct devfreq *devfreq, unsigned long freq)
{
int lev, prev_lev, ret = 0;
- unsigned long cur_time;
+ unsigned long long cur_time;

- cur_time = jiffies;
+ cur_time = get_jiffies_64();

/* Immediately exit if previous_freq is not initialized yet. */
if (!devfreq->previous_freq)
@@ -478,7 +478,7 @@ void devfreq_monitor_resume(struct devfreq *devfreq)
queue_delayed_work(devfreq_wq, &devfreq->work,
msecs_to_jiffies(devfreq->profile->polling_ms));

- devfreq->last_stat_updated = jiffies;
+ devfreq->last_stat_updated = get_jiffies_64();
devfreq->stop_polling = false;

if (devfreq->profile->get_cur_freq &&
@@ -698,7 +698,7 @@ struct devfreq *devfreq_add_device(struct device *dev,

devfreq->time_in_state = devm_kcalloc(&devfreq->dev,
devfreq->profile->max_state,
- sizeof(unsigned long),
+ sizeof(*devfreq->time_in_state),
GFP_KERNEL);
if (!devfreq->time_in_state) {
mutex_unlock(&devfreq->lock);
@@ -706,7 +706,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
goto err_devfreq;
}

- devfreq->last_stat_updated = jiffies;
+ devfreq->last_stat_updated = get_jiffies_64();

srcu_init_notifier_head(&devfreq->transition_notifier_list);

@@ -1423,8 +1423,8 @@ static ssize_t trans_stat_show(struct device *dev,
for (j = 0; j < max_state; j++)
len += sprintf(buf + len, "%10u",
devfreq->trans_table[(i * max_state) + j]);
- len += sprintf(buf + len, "%10u\n",
- jiffies_to_msecs(devfreq->time_in_state[i]));
+ len += sprintf(buf + len, "%10llu\n", (u64)
+ jiffies64_to_msecs(devfreq->time_in_state[i]));
}

len += sprintf(buf + len, "Total transition : %u\n",
diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
index 2bae9ed3c783..b81a86e47fb9 100644
--- a/include/linux/devfreq.h
+++ b/include/linux/devfreq.h
@@ -174,8 +174,8 @@ struct devfreq {
/* information for device frequency transition */
unsigned int total_trans;
unsigned int *trans_table;
- unsigned long *time_in_state;
- unsigned long last_stat_updated;
+ u64 *time_in_state;
+ unsigned long long last_stat_updated;

struct srcu_notifier_head transition_notifier_list;
};
--
2.24.0


2019-11-13 09:42:22

by Chanwoo Choi

[permalink] [raw]
Subject: Re: [PATCH 1/7] devfreq: change time stats to 64-bit

Hi,

On 11/13/19 6:13 PM, Kamil Konieczny wrote:
> Change time stats counting to bigger type by using 64-bit jiffies.
> This will make devfreq stats code look similar to cpufreq stats and
> prevents overflow (for HZ = 1000 after 49.7 days).
>
> Signed-off-by: Kamil Konieczny <[email protected]>
> ---
> drivers/devfreq/devfreq.c | 14 +++++++-------
> include/linux/devfreq.h | 4 ++--
> 2 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index ab22bf8a12d6..1602cca20fc4 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -158,9 +158,9 @@ static int set_freq_table(struct devfreq *devfreq)
> int devfreq_update_status(struct devfreq *devfreq, unsigned long freq)
> {
> int lev, prev_lev, ret = 0;
> - unsigned long cur_time;
> + unsigned long long cur_time;
>
> - cur_time = jiffies;
> + cur_time = get_jiffies_64();
>
> /* Immediately exit if previous_freq is not initialized yet. */
> if (!devfreq->previous_freq)
> @@ -478,7 +478,7 @@ void devfreq_monitor_resume(struct devfreq *devfreq)
> queue_delayed_work(devfreq_wq, &devfreq->work,
> msecs_to_jiffies(devfreq->profile->polling_ms));
>
> - devfreq->last_stat_updated = jiffies;
> + devfreq->last_stat_updated = get_jiffies_64();
> devfreq->stop_polling = false;
>
> if (devfreq->profile->get_cur_freq &&
> @@ -698,7 +698,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
>
> devfreq->time_in_state = devm_kcalloc(&devfreq->dev,
> devfreq->profile->max_state,
> - sizeof(unsigned long),
> + sizeof(*devfreq->time_in_state),
> GFP_KERNEL);
> if (!devfreq->time_in_state) {
> mutex_unlock(&devfreq->lock);
> @@ -706,7 +706,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
> goto err_devfreq;
> }
>
> - devfreq->last_stat_updated = jiffies;
> + devfreq->last_stat_updated = get_jiffies_64();
>
> srcu_init_notifier_head(&devfreq->transition_notifier_list);
>
> @@ -1423,8 +1423,8 @@ static ssize_t trans_stat_show(struct device *dev,
> for (j = 0; j < max_state; j++)
> len += sprintf(buf + len, "%10u",
> devfreq->trans_table[(i * max_state) + j]);
> - len += sprintf(buf + len, "%10u\n",
> - jiffies_to_msecs(devfreq->time_in_state[i]));
> + len += sprintf(buf + len, "%10llu\n", (u64)
> + jiffies64_to_msecs(devfreq->time_in_state[i]));
> }
>
> len += sprintf(buf + len, "Total transition : %u\n",
> diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
> index 2bae9ed3c783..b81a86e47fb9 100644
> --- a/include/linux/devfreq.h
> +++ b/include/linux/devfreq.h
> @@ -174,8 +174,8 @@ struct devfreq {
> /* information for device frequency transition */
> unsigned int total_trans;
> unsigned int *trans_table;
> - unsigned long *time_in_state;
> - unsigned long last_stat_updated;
> + u64 *time_in_state;
> + unsigned long long last_stat_updated;
>
> struct srcu_notifier_head transition_notifier_list;
> };
>

Looks good to me.

Acked-by: Chanwoo Choi <[email protected]>

But, When I tried to apply it to devfreq-next branch[1],
the merge conflict happen. You need to rebase it on devfreq-next branch[1] or linux-next.git.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux.git/ (branch : devfreq-next)

--
Best Regards,
Chanwoo Choi
Samsung Electronics