All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 3/3] PM/runtime:Replace jiffies based accounting with ktime based accounting
@ 2018-12-20 14:17 Vincent Guittot
  2018-12-20 22:02   ` Ulf Hansson
  0 siblings, 1 reply; 9+ messages in thread
From: Vincent Guittot @ 2018-12-20 14:17 UTC (permalink / raw)
  To: linux-pm, linux-kernel, rjw, thara.gopinath, jani.nikula,
	joonas.lahtinen, rodrigo.vivi, airlied, intel-gfx, dri-devel
  Cc: ulf.hansson, Vincent Guittot

From: Thara Gopinath <thara.gopinath@linaro.org>

This patch replaces jiffies based accounting for runtime_active_time
and runtime_suspended_time with ktime base accounting. This makes the
runtime debug counters inline with genpd and other pm subsytems which
uses ktime based accounting.

Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org>
[move from ktime to raw nsec]
Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
---
 drivers/base/power/runtime.c | 17 +++++++++--------
 drivers/base/power/sysfs.c   | 11 ++++++++---
 include/linux/pm.h           |  6 +++---
 3 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index e695544..f700524 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -64,8 +64,8 @@ static int rpm_suspend(struct device *dev, int rpmflags);
  */
 void update_pm_runtime_accounting(struct device *dev)
 {
-	unsigned long now = jiffies;
-	unsigned long delta;
+	u64 now = ktime_to_ns(ktime_get());
+	u64 delta;
 
 	delta = now - dev->power.accounting_timestamp;
 
@@ -75,9 +75,9 @@ void update_pm_runtime_accounting(struct device *dev)
 		return;
 
 	if (dev->power.runtime_status == RPM_SUSPENDED)
-		dev->power.suspended_jiffies += delta;
+		dev->power.suspended_time += delta;
 	else
-		dev->power.active_jiffies += delta;
+		dev->power.active_time += delta;
 }
 
 static void __update_runtime_status(struct device *dev, enum rpm_status status)
@@ -88,17 +88,18 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status)
 
 u64 pm_runtime_suspended_time(struct device *dev)
 {
-	unsigned long flags, time;
+	u64 time;
+	unsigned long flags;
 
 	spin_lock_irqsave(&dev->power.lock, flags);
 
 	update_pm_runtime_accounting(dev);
 
-	time = dev->power.suspended_jiffies;
+	time = dev->power.suspended_time;
 
 	spin_unlock_irqrestore(&dev->power.lock, flags);
 
-	return jiffies_to_nsecs(time);
+	return time;
 }
 EXPORT_SYMBOL_GPL(pm_runtime_suspended_time);
 
@@ -1503,7 +1504,7 @@ void pm_runtime_init(struct device *dev)
 	dev->power.request_pending = false;
 	dev->power.request = RPM_REQ_NONE;
 	dev->power.deferred_resume = false;
-	dev->power.accounting_timestamp = jiffies;
+	dev->power.accounting_timestamp = ktime_to_ns(ktime_get());
 	INIT_WORK(&dev->power.work, pm_runtime_work);
 
 	dev->power.timer_expires = 0;
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index d713738..96c8a22 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -125,9 +125,12 @@ static ssize_t runtime_active_time_show(struct device *dev,
 				struct device_attribute *attr, char *buf)
 {
 	int ret;
+	u64 tmp;
 	spin_lock_irq(&dev->power.lock);
 	update_pm_runtime_accounting(dev);
-	ret = sprintf(buf, "%i\n", jiffies_to_msecs(dev->power.active_jiffies));
+	tmp = dev->power.active_time;
+	do_div(tmp, NSEC_PER_MSEC);
+	ret = sprintf(buf, "%llu\n", tmp);
 	spin_unlock_irq(&dev->power.lock);
 	return ret;
 }
@@ -138,10 +141,12 @@ static ssize_t runtime_suspended_time_show(struct device *dev,
 				struct device_attribute *attr, char *buf)
 {
 	int ret;
+	u64 tmp;
 	spin_lock_irq(&dev->power.lock);
 	update_pm_runtime_accounting(dev);
-	ret = sprintf(buf, "%i\n",
-		jiffies_to_msecs(dev->power.suspended_jiffies));
+	tmp = dev->power.suspended_time;
+	do_div(tmp, NSEC_PER_MSEC);
+	ret = sprintf(buf, "%llu\n", tmp);
 	spin_unlock_irq(&dev->power.lock);
 	return ret;
 }
diff --git a/include/linux/pm.h b/include/linux/pm.h
index e723b78..e5a34e2 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -632,9 +632,9 @@ struct dev_pm_info {
 	int			runtime_error;
 	int			autosuspend_delay;
 	unsigned long		last_busy;
-	unsigned long		active_jiffies;
-	unsigned long		suspended_jiffies;
-	unsigned long		accounting_timestamp;
+	u64			active_time;
+	u64			suspended_time;
+	u64			accounting_timestamp;
 #endif
 	struct pm_subsys_data	*subsys_data;  /* Owned by the subsystem. */
 	void (*set_latency_tolerance)(struct device *, s32);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v4 3/3] PM/runtime:Replace jiffies based accounting with ktime based accounting
  2018-12-20 14:17 [PATCH v4 3/3] PM/runtime:Replace jiffies based accounting with ktime based accounting Vincent Guittot
@ 2018-12-20 22:02   ` Ulf Hansson
  0 siblings, 0 replies; 9+ messages in thread
