xref: /kvm-unit-tests/lib/s390x/asm/time.h (revision 65b436f22a2986fb95a34f200dcc11bccb111ad9)
1*65b436f2SPierre Morel /*
2*65b436f2SPierre Morel  * Clock utilities for s390
3*65b436f2SPierre Morel  *
4*65b436f2SPierre Morel  * Authors:
5*65b436f2SPierre Morel  *  Thomas Huth <thuth@redhat.com>
6*65b436f2SPierre Morel  *
7*65b436f2SPierre Morel  * Copied from the s390/intercept test by:
8*65b436f2SPierre Morel  *  Pierre Morel <pmorel@linux.ibm.com>
9*65b436f2SPierre Morel  *
10*65b436f2SPierre Morel  * This code is free software; you can redistribute it and/or modify it
11*65b436f2SPierre Morel  * under the terms of the GNU General Public License version 2.
12*65b436f2SPierre Morel  */
13*65b436f2SPierre Morel #ifndef ASM_S390X_TIME_H
14*65b436f2SPierre Morel #define ASM_S390X_TIME_H
15*65b436f2SPierre Morel 
16*65b436f2SPierre Morel static inline uint64_t get_clock_ms(void)
17*65b436f2SPierre Morel {
18*65b436f2SPierre Morel 	uint64_t clk;
19*65b436f2SPierre Morel 
20*65b436f2SPierre Morel 	asm volatile(" stck %0 " : : "Q"(clk) : "memory");
21*65b436f2SPierre Morel 
22*65b436f2SPierre Morel 	/* Bit 51 is incrememented each microsecond */
23*65b436f2SPierre Morel 	return (clk >> (63 - 51)) / 1000;
24*65b436f2SPierre Morel }
25*65b436f2SPierre Morel 
26*65b436f2SPierre Morel #endif
27