Message ID | 20221011170024.972135-2-nrb@linux.ibm.com (mailing list archive) |
---|---|
State | Mainlined |
Headers | show |
Series | s390x: Add migration test for guest TOD clock | expand |
On Tue, 11 Oct 2022 19:00:23 +0200 Nico Boehr <nrb@linux.ibm.com> wrote: > The TOD-clock related functions can be useful for other tests beside the > sck test, hence move them to the library. > > While at it, add a wrapper for stckf, express get_clock_us() with > stck() and remove an unneeded memory clobber. > > Signed-off-by: Nico Boehr <nrb@linux.ibm.com> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com> > --- > lib/s390x/asm/time.h | 50 +++++++++++++++++++++++++++++++++++++++++++- > s390x/sck.c | 32 ---------------------------- > 2 files changed, 49 insertions(+), 33 deletions(-) > > diff --git a/lib/s390x/asm/time.h b/lib/s390x/asm/time.h > index d8d91d68a667..ad689b098eab 100644 > --- a/lib/s390x/asm/time.h > +++ b/lib/s390x/asm/time.h > @@ -18,11 +18,59 @@ > > #define CPU_TIMER_SHIFT_US S390_CLOCK_SHIFT_US > > +static inline int sck(uint64_t *time) > +{ > + int cc; > + > + asm volatile( > + " sck %[time]\n" > + " ipm %[cc]\n" > + " srl %[cc],28\n" > + : [cc] "=d"(cc) > + : [time] "Q"(*time) > + : "cc" > + ); > + > + return cc; > +} > + > +static inline int stck(uint64_t *time) > +{ > + int cc; > + > + asm volatile( > + " stck %[time]\n" > + " ipm %[cc]\n" > + " srl %[cc],28\n" > + : [cc] "=d" (cc), [time] "=Q" (*time) > + : > + : "cc" > + ); > + > + return cc; > +} > + > +static inline int stckf(uint64_t *time) > +{ > + int cc; > + > + asm volatile( > + " stckf %[time]\n" > + " ipm %[cc]\n" > + " srl %[cc],28\n" > + : [cc] "=d" (cc), [time] "=Q" (*time) > + : > + : "cc" > + ); > + > + return cc; > +} > + > static inline uint64_t get_clock_us(void) > { > uint64_t clk; > > - asm volatile(" stck %0 " : : "Q"(clk) : "memory"); > + stck(&clk); > > return clk >> STCK_SHIFT_US; > } > diff --git a/s390x/sck.c b/s390x/sck.c > index 88d52b74a586..dff496187602 100644 > --- a/s390x/sck.c > +++ b/s390x/sck.c > @@ -12,38 +12,6 @@ > #include <asm/interrupt.h> > #include <asm/time.h> > > -static inline int sck(uint64_t *time) > -{ > - int cc; > - > - asm volatile( > - " sck %[time]\n" > - " ipm %[cc]\n" > - " srl %[cc],28\n" > - : [cc] "=d"(cc) > - : [time] "Q"(*time) > - : "cc" > - ); > - > - return cc; > -} > - > -static inline int stck(uint64_t *time) > -{ > - int cc; > - > - asm volatile( > - " stck %[time]\n" > - " ipm %[cc]\n" > - " srl %[cc],28\n" > - : [cc] "=d" (cc), [time] "=Q" (*time) > - : > - : "cc", "memory" > - ); > - > - return cc; > -} > - > static void test_priv(void) > { > uint64_t time_to_set_privileged = 0xfacef00dcafe0000,
diff --git a/lib/s390x/asm/time.h b/lib/s390x/asm/time.h index d8d91d68a667..ad689b098eab 100644 --- a/lib/s390x/asm/time.h +++ b/lib/s390x/asm/time.h @@ -18,11 +18,59 @@ #define CPU_TIMER_SHIFT_US S390_CLOCK_SHIFT_US +static inline int sck(uint64_t *time) +{ + int cc; + + asm volatile( + " sck %[time]\n" + " ipm %[cc]\n" + " srl %[cc],28\n" + : [cc] "=d"(cc) + : [time] "Q"(*time) + : "cc" + ); + + return cc; +} + +static inline int stck(uint64_t *time) +{ + int cc; + + asm volatile( + " stck %[time]\n" + " ipm %[cc]\n" + " srl %[cc],28\n" + : [cc] "=d" (cc), [time] "=Q" (*time) + : + : "cc" + ); + + return cc; +} + +static inline int stckf(uint64_t *time) +{ + int cc; + + asm volatile( + " stckf %[time]\n" + " ipm %[cc]\n" + " srl %[cc],28\n" + : [cc] "=d" (cc), [time] "=Q" (*time) + : + : "cc" + ); + + return cc; +} + static inline uint64_t get_clock_us(void) { uint64_t clk; - asm volatile(" stck %0 " : : "Q"(clk) : "memory"); + stck(&clk); return clk >> STCK_SHIFT_US; } diff --git a/s390x/sck.c b/s390x/sck.c index 88d52b74a586..dff496187602 100644 --- a/s390x/sck.c +++ b/s390x/sck.c @@ -12,38 +12,6 @@ #include <asm/interrupt.h> #include <asm/time.h> -static inline int sck(uint64_t *time) -{ - int cc; - - asm volatile( - " sck %[time]\n" - " ipm %[cc]\n" - " srl %[cc],28\n" - : [cc] "=d"(cc) - : [time] "Q"(*time) - : "cc" - ); - - return cc; -} - -static inline int stck(uint64_t *time) -{ - int cc; - - asm volatile( - " stck %[time]\n" - " ipm %[cc]\n" - " srl %[cc],28\n" - : [cc] "=d" (cc), [time] "=Q" (*time) - : - : "cc", "memory" - ); - - return cc; -} - static void test_priv(void) { uint64_t time_to_set_privileged = 0xfacef00dcafe0000,
The TOD-clock related functions can be useful for other tests beside the sck test, hence move them to the library. While at it, add a wrapper for stckf, express get_clock_us() with stck() and remove an unneeded memory clobber. Signed-off-by: Nico Boehr <nrb@linux.ibm.com> --- lib/s390x/asm/time.h | 50 +++++++++++++++++++++++++++++++++++++++++++- s390x/sck.c | 32 ---------------------------- 2 files changed, 49 insertions(+), 33 deletions(-)