Skip to content

Commit b7eacb5

Browse files
author
Martin Schwidefsky
committed
s390/vdso: add vdso support for coarse clocks
Add CLOCK_REALTIME_COARSE and CLOCK_MONOTONIC_COARSE optimization to the 64-bit and 31-bit vdso. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 070b7be commit b7eacb5

7 files changed

Lines changed: 95 additions & 10 deletions

File tree

‎arch/s390/include/asm/vdso.h‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ struct vdso_data {
2222
__u64 xtime_tod_stamp; /* TOD clock for xtime 0x08 */
2323
__u64 xtime_clock_sec; /* Kernel time 0x10 */
2424
__u64 xtime_clock_nsec; /* 0x18 */
25-
__u64 wtom_clock_sec; /* Wall to monotonic clock 0x20 */
26-
__u64 wtom_clock_nsec; /* 0x28 */
27-
__u32 tz_minuteswest; /* Minutes west of Greenwich 0x30 */
28-
__u32 tz_dsttime; /* Type of dst correction 0x34 */
29-
__u32 ectg_available; /* ECTG instruction present 0x38 */
30-
__u32 tk_mult; /* Mult. used for xtime_nsec 0x3c */
31-
__u32 tk_shift; /* Shift used for xtime_nsec 0x40 */
25+
__u64 xtime_coarse_sec; /* Coarse kernel time 0x20 */
26+
__u64 xtime_coarse_nsec; /* 0x28 */
27+
__u64 wtom_clock_sec; /* Wall to monotonic clock 0x30 */
28+
__u64 wtom_clock_nsec; /* 0x38 */
29+
__u64 wtom_coarse_sec; /* Coarse wall to monotonic 0x40 */
30+
__u64 wtom_coarse_nsec; /* 0x48 */
31+
__u32 tz_minuteswest; /* Minutes west of Greenwich 0x50 */
32+
__u32 tz_dsttime; /* Type of dst correction 0x54 */
33+
__u32 ectg_available; /* ECTG instruction present 0x58 */
34+
__u32 tk_mult; /* Mult. used for xtime_nsec 0x5c */
35+
__u32 tk_shift; /* Shift used for xtime_nsec 0x60 */
3236
};
3337

3438
struct vdso_per_cpu_data {

‎arch/s390/kernel/asm-offsets.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ int main(void)
6262
DEFINE(__VDSO_XTIME_STAMP, offsetof(struct vdso_data, xtime_tod_stamp));
6363
DEFINE(__VDSO_XTIME_SEC, offsetof(struct vdso_data, xtime_clock_sec));
6464
DEFINE(__VDSO_XTIME_NSEC, offsetof(struct vdso_data, xtime_clock_nsec));
65+
DEFINE(__VDSO_XTIME_CRS_SEC, offsetof(struct vdso_data, xtime_coarse_sec));
66+
DEFINE(__VDSO_XTIME_CRS_NSEC, offsetof(struct vdso_data, xtime_coarse_nsec));
6567
DEFINE(__VDSO_WTOM_SEC, offsetof(struct vdso_data, wtom_clock_sec));
6668
DEFINE(__VDSO_WTOM_NSEC, offsetof(struct vdso_data, wtom_clock_nsec));
69+
DEFINE(__VDSO_WTOM_CRS_SEC, offsetof(struct vdso_data, wtom_coarse_sec));
70+
DEFINE(__VDSO_WTOM_CRS_NSEC, offsetof(struct vdso_data, wtom_coarse_nsec));
6771
DEFINE(__VDSO_TIMEZONE, offsetof(struct vdso_data, tz_minuteswest));
6872
DEFINE(__VDSO_ECTG_OK, offsetof(struct vdso_data, ectg_available));
6973
DEFINE(__VDSO_TK_MULT, offsetof(struct vdso_data, tk_mult));
@@ -73,8 +77,11 @@ int main(void)
7377
/* constants used by the vdso */
7478
DEFINE(__CLOCK_REALTIME, CLOCK_REALTIME);
7579
DEFINE(__CLOCK_MONOTONIC, CLOCK_MONOTONIC);
80+
DEFINE(__CLOCK_REALTIME_COARSE, CLOCK_REALTIME_COARSE);
81+
DEFINE(__CLOCK_MONOTONIC_COARSE, CLOCK_MONOTONIC_COARSE);
7682
DEFINE(__CLOCK_THREAD_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID);
7783
DEFINE(__CLOCK_REALTIME_RES, MONOTONIC_RES_NSEC);
84+
DEFINE(__CLOCK_COARSE_RES, LOW_RES_NSEC);
7885
BLANK();
7986
/* idle data offsets */
8087
DEFINE(__CLOCK_IDLE_ENTER, offsetof(struct s390_idle_data, clock_idle_enter));

‎arch/s390/kernel/time.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,19 @@ void update_vsyscall(struct timekeeper *tk)
232232
vdso_data->wtom_clock_nsec -= nsecps;
233233
vdso_data->wtom_clock_sec++;
234234
}
235+
236+
vdso_data->xtime_coarse_sec = tk->xtime_sec;
237+
vdso_data->xtime_coarse_nsec =
238+
(long)(tk->tkr.xtime_nsec >> tk->tkr.shift);
239+
vdso_data->wtom_coarse_sec =
240+
vdso_data->xtime_coarse_sec + tk->wall_to_monotonic.tv_sec;
241+
vdso_data->wtom_coarse_nsec =
242+
vdso_data->xtime_coarse_nsec + tk->wall_to_monotonic.tv_nsec;
243+
while (vdso_data->wtom_coarse_nsec >= NSEC_PER_SEC) {
244+
vdso_data->wtom_coarse_nsec -= NSEC_PER_SEC;
245+
vdso_data->wtom_coarse_sec++;
246+
}
247+
235248
vdso_data->tk_mult = tk->tkr.mult;
236249
vdso_data->tk_shift = tk->tkr.shift;
237250
smp_wmb();

