qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/5] Clean and improve time related helpers
@ 2015-05-18 21:42 Aurelien Jarno
  2015-05-18 21:42 ` [Qemu-devel] [PATCH 1/5] target-s390x: add a tod2time function Aurelien Jarno
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Aurelien Jarno @ 2015-05-18 21:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alexander Graf, Aurelien Jarno, Richard Henderson

This patch series cleans and improves the time-of-day clock and CPU
timer. Most notably it implements the STPT instruction, which allow
the Linux kernel to do time accouting (so top reports correct values).

Aurelien Jarno (5):
  target-s390x: add a tod2time function
  target-s390x: simplify SCKC helper
  target-s390x: streamline STCK helper
  target-s390x: implement STCKC helper
  target-s390x: implement STPT helper

 target-s390x/cpu.h         |  5 +++++
 target-s390x/misc_helper.c | 32 +++++++++++++++-----------------
 2 files changed, 20 insertions(+), 17 deletions(-)

-- 
2.1.4

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

* [Qemu-devel] [PATCH 1/5] target-s390x: add a tod2time function
  2015-05-18 21:42 [Qemu-devel] [PATCH 0/5] Clean and improve time related helpers Aurelien Jarno
@ 2015-05-18 21:42 ` Aurelien Jarno
  2015-05-18 21:42 ` [Qemu-devel] [PATCH 2/5] target-s390x: simplify SCKC helper Aurelien Jarno
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Aurelien Jarno @ 2015-05-18 21:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alexander Graf, Aurelien Jarno, Richard Henderson

Add a tod2time function similar to the time2tod one, instead of open
coding the conversion.

Cc: Alexander Graf <agraf@suse.de>
Cc: Richard Henderson <rth@twiddle.net>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 target-s390x/cpu.h         | 5 +++++
 target-s390x/misc_helper.c | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 8135dda..28aa39d 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -970,6 +970,11 @@ static inline uint64_t time2tod(uint64_t ns) {
     return (ns << 9) / 125;
 }
 
+/* Converts s390's clock format to ns */
+static inline uint64_t tod2time(uint64_t t) {
+    return (t * 125) >> 9;
+}
+
 static inline void cpu_inject_ext(S390CPU *cpu, uint32_t code, uint32_t param,
                                   uint64_t param64)
 {
diff --git a/target-s390x/misc_helper.c b/target-s390x/misc_helper.c
index e1007fa..230bafd 100644
--- a/target-s390x/misc_helper.c
+++ b/target-s390x/misc_helper.c
@@ -294,7 +294,7 @@ void HELPER(sckc)(CPUS390XState *env, uint64_t time)
     /* difference between now and then */
     time -= clock_value(env);
     /* nanoseconds */
-    time = (time * 125) >> 9;
+    time = tod2time(time);
 
     timer_mod(env->tod_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + time);
 }
@@ -314,7 +314,7 @@ void HELPER(spt)(CPUS390XState *env, uint64_t time)
     }
 
     /* nanoseconds */
-    time = (time * 125) >> 9;
+    time = tod2time(time);
 
     timer_mod(env->cpu_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + time);
 }
-- 
2.1.4

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

* [Qemu-devel] [PATCH 2/5] target-s390x: simplify SCKC helper
  2015-05-18 21:42 [Qemu-devel] [PATCH 0/5] Clean and improve time related helpers Aurelien Jarno
  2015-05-18 21:42 ` [Qemu-devel] [PATCH 1/5] target-s390x: add a tod2time function Aurelien Jarno
@ 2015-05-18 21:42 ` Aurelien Jarno
  2015-05-18 21:42 ` [Qemu-devel] [PATCH 3/5] target-s390x: streamline STCK helper Aurelien Jarno
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Aurelien Jarno @ 2015-05-18 21:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alexander Graf, Aurelien Jarno, Richard Henderson

The clock comparator and the QEMU timer work the same way, triggering
at a given time, they just differ by the origin and the scale. It is
therefore possible to go from one to another without using the current
clock value. This spares two calls to qemu_clock_get_ns, which probably
return slightly different values, possibly reducing the accuracy.

