1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Userland implementation of clock_gettime() for 64 bits processes in a
4 * s390 kernel for use in the vDSO
6 * Copyright IBM Corp. 2008
7 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License (version 2 only)
11 * as published by the Free Software Foundation.
14 #include <asm/asm-offsets.h>
15 #include <asm/unistd.h>
19 .globl __kernel_clock_gettime
20 .type __kernel_clock_gettime,@function
21 __kernel_clock_gettime:
25 cghi %r2,__CLOCK_REALTIME_COARSE
27 cghi %r2,__CLOCK_REALTIME
29 cghi %r2,-3 /* Per-thread CPUCLOCK with PID=0, VIRT=1 */
31 cghi %r2,__CLOCK_MONOTONIC_COARSE
33 cghi %r2,__CLOCK_MONOTONIC
37 0: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
38 tmll %r4,0x0001 /* pending update ? loop */
40 stcke 0(%r15) /* Store TOD clock */
41 lgf %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
42 lg %r0,__VDSO_WTOM_SEC(%r5)
44 sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
45 msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */
46 alg %r1,__VDSO_WTOM_NSEC(%r5)
47 srlg %r1,%r1,0(%r2) /* >> tk->shift */
48 clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */
56 2: stg %r0,0(%r3) /* store tp->tv_sec */
57 stg %r1,8(%r3) /* store tp->tv_nsec */
62 /* CLOCK_MONOTONIC_COARSE */
63 3: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
64 tmll %r4,0x0001 /* pending update ? loop */
66 lg %r0,__VDSO_WTOM_CRS_SEC(%r5)
67 lg %r1,__VDSO_WTOM_CRS_NSEC(%r5)
68 clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */
72 /* CLOCK_REALTIME_COARSE */
73 4: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
74 tmll %r4,0x0001 /* pending update ? loop */
76 lg %r0,__VDSO_XTIME_CRS_SEC(%r5)
77 lg %r1,__VDSO_XTIME_CRS_NSEC(%r5)
78 clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */
83 5: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
84 tmll %r4,0x0001 /* pending update ? loop */
86 stcke 0(%r15) /* Store TOD clock */
88 lg %r0,__VDSO_TS_END(%r5) /* TOD steering end time */
89 slgr %r0,%r1 /* now - ts_steering_end */
90 ltgr %r0,%r0 /* past end of steering ? */
92 srlg %r0,%r0,15 /* 1 per 2^16 */
93 tm __VDSO_TS_DIR+3(%r5),0x01 /* steering direction? */
95 lcgr %r0,%r0 /* negative TOD offset */
96 18: algr %r1,%r0 /* add steering offset */
97 17: lgf %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
98 sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
99 msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */
100 alg %r1,__VDSO_XTIME_NSEC(%r5) /* + tk->xtime_nsec */
101 srlg %r1,%r1,0(%r2) /* >> tk->shift */
102 lg %r0,__VDSO_XTIME_SEC(%r5) /* tk->xtime_sec */
103 clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */
111 7: stg %r0,0(%r3) /* store tp->tv_sec */
112 stg %r1,8(%r3) /* store tp->tv_nsec */
117 /* CPUCLOCK_VIRT for this thread */
119 icm %r0,15,__VDSO_ECTG_OK(%r5)
121 sacf 256 /* Magic ectg instruction */
122 .insn ssf,0xc80100000000,__VDSO_ECTG_BASE(4),__VDSO_ECTG_USER(4),4
124 algr %r1,%r0 /* r1 = cputime as TOD value */
125 mghi %r1,1000 /* convert to nanoseconds */
126 srlg %r1,%r1,12 /* r1 = cputime in nanosec */
129 srlg %r1,%r1,9 /* divide by 1000000000 */
131 srlg %r0,%r0,11 /* r0 = tv_sec */
133 msg %r0,0(%r5) /* calculate tv_nsec */
134 slgr %r4,%r0 /* r4 = tv_nsec */
140 /* Fallback to system call */
141 12: lghi %r1,__NR_clock_gettime
147 14: .quad 19342813113834067
149 .size __kernel_clock_gettime,.-__kernel_clock_gettime