* [PATCH] power: supply: ab8500: stop using getnstimeofday64()
@ 2018-06-18 14:23 Arnd Bergmann
2018-06-28 14:14 ` Linus Walleij
2018-07-06 15:05 ` Sebastian Reichel
0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2018-06-18 14:23 UTC (permalink / raw)
To: Sebastian Reichel
Cc: Arnd Bergmann, Linus Walleij, Lee Jones, linux-pm, linux-kernel
getnstimeofday64() is deprecated in favor of the ktime_get() family.
The direct replacement would be ktime_get_real_ts64(), but we only need
the seconds value, and it seems better to use boottime than real time
to avoid unexpected behavior with a concurrent settimeofday().
ktime_get_seconds() might also work, but it seems better to use
boottime than monotonic time since I assume that the charging
process continues during suspend.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/power/supply/ab8500_fg.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c
index d9c6c7bedd85..02356f9b5f22 100644
--- a/drivers/power/supply/ab8500_fg.c
+++ b/drivers/power/supply/ab8500_fg.c
@@ -379,15 +379,13 @@ static int ab8500_fg_is_low_curr(struct ab8500_fg *di, int curr)
*/
static int ab8500_fg_add_cap_sample(struct ab8500_fg *di, int sample)
{
- struct timespec64 ts64;
+ time64_t now = ktime_get_boottime_seconds();
struct ab8500_fg_avg_cap *avg = &di->avg_cap;
- getnstimeofday64(&ts64);
-
do {
avg->sum += sample - avg->samples[avg->pos];
avg->samples[avg->pos] = sample;
- avg->time_stamps[avg->pos] = ts64.tv_sec;
+ avg->time_stamps[avg->pos] = now;
avg->pos++;
if (avg->pos == NBR_AVG_SAMPLES)
@@ -400,7 +398,7 @@ static int ab8500_fg_add_cap_sample(struct ab8500_fg *di, int sample)
* Check the time stamp for each sample. If too old,
* replace with latest sample
*/
- } while (ts64.tv_sec - VALID_CAPACITY_SEC > avg->time_stamps[avg->pos]);
+ } while (now - VALID_CAPACITY_SEC > avg->time_stamps[avg->pos]);
avg->avg = avg->sum / avg->nbr_samples;
@@ -439,14 +437,14 @@ static void ab8500_fg_clear_cap_samples(struct ab8500_fg *di)
static void ab8500_fg_fill_cap_sample(struct ab8500_fg *di, int sample)
{
int i;
- struct timespec64 ts64;
+ time64_t now;
struct ab8500_fg_avg_cap *avg = &di->avg_cap;
- getnstimeofday64(&ts64);
+ now = ktime_get_boottime_seconds();
for (i = 0; i < NBR_AVG_SAMPLES; i++) {
avg->samples[i] = sample;
- avg->time_stamps[i] = ts64.tv_sec;
+ avg->time_stamps[i] = now;
}
avg->pos = 0;
--
2.9.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] power: supply: ab8500: stop using getnstimeofday64()
2018-06-18 14:23 [PATCH] power: supply: ab8500: stop using getnstimeofday64() Arnd Bergmann
@ 2018-06-28 14:14 ` Linus Walleij
2018-07-06 15:05 ` Sebastian Reichel
1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2018-06-28 14:14 UTC (permalink / raw)
To: Arnd Bergmann; +Cc: Sebastian Reichel, Lee Jones, Linux PM list, linux-kernel
On Mon, Jun 18, 2018 at 4:23 PM Arnd Bergmann <arnd@arndb.de> wrote:
> getnstimeofday64() is deprecated in favor of the ktime_get() family.
>
> The direct replacement would be ktime_get_real_ts64(), but we only need
> the seconds value, and it seems better to use boottime than real time
> to avoid unexpected behavior with a concurrent settimeofday().
>
> ktime_get_seconds() might also work, but it seems better to use
> boottime than monotonic time since I assume that the charging
> process continues during suspend.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] power: supply: ab8500: stop using getnstimeofday64()
2018-06-18 14:23 [PATCH] power: supply: ab8500: stop using getnstimeofday64() Arnd Bergmann
2018-06-28 14:14 ` Linus Walleij
@ 2018-07-06 15:05 ` Sebastian Reichel
1 sibling, 0 replies; 3+ messages in thread
From: Sebastian Reichel @ 2018-07-06 15:05 UTC (permalink / raw)
To: Arnd Bergmann; +Cc: Linus Walleij, Lee Jones, linux-pm, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2537 bytes --]
Hi,
On Mon, Jun 18, 2018 at 04:23:29PM +0200, Arnd Bergmann wrote:
> getnstimeofday64() is deprecated in favor of the ktime_get() family.
>
> The direct replacement would be ktime_get_real_ts64(), but we only need
> the seconds value, and it seems better to use boottime than real time
> to avoid unexpected behavior with a concurrent settimeofday().
>
> ktime_get_seconds() might also work, but it seems better to use
> boottime than monotonic time since I assume that the charging
> process continues during suspend.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
Thanks, queued to power-supply-next.
-- Sebastian
> drivers/power/supply/ab8500_fg.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c
> index d9c6c7bedd85..02356f9b5f22 100644
> --- a/drivers/power/supply/ab8500_fg.c
> +++ b/drivers/power/supply/ab8500_fg.c
> @@ -379,15 +379,13 @@ static int ab8500_fg_is_low_curr(struct ab8500_fg *di, int curr)
> */
> static int ab8500_fg_add_cap_sample(struct ab8500_fg *di, int sample)
> {
> - struct timespec64 ts64;
> + time64_t now = ktime_get_boottime_seconds();
> struct ab8500_fg_avg_cap *avg = &di->avg_cap;
>
> - getnstimeofday64(&ts64);
> -
> do {
> avg->sum += sample - avg->samples[avg->pos];
> avg->samples[avg->pos] = sample;
> - avg->time_stamps[avg->pos] = ts64.tv_sec;
> + avg->time_stamps[avg->pos] = now;
> avg->pos++;
>
> if (avg->pos == NBR_AVG_SAMPLES)
> @@ -400,7 +398,7 @@ static int ab8500_fg_add_cap_sample(struct ab8500_fg *di, int sample)
> * Check the time stamp for each sample. If too old,
> * replace with latest sample
> */
> - } while (ts64.tv_sec - VALID_CAPACITY_SEC > avg->time_stamps[avg->pos]);
> + } while (now - VALID_CAPACITY_SEC > avg->time_stamps[avg->pos]);
>
> avg->avg = avg->sum / avg->nbr_samples;
>
> @@ -439,14 +437,14 @@ static void ab8500_fg_clear_cap_samples(struct ab8500_fg *di)
> static void ab8500_fg_fill_cap_sample(struct ab8500_fg *di, int sample)
> {
> int i;
> - struct timespec64 ts64;
> + time64_t now;
> struct ab8500_fg_avg_cap *avg = &di->avg_cap;
>
> - getnstimeofday64(&ts64);
> + now = ktime_get_boottime_seconds();
>
> for (i = 0; i < NBR_AVG_SAMPLES; i++) {
> avg->samples[i] = sample;
> - avg->time_stamps[i] = ts64.tv_sec;
> + avg->time_stamps[i] = now;
> }
>
> avg->pos = 0;
> --
> 2.9.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-07-06 15:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-18 14:23 [PATCH] power: supply: ab8500: stop using getnstimeofday64() Arnd Bergmann
2018-06-28 14:14 ` Linus Walleij
2018-07-06 15:05 ` Sebastian Reichel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®