Cc: Alexander Graf <agraf@suse.de>
Cc: Richard Henderson <rth@twiddle.net>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 target-s390x/misc_helper.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/target-s390x/misc_helper.c b/target-s390x/misc_helper.c
index 230bafd..120807f 100644
--- a/target-s390x/misc_helper.c
+++ b/target-s390x/misc_helper.c
@@ -291,12 +291,13 @@ void HELPER(sckc)(CPUS390XState *env, uint64_t time)
         return;
     }
 
-    /* difference between now and then */
-    time -= clock_value(env);
+    /* difference between origins */
+    time -= env->tod_offset;
+
     /* nanoseconds */
     time = tod2time(time);
 
-    timer_mod(env->tod_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + time);
+    timer_mod(env->tod_timer, env->tod_basetime + time);
 }
 
 /* Store Clock Comparator */
-- 
2.1.4

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

* [Qemu-devel] [PATCH 3/5] target-s390x: streamline STCK helper
  2015-05-18 21:42 [Qemu-devel] [PATCH 0/5] Clean and improve time related helpers Aurelien Jarno
  2015-05-18 21:42 ` [Qemu-devel] [PATCH 1/5] target-s390x: add a tod2time function Aurelien Jarno
  2015-05-18 21:42 ` [Qemu-devel] [PATCH 2/5] target-s390x: simplify SCKC helper Aurelien Jarno
@ 2015-05-18 21:42 ` Aurelien Jarno
  2015-05-18 21:42 ` [Qemu-devel] [PATCH 4/5] target-s390x: implement STCKC helper Aurelien Jarno
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Aurelien Jarno @ 2015-05-18 21:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alexander Graf, Aurelien Jarno, Richard Henderson

Now that clock_value is only used in one place, we can inline it in
the STCK helper.

Cc: Alexander Graf <agraf@suse.de>
Cc: Richard Henderson <rth@twiddle.net>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 target-s390x/misc_helper.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/target-s390x/misc_helper.c b/target-s390x/misc_helper.c
index 120807f..fa105fa 100644
--- a/target-s390x/misc_helper.c
+++ b/target-s390x/misc_helper.c
@@ -268,7 +268,8 @@ void HELPER(spx)(CPUS390XState *env, uint64_t a1)
     tlb_flush_page(cs, TARGET_PAGE_SIZE);
 }
 
-static inline uint64_t clock_value(CPUS390XState *env)
+/* Store Clock */
+uint64_t HELPER(stck)(CPUS390XState *env)
 {
     uint64_t time;
 
@@ -278,12 +279,6 @@ static inline uint64_t clock_value(CPUS390XState *env)
     return time;
 }
 
