Skip to content

Commit 9fd9e33

Browse files
committed
assure accurate timer selection in runtime.WakeG
1 parent ec05eea commit 9fd9e33

File tree

3 files changed

+35
-41
lines changed

3 files changed

+35
-41
lines changed

src/runtime/sys_tamago_amd64.s

+12-13
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,21 @@ testing:
186186
//
187187
// * AX: G pointer
188188
TEXT runtime·WakeG(SB),NOSPLIT|NOFRAME,$0-0
189-
MOVQ (g_timer)(AX), AX
190-
CMPQ AX, $0
189+
MOVQ (g_timer)(AX), DX
190+
CMPQ DX, $0
191191
JE done
192192

193193
// g->timer.when = 1
194194
MOVQ $(1 << 32), BX
195-
MOVQ BX, (timer_when)(AX)
195+
MOVQ BX, (timer_when)(DX)
196196

197197
// g->timer.astate &= timerModified
198198
// g->timer.state &= timerModified
199-
MOVQ (timer_astate)(AX), CX
199+
MOVQ (timer_astate)(DX), CX
200200
ORQ $const_timerModified<<8|const_timerModified, CX
201-
MOVQ CX, (timer_astate)(AX)
201+
MOVQ CX, (timer_astate)(DX)
202202

203-
MOVQ (timer_ts)(AX), AX
203+
MOVQ (timer_ts)(DX), AX
204204
CMPQ AX, $0
205205
JE done
206206

@@ -215,8 +215,8 @@ TEXT runtime·WakeG(SB),NOSPLIT|NOFRAME,$0-0
215215

216216
// offset to last element
217217
SUBQ $1, CX
218-
MOVQ $(timerWhen__size), DX
219-
IMULQ DX, CX
218+
MOVQ $(timerWhen__size), BX
219+
IMULQ BX, CX
220220

221221
MOVQ (timers_heap)(AX), AX
222222
CMPQ AX, $0
@@ -232,13 +232,12 @@ prev:
232232
JE done
233233

234234
check:
235-
// find longest timer as *timers.adjust() might be pending
236-
MOVQ (timerWhen_when)(AX), BX
237-
MOVQ $((1 << 63) - 1), CX // math.MaxInt64
238-
CMPQ CX, BX
235+
// find heap entry matching g.timer
236+
MOVQ (timerWhen_timer)(AX), BX
237+
CMPQ BX, DX
239238
JNE prev
240239

241-
// g->timer.ts.heap[off] = 1
240+
// g->timer.ts.heap[off].when = 1
242241
MOVQ $(1 << 32), BX
243242
MOVQ BX, (timerWhen_when)(AX)
244243

src/runtime/sys_tamago_arm.s

+12-16
Original file line numberDiff line numberDiff line change
@@ -145,23 +145,23 @@ TEXT runtime·GetG(SB),NOSPLIT,$0-8
145145
//
146146
// * R0: G pointer
147147
TEXT runtime·WakeG(SB),NOSPLIT|NOFRAME,$0-0
148-
MOVW (g_timer)(R0), R0
149-
CMP $0, R0
148+
MOVW (g_timer)(R0), R3
149+
CMP $0, R3
150150
B.EQ done
151151

152152
// g->timer.when = 1
153153
MOVW $1, R1
154-
MOVW R1, (timer_when+0)(R0)
154+
MOVW R1, (timer_when+0)(R3)
155155
MOVW $0, R1
156-
MOVW R1, (timer_when+4)(R0)
156+
MOVW R1, (timer_when+4)(R3)
157157

158158
// g->timer.astate &= timerModified
159159
// g->timer.state &= timerModified
160-
MOVW (timer_astate)(R0), R2
160+
MOVW (timer_astate)(R3), R2
161161
ORR $const_timerModified<<8|const_timerModified, R2, R2
162-
MOVW R2, (timer_astate)(R0)
162+
MOVW R2, (timer_astate)(R3)
163163

164-
MOVW (timer_ts)(R0), R0
164+
MOVW (timer_ts)(R3), R0
165165
CMP $0, R0
166166
B.EQ done
167167

@@ -178,8 +178,8 @@ TEXT runtime·WakeG(SB),NOSPLIT|NOFRAME,$0-0
178178

179179
// offset to last element
180180
SUB $1, R2, R2
181-
MOVW $(timerWhen__size), R3
182-
MUL R3, R2, R2
181+
MOVW $(timerWhen__size), R1
182+
MUL R1, R2, R2
183183

184184
MOVW (timers_heap)(R0), R0
185185
CMP $0, R0
@@ -195,13 +195,9 @@ prev:
195195
B.EQ done
196196

197197
check:
198-
// find longest timer as *timers.adjust() might be pending
199-
MOVW (timerWhen_when+0)(R0), R1
200-
CMP $0xffffffff, R1 // LS word of math.MaxInt64
201-
B.NE prev
202-
203-
MOVW (timerWhen_when+4)(R0), R1
204-
CMP $0x7fffffff, R1 // MS word of math.MaxInt64
198+
// find heap entry matching g.timer
199+
MOVW (timerWhen_timer)(R0), R1
200+
CMP R3, R1
205201
B.NE prev
206202

207203
// g->timer.ts.heap[off] = 1

src/runtime/sys_tamago_riscv64.s

+11-12
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ TEXT runtime·GetG(SB),NOSPLIT,$0-16
6868
//
6969
// * T0: G pointer
7070
TEXT runtime·WakeG(SB),NOSPLIT|NOFRAME,$0-0
71-
MOV (g_timer)(T0), T0
72-
BEQ T0, ZERO, done
71+
MOV (g_timer)(T0), T3
72+
BEQ T3, ZERO, done
7373

7474
// g->timer.when = 1
7575
MOV $(1 << 32), T1
76-
MOV T1, (timer_when)(T0)
76+
MOV T1, (timer_when)(T3)
7777

7878
// g->timer.astate &= timerModified
7979
// g->timer.state &= timerModified
80-
MOV (timer_astate)(T0), T2
80+
MOV (timer_astate)(T3), T2
8181
OR $const_timerModified<<8|const_timerModified, T2, T2
82-
MOV T2, (timer_astate)(T0)
82+
MOV T2, (timer_astate)(T3)
8383

84-
MOV (timer_ts)(T0), T0
84+
MOV (timer_ts)(T3), T0
8585
BEQ T0, ZERO, done
8686

8787
// g->timer.ts.minWhenModified = 1
@@ -94,8 +94,8 @@ TEXT runtime·WakeG(SB),NOSPLIT|NOFRAME,$0-0
9494

9595
// offset to last element
9696
SUB $1, T2, T2
97-
MOV $(timerWhen__size), T3
98-
MUL T3, T2, T2
97+
MOV $(timerWhen__size), T1
98+
MUL T1, T2, T2
9999

100100
MOV (timers_heap)(T0), T0
101101
BEQ T0, ZERO, done
@@ -109,10 +109,9 @@ prev:
109109
BEQ T0, ZERO, done
110110

111111
check:
112-
// find longest timer as *timers.adjust() might be pending
113-
MOV (timerWhen_when)(T0), T1
114-
MOV $((1 << 63) - 1), T2 // math.MaxInt64
115-
BNE T2, T1, prev
112+
// find heap entry matching g.timer
113+
MOV (timerWhen_timer)(T0), T1
114+
BNE T3, T1, prev
116115

117116
// g->timer.ts.heap[off] = 1
118117
MOV $(1 << 32), T1

0 commit comments

Comments
 (0)