‎arch/s390/kernel/vdso32/clock_getres.S‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,20 @@
1919
.type __kernel_clock_getres,@function
2020
__kernel_clock_getres:
2121
.cfi_startproc
22+
basr %r1,0
23+
la %r1,4f-.(%r1)
2224
chi %r2,__CLOCK_REALTIME
2325
je 0f
2426
chi %r2,__CLOCK_MONOTONIC
27+
je 0f
28+
la %r1,5f-4f(%r1)
29+
chi %r2,__CLOCK_REALTIME_COARSE
30+
je 0f
31+
chi %r2,__CLOCK_MONOTONIC_COARSE
2532
jne 3f
2633
0: ltr %r3,%r3
2734
jz 2f /* res == NULL */
28-
basr %r1,0
29-
1: l %r0,4f-1b(%r1)
35+
1: l %r0,0(%r1)
3036
xc 0(4,%r3),0(%r3) /* set tp->tv_sec to zero */
3137
st %r0,4(%r3) /* store tp->tv_usec */
3238
2: lhi %r2,0
@@ -35,5 +41,6 @@ __kernel_clock_getres:
3541
svc 0
3642
br %r14
3743
4: .long __CLOCK_REALTIME_RES
44+
5: .long __CLOCK_COARSE_RES
3845
.cfi_endproc
3946
.size __kernel_clock_getres,.-__kernel_clock_getres

‎arch/s390/kernel/vdso32/clock_gettime.S‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ __kernel_clock_gettime:
2121
.cfi_startproc
2222
basr %r5,0
2323
0: al %r5,21f-0b(%r5) /* get &_vdso_data */
24+
chi %r2,__CLOCK_REALTIME_COARSE
25+
je 10f
2426
chi %r2,__CLOCK_REALTIME
2527
je 11f
28+
chi %r2,__CLOCK_MONOTONIC_COARSE
29+
je 9f
2630
chi %r2,__CLOCK_MONOTONIC
2731
jne 19f
2832

@@ -68,6 +72,26 @@ __kernel_clock_gettime:
6872
lhi %r2,0
6973
br %r14
7074

75+
/* CLOCK_MONOTONIC_COARSE */
76+
9: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
77+
tml %r4,0x0001 /* pending update ? loop */
78+
jnz 9b
79+
l %r2,__VDSO_WTOM_CRS_SEC+4(%r5)
80+
l %r1,__VDSO_WTOM_CRS_NSEC+4(%r5)
81+
cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */
82+
jne 9b
83+
j 8b
84+
85+
/* CLOCK_REALTIME_COARSE */
86+
10: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
87+
tml %r4,0x0001 /* pending update ? loop */
88+
jnz 10b
89+
l %r2,__VDSO_XTIME_CRS_SEC+4(%r5)
90+
l %r1,__VDSO_XTIME_CRS_NSEC+4(%r5)
91+
cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */
92+
jne 10b
93+
j 17f
94+
7195
/* CLOCK_REALTIME */
7296
11: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
7397
tml %r4,0x0001 /* pending update ? loop */

‎arch/s390/kernel/vdso64/clock_getres.S‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
.type __kernel_clock_getres,@function
2020
__kernel_clock_getres:
2121
.cfi_startproc
22+
larl %r1,4f
23+
cghi %r2,__CLOCK_REALTIME_COARSE
24+
je 0f
25+
cghi %r2,__CLOCK_MONOTONIC_COARSE
26+
je 0f
27+
larl %r1,3f
2228
cghi %r2,__CLOCK_REALTIME
2329
je 0f
2430
cghi %r2,__CLOCK_MONOTONIC
@@ -32,7 +38,6 @@ __kernel_clock_getres:
3238
jz 2f
3339
0: ltgr %r3,%r3
3440
jz 1f /* res == NULL */
35-
larl %r1,3f
3641
lg %r0,0(%r1)
3742
xc 0(8,%r3),0(%r3) /* set tp->tv_sec to zero */
3843
stg %r0,8(%r3) /* store tp->tv_usec */
@@ -42,5 +47,6 @@ __kernel_clock_getres:
4247
svc 0
4348
br %r14
4449
3: .quad __CLOCK_REALTIME_RES
50+
4: .quad __CLOCK_COARSE_RES
4551
.cfi_endproc
4652
.size __kernel_clock_getres,.-__kernel_clock_getres

‎arch/s390/kernel/vdso64/clock_gettime.S‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@
2020
__kernel_clock_gettime:
2121
.cfi_startproc
2222
larl %r5,_vdso_data
23+
cghi %r2,__CLOCK_REALTIME_COARSE
24+
je 4f
2325
cghi %r2,__CLOCK_REALTIME
2426
je 5f
2527
cghi %r2,__CLOCK_THREAD_CPUTIME_ID
2628
je 9f
2729
cghi %r2,-2 /* Per-thread CPUCLOCK with PID=0, VIRT=1 */
2830
je 9f
31+
cghi %r2,__CLOCK_MONOTONIC_COARSE
32+
je 3f
2933
cghi %r2,__CLOCK_MONOTONIC
3034
jne 12f
3135

@@ -54,6 +58,26 @@ __kernel_clock_gettime:
5458
lghi %r2,0
5559
br %r14
5660

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+
5781
/* CLOCK_REALTIME */
5882
5: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
5983
tmll %r4,0x0001 /* pending update ? loop */

0 commit comments

Comments
 (0)