2 * Userland implementation of clock_gettime() for 64 bits processes in a
3 * s390 kernel for use in the vDSO
5 * Copyright IBM Corp. 2008
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License (version 2 only)
10 * as published by the Free Software Foundation.
13 #include <asm/asm-offsets.h>
14 #include <asm/unistd.h>
18 .globl __kernel_clock_gettime
19 .type __kernel_clock_gettime,@function
20 __kernel_clock_gettime:
24 cghi %r2,__CLOCK_REALTIME_COARSE
26 cghi %r2,__CLOCK_REALTIME
28 cghi %r2,-3 /* Per-thread CPUCLOCK with PID=0, VIRT=1 */
30 cghi %r2,__CLOCK_MONOTONIC_COARSE
32 cghi %r2,__CLOCK_MONOTONIC
36 0: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
37 tmll %r4,0x0001 /* pending update ? loop */
39 stcke 0(%r15) /* Store TOD clock */
40 lgf %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
41 lg %r0,__VDSO_WTOM_SEC(%r5)
43 sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
44 msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */
45 alg %r1,__VDSO_WTOM_NSEC(%r5)
46 srlg %r1,%r1,0(%r2) /* >> tk->shift */
47 clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */
55 2: stg %r0,0(%r3) /* store tp->tv_sec */
56 stg %r1,8(%r3) /* store tp->tv_nsec */
61 /* CLOCK_MONOTONIC_COARSE */
62 3: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
63 tmll %r4,0x0001 /* pending update ? loop */
65 lg %r0,__VDSO_WTOM_CRS_SEC(%r5)
66 lg %r1,__VDSO_WTOM_CRS_NSEC(%r5)
67 clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */
71 /* CLOCK_REALTIME_COARSE */
72 4: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
73 tmll %r4,0x0001 /* pending update ? loop */
75 lg %r0,__VDSO_XTIME_CRS_SEC(%r5)
76 lg %r1,__VDSO_XTIME_CRS_NSEC(%r5)
77 clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */
82 5: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
83 tmll %r4,0x0001 /* pending update ? loop */
85 stcke 0(%r15) /* Store TOD clock */
87 lg %r0,__VDSO_TS_END(%r5) /* TOD steering end time */
88 slgr %r0,%r1 /* now - ts_steering_end */
89 ltgr %r0,%r0 /* past end of steering ? */
91 srlg %r0,%r0,15 /* 1 per 2^16 */
92 tm __VDSO_TS_DIR+3(%r5),0x01 /* steering direction? */
94 lcgr %r0,%r0 /* negative TOD offset */
95 18: algr %r1,%r0 /* add steering offset */
96 17: lgf %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
97 sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
98 msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */
99 alg %r1,__VDSO_XTIME_NSEC(%r5) /* + tk->xtime_nsec */
100 srlg %r1,%r1,0(%r2) /* >> tk->shift */
101 lg %r0,__VDSO_XTIME_SEC(%r5) /* tk->xtime_sec */
102 clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */
110 7: stg %r0,0(%r3) /* store tp->tv_sec */
111 stg %r1,8(%r3) /* store tp->tv_nsec */
116 /* CPUCLOCK_VIRT for this thread */
117 9: icm %r0,15,__VDSO_ECTG_OK(%r5)
124 sacf 512 /* Magic ectg instruction */
125 .insn ssf,0xc80100000000,__VDSO_ECTG_BASE(4),__VDSO_ECTG_USER(4),4
134 algr %r1,%r0 /* r1 = cputime as TOD value */
135 mghi %r1,1000 /* convert to nanoseconds */
136 srlg %r1,%r1,12 /* r1 = cputime in nanosec */
139 srlg %r1,%r1,9 /* divide by 1000000000 */
141 srlg %r0,%r0,11 /* r0 = tv_sec */
143 msg %r0,0(%r5) /* calculate tv_nsec */
144 slgr %r4,%r0 /* r4 = tv_nsec */
150 /* Fallback to system call */
151 12: lghi %r1,__NR_clock_gettime
157 14: .quad 19342813113834067
159 .size __kernel_clock_gettime,.-__kernel_clock_gettime