All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpuidle-pseries: Fix CEDE latency conversion from tb to us
@ 2020-09-01 14:08 ` Gautham R. Shenoy
  0 siblings, 0 replies; 6+ messages in thread
From: Gautham R. Shenoy @ 2020-09-01 14:08 UTC (permalink / raw)
  To: Michael Ellerman, Rafael J. Wysocki, Vaidyanathan Srinivasan
  Cc: linux-pm, linuxppc-dev, linux-kernel, Gautham R. Shenoy

From: "Gautham R. Shenoy" <ego@linux.vnet.ibm.com>

commit d947fb4c965c ("cpuidle: pseries: Fixup exit latency for
CEDE(0)") sets the exit latency of CEDE(0) based on the latency values
of the Extended CEDE states advertised by the platform. The values
advertised by the platform are in timebase ticks. However the cpuidle
framework requires the latency values in microseconds.

If the tb-ticks value advertised by the platform correspond to a value
smaller than 1us, during the conversion from tb-ticks to microseconds,
in the current code, the result becomes zero. This is incorrect as it
puts a CEDE state on par with the snooze state.

This patch fixes this by rounding up the result obtained while
converting the latency value from tb-ticks to microseconds.

Fixes: commit d947fb4c965c ("cpuidle: pseries: Fixup exit latency for
CEDE(0)")

Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
---
 drivers/cpuidle/cpuidle-pseries.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c
index ff6d99e..9043358 100644
--- a/drivers/cpuidle/cpuidle-pseries.c
+++ b/drivers/cpuidle/cpuidle-pseries.c
@@ -361,7 +361,7 @@ static void __init fixup_cede0_latency(void)
 	for (i = 0; i < nr_xcede_records; i++) {
 		struct xcede_latency_record *record = &payload->records[i];
 		u64 latency_tb = be64_to_cpu(record->latency_ticks);
-		u64 latency_us = tb_to_ns(latency_tb) / NSEC_PER_USEC;
+		u64 latency_us = DIV_ROUND_UP_ULL(tb_to_ns(latency_tb), NSEC_PER_USEC);
 
 		if (latency_us < min_latency_us)
 			min_latency_us = latency_us;
-- 
1.9.4


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

* [PATCH] cpuidle-pseries: Fix CEDE latency conversion from tb to us
@ 2020-09-01 14:08 ` Gautham R. Shenoy
  0 siblings, 0 replies; 6+ messages in thread
From: Gautham R. Shenoy @ 2020-09-01 14:08 UTC (permalink / raw)
  To: Michael Ellerman, Rafael J. Wysocki, Vaidyanathan Srinivasan
  Cc: Gautham R. Shenoy, linuxppc-dev, linux-kernel, linux-pm

From: "Gautham R. Shenoy" <ego@linux.vnet.ibm.com>

