Merge tag 'trace-v4.15' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[sfrench/cifs-2.6.git] / arch / s390 / kernel / vdso64 / clock_gettime.S
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 */
36 0:      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
50 1:      clg     %r1,0(%r5)
51         jl      2f
52         slg     %r1,0(%r5)
53         aghi    %r0,1
54         j       1b
55 2:      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 */
62 3:      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 */
72 4:      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 */
82 5:      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 */
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 */
103         jne     5b
104         larl    %r5,13f
105 6:      clg     %r1,0(%r5)
106         jl      7f
107         slg     %r1,0(%r5)
108         aghi    %r0,1
109         j       6b
110 7:      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 */
117 9:      lghi    %r4,0
118         icm     %r0,15,__VDSO_ECTG_OK(%r5)
119         jz      12f
120         sacf    256                             /* Magic ectg instruction */
121         .insn   ssf,0xc80100000000,__VDSO_ECTG_BASE(4),__VDSO_ECTG_USER(4),4
122         sacf    0
123         algr    %r1,%r0                         /* r1 = cputime as TOD value */
124         mghi    %r1,1000                        /* convert to nanoseconds */
125         srlg    %r1,%r1,12                      /* r1 = cputime in nanosec */
126         lgr     %r4,%r1
127         larl    %r5,13f
128         srlg    %r1,%r1,9                       /* divide by 1000000000 */
129         mlg     %r0,8(%r5)
130         srlg    %r0,%r0,11                      /* r0 = tv_sec */
131         stg     %r0,0(%r3)
132         msg     %r0,0(%r5)                      /* calculate tv_nsec */
133         slgr    %r4,%r0                         /* r4 = tv_nsec */
134         stg     %r4,8(%r3)
135         lghi    %r2,0
136         aghi    %r15,16
137         br      %r14
138
139         /* Fallback to system call */
140 12:     lghi    %r1,__NR_clock_gettime
141         svc     0
142         aghi    %r15,16
143         br      %r14
144
145 13:     .quad   1000000000
146 14:     .quad   19342813113834067
147         .cfi_endproc
148         .size   __kernel_clock_gettime,.-__kernel_clock_gettime