From: Ulf Hansson @ 2018-12-20 22:02 UTC (permalink / raw)
  To: Vincent Guittot
  Cc: Linux PM, Linux Kernel Mailing List, Rafael J. Wysocki,
	Thara Gopinath, jani.nikula, Joonas Lahtinen, rodrigo.vivi,
	David Airlie,
	Intel graphics driver community testing & development,
	dri-devel

On Thu, 20 Dec 2018 at 15:17, Vincent Guittot
<vincent.guittot@linaro.org> wrote:
>
> From: Thara Gopinath <thara.gopinath@linaro.org>
>
> This patch replaces jiffies based accounting for runtime_active_time
> and runtime_suspended_time with ktime base accounting. This makes the
> runtime debug counters inline with genpd and other pm subsytems which
> uses ktime based accounting.
>
> Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org>
> [move from ktime to raw nsec]
> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
> ---
>  drivers/base/power/runtime.c | 17 +++++++++--------
>  drivers/base/power/sysfs.c   | 11 ++++++++---
>  include/linux/pm.h           |  6 +++---
>  3 files changed, 20 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> index e695544..f700524 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -64,8 +64,8 @@ static int rpm_suspend(struct device *dev, int rpmflags);
>   */
>  void update_pm_runtime_accounting(struct device *dev)
>  {
> -       unsigned long now = jiffies;
> -       unsigned long delta;
> +       u64 now = ktime_to_ns(ktime_get());
> +       u64 delta;
>
>         delta = now - dev->power.accounting_timestamp;
>
> @@ -75,9 +75,9 @@ void update_pm_runtime_accounting(struct device *dev)
>                 return;
>
>         if (dev->power.runtime_status == RPM_SUSPENDED)
> -               dev->power.suspended_jiffies += delta;
> +               dev->power.suspended_time += delta;
>         else
> -               dev->power.active_jiffies += delta;
> +               dev->power.active_time += delta;
>  }
>
>  static void __update_runtime_status(struct device *dev, enum rpm_status status)
> @@ -88,17 +88,18 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status)
>
>  u64 pm_runtime_suspended_time(struct device *dev)
>  {
> -       unsigned long flags, time;
> +       u64 time;
> +       unsigned long flags;
>
>         spin_lock_irqsave(&dev->power.lock, flags);
>
>         update_pm_runtime_accounting(dev);
>
> -       time = dev->power.suspended_jiffies;
> +       time = dev->power.suspended_time;
>
>         spin_unlock_irqrestore(&dev->power.lock, flags);
>
> -       return jiffies_to_nsecs(time);
> +       return time;
>  }
>  EXPORT_SYMBOL_GPL(pm_runtime_suspended_time);
>
> @@ -1503,7 +1504,7 @@ void pm_runtime_init(struct device *dev)
>         dev->power.request_pending = false;
>         dev->power.request = RPM_REQ_NONE;
>         dev->power.deferred_resume = false;
> -       dev->power.accounting_timestamp = jiffies;
> +       dev->power.accounting_timestamp = ktime_to_ns(ktime_get());

This change worries me a bit, but it may not be a problem in practice.

pm_runtime_init() is called when devices get initialized, via
device_initialize(). If timekeeping has not been initialized prior a
call to ktime_get() is done, it will fail and causing a NULL pointer
deference or something along those lines.

In other words, do we know that device_initialize() is always called
after timekeeping has been initialized during boot?

[...]