commit d947fb4c965c ("cpuidle: pseries: Fixup exit latency for
CEDE(0)") sets the exit latency of CEDE(0) based on the latency values
of the Extended CEDE states advertised by the platform. The values
advertised by the platform are in timebase ticks. However the cpuidle
framework requires the latency values in microseconds.

If the tb-ticks value advertised by the platform correspond to a value
smaller than 1us, during the conversion from tb-ticks to microseconds,
in the current code, the result becomes zero. This is incorrect as it
puts a CEDE state on par with the snooze state.

This patch fixes this by rounding up the result obtained while
converting the latency value from tb-ticks to microseconds.

Fixes: commit d947fb4c965c ("cpuidle: pseries: Fixup exit latency for
CEDE(0)")

Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
---
 drivers/cpuidle/cpuidle-pseries.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c
index ff6d99e..9043358 100644
--- a/drivers/cpuidle/cpuidle-pseries.c
+++ b/drivers/cpuidle/cpuidle-pseries.c
@@ -361,7 +361,7 @@ static void __init fixup_cede0_latency(void)
 	for (i = 0; i < nr_xcede_records; i++) {
 		struct xcede_latency_record *record = &payload->records[i];
 		u64 latency_tb = be64_to_cpu(record->latency_ticks);
-		u64 latency_us = tb_to_ns(latency_tb) / NSEC_PER_USEC;
+		u64 latency_us = DIV_ROUND_UP_ULL(tb_to_ns(latency_tb), NSEC_PER_USEC);
 
 		if (latency_us < min_latency_us)
 			min_latency_us = latency_us;
-- 
1.9.4


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

* Re: [PATCH] cpuidle-pseries: Fix CEDE latency conversion from tb to us
  2020-09-01 14:08 ` Gautham R. Shenoy
@ 2020-09-02  1:08   ` Joel Stanley
  -1 siblings, 0 replies; 6+ messages in thread
From: Joel Stanley @ 2020-09-02  1:08 UTC (permalink / raw)
  To: Gautham R. Shenoy
  Cc: Michael Ellerman, Rafael J. Wysocki, Vaidyanathan Srinivasan,
	linuxppc-dev, Linux Kernel Mailing List, linux-pm

On Tue, 1 Sep 2020 at 14:09, Gautham R. Shenoy <ego@linux.vnet.ibm.com> wrote:
>
> From: "Gautham R. Shenoy" <ego@linux.vnet.ibm.com>
>
> commit d947fb4c965c ("cpuidle: pseries: Fixup exit latency for
> CEDE(0)") sets the exit latency of CEDE(0) based on the latency values
> of the Extended CEDE states advertised by the platform. The values
> advertised by the platform are in timebase ticks. However the cpuidle
> framework requires the latency values in microseconds.
>
> If the tb-ticks value advertised by the platform correspond to a value
> smaller than 1us, during the conversion from tb-ticks to microseconds,
> in the current code, the result becomes zero. This is incorrect as it
> puts a CEDE state on par with the snooze state.
>
> This patch fixes this by rounding up the result obtained while
> converting the latency value from tb-ticks to microseconds.
>
> Fixes: commit d947fb4c965c ("cpuidle: pseries: Fixup exit latency for
> CEDE(0)")
>
> Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>

Reviewed-by: Joel Stanley <joel@jms.id.au>

Should you check for the zero case and print a warning?

> ---
>  drivers/cpuidle/cpuidle-pseries.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c
> index ff6d99e..9043358 100644
> --- a/drivers/cpuidle/cpuidle-pseries.c
> +++ b/drivers/cpuidle/cpuidle-pseries.c
> @@ -361,7 +361,7 @@ static void __init fixup_cede0_latency(void)
>         for (i = 0; i < nr_xcede_records; i++) {
>                 struct xcede_latency_record *record = &payload->records[i];
>                 u64 latency_tb = be64_to_cpu(record->latency_ticks);
> -               u64 latency_us = tb_to_ns(latency_tb) / NSEC_PER_USEC;
> +               u64 latency_us = DIV_ROUND_UP_ULL(tb_to_ns(latency_tb), NSEC_PER_USEC);
>
>                 if (latency_us < min_latency_us)
>                         min_latency_us = latency_us;
> --
> 1.9.4
>

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

* Re: [PATCH] cpuidle-pseries: Fix CEDE latency conversion from tb to us
@ 2020-09-02  1:08   ` Joel Stanley
  0 siblings, 0 replies; 6+ messages in thread
From: Joel Stanley @ 2020-09-02  1:08 UTC (permalink / raw)
  To: Gautham R. Shenoy
  Cc: linux-pm, Rafael J. Wysocki, Linux Kernel Mailing List,
	Vaidyanathan Srinivasan, linuxppc-dev

On Tue, 1 Sep 2020 at 14:09, Gautham R. Shenoy <ego@linux.vnet.ibm.com> wrote:
>
> From: "Gautham R. Shenoy" <ego@linux.vnet.ibm.com>
>
> commit d947fb4c965c ("cpuidle: pseries: Fixup exit latency for
> CEDE(0)") sets the exit latency of CEDE(0) based on the latency values
> of the Extended CEDE states advertised by the platform. The values
> advertised by the platform are in timebase ticks. However the cpuidle
> framework requires the latency values in microseconds.
>
> If the tb-ticks value advertised by the platform correspond to a value
> smaller than 1us, during the conversion from tb-ticks to microseconds,
> in the current code, the result becomes zero. This is incorrect as it
> puts a CEDE state on par with the snooze state.
>
> This patch fixes this by rounding up the result obtained while
> converting the latency value from tb-ticks to microseconds.
>
> Fixes: commit d947fb4c965c ("cpuidle: pseries: Fixup exit latency for
> CEDE(0)")
>
> Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>

Reviewed-by: Joel Stanley <joel@jms.id.au>

Should you check for the zero case and print a warning?

> ---
>  drivers/cpuidle/cpuidle-pseries.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c
> index ff6d99e..9043358 100644
> --- a/drivers/cpuidle/cpuidle-pseries.c
> +++ b/drivers/cpuidle/cpuidle-pseries.c
> @@ -361,7 +361,7 @@ static void __init fixup_cede0_latency(void)
>         for (i = 0; i < nr_xcede_records; i++) {
>                 struct xcede_latency_record *record = &payload->records[i];
>                 u64 latency_tb = be64_to_cpu(record->latency_ticks);
> -               u64 latency_us = tb_to_ns(latency_tb) / NSEC_PER_USEC;
> +               u64 latency_us = DIV_ROUND_UP_ULL(tb_to_ns(latency_tb), NSEC_PER_USEC);
>
>                 if (latency_us < min_latency_us)
>                         min_latency_us = latency_us;
> --
> 1.9.4
>

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

* Re: [PATCH] cpuidle-pseries: Fix CEDE latency conversion from tb to us
  2020-09-02  1:08   ` Joel Stanley
@ 2020-09-02  8:35     ` Gautham R Shenoy
  -1 siblings, 0 replies; 6+ messages in thread
From: Gautham R Shenoy @ 2020-09-02  8:35 UTC (permalink / raw)
  To: Joel Stanley
  Cc: Gautham R. Shenoy, Michael Ellerman, Rafael J. Wysocki,
	Vaidyanathan Srinivasan, linuxppc-dev, Linux Kernel Mailing List,
	linux-pm

Hello Joel,

On Wed, Sep 02, 2020 at 01:08:35AM +0000, Joel Stanley wrote:
> On Tue, 1 Sep 2020 at 14:09, Gautham R. Shenoy <ego@linux.vnet.ibm.com> wrote:
> >
> > From: "Gautham R. Shenoy" <ego@linux.vnet.ibm.com>
> >
> > commit d947fb4c965c ("cpuidle: pseries: Fixup exit latency for
> > CEDE(0)") sets the exit latency of CEDE(0) based on the latency values
> > of the Extended CEDE states advertised by the platform. The values
> > advertised by the platform are in timebase ticks. However the cpuidle
> > framework requires the latency values in microseconds.
> >
> > If the tb-ticks value advertised by the platform correspond to a value
> > smaller than 1us, during the conversion from tb-ticks to microseconds,
> > in the current code, the result becomes zero. This is incorrect as it
> > puts a CEDE state on par with the snooze state.
> >
> > This patch fixes this by rounding up the result obtained while
> > converting the latency value from tb-ticks to microseconds.
> >
> > Fixes: commit d947fb4c965c ("cpuidle: pseries: Fixup exit latency for
> > CEDE(0)")
> >
> > Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
> 
> Reviewed-by: Joel Stanley <joel@jms.id.au>
>

Thanks for reviewing the fix.

> Should you check for the zero case and print a warning?

Yes, that would be better. I will post a v2 with that.

> 
> > ---
> >  drivers/cpuidle/cpuidle-pseries.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c
> > index ff6d99e..9043358 100644
> > --- a/drivers/cpuidle/cpuidle-pseries.c
> > +++ b/drivers/cpuidle/cpuidle-pseries.c
> > @@ -361,7 +361,7 @@ static void __init fixup_cede0_latency(void)
> >         for (i = 0; i < nr_xcede_records; i++) {
> >                 struct xcede_latency_record *record = &payload->records[i];
> >                 u64 latency_tb = be64_to_cpu(record->latency_ticks);
> > -               u64 latency_us = tb_to_ns(latency_tb) / NSEC_PER_USEC;
> > +               u64 latency_us = DIV_ROUND_UP_ULL(tb_to_ns(latency_tb), NSEC_PER_USEC);
> >
> >                 if (latency_us < min_latency_us)
> >                         min_latency_us = latency_us;
> > --
> > 1.9.4
> >

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

* Re: [PATCH] cpuidle-pseries: Fix CEDE latency conversion from tb to us
@ 2020-09-02  8:35     ` Gautham R Shenoy
  0 siblings, 0 replies; 6+ messages in thread
From: Gautham R Shenoy @ 2020-09-02  8:35 UTC (permalink / raw)
  To: Joel Stanley
  Cc: Gautham R. Shenoy, linux-pm, Rafael J. Wysocki,
	Linux Kernel Mailing List, Vaidyanathan Srinivasan, linuxppc-dev

Hello Joel,

On Wed, Sep 02, 2020 at 01:08:35AM +0000, Joel Stanley wrote:
> On Tue, 1 Sep 2020 at 14:09, Gautham R. Shenoy <ego@linux.vnet.ibm.com> wrote:
> >
> > From: "Gautham R. Shenoy" <ego@linux.vnet.ibm.com>
> >
> > commit d947fb4c965c ("cpuidle: pseries: Fixup exit latency for
> > CEDE(0)") sets the exit latency of CEDE(0) based on the latency values
> > of the Extended CEDE states advertised by the platform. The values
> > advertised by the platform are in timebase ticks. However the cpuidle
> > framework requires the latency values in microseconds.
> >
> > If the tb-ticks value advertised by the platform correspond to a value
> > smaller than 1us, during the conversion from tb-ticks to microseconds,
> > in the current code, the result becomes zero. This is incorrect as it
> > puts a CEDE state on par with the snooze state.
> >
> > This patch fixes this by rounding up the result obtained while
> > converting the latency value from tb-ticks to microseconds.
> >
> > Fixes: commit d947fb4c965c ("cpuidle: pseries: Fixup exit latency for
> > CEDE(0)")
> >
> > Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
> 
> Reviewed-by: Joel Stanley <joel@jms.id.au>
>

Thanks for reviewing the fix.

> Should you check for the zero case and print a warning?

Yes, that would be better. I will post a v2 with that.

> 
> > ---
> >  drivers/cpuidle/cpuidle-pseries.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c
> > index ff6d99e..9043358 100644
> > --- a/drivers/cpuidle/cpuidle-pseries.c
> > +++ b/drivers/cpuidle/cpuidle-pseries.c
> > @@ -361,7 +361,7 @@ static void __init fixup_cede0_latency(void)
> >         for (i = 0; i < nr_xcede_records; i++) {
> >                 struct xcede_latency_record *record = &payload->records[i];
> >                 u64 latency_tb = be64_to_cpu(record->latency_ticks);
> > -               u64 latency_us = tb_to_ns(latency_tb) / NSEC_PER_USEC;
> > +               u64 latency_us = DIV_ROUND_UP_ULL(tb_to_ns(latency_tb), NSEC_PER_USEC);
> >
> >                 if (latency_us < min_latency_us)
> >                         min_latency_us = latency_us;
> > --
> > 1.9.4
> >

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

end of thread, other threads:[~2020-09-02  8:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-01 14:08 [PATCH] cpuidle-pseries: Fix CEDE latency conversion from tb to us Gautham R. Shenoy
2020-09-01 14:08 ` Gautham R. Shenoy
2020-09-02  1:08 ` Joel Stanley
2020-09-02  1:08   ` Joel Stanley
2020-09-02  8:35   ` Gautham R Shenoy
2020-09-02  8:35     ` Gautham R Shenoy

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.