All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] KVM: PPC: Use clockevent multiplier and shifter for decrementer
@ 2012-04-09  4:45 ` Bharat Bhushan
  0 siblings, 0 replies; 5+ messages in thread
From: Bharat Bhushan @ 2012-04-09  4:33 UTC (permalink / raw)
  To: linuxppc-dev, kvm-ppc, kvm; +Cc: Bharat Bhushan

Time for which the hrtimer is started for decrementer emulation is calculated using tb_ticks_per_usec. While hrtimer uses the clockevent for DEC reprogramming (if needed) and which calculate timebase ticks using the multiplier and shifter mechanism implemented within clockevent layer. It was observed that this conversion (timebase->time->timebase) are not correct because the mechanism are not consistent. In our setup it adds 2% jitter.

With this patch clockevent multiplier and shifter mechanism are used when starting hrtimer for decrementer emulation. Now the jitter is < 0.5%.

Signed-off-by: Bharat Bhushan <bharat.bhushan@freescale.com>
---
v2:
 - decrementer_clockevent is made non-static rather than a seprate API to get mult/shift

 arch/powerpc/include/asm/time.h |    1 +
 arch/powerpc/kernel/time.c      |    2 +-
 arch/powerpc/kvm/emulate.c      |    5 +++--
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/time.h b/arch/powerpc/include/asm/time.h
index 7eb10fb..b3c7959 100644
--- a/arch/powerpc/include/asm/time.h
+++ b/arch/powerpc/include/asm/time.h
@@ -28,6 +28,7 @@
 extern unsigned long tb_ticks_per_jiffy;
 extern unsigned long tb_ticks_per_usec;
 extern unsigned long tb_ticks_per_sec;
+extern struct clock_event_device decrementer_clockevent;
 
 struct rtc_time;
 extern void to_tm(int tim, struct rtc_time * tm);
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 567dd7c..e237225 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -105,7 +105,7 @@ static int decrementer_set_next_event(unsigned long evt,
 static void decrementer_set_mode(enum clock_event_mode mode,
 				 struct clock_event_device *dev);
 
-static struct clock_event_device decrementer_clockevent = {
+struct clock_event_device decrementer_clockevent = {
 	.name           = "decrementer",
 	.rating         = 200,
 	.irq            = 0,
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index afc9154..c8b5206 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -23,6 +23,7 @@
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/kvm_host.h>
+#include <linux/clockchips.h>
 
 #include <asm/reg.h>
 #include <asm/time.h>
@@ -104,8 +105,8 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
 	 */
 
 	dec_time = vcpu->arch.dec;
-	dec_time *= 1000;
-	do_div(dec_time, tb_ticks_per_usec);
+	dec_time = dec_time << decrementer_clockevent.shift;
+	do_div(dec_time, decrementer_clockevent.mult);
 	dec_nsec = do_div(dec_time, NSEC_PER_SEC);
 	hrtimer_start(&vcpu->arch.dec_timer,
 		ktime_set(dec_time, dec_nsec), HRTIMER_MODE_REL);
-- 
1.7.0.4

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

* [PATCH v2] KVM: PPC: Use clockevent multiplier and shifter for decrementer
@ 2012-04-09  4:45 ` Bharat Bhushan
  0 siblings, 0 replies; 5+ messages in thread
From: Bharat Bhushan @ 2012-04-09  4:45 UTC (permalink / raw)
  To: linuxppc-dev, kvm-ppc, kvm; +Cc: Bharat Bhushan

Time for which the hrtimer is started for decrementer emulation is calculated using tb_ticks_per_usec. While hrtimer uses the clockevent for DEC reprogramming (if needed) and which calculate timebase ticks using the multiplier and shifter mechanism implemented within clockevent layer. It was observed that this conversion (timebase->time->timebase) are not correct because the mechanism are not consistent. In our setup it adds 2% jitter.

With this patch clockevent multiplier and shifter mechanism are used when starting hrtimer for decrementer emulation. Now the jitter is < 0.5%.