Kind regards
Uffe

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4 3/3] PM/runtime:Replace jiffies based accounting with ktime based accounting
@ 2018-12-20 22:02   ` Ulf Hansson
  0 siblings, 0 replies; 9+ messages in thread
From: Ulf Hansson @ 2018-12-20 22:02 UTC (permalink / raw)
  To: Vincent Guittot
  Cc: dri-devel, Linux PM, David Airlie,
	Intel graphics driver community testing & development,
	Rafael J. Wysocki, Linux Kernel Mailing List, Thara Gopinath,
	rodrigo.vivi

On Thu, 20 Dec 2018 at 15:17, Vincent Guittot
<vincent.guittot@linaro.org> wrote:
>
> From: Thara Gopinath <thara.gopinath@linaro.org>
>
> This patch replaces jiffies based accounting for runtime_active_time
> and runtime_suspended_time with ktime base accounting. This makes the
> runtime debug counters inline with genpd and other pm subsytems which
> uses ktime based accounting.
>
> Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org>
> [move from ktime to raw nsec]
> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
> ---
>  drivers/base/power/runtime.c | 17 +++++++++--------
>  drivers/base/power/sysfs.c   | 11 ++++++++---
>  include/linux/pm.h           |  6 +++---
>  3 files changed, 20 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> index e695544..f700524 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -64,8 +64,8 @@ static int rpm_suspend(struct device *dev, int rpmflags);
>   */
>  void update_pm_runtime_accounting(struct device *dev)
>  {
> -       unsigned long now = jiffies;
> -       unsigned long delta;
> +       u64 now = ktime_to_ns(ktime_get());
> +       u64 delta;
>
>         delta = now - dev->power.accounting_timestamp;
>
> @@ -75,9 +75,9 @@ void update_pm_runtime_accounting(struct device *dev)
>                 return;
>
>         if (dev->power.runtime_status == RPM_SUSPENDED)
> -               dev->power.suspended_jiffies += delta;
> +               dev->power.suspended_time += delta;
>         else
> -               dev->power.active_jiffies += delta;
> +               dev->power.active_time += delta;
>  }
>
>  static void __update_runtime_status(struct device *dev, enum rpm_status status)
> @@ -88,17 +88,18 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status)
>
>  u64 pm_runtime_suspended_time(struct device *dev)
>  {
> -       unsigned long flags, time;
> +       u64 time;
> +       unsigned long flags;
>
>         spin_lock_irqsave(&dev->power.lock, flags);
>
>         update_pm_runtime_accounting(dev);
>
> -       time = dev->power.suspended_jiffies;
> +       time = dev->power.suspended_time;
>
>         spin_unlock_irqrestore(&dev->power.lock, flags);
>
> -       return jiffies_to_nsecs(time);
> +       return time;
>  }
>  EXPORT_SYMBOL_GPL(pm_runtime_suspended_time);
>
> @@ -1503,7 +1504,7 @@ void pm_runtime_init(struct device *dev)
>         dev->power.request_pending = false;
>         dev->power.request = RPM_REQ_NONE;
>         dev->power.deferred_resume = false;
> -       dev->power.accounting_timestamp = jiffies;
> +       dev->power.accounting_timestamp = ktime_to_ns(ktime_get());

This change worries me a bit, but it may not be a problem in practice.

pm_runtime_init() is called when devices get initialized, via
device_initialize(). If timekeeping has not been initialized prior a
call to ktime_get() is done, it will fail and causing a NULL pointer
deference or something along those lines.

In other words, do we know that device_initialize() is always called
after timekeeping has been initialized during boot?

[...]

Kind regards
Uffe
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4 3/3] PM/runtime:Replace jiffies based accounting with ktime based accounting
  2018-12-20 22:02   ` Ulf Hansson
