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:
23 cghi %r2,__CLOCK_REALTIME
25 cghi %r2,__CLOCK_THREAD_CPUTIME_ID
27 cghi %r2,-2 /* Per-thread CPUCLOCK with PID=0, VIRT=1 */
29 cghi %r2,__CLOCK_MONOTONIC
34 jz 3f /* tp == NULL */
35 0: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
36 tmll %r4,0x0001 /* pending update ? loop */
38 stck 48(%r15) /* Store TOD clock */
39 lgf %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
40 lg %r0,__VDSO_WTOM_SEC(%r5)
42 sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
43 msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */
44 alg %r1,__VDSO_WTOM_NSEC(%r5)
45 srlg %r1,%r1,0(%r2) /* >> tk->shift */
46 clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */
54 2: stg %r0,0(%r3) /* store tp->tv_sec */
55 stg %r1,8(%r3) /* store tp->tv_nsec */
60 4: ltr %r3,%r3 /* tp == NULL */
62 5: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
63 tmll %r4,0x0001 /* pending update ? loop */
65 stck 48(%r15) /* Store TOD clock */
66 lgf %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
68 sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
69 msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */
70 alg %r1,__VDSO_XTIME_NSEC(%r5) /* + tk->xtime_nsec */
71 srlg %r1,%r1,0(%r2) /* >> tk->shift */
72 lg %r0,__VDSO_XTIME_SEC(%r5) /* tk->xtime_sec */
73 clg %r4,__VDSO_UPD_COUNT(%r5) /* check update counter */
81 7: stg %r0,0(%r3) /* store tp->tv_sec */
82 stg %r1,8(%r3) /* store tp->tv_nsec */
86 /* CLOCK_THREAD_CPUTIME_ID for this thread */
87 9: icm %r0,15,__VDSO_ECTG_OK(%r5)
94 sacf 512 /* Magic ectg instruction */
95 .insn ssf,0xc80100000000,__VDSO_ECTG_BASE(4),__VDSO_ECTG_USER(4),4
104 algr %r1,%r0 /* r1 = cputime as TOD value */
105 mghi %r1,1000 /* convert to nanoseconds */
106 srlg %r1,%r1,12 /* r1 = cputime in nanosec */
109 srlg %r1,%r1,9 /* divide by 1000000000 */
111 srlg %r0,%r0,11 /* r0 = tv_sec */
113 msg %r0,0(%r5) /* calculate tv_nsec */
114 slgr %r4,%r0 /* r4 = tv_nsec */
119 /* Fallback to system call */
120 12: lghi %r1,__NR_clock_gettime
125 14: .quad 19342813113834067
127 .size __kernel_clock_gettime,.-__kernel_clock_gettime