Signed-off-by: Bharat Bhushan <bharat.bhushan@freescale.com>
---
v2:
 - decrementer_clockevent is made non-static rather than a seprate API to get mult/shift

 arch/powerpc/include/asm/time.h |    1 +
 arch/powerpc/kernel/time.c      |    2 +-
 arch/powerpc/kvm/emulate.c      |    5 +++--
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/time.h b/arch/powerpc/include/asm/time.h
index 7eb10fb..b3c7959 100644
--- a/arch/powerpc/include/asm/time.h
+++ b/arch/powerpc/include/asm/time.h
@@ -28,6 +28,7 @@
 extern unsigned long tb_ticks_per_jiffy;
 extern unsigned long tb_ticks_per_usec;
 extern unsigned long tb_ticks_per_sec;
+extern struct clock_event_device decrementer_clockevent;
 
 struct rtc_time;
 extern void to_tm(int tim, struct rtc_time * tm);
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 567dd7c..e237225 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -105,7 +105,7 @@ static int decrementer_set_next_event(unsigned long evt,
 static void decrementer_set_mode(enum clock_event_mode mode,
 				 struct clock_event_device *dev);
 
-static struct clock_event_device decrementer_clockevent = {
+struct clock_event_device decrementer_clockevent = {
 	.name           = "decrementer",
 	.rating         = 200,
 	.irq            = 0,
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index afc9154..c8b5206 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -23,6 +23,7 @@
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/kvm_host.h>
+#include <linux/clockchips.h>
 
 #include <asm/reg.h>
 #include <asm/time.h>
@@ -104,8 +105,8 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
 	 */
 
 	dec_time = vcpu->arch.dec;
-	dec_time *= 1000;
-	do_div(dec_time, tb_ticks_per_usec);
+	dec_time = dec_time << decrementer_clockevent.shift;
+	do_div(dec_time, decrementer_clockevent.mult);
 	dec_nsec = do_div(dec_time, NSEC_PER_SEC);
 	hrtimer_start(&vcpu->arch.dec_timer,
 		ktime_set(dec_time, dec_nsec), HRTIMER_MODE_REL);
-- 
1.7.0.4



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

* Re: [PATCH v2] KVM: PPC: Use clockevent multiplier and shifter for decrementer
  2012-04-09  4:45 ` Bharat Bhushan
  (?)
@ 2012-04-16 13:22   ` Alexander Graf
  -1 siblings, 0 replies; 5+ messages in thread
From: Alexander Graf @ 2012-04-16 13:22 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: linuxppc-dev, kvm-ppc, kvm, Bharat Bhushan


On 09.04.2012, at 06:33, Bharat Bhushan wrote:

> Time for which the hrtimer is started for decrementer emulation is calculated using tb_ticks_per_usec. While hrtimer uses the clockevent for DEC reprogramming (if needed) and which calculate timebase ticks using the multiplier and shifter mechanism implemented within clockevent layer. It was observed that this conversion (timebase->time->timebase) are not correct because the mechanism are not consistent. In our setup it adds 2% jitter.
> 
> With this patch clockevent multiplier and shifter mechanism are used when starting hrtimer for decrementer emulation. Now the jitter is < 0.5%.
> 
> Signed-off-by: Bharat Bhushan <bharat.bhushan@freescale.com>
> ---
> v2:
> - decrementer_clockevent is made non-static rather than a seprate API to get mult/shift
> 
> arch/powerpc/include/asm/time.h |    1 +
> arch/powerpc/kernel/time.c      |    2 +-
> arch/powerpc/kvm/emulate.c      |    5 +++--
> 3 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/time.h b/arch/powerpc/include/asm/time.h
> index 7eb10fb..b3c7959 100644
> --- a/arch/powerpc/include/asm/time.h
> +++ b/arch/powerpc/include/asm/time.h
> @@ -28,6 +28,7 @@
> extern unsigned long tb_ticks_per_jiffy;
> extern unsigned long tb_ticks_per_usec;
> extern unsigned long tb_ticks_per_sec;
> +extern struct clock_event_device decrementer_clockevent;
> 
> struct rtc_time;
> extern void to_tm(int tim, struct rtc_time * tm);
> diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
> index 567dd7c..e237225 100644
> --- a/arch/powerpc/kernel/time.c
> +++ b/arch/powerpc/kernel/time.c
> @@ -105,7 +105,7 @@ static int decrementer_set_next_event(unsigned long evt,
> static void decrementer_set_mode(enum clock_event_mode mode,
> 				 struct clock_event_device *dev);
> 
> -static struct clock_event_device decrementer_clockevent = {
> +struct clock_event_device decrementer_clockevent = {

This one also needs a EXPORT_SYMBOL ...

> 	.name           = "decrementer",
> 	.rating         = 200,
> 	.irq            = 0,
> diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
> index afc9154..c8b5206 100644
> --- a/arch/powerpc/kvm/emulate.c
> +++ b/arch/powerpc/kvm/emulate.c
> @@ -23,6 +23,7 @@
> #include <linux/types.h>
> #include <linux/string.h>
> #include <linux/kvm_host.h>
> +#include <linux/clockchips.h>
> 
> #include <asm/reg.h>
> #include <asm/time.h>
> @@ -104,8 +105,8 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
> 	 */
> 
> 	dec_time = vcpu->arch.dec;
> -	dec_time *= 1000;
> -	do_div(dec_time, tb_ticks_per_usec);
> +	dec_time = dec_time << decrementer_clockevent.shift;
> +	do_div(dec_time, decrementer_clockevent.mult);

... because emulate.c can be built as a module.


Alex


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

* Re: [PATCH v2] KVM: PPC: Use clockevent multiplier and shifter for decrementer
@ 2012-04-16 13:22   ` Alexander Graf
  0 siblings, 0 replies; 5+ messages in thread
From: Alexander Graf @ 2012-04-16 13:22 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: Bharat Bhushan, linuxppc-dev, kvm, kvm-ppc


On 09.04.2012, at 06:33, Bharat Bhushan wrote:

> Time for which the hrtimer is started for decrementer emulation is =
calculated using tb_ticks_per_usec. While hrtimer uses the clockevent =
for DEC reprogramming (if needed) and which calculate timebase ticks =
using the multiplier and shifter mechanism implemented within clockevent =
layer. It was observed that this conversion (timebase->time->timebase) =
are not correct because the mechanism are not consistent. In our setup =
it adds 2% jitter.
>=20
> With this patch clockevent multiplier and shifter mechanism are used =
when starting hrtimer for decrementer emulation. Now the jitter is < =
0.5%.
>=20
> Signed-off-by: Bharat Bhushan <bharat.bhushan@freescale.com>
> ---
> v2:
> - decrementer_clockevent is made non-static rather than a seprate API =
to get mult/shift
>=20
> arch/powerpc/include/asm/time.h |    1 +
> arch/powerpc/kernel/time.c      |    2 +-
> arch/powerpc/kvm/emulate.c      |    5 +++--
> 3 files changed, 5 insertions(+), 3 deletions(-)
>=20
> diff --git a/arch/powerpc/include/asm/time.h =
b/arch/powerpc/include/asm/time.h
> index 7eb10fb..b3c7959 100644
> --- a/arch/powerpc/include/asm/time.h
> +++ b/arch/powerpc/include/asm/time.h
> @@ -28,6 +28,7 @@
> extern unsigned long tb_ticks_per_jiffy;
> extern unsigned long tb_ticks_per_usec;
> extern unsigned long tb_ticks_per_sec;
> +extern struct clock_event_device decrementer_clockevent;
>=20
> struct rtc_time;
> extern void to_tm(int tim, struct rtc_time * tm);
> diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
> index 567dd7c..e237225 100644
> --- a/arch/powerpc/kernel/time.c
> +++ b/arch/powerpc/kernel/time.c
> @@ -105,7 +105,7 @@ static int decrementer_set_next_event(unsigned =
long evt,
> static void decrementer_set_mode(enum clock_event_mode mode,
> 				 struct clock_event_device *dev);
>=20
> -static struct clock_event_device decrementer_clockevent =3D {
> +struct clock_event_device decrementer_clockevent =3D {

This one also needs a EXPORT_SYMBOL ...

> 	.name           =3D "decrementer",
> 	.rating         =3D 200,
> 	.irq            =3D 0,
> diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
> index afc9154..c8b5206 100644
> --- a/arch/powerpc/kvm/emulate.c
> +++ b/arch/powerpc/kvm/emulate.c
> @@ -23,6 +23,7 @@
> #include <linux/types.h>
> #include <linux/string.h>
> #include <linux/kvm_host.h>
> +#include <linux/clockchips.h>
>=20
> #include <asm/reg.h>
> #include <asm/time.h>
> @@ -104,8 +105,8 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
> 	 */
>=20
> 	dec_time =3D vcpu->arch.dec;
> -	dec_time *=3D 1000;
> -	do_div(dec_time, tb_ticks_per_usec);
> +	dec_time =3D dec_time << decrementer_clockevent.shift;
> +	do_div(dec_time, decrementer_clockevent.mult);

... because emulate.c can be built as a module.


Alex

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

* Re: [PATCH v2] KVM: PPC: Use clockevent multiplier and shifter for decrementer
@ 2012-04-16 13:22   ` Alexander Graf
  0 siblings, 0 replies; 5+ messages in thread
From: Alexander Graf @ 2012-04-16 13:22 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: linuxppc-dev, kvm-ppc, kvm, Bharat Bhushan


On 09.04.2012, at 06:33, Bharat Bhushan wrote:

> Time for which the hrtimer is started for decrementer emulation is calculated using tb_ticks_per_usec. While hrtimer uses the clockevent for DEC reprogramming (if needed) and which calculate timebase ticks using the multiplier and shifter mechanism implemented within clockevent layer. It was observed that this conversion (timebase->time->timebase) are not correct because the mechanism are not consistent. In our setup it adds 2% jitter.
> 
> With this patch clockevent multiplier and shifter mechanism are used when starting hrtimer for decrementer emulation. Now the jitter is < 0.5%.
> 
> Signed-off-by: Bharat Bhushan <bharat.bhushan@freescale.com>
> ---
> v2:
> - decrementer_clockevent is made non-static rather than a seprate API to get mult/shift
> 
> arch/powerpc/include/asm/time.h |    1 +
> arch/powerpc/kernel/time.c      |    2 +-
> arch/powerpc/kvm/emulate.c      |    5 +++--
> 3 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/time.h b/arch/powerpc/include/asm/time.h
> index 7eb10fb..b3c7959 100644
> --- a/arch/powerpc/include/asm/time.h
> +++ b/arch/powerpc/include/asm/time.h
> @@ -28,6 +28,7 @@
> extern unsigned long tb_ticks_per_jiffy;
> extern unsigned long tb_ticks_per_usec;
> extern unsigned long tb_ticks_per_sec;
> +extern struct clock_event_device decrementer_clockevent;
> 
> struct rtc_time;
> extern void to_tm(int tim, struct rtc_time * tm);
> diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
> index 567dd7c..e237225 100644
> --- a/arch/powerpc/kernel/time.c
> +++ b/arch/powerpc/kernel/time.c
> @@ -105,7 +105,7 @@ static int decrementer_set_next_event(unsigned long evt,
> static void decrementer_set_mode(enum clock_event_mode mode,
> 				 struct clock_event_device *dev);
> 
> -static struct clock_event_device decrementer_clockevent = {
> +struct clock_event_device decrementer_clockevent = {

This one also needs a EXPORT_SYMBOL ...

> 	.name           = "decrementer",
> 	.rating         = 200,
> 	.irq            = 0,
> diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
> index afc9154..c8b5206 100644
> --- a/arch/powerpc/kvm/emulate.c
> +++ b/arch/powerpc/kvm/emulate.c
> @@ -23,6 +23,7 @@
> #include <linux/types.h>
> #include <linux/string.h>
> #include <linux/kvm_host.h>
> +#include <linux/clockchips.h>
> 
> #include <asm/reg.h>
> #include <asm/time.h>
> @@ -104,8 +105,8 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
> 	 */
> 
> 	dec_time = vcpu->arch.dec;
> -	dec_time *= 1000;
> -	do_div(dec_time, tb_ticks_per_usec);
> +	dec_time = dec_time << decrementer_clockevent.shift;
> +	do_div(dec_time, decrementer_clockevent.mult);

... because emulate.c can be built as a module.


Alex


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

end of thread, other threads:[~2012-04-16 13:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-09  4:33 [PATCH v2] KVM: PPC: Use clockevent multiplier and shifter for decrementer Bharat Bhushan
2012-04-09  4:45 ` Bharat Bhushan
2012-04-16 13:22 ` Alexander Graf
2012-04-16 13:22   ` Alexander Graf
2012-04-16 13:22   ` Alexander Graf

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.