-/* Store Clock */
-uint64_t HELPER(stck)(CPUS390XState *env)
-{
-    return clock_value(env);
-}
-
 /* Set Clock Comparator */
 void HELPER(sckc)(CPUS390XState *env, uint64_t time)
 {
-- 
2.1.4

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

* [Qemu-devel] [PATCH 4/5] target-s390x: implement STCKC helper
  2015-05-18 21:42 [Qemu-devel] [PATCH 0/5] Clean and improve time related helpers Aurelien Jarno
                   ` (2 preceding siblings ...)
  2015-05-18 21:42 ` [Qemu-devel] [PATCH 3/5] target-s390x: streamline STCK helper Aurelien Jarno
@ 2015-05-18 21:42 ` Aurelien Jarno
  2015-05-18 21:42 ` [Qemu-devel] [PATCH 5/5] target-s390x: implement STPT helper Aurelien Jarno
  2015-05-25 22:02 ` [Qemu-devel] [PATCH 0/5] Clean and improve time related helpers Alexander Graf
  5 siblings, 0 replies; 7+ messages in thread
From: Aurelien Jarno @ 2015-05-18 21:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alexander Graf, Aurelien Jarno, Richard Henderson

The STCKC instruction just returns the last written clock comparator
value and KVM already provides the corresponding variable.

Cc: Alexander Graf <agraf@suse.de>
Cc: Richard Henderson <rth@twiddle.net>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 target-s390x/misc_helper.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/target-s390x/misc_helper.c b/target-s390x/misc_helper.c
index fa105fa..57aee95 100644
--- a/target-s390x/misc_helper.c
+++ b/target-s390x/misc_helper.c
@@ -286,6 +286,8 @@ void HELPER(sckc)(CPUS390XState *env, uint64_t time)
         return;
     }
 
+    env->ckc = time;
+
     /* difference between origins */
     time -= env->tod_offset;
 
@@ -298,8 +300,7 @@ void HELPER(sckc)(CPUS390XState *env, uint64_t time)
 /* Store Clock Comparator */
 uint64_t HELPER(stckc)(CPUS390XState *env)
 {
-    /* XXX implement */
-    return 0;
+    return env->ckc;
 }
 
 /* Set CPU Timer */
-- 
2.1.4

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

* [Qemu-devel] [PATCH 5/5] target-s390x: implement STPT helper
  2015-05-18 21:42 [Qemu-devel] [PATCH 0/5] Clean and improve time related helpers Aurelien Jarno
                   ` (3 preceding siblings ...)
  2015-05-18 21:42 ` [Qemu-devel] [PATCH 4/5] target-s390x: implement STCKC helper Aurelien Jarno
@ 2015-05-18 21:42 ` Aurelien Jarno
  2015-05-25 22:02 ` [Qemu-devel] [PATCH 0/5] Clean and improve time related helpers Alexander Graf
  5 siblings, 0 replies; 7+ messages in thread
From: Aurelien Jarno @ 2015-05-18 21:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alexander Graf, Aurelien Jarno, Richard Henderson

Save the timer target value in the SPT helper, so that the STPT helper
can compute the remaining time.

This allow the Linux kernel to correctly do time accounting.

Cc: Alexander Graf <agraf@suse.de>
Cc: Richard Henderson <rth@twiddle.net>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 target-s390x/misc_helper.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/target-s390x/misc_helper.c b/target-s390x/misc_helper.c
index 57aee95..3ec7268 100644
--- a/target-s390x/misc_helper.c
+++ b/target-s390x/misc_helper.c
@@ -313,14 +313,15 @@ void HELPER(spt)(CPUS390XState *env, uint64_t time)
     /* nanoseconds */
     time = tod2time(time);
 
-    timer_mod(env->cpu_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + time);
+    env->cputm = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + time;
+
+    timer_mod(env->cpu_timer, env->cputm);
 }
 
 /* Store CPU Timer */
 uint64_t HELPER(stpt)(CPUS390XState *env)
 {
-    /* XXX implement */
-    return 0;
+    return time2tod(env->cputm - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
 }
 
 /* Store System Information */
-- 
2.1.4

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

* Re: [Qemu-devel] [PATCH 0/5] Clean and improve time related helpers
  2015-05-18 21:42 [Qemu-devel] [PATCH 0/5] Clean and improve time related helpers Aurelien Jarno
                   ` (4 preceding siblings ...)
  2015-05-18 21:42 ` [Qemu-devel] [PATCH 5/5] target-s390x: implement STPT helper Aurelien Jarno
@ 2015-05-25 22:02 ` Alexander Graf
  5 siblings, 0 replies; 7+ messages in thread
From: Alexander Graf @ 2015-05-25 22:02 UTC (permalink / raw)
  To: Aurelien Jarno, qemu-devel; +Cc: Richard Henderson



On 18.05.15 23:42, Aurelien Jarno wrote:
> This patch series cleans and improves the time-of-day clock and CPU
> timer. Most notably it implements the STPT instruction, which allow
> the Linux kernel to do time accouting (so top reports correct values).

Thanks, applied all to s390-next.


Alex

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

end of thread, other threads:[~2015-05-25 22:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-18 21:42 [Qemu-devel] [PATCH 0/5] Clean and improve time related helpers Aurelien Jarno
2015-05-18 21:42 ` [Qemu-devel] [PATCH 1/5] target-s390x: add a tod2time function Aurelien Jarno
2015-05-18 21:42 ` [Qemu-devel] [PATCH 2/5] target-s390x: simplify SCKC helper Aurelien Jarno
2015-05-18 21:42 ` [Qemu-devel] [PATCH 3/5] target-s390x: streamline STCK helper Aurelien Jarno
2015-05-18 21:42 ` [Qemu-devel] [PATCH 4/5] target-s390x: implement STCKC helper Aurelien Jarno
2015-05-18 21:42 ` [Qemu-devel] [PATCH 5/5] target-s390x: implement STPT helper Aurelien Jarno
2015-05-25 22:02 ` [Qemu-devel] [PATCH 0/5] Clean and improve time related helpers Alexander Graf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).