Clean and improve time related helpers
cover Clean and improve time related helpers
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(-)
Signature · 1 line
2.1.4
PATCH 1/5 target-s390x: add a tod2time function
Add a tod2time function similar to the time2tod one, instead of open coding the conversion.
--- target-s390x/cpu.h | 5 +++++ target-s390x/misc_helper.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-)
target-s390x/cpu.h +5 -0
@@ -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) {
target-s390x/misc_helper.c +2 -2
@@ -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); }
Signature · 1 line
2.1.4
PATCH 2/5 target-s390x: simplify SCKC helper
In reply to Aurelien JarnoThe 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.
--- target-s390x/misc_helper.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
target-s390x/misc_helper.c +4 -3
@@ -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 */
Signature · 1 line
2.1.4
PATCH 3/5 target-s390x: streamline STCK helper
In reply to Aurelien JarnoNow that clock_value is only used in one place, we can inline it in the STCK helper.
--- target-s390x/misc_helper.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
target-s390x/misc_helper.c +2 -7
@@ -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) {
Signature · 1 line
2.1.4
PATCH 4/5 target-s390x: implement STCKC helper
In reply to Aurelien JarnoThe STCKC instruction just returns the last written clock comparator value and KVM already provides the corresponding variable.
--- target-s390x/misc_helper.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target-s390x/misc_helper.c +3 -2
@@ -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 */
Signature · 1 line
2.1.4
PATCH 5/5 target-s390x: implement STPT helper
In reply to Aurelien JarnoSave 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.
--- target-s390x/misc_helper.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
target-s390x/misc_helper.c +4 -3
@@ -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 */
Signature · 1 line
2.1.4
Alexander Graf
AppliedQuoted 3 lines · Aurelien Jarno
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