Loading...
Note: File does not exist in v6.8.
1/*
2 * Userland implementation of clock_gettime() for 64 bits processes in a
3 * s390 kernel for use in the vDSO
4 *
5 * Copyright IBM Corp. 2008
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
7 *
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.
11 */
12#include <asm/vdso.h>
13#include <asm/asm-offsets.h>
14#include <asm/unistd.h>
15
16 .text
17 .align 4
18 .globl __kernel_clock_gettime
19 .type __kernel_clock_gettime,@function
20__kernel_clock_gettime:
21 .cfi_startproc
22 aghi %r15,-16
23 larl %r5,_vdso_data
24 cghi %r2,__CLOCK_REALTIME_COARSE
25 je 4f
26 cghi %r2,__CLOCK_REALTIME
27 je 5f
28 cghi %r2,-3 /* Per-thread CPUCLOCK with PID=0, VIRT=1 */
29 je 9f
30 cghi %r2,__CLOCK_MONOTONIC_COARSE
31 je 3f
32 cghi %r2,__CLOCK_MONOTONIC
33 jne 12f
34
35 /* CLOCK_MONOTONIC */
360: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
37 tmll %r4,0x0001 /* pending update ? loop */
38 jnz 0b
39 stcke 0(%r15) /* Store TOD clock */
40 lgf %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
41 lg %r0,__VDSO_WTOM_SEC(%r5)
42 lg %r1,1(%r15)
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 */
48 jne 0b
49 larl %r5,13f
501: clg %r1,0(%r5)
51 jl 2f
52 slg %r1,0(%r5)
53 aghi %r0,1
54 j 1b
552: stg %r0,0(%r3) /* store tp->tv_sec */
56 stg %r1,8(%r3) /* store tp->tv_nsec */
57 lghi %r2,0
58 aghi %r15,16
59 br %r14
60
61 /* CLOCK_MONOTONIC_COARSE */
623: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
63 tmll %r4,0x0001 /* pending update ? loop */
64 jnz 3b
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 */
68 jne 3b
69 j 2b
70
71 /* CLOCK_REALTIME_COARSE */
724: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
73 tmll %r4,0x0001 /* pending update ? loop */
74 jnz 4b
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 */
78 jne 4b
79 j 7f
80
81 /* CLOCK_REALTIME */
825: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
83 tmll %r4,0x0001 /* pending update ? loop */
84 jnz 5b
85 stcke 0(%r15) /* Store TOD clock */
86 lg %r1,1(%r15)
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 ? */
90 jm 17f
91 srlg %r0,%r0,15 /* 1 per 2^16 */
92 tm __VDSO_TS_DIR+3(%r5),0x01 /* steering direction? */
93 jz 18f
94 lcgr %r0,%r0 /* negative TOD offset */
9518: algr %r1,%r0 /* add steering offset */
9617: 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 */
103 jne 5b
104 larl %r5,13f
1056: clg %r1,0(%r5)
106 jl 7f
107 slg %r1,0(%r5)
108 aghi %r0,1
109 j 6b
1107: stg %r0,0(%r3) /* store tp->tv_sec */
111 stg %r1,8(%r3) /* store tp->tv_nsec */
112 lghi %r2,0
113 aghi %r15,16
114 br %r14
115
116 /* CPUCLOCK_VIRT for this thread */
1179: icm %r0,15,__VDSO_ECTG_OK(%r5)
118 jz 12f
119 ear %r2,%a4
120 llilh %r4,0x0100
121 sar %a4,%r4
122 lghi %r4,0
123 epsw %r5,0
124 sacf 512 /* Magic ectg instruction */
125 .insn ssf,0xc80100000000,__VDSO_ECTG_BASE(4),__VDSO_ECTG_USER(4),4
126 tml %r5,0x4000
127 jo 11f
128 tml %r5,0x8000
129 jno 10f
130 sacf 256
131 j 11f
13210: sacf 0
13311: sar %a4,%r2
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 */
137 lgr %r4,%r1
138 larl %r5,13f
139 srlg %r1,%r1,9 /* divide by 1000000000 */
140 mlg %r0,8(%r5)
141 srlg %r0,%r0,11 /* r0 = tv_sec */
142 stg %r0,0(%r3)
143 msg %r0,0(%r5) /* calculate tv_nsec */
144 slgr %r4,%r0 /* r4 = tv_nsec */
145 stg %r4,8(%r3)
146 lghi %r2,0
147 aghi %r15,16
148 br %r14
149
150 /* Fallback to system call */
15112: lghi %r1,__NR_clock_gettime
152 svc 0
153 aghi %r15,16
154 br %r14
155
15613: .quad 1000000000
15714: .quad 19342813113834067
158 .cfi_endproc
159 .size __kernel_clock_gettime,.-__kernel_clock_gettime