@ 2018-12-21  8:31     ` Vincent Guittot
  -1 siblings, 0 replies; 9+ messages in thread
From: Vincent Guittot @ 2018-12-21  8:31 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Linux PM, Linux Kernel Mailing List, Rafael J. Wysocki,
	Thara Gopinath, jani.nikula, Joonas Lahtinen, rodrigo.vivi,
	David Airlie,
	Intel graphics driver community testing & development,
	dri-devel

On Thu, 20 Dec 2018 at 23:03, Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> On Thu, 20 Dec 2018 at 15:17, Vincent Guittot
> <vincent.guittot@linaro.org> wrote:
> >
> > From: Thara Gopinath <thara.gopinath@linaro.org>
> >
> > This patch replaces jiffies based accounting for runtime_active_time
> > and runtime_suspended_time with ktime base accounting. This makes the
> > runtime debug counters inline with genpd and other pm subsytems which
> > uses ktime based accounting.
> >
> > Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org>
> > [move from ktime to raw nsec]
> > Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
> > ---
> >  drivers/base/power/runtime.c | 17 +++++++++--------
> >  drivers/base/power/sysfs.c   | 11 ++++++++---
> >  include/linux/pm.h           |  6 +++---
> >  3 files changed, 20 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> > index e695544..f700524 100644
> > --- a/drivers/base/power/runtime.c
> > +++ b/drivers/base/power/runtime.c
> > @@ -64,8 +64,8 @@ static int rpm_suspend(struct device *dev, int rpmflags);
> >   */
> >  void update_pm_runtime_accounting(struct device *dev)
> >  {
> > -       unsigned long now = jiffies;
> > -       unsigned long delta;
> > +       u64 now = ktime_to_ns(ktime_get());
> > +       u64 delta;
> >
> >         delta = now - dev->power.accounting_timestamp;
> >
> > @@ -75,9 +75,9 @@ void update_pm_runtime_accounting(struct device *dev)
> >                 return;
> >
> >         if (dev->power.runtime_status == RPM_SUSPENDED)
> > -               dev->power.suspended_jiffies += delta;
> > +               dev->power.suspended_time += delta;
> >         else
> > -               dev->power.active_jiffies += delta;
> > +               dev->power.active_time += delta;
> >  }
> >
> >  static void __update_runtime_status(struct device *dev, enum rpm_status status)
> > @@ -88,17 +88,18 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status)
> >
> >  u64 pm_runtime_suspended_time(struct device *dev)
> >  {
> > -       unsigned long flags, time;
> > +       u64 time;
> > +       unsigned long flags;
> >
> >         spin_lock_irqsave(&dev->power.lock, flags);
> >
> >         update_pm_runtime_accounting(dev);
> >
> > -       time = dev->power.suspended_jiffies;
> > +       time = dev->power.suspended_time;
> >
> >         spin_unlock_irqrestore(&dev->power.lock, flags);
> >
> > -       return jiffies_to_nsecs(time);
> > +       return time;
> >  }
> >  EXPORT_SYMBOL_GPL(pm_runtime_suspended_time);
> >
> > @@ -1503,7 +1504,7 @@ void pm_runtime_init(struct device *dev)
> >         dev->power.request_pending = false;
> >         dev->power.request = RPM_REQ_NONE;
> >         dev->power.deferred_resume = false;
> > -       dev->power.accounting_timestamp = jiffies;
> > +       dev->power.accounting_timestamp = ktime_to_ns(ktime_get());
>
> This change worries me a bit, but it may not be a problem in practice.
>
> pm_runtime_init() is called when devices get initialized, via
> device_initialize(). If timekeeping has not been initialized prior a
> call to ktime_get() is done, it will fail and causing a NULL pointer
> deference or something along those lines.
>
> In other words, do we know that device_initialize() is always called
> after timekeeping has been initialized during boot?

That something we discussed at lpc and we should be safe

>
> [...]
>
> Kind regards
> Uffe

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4 3/3] PM/runtime:Replace jiffies based accounting with ktime based accounting
@ 2018-12-21  8:31     ` Vincent Guittot
  0 siblings, 0 replies; 9+ messages in thread
From: Vincent Guittot @ 2018-12-21  8:31 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: dri-devel, Linux PM, David Airlie,
	Intel graphics driver community testing & development,
	Rafael J. Wysocki, Linux Kernel Mailing List, Thara Gopinath,
	rodrigo.vivi

On Thu, 20 Dec 2018 at 23:03, Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> On Thu, 20 Dec 2018 at 15:17, Vincent Guittot
> <vincent.guittot@linaro.org> wrote:
> >
> > From: Thara Gopinath <thara.gopinath@linaro.org>
> >
> > This patch replaces jiffies based accounting for runtime_active_time
> > and runtime_suspended_time with ktime base accounting. This makes the
> > runtime debug counters inline with genpd and other pm subsytems which
> > uses ktime based accounting.
> >
> > Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org>
> > [move from ktime to raw nsec]
> > Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
> > ---
> >  drivers/base/power/runtime.c | 17 +++++++++--------
> >  drivers/base/power/sysfs.c   | 11 ++++++++---
> >  include/linux/pm.h           |  6 +++---
> >  3 files changed, 20 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> > index e695544..f700524 100644
> > --- a/drivers/base/power/runtime.c
> > +++ b/drivers/base/power/runtime.c
> > @@ -64,8 +64,8 @@ static int rpm_suspend(struct device *dev, int rpmflags);
> >   */
> >  void update_pm_runtime_accounting(struct device *dev)
> >  {
> > -       unsigned long now = jiffies;
> > -       unsigned long delta;
> > +       u64 now = ktime_to_ns(ktime_get());
> > +       u64 delta;
> >
> >         delta = now - dev->power.accounting_timestamp;
> >
> > @@ -75,9 +75,9 @@ void update_pm_runtime_accounting(struct device *dev)
> >                 return;
> >
> >         if (dev->power.runtime_status == RPM_SUSPENDED)
> > -               dev->power.suspended_jiffies += delta;
> > +               dev->power.suspended_time += delta;
> >         else
> > -               dev->power.active_jiffies += delta;
> > +               dev->power.active_time += delta;
> >  }
> >
> >  static void __update_runtime_status(struct device *dev, enum rpm_status status)
> > @@ -88,17 +88,18 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status)
> >
> >  u64 pm_runtime_suspended_time(struct device *dev)
> >  {
> > -       unsigned long flags, time;
> > +       u64 time;
> > +       unsigned long flags;
> >
> >         spin_lock_irqsave(&dev->power.lock, flags);
> >
> >         update_pm_runtime_accounting(dev);
> >
> > -       time = dev->power.suspended_jiffies;
> > +       time = dev->power.suspended_time;
> >
> >         spin_unlock_irqrestore(&dev->power.lock, flags);
> >
> > -       return jiffies_to_nsecs(time);
> > +       return time;
> >  }
> >  EXPORT_SYMBOL_GPL(pm_runtime_suspended_time);
> >
> > @@ -1503,7 +1504,7 @@ void pm_runtime_init(struct device *dev)
> >         dev->power.request_pending = false;
> >         dev->power.request = RPM_REQ_NONE;
> >         dev->power.deferred_resume = false;
> > -       dev->power.accounting_timestamp = jiffies;
> > +       dev->power.accounting_timestamp = ktime_to_ns(ktime_get());
>
> This change worries me a bit, but it may not be a problem in practice.
>
> pm_runtime_init() is called when devices get initialized, via
> device_initialize(). If timekeeping has not been initialized prior a
> call to ktime_get() is done, it will fail and causing a NULL pointer
> deference or something along those lines.
>
> In other words, do we know that device_initialize() is always called
> after timekeeping has been initialized during boot?

That something we discussed at lpc and we should be safe

>
> [...]
>
> Kind regards
> Uffe
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4 3/3] PM/runtime:Replace jiffies based accounting with ktime based accounting
  2018-12-20 22:02   ` Ulf Hansson
@ 2018-12-21  8:58     ` Rafael J. Wysocki
  -1 siblings, 0 replies; 9+ messages in thread
From: Rafael J. Wysocki @ 2018-12-21  8:58 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Vincent Guittot, Linux PM, Linux Kernel Mailing List,
	Rafael J. Wysocki, Thara Gopinath, Jani Nikula, Joonas Lahtinen,
	rodrigo.vivi, David Airlie, intel-gfx, dri-devel

On Thu, Dec 20, 2018 at 11:03 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> On Thu, 20 Dec 2018 at 15:17, Vincent Guittot
> <vincent.guittot@linaro.org> wrote:
> >
> > From: Thara Gopinath <thara.gopinath@linaro.org>
> >
> > This patch replaces jiffies based accounting for runtime_active_time
> > and runtime_suspended_time with ktime base accounting. This makes the
> > runtime debug counters inline with genpd and other pm subsytems which
> > uses ktime based accounting.
> >
> > Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org>
> > [move from ktime to raw nsec]
> > Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
> > ---
> >  drivers/base/power/runtime.c | 17 +++++++++--------
> >  drivers/base/power/sysfs.c   | 11 ++++++++---
> >  include/linux/pm.h           |  6 +++---
> >  3 files changed, 20 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> > index e695544..f700524 100644
> > --- a/drivers/base/power/runtime.c
> > +++ b/drivers/base/power/runtime.c
> > @@ -64,8 +64,8 @@ static int rpm_suspend(struct device *dev, int rpmflags);
> >   */
> >  void update_pm_runtime_accounting(struct device *dev)
> >  {
> > -       unsigned long now = jiffies;
> > -       unsigned long delta;
> > +       u64 now = ktime_to_ns(ktime_get());
> > +       u64 delta;
> >
> >         delta = now - dev->power.accounting_timestamp;
> >
> > @@ -75,9 +75,9 @@ void update_pm_runtime_accounting(struct device *dev)
> >                 return;
> >
> >         if (dev->power.runtime_status == RPM_SUSPENDED)
> > -               dev->power.suspended_jiffies += delta;
> > +               dev->power.suspended_time += delta;
> >         else
> > -               dev->power.active_jiffies += delta;
> > +               dev->power.active_time += delta;
> >  }
> >
> >  static void __update_runtime_status(struct device *dev, enum rpm_status status)
> > @@ -88,17 +88,18 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status)
> >
> >  u64 pm_runtime_suspended_time(struct device *dev)
> >  {
> > -       unsigned long flags, time;
> > +       u64 time;
> > +       unsigned long flags;
> >
> >         spin_lock_irqsave(&dev->power.lock, flags);
> >
> >         update_pm_runtime_accounting(dev);
> >
> > -       time = dev->power.suspended_jiffies;
> > +       time = dev->power.suspended_time;
> >
> >         spin_unlock_irqrestore(&dev->power.lock, flags);
> >
> > -       return jiffies_to_nsecs(time);
> > +       return time;
> >  }
> >  EXPORT_SYMBOL_GPL(pm_runtime_suspended_time);
> >
> > @@ -1503,7 +1504,7 @@ void pm_runtime_init(struct device *dev)
> >         dev->power.request_pending = false;
> >         dev->power.request = RPM_REQ_NONE;
> >         dev->power.deferred_resume = false;
> > -       dev->power.accounting_timestamp = jiffies;
> > +       dev->power.accounting_timestamp = ktime_to_ns(ktime_get());
>
> This change worries me a bit, but it may not be a problem in practice.
>
> pm_runtime_init() is called when devices get initialized, via
> device_initialize(). If timekeeping has not been initialized prior a
> call to ktime_get() is done, it will fail and causing a NULL pointer
> deference or something along those lines.
>
> In other words, do we know that device_initialize() is always called
> after timekeeping has been initialized during boot?

We do.

timekeeping_init() is called early in start_kernel() which is way
before driver_init() (and that's when devices can start to be
initialized) called from rest_init() via kernel_init_freeable() and
do_basic_setup().

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4 3/3] PM/runtime:Replace jiffies based accounting with ktime based accounting
@ 2018-12-21  8:58     ` Rafael J. Wysocki
  0 siblings, 0 replies; 9+ messages in thread
From: Rafael J. Wysocki @ 2018-12-21  8:58 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Vincent Guittot, dri-devel, Linux PM, David Airlie, intel-gfx,
	Rafael J. Wysocki, Linux Kernel Mailing List, Thara Gopinath,
	rodrigo.vivi

On Thu, Dec 20, 2018 at 11:03 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> On Thu, 20 Dec 2018 at 15:17, Vincent Guittot
> <vincent.guittot@linaro.org> wrote:
> >
> > From: Thara Gopinath <thara.gopinath@linaro.org>
> >
> > This patch replaces jiffies based accounting for runtime_active_time
> > and runtime_suspended_time with ktime base accounting. This makes the
> > runtime debug counters inline with genpd and other pm subsytems which
> > uses ktime based accounting.
> >
> > Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org>
> > [move from ktime to raw nsec]
> > Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
> > ---
> >  drivers/base/power/runtime.c | 17 +++++++++--------
> >  drivers/base/power/sysfs.c   | 11 ++++++++---
> >  include/linux/pm.h           |  6 +++---
> >  3 files changed, 20 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> > index e695544..f700524 100644
> > --- a/drivers/base/power/runtime.c
> > +++ b/drivers/base/power/runtime.c
> > @@ -64,8 +64,8 @@ static int rpm_suspend(struct device *dev, int rpmflags);
> >   */
> >  void update_pm_runtime_accounting(struct device *dev)
> >  {
> > -       unsigned long now = jiffies;
> > -       unsigned long delta;
> > +       u64 now = ktime_to_ns(ktime_get());
> > +       u64 delta;
> >
> >         delta = now - dev->power.accounting_timestamp;
> >
> > @@ -75,9 +75,9 @@ void update_pm_runtime_accounting(struct device *dev)
> >                 return;
> >
> >         if (dev->power.runtime_status == RPM_SUSPENDED)
> > -               dev->power.suspended_jiffies += delta;
> > +               dev->power.suspended_time += delta;
> >         else
> > -               dev->power.active_jiffies += delta;
> > +               dev->power.active_time += delta;
> >  }
> >
> >  static void __update_runtime_status(struct device *dev, enum rpm_status status)
> > @@ -88,17 +88,18 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status)
> >
> >  u64 pm_runtime_suspended_time(struct device *dev)
> >  {
> > -       unsigned long flags, time;
> > +       u64 time;
> > +       unsigned long flags;
> >
> >         spin_lock_irqsave(&dev->power.lock, flags);
> >
> >         update_pm_runtime_accounting(dev);
> >
> > -       time = dev->power.suspended_jiffies;
> > +       time = dev->power.suspended_time;
> >
> >         spin_unlock_irqrestore(&dev->power.lock, flags);
> >
> > -       return jiffies_to_nsecs(time);
> > +       return time;
> >  }
> >  EXPORT_SYMBOL_GPL(pm_runtime_suspended_time);
> >
> > @@ -1503,7 +1504,7 @@ void pm_runtime_init(struct device *dev)
> >         dev->power.request_pending = false;
> >         dev->power.request = RPM_REQ_NONE;
> >         dev->power.deferred_resume = false;
> > -       dev->power.accounting_timestamp = jiffies;
> > +       dev->power.accounting_timestamp = ktime_to_ns(ktime_get());
>
> This change worries me a bit, but it may not be a problem in practice.
>
> pm_runtime_init() is called when devices get initialized, via
> device_initialize(). If timekeeping has not been initialized prior a
> call to ktime_get() is done, it will fail and causing a NULL pointer
> deference or something along those lines.
>
> In other words, do we know that device_initialize() is always called
> after timekeeping has been initialized during boot?

We do.

timekeeping_init() is called early in start_kernel() which is way
before driver_init() (and that's when devices can start to be
initialized) called from rest_init() via kernel_init_freeable() and
do_basic_setup().
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4 3/3] PM/runtime:Replace jiffies based accounting with ktime based accounting
  2018-12-21  8:58     ` Rafael J. Wysocki
@ 2018-12-21 10:06       ` Vincent Guittot
  -1 siblings, 0 replies; 9+ messages in thread
From: Vincent Guittot @ 2018-12-21 10:06 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Ulf Hansson, Linux PM, Linux Kernel Mailing List,
	Rafael J. Wysocki, Thara Gopinath, Jani Nikula, Joonas Lahtinen,
	rodrigo.vivi, David Airlie, intel-gfx, dri-devel

Hi Rafael,

On Fri, 21 Dec 2018 at 09:58, Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Thu, Dec 20, 2018 at 11:03 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
> >
> > On Thu, 20 Dec 2018 at 15:17, Vincent Guittot
> > <vincent.guittot@linaro.org> wrote:
> > >
> > > From: Thara Gopinath <thara.gopinath@linaro.org>
> > >
> > > This patch replaces jiffies based accounting for runtime_active_time
> > > and runtime_suspended_time with ktime base accounting. This makes the
> > > runtime debug counters inline with genpd and other pm subsytems which
> > > uses ktime based accounting.
> > >
> > > Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org>
> > > [move from ktime to raw nsec]
> > > Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
> > > ---
> > >  drivers/base/power/runtime.c | 17 +++++++++--------
> > >  drivers/base/power/sysfs.c   | 11 ++++++++---
> > >  include/linux/pm.h           |  6 +++---
> > >  3 files changed, 20 insertions(+), 14 deletions(-)
> > >
> > > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> > > index e695544..f700524 100644
> > > --- a/drivers/base/power/runtime.c
> > > +++ b/drivers/base/power/runtime.c
> > > @@ -64,8 +64,8 @@ static int rpm_suspend(struct device *dev, int rpmflags);
> > >   */
> > >  void update_pm_runtime_accounting(struct device *dev)
> > >  {
> > > -       unsigned long now = jiffies;
> > > -       unsigned long delta;
> > > +       u64 now = ktime_to_ns(ktime_get());
> > > +       u64 delta;
> > >
> > >         delta = now - dev->power.accounting_timestamp;
> > >
> > > @@ -75,9 +75,9 @@ void update_pm_runtime_accounting(struct device *dev)
> > >                 return;
> > >
> > >         if (dev->power.runtime_status == RPM_SUSPENDED)
> > > -               dev->power.suspended_jiffies += delta;
> > > +               dev->power.suspended_time += delta;
> > >         else
> > > -               dev->power.active_jiffies += delta;
> > > +               dev->power.active_time += delta;
> > >  }
> > >
> > >  static void __update_runtime_status(struct device *dev, enum rpm_status status)
> > > @@ -88,17 +88,18 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status)
> > >
> > >  u64 pm_runtime_suspended_time(struct device *dev)
> > >  {
> > > -       unsigned long flags, time;
> > > +       u64 time;
> > > +       unsigned long flags;
> > >
> > >         spin_lock_irqsave(&dev->power.lock, flags);
> > >
> > >         update_pm_runtime_accounting(dev);
> > >
> > > -       time = dev->power.suspended_jiffies;
> > > +       time = dev->power.suspended_time;
> > >
> > >         spin_unlock_irqrestore(&dev->power.lock, flags);
> > >
> > > -       return jiffies_to_nsecs(time);
> > > +       return time;
> > >  }
> > >  EXPORT_SYMBOL_GPL(pm_runtime_suspended_time);
> > >
> > > @@ -1503,7 +1504,7 @@ void pm_runtime_init(struct device *dev)
> > >         dev->power.request_pending = false;
> > >         dev->power.request = RPM_REQ_NONE;
> > >         dev->power.deferred_resume = false;
> > > -       dev->power.accounting_timestamp = jiffies;
> > > +       dev->power.accounting_timestamp = ktime_to_ns(ktime_get());
> >
> > This change worries me a bit, but it may not be a problem in practice.
> >
> > pm_runtime_init() is called when devices get initialized, via
> > device_initialize(). If timekeeping has not been initialized prior a
> > call to ktime_get() is done, it will fail and causing a NULL pointer
> > deference or something along those lines.
> >
> > In other words, do we know that device_initialize() is always called
> > after timekeeping has been initialized during boot?
>
> We do.
>
> timekeeping_init() is called early in start_kernel() which is way
> before driver_init() (and that's when devices can start to be
> initialized) called from rest_init() via kernel_init_freeable() and
> do_basic_setup().

Thanks for the confirmation. I'm going to add your answer in the
commit message so we will have the answer next time someone will
wonder

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4 3/3] PM/runtime:Replace jiffies based accounting with ktime based accounting
@ 2018-12-21 10:06       ` Vincent Guittot
  0 siblings, 0 replies; 9+ messages in thread
From: Vincent Guittot @ 2018-12-21 10:06 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Ulf Hansson, dri-devel, Linux PM, David Airlie, intel-gfx,
	Rafael J. Wysocki, Linux Kernel Mailing List, Thara Gopinath,
	rodrigo.vivi

Hi Rafael,

On Fri, 21 Dec 2018 at 09:58, Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Thu, Dec 20, 2018 at 11:03 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
> >
> > On Thu, 20 Dec 2018 at 15:17, Vincent Guittot
> > <vincent.guittot@linaro.org> wrote:
> > >
> > > From: Thara Gopinath <thara.gopinath@linaro.org>
> > >
> > > This patch replaces jiffies based accounting for runtime_active_time
> > > and runtime_suspended_time with ktime base accounting. This makes the
> > > runtime debug counters inline with genpd and other pm subsytems which
> > > uses ktime based accounting.
> > >
> > > Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org>
> > > [move from ktime to raw nsec]
> > > Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
> > > ---
> > >  drivers/base/power/runtime.c | 17 +++++++++--------
> > >  drivers/base/power/sysfs.c   | 11 ++++++++---
> > >  include/linux/pm.h           |  6 +++---
> > >  3 files changed, 20 insertions(+), 14 deletions(-)
> > >
> > > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> > > index e695544..f700524 100644
> > > --- a/drivers/base/power/runtime.c
> > > +++ b/drivers/base/power/runtime.c
> > > @@ -64,8 +64,8 @@ static int rpm_suspend(struct device *dev, int rpmflags);
> > >   */
> > >  void update_pm_runtime_accounting(struct device *dev)
> > >  {
> > > -       unsigned long now = jiffies;
> > > -       unsigned long delta;
> > > +       u64 now = ktime_to_ns(ktime_get());
> > > +       u64 delta;
> > >
> > >         delta = now - dev->power.accounting_timestamp;
> > >
> > > @@ -75,9 +75,9 @@ void update_pm_runtime_accounting(struct device *dev)
> > >                 return;
> > >
> > >         if (dev->power.runtime_status == RPM_SUSPENDED)
> > > -               dev->power.suspended_jiffies += delta;
> > > +               dev->power.suspended_time += delta;
> > >         else
> > > -               dev->power.active_jiffies += delta;
> > > +               dev->power.active_time += delta;
> > >  }
> > >
> > >  static void __update_runtime_status(struct device *dev, enum rpm_status status)
> > > @@ -88,17 +88,18 @@ static void __update_runtime_status(struct device *dev, enum rpm_status status)
> > >
> > >  u64 pm_runtime_suspended_time(struct device *dev)
> > >  {
> > > -       unsigned long flags, time;
> > > +       u64 time;
> > > +       unsigned long flags;
> > >
> > >         spin_lock_irqsave(&dev->power.lock, flags);
> > >
> > >         update_pm_runtime_accounting(dev);
> > >
> > > -       time = dev->power.suspended_jiffies;
> > > +       time = dev->power.suspended_time;
> > >
> > >         spin_unlock_irqrestore(&dev->power.lock, flags);
> > >
> > > -       return jiffies_to_nsecs(time);
> > > +       return time;
> > >  }
> > >  EXPORT_SYMBOL_GPL(pm_runtime_suspended_time);
> > >
> > > @@ -1503,7 +1504,7 @@ void pm_runtime_init(struct device *dev)
> > >         dev->power.request_pending = false;
> > >         dev->power.request = RPM_REQ_NONE;
> > >         dev->power.deferred_resume = false;
> > > -       dev->power.accounting_timestamp = jiffies;
> > > +       dev->power.accounting_timestamp = ktime_to_ns(ktime_get());
> >
> > This change worries me a bit, but it may not be a problem in practice.
> >
> > pm_runtime_init() is called when devices get initialized, via
> > device_initialize(). If timekeeping has not been initialized prior a
> > call to ktime_get() is done, it will fail and causing a NULL pointer
> > deference or something along those lines.
> >
> > In other words, do we know that device_initialize() is always called
> > after timekeeping has been initialized during boot?
>
> We do.
>
> timekeeping_init() is called early in start_kernel() which is way
> before driver_init() (and that's when devices can start to be
> initialized) called from rest_init() via kernel_init_freeable() and
> do_basic_setup().

Thanks for the confirmation. I'm going to add your answer in the
commit message so we will have the answer next time someone will
wonder
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-12-21 10:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-20 14:17 [PATCH v4 3/3] PM/runtime:Replace jiffies based accounting with ktime based accounting Vincent Guittot
2018-12-20 22:02 ` Ulf Hansson
2018-12-20 22:02   ` Ulf Hansson
2018-12-21  8:31   ` Vincent Guittot
2018-12-21  8:31     ` Vincent Guittot
2018-12-21  8:58   ` Rafael J. Wysocki
2018-12-21  8:58     ` Rafael J. Wysocki
2018-12-21 10:06     ` Vincent Guittot
2018-12-21 10:06       ` Vincent